adding first pie chart
This commit is contained in:
@@ -4654,6 +4654,68 @@ class AlertDelete(DeleteView):
|
||||
@login_required()
|
||||
def history_view(request,userid=0):
|
||||
r = getrequestrower(request,userid=userid)
|
||||
usertimezone = pytz.timezone(r.defaulttimezone)
|
||||
|
||||
activity_enddate = timezone.now()
|
||||
activity_enddate = activity_enddate.replace(hour=23,minute=59,second=59).astimezone(usertimezone)
|
||||
activity_startdate = activity_enddate-datetime.timedelta(days=15)
|
||||
activity_startdate = activity_startdate.replace(hour=0,minute=0,second=0)
|
||||
|
||||
g_workouts = Workout.objects.filter(
|
||||
user=r,
|
||||
startdatetime__gte=activity_startdate,
|
||||
startdatetime__lte=activity_enddate,
|
||||
duplicate=False,
|
||||
privacy='visible'
|
||||
).order_by("-startdatetime")
|
||||
|
||||
ids = [w.id for w in g_workouts]
|
||||
|
||||
columns = ['hr','power']
|
||||
|
||||
df = getsmallrowdata_db(columns,ids=ids)
|
||||
|
||||
totalmeters,totalhours, totalminutes = get_totals(g_workouts)
|
||||
|
||||
# meters, duration per workout type
|
||||
wtypes = list(set([w.workouttype for w in g_workouts]))
|
||||
listofdicts = []
|
||||
|
||||
for wtype in wtypes:
|
||||
a_workouts = g_workouts.filter(workouttype=wtype)
|
||||
wmeters, whours, wminutes = get_totals(a_workouts)
|
||||
ddict = {}
|
||||
ddict['wtype'] = mytypes.workouttypes_ordered[wtype]
|
||||
ddict['distance'] = wmeters
|
||||
ddict['duration'] = "{whours}:{wminutes:02d}".format(
|
||||
whours=whours,
|
||||
wminutes=wminutes
|
||||
)
|
||||
ddf = getsmallrowdata_db(columns,ids=[w.id for w in a_workouts])
|
||||
ddict['hrmean'] = ddf['hr'].mean().astype(int)
|
||||
ddict['hrmax'] = ddf['hr'].max().astype(int)
|
||||
ddict['powermean'] = ddf['power'].mean().astype(int)
|
||||
ddict['powermax'] = ddf['power'].max().astype(int)
|
||||
ddict['nrworkouts'] = a_workouts.count()
|
||||
listofdicts.append(ddict)
|
||||
|
||||
# interactive hr pie chart
|
||||
totalscript,totaldiv = interactive_hr_piechart(df,r,'All Workouts')
|
||||
|
||||
# interactive power pie chart
|
||||
|
||||
totalsdict = {}
|
||||
totalsdict['duration'] = "{totalhours}:{totalminutes}".format(
|
||||
totalhours=totalhours,
|
||||
totalminutes=totalminutes
|
||||
)
|
||||
|
||||
totalsdict['distance'] = totalmeters
|
||||
totalsdict['powermean'] = df['power'].mean().astype(int)
|
||||
totalsdict['powermax'] = df['power'].max().astype(int)
|
||||
totalsdict['hrmean'] = df['hr'].mean().astype(int)
|
||||
totalsdict['hrmax'] = df['hr'].max().astype(int)
|
||||
totalsdict['nrworkouts'] = g_workouts.count()
|
||||
|
||||
breadcrumbs = [
|
||||
{
|
||||
@@ -4670,5 +4732,9 @@ def history_view(request,userid=0):
|
||||
{
|
||||
'rower':r,
|
||||
'breadcrumbs':breadcrumbs,
|
||||
'active':'nav-analysis'
|
||||
'active':'nav-analysis',
|
||||
'totalsdict':totalsdict,
|
||||
'typedicts':listofdicts,
|
||||
'totalscript':totalscript,
|
||||
'totaldiv':totaldiv,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user