Private
Public Access
1
0

boxchart pandas to polars

This commit is contained in:
2024-04-13 17:19:47 +02:00
parent acf5e401df
commit 5d8968fc5f
3 changed files with 15 additions and 28 deletions

View File

@@ -328,7 +328,7 @@ def interactive_workouttype_piechart(workouts):
def interactive_boxchart(datadf, fieldname, extratitle='',
spmmin=0, spmmax=0, workmin=0, workmax=0):
if datadf.empty: # pragma: no cover
if datadf.is_empty(): # pragma: no cover
return '', 'It looks like there are no data matching your filter'
columns = datadf.columns
@@ -339,20 +339,17 @@ def interactive_boxchart(datadf, fieldname, extratitle='',
if 'date' not in columns: # pragma: no cover
return '', 'Not enough data'
try:
datadf.date = datadf.date.apply(lambda x:x.strftime("%Y-%m-%d"))
except AttributeError:
datadf.date = "2000-01-01"
datadf = datadf.with_columns((pl.col("date").apply(lambda x:x.strftime("%Y-%m-%d"))).alias("date"))
datadf = datadf.with_columns((pl.col(fieldname)).alias("value"))
datadf['value'] = datadf[fieldname]
data_dict = datadf.to_dict("records")
data_dict = datadf.to_dicts()
boxplot_data = {
"metric": metricsdicts[fieldname]["verbose_name"],
"data": data_dict
}
script, div = get_chart("/boxplot", boxplot_data)
script, div = get_chart("/boxplot", boxplot_data, debug=False)
return script, div

Binary file not shown.

View File

@@ -927,28 +927,18 @@ def boxplotdata(workouts, options):
ids = [w.id for w in workouts]
# prepare data frame
datadf, extracols = dataprep.read_cols_df_sql(ids, fieldlist)
datadf = getsmallrowdata_pl(fieldlist, ids)
datadf = dataprep.clean_df_stats(datadf, workstrokesonly=workstrokesonly)
datadf = dataprep.clean_df_stats_pl(datadf, workstrokesonly=workstrokesonly)
datadf = dataprep.filter_df(datadf, 'spm', spmmin,
largerthan=True)
datadf = dataprep.filter_df(datadf, 'spm', spmmax,
largerthan=False)
datadf = dataprep.filter_df(datadf, 'driveenergy', workmin,
largerthan=True)
datadf = dataprep.filter_df(datadf, 'driveneergy', workmax,
largerthan=False)
datadf = datadf.filter(
pl.col("spm")>spmmin,
pl.col("spm")<spmmax,
pl.col("driveenergy")>workmin,
pl.col("driveenergy")<workmax,
)
datadf.dropna(axis=0, how='any', inplace=True)
datadf = datadf[datadf['workoutid'].isin(ids) == True]
datadf['workoutid'].replace(datemapping, inplace=True)
datadf.rename(columns={"workoutid": "date"}, inplace=True)
datadf['date'] = pd.to_datetime(datadf['date'], errors='coerce')
datadf = datadf.dropna(subset=['date'])
datadf = datadf.sort_values(['date'])
datadf = datadf.with_columns((pl.col("workoutid").apply(lambda x: datemapping[x])).alias("date"))
if userid == 0: # pragma: no cover
extratitle = ''
@@ -958,7 +948,7 @@ def boxplotdata(workouts, options):
savedata = options.get('savedata',False)
if savedata: # pragma: no cover
return datadf
return datadf.to_pandas()
script, div = interactive_boxchart(datadf, plotfield,
extratitle=extratitle,