history data
This commit is contained in:
@@ -755,6 +755,8 @@ urlpatterns = [
|
||||
re_path(r'^access/(?P<key>\w+)/$', views.sharedPage, name="sharedPage"),
|
||||
re_path(r'^history/user/(?P<userid>\d+)/$',views.history_view,name="history_view"),
|
||||
re_path(r'^history/$',views.history_view,name="history_view"),
|
||||
re_path(r'^history/user/(?P<userid>\d+)/data/$',views.history_view_data,name="history_view_data"),
|
||||
re_path(r'^history/data/$',views.history_view_data,name="history_view_data"),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
|
||||
@@ -4823,3 +4823,72 @@ def history_view(request,userid=0):
|
||||
'workouttype':typeselect,
|
||||
'firstmay':firstmay,
|
||||
})
|
||||
|
||||
@login_required()
|
||||
def history_view_data(request,userid=0):
|
||||
r = getrequestrower(request,userid=userid)
|
||||
|
||||
usertimezone = pytz.timezone(r.defaulttimezone)
|
||||
|
||||
if request.GET.get('startdate'):
|
||||
startdate,enddate = get_dates_timeperiod(request)
|
||||
activity_startdate = datetime.datetime(
|
||||
startdate.year,startdate.month,startdate.day
|
||||
).replace(hour=0,minute=0,second=0).astimezone(usertimezone)
|
||||
activity_enddate = datetime.datetime(
|
||||
enddate.year,enddate.month,enddate.day
|
||||
).replace(hour=23,minute=59,second=59).astimezone(usertimezone)
|
||||
else:
|
||||
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).astimezone(usertimezone)
|
||||
|
||||
typeselect = 'All'
|
||||
if request.GET.get('workouttype'):
|
||||
typeselect = request.GET.get('workouttype')
|
||||
|
||||
if typeselect not in mytypes.checktypes:
|
||||
typeselect = 'All'
|
||||
|
||||
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','time']
|
||||
|
||||
df = getsmallrowdata_db(columns,ids=ids)
|
||||
try:
|
||||
df['deltat'] = df['time'].diff()
|
||||
except KeyError:
|
||||
pass
|
||||
df = dataprep.clean_df_stats(df,workstrokesonly=True,
|
||||
ignoreadvanced=True)
|
||||
|
||||
|
||||
|
||||
|
||||
# interactive hr pie chart
|
||||
if typeselect == 'All':
|
||||
totalscript,totaldiv = interactive_hr_piechart(df,r,'All Workouts')
|
||||
else:
|
||||
a_workouts = g_workouts.filter(workouttype=typeselect)
|
||||
ddf = getsmallrowdata_db(columns,ids=[w.id for w in a_workouts])
|
||||
try:
|
||||
ddf['deltat'] = ddf['time'].diff()
|
||||
except KeyError:
|
||||
pass
|
||||
ddf = dataprep.clean_df_stats(ddf,workstrokesonly=True,
|
||||
ignoreadvanced=True)
|
||||
totalscript, totaldiv = interactive_hr_piechart(ddf,r,mytypes.workouttypes_ordered[typeselect])
|
||||
|
||||
return JSONResponse({
|
||||
'script':totalscript,
|
||||
'div':totaldiv,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user