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