polarized marker workouts chart
This commit is contained in:
@@ -559,20 +559,20 @@ def goldmedalscorechart(user, startdate=None, enddate=None):
|
|||||||
testduration = [
|
testduration = [
|
||||||
w.goldmedalseconds if w.rankingpiece else 0 for w in markerworkouts]
|
w.goldmedalseconds if w.rankingpiece else 0 for w in markerworkouts]
|
||||||
|
|
||||||
df = pd.DataFrame({
|
df = pl.DataFrame({
|
||||||
'id': outids,
|
'id': outids,
|
||||||
'date': dates,
|
'date': dates,
|
||||||
'testpower': testpower,
|
'testpower': testpower,
|
||||||
'testduration': testduration,
|
'testduration': testduration,
|
||||||
})
|
})
|
||||||
df.sort_values(['date'], inplace=True)
|
df = df.sort('date')
|
||||||
|
df = df.drop_nulls()
|
||||||
|
|
||||||
mask = df['testpower'].isnull()
|
dates = df['date']
|
||||||
dates = df.mask(mask)['date'].dropna().values
|
testpower = df['testpower']
|
||||||
testpower = df.mask(mask)['testpower'].dropna().values
|
ids = df['id']
|
||||||
ids = df.mask(mask)['id'].dropna().values
|
|
||||||
|
|
||||||
outids = df.mask(mask)['id'].dropna().unique()
|
outids = ids.unique()
|
||||||
|
|
||||||
# all workouts
|
# all workouts
|
||||||
alldates, alltestpower, allduration, allids = all_goldmedalstandards(
|
alldates, alltestpower, allduration, allids = all_goldmedalstandards(
|
||||||
@@ -614,7 +614,7 @@ def goldmedalscorechart(user, startdate=None, enddate=None):
|
|||||||
duration.append(np.nan)
|
duration.append(np.nan)
|
||||||
workoutid.append(0)
|
workoutid.append(0)
|
||||||
|
|
||||||
df = pd.DataFrame({
|
df = pl.DataFrame({
|
||||||
'markerscore': markerscore,
|
'markerscore': markerscore,
|
||||||
'markerduration': markerduration,
|
'markerduration': markerduration,
|
||||||
'score': score,
|
'score': score,
|
||||||
@@ -623,32 +623,20 @@ def goldmedalscorechart(user, startdate=None, enddate=None):
|
|||||||
'id': workoutid,
|
'id': workoutid,
|
||||||
})
|
})
|
||||||
|
|
||||||
df['url'] = df['id'].apply(lambda x: settings.SITE_URL +
|
df = df.with_columns((pl.col("id").apply(lambda x: settings.SITE_URL +
|
||||||
'/rowers/workout/{id}/'.format(id=encoder.encode_hex(x)))
|
'/rowers/workout/{id}/'.format(id=encoder.encode_hex(x)))).alias("url"))
|
||||||
df['workout'] = df['id'].apply(lambda x: workoutname(x))
|
df = df.with_columns((pl.col("id").apply(lambda x: workoutname(x))).alias("workout"))
|
||||||
|
|
||||||
df.sort_values(['date'], inplace=True)
|
df = df.sort('date')
|
||||||
|
|
||||||
# find index values where score is max
|
# find index values where score is max
|
||||||
idx = df.groupby(['date'])['score'].transform(max) == df['score']
|
dfmax = df.group_by("date", maintain_order=True).max()
|
||||||
df = df[idx]
|
dfmax = dfmax.fill_nan(0)
|
||||||
|
dfmax = dfmax.with_columns((pl.col("date").apply(lambda x: x.strftime("%Y-%m-%d"))).alias("date"))
|
||||||
|
dfmax = dfmax.with_columns((pl.col("duration").apply(lambda x: totaltime_sec_to_string(x, shorten=True))).alias("duration"))
|
||||||
|
dfmax = dfmax.with_columns((pl.col("markerduration").apply(lambda x: totaltime_sec_to_string(x, shorten=True))).alias("markerduration"))
|
||||||
|
|
||||||
df.fillna(value=0, inplace=True)
|
data_dicts = dfmax.to_dicts()
|
||||||
df['dat1'] = df['date'].map(lambda x: x.to_pydatetime(x).strftime("%Y-%m-%d"))
|
|
||||||
|
|
||||||
df2 = pd.DataFrame({
|
|
||||||
'markerscore': df['markerscore'],
|
|
||||||
'score': df['score'],
|
|
||||||
'markerduration':df['markerduration'].apply(
|
|
||||||
lambda x: totaltime_sec_to_string(x, shorten=True)),
|
|
||||||
'duration': df['duration'].apply(
|
|
||||||
lambda x: totaltime_sec_to_string(x, shorten=True)),
|
|
||||||
'date': df['dat1'],
|
|
||||||
'url':df['url'],
|
|
||||||
'workout':df['workout']
|
|
||||||
})
|
|
||||||
|
|
||||||
data_dicts = df2.to_dict("records")
|
|
||||||
chart_data = {
|
chart_data = {
|
||||||
'data': data_dicts
|
'data': data_dicts
|
||||||
}
|
}
|
||||||
@@ -708,7 +696,6 @@ def performance_chart(user, startdate=None, enddate=None, kfitness=42, kfatigue=
|
|||||||
df = pd.DataFrame.from_records(records)
|
df = pd.DataFrame.from_records(records)
|
||||||
if df.empty: # pragma: no cover
|
if df.empty: # pragma: no cover
|
||||||
return ['', 'No Data', 0, 0, 0, outids]
|
return ['', 'No Data', 0, 0, 0, outids]
|
||||||
df.set_index('date', inplace=True)
|
|
||||||
|
|
||||||
markerworkouts = Workout.objects.filter(
|
markerworkouts = Workout.objects.filter(
|
||||||
user=user.rower, date__gte=startdate-datetime.timedelta(days=90),
|
user=user.rower, date__gte=startdate-datetime.timedelta(days=90),
|
||||||
|
|||||||
Reference in New Issue
Block a user