rudimentary alert report page
This commit is contained in:
@@ -93,6 +93,7 @@ def alert_get_stats(alert,nperiod=0):
|
|||||||
ids = [w.id for w in workouts]
|
ids = [w.id for w in workouts]
|
||||||
|
|
||||||
df = getsmallrowdata_db(columns,ids=ids,doclean=True,workstrokesonly=workstrokesonly)
|
df = getsmallrowdata_db(columns,ids=ids,doclean=True,workstrokesonly=workstrokesonly)
|
||||||
|
|
||||||
if df.empty:
|
if df.empty:
|
||||||
return {
|
return {
|
||||||
'workouts':len(workouts),
|
'workouts':len(workouts),
|
||||||
@@ -102,25 +103,37 @@ def alert_get_stats(alert,nperiod=0):
|
|||||||
'nr_strokes_qualifying':0,
|
'nr_strokes_qualifying':0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# check if filters are in columns list
|
||||||
|
pdcolumns = set(df.columns)
|
||||||
|
|
||||||
# drop strokes through filter
|
# drop strokes through filter
|
||||||
for condition in alert.filter.all():
|
if set(columns) <= pdcolumns:
|
||||||
if condition.condition == '>':
|
for condition in alert.filter.all():
|
||||||
mask = df[condition.metric] > condition.value1
|
if condition.condition == '>':
|
||||||
df.loc[mask,alert.measured.metric] = np.nan
|
mask = df[condition.metric] > condition.value1
|
||||||
elif condition.condition == '<':
|
df.loc[mask,alert.measured.metric] = np.nan
|
||||||
mask = df[condition.metric] < condition.value1
|
elif condition.condition == '<':
|
||||||
df.loc[mask,alert.measured.metric] = np.nan
|
mask = df[condition.metric] < condition.value1
|
||||||
elif condition.condition == 'between':
|
df.loc[mask,alert.measured.metric] = np.nan
|
||||||
mask = df[condition.metric] > condition.value1
|
elif condition.condition == 'between':
|
||||||
mask2 = df[condition.metric] < condition.value2
|
mask = df[condition.metric] > condition.value1
|
||||||
df.loc[mask & mask2,alert.measured.metric] = np.nan
|
mask2 = df[condition.metric] < condition.value2
|
||||||
elif condition.condition == '=':
|
df.loc[mask & mask2,alert.measured.metric] = np.nan
|
||||||
mask = df[condition.metric] == condition.value1
|
elif condition.condition == '=':
|
||||||
df.loc[mask,alert.measured.metric] = np.nan
|
mask = df[condition.metric] == condition.value1
|
||||||
|
df.loc[mask,alert.measured.metric] = np.nan
|
||||||
|
|
||||||
df.dropna(inplace=True,axis=0)
|
df.dropna(inplace=True,axis=0)
|
||||||
|
else:
|
||||||
|
return {
|
||||||
|
'workouts':len(workouts),
|
||||||
|
'startdate':startdate,
|
||||||
|
'enddate':enddate,
|
||||||
|
'nr_strokes':0,
|
||||||
|
'nr_strokes_qualifying':0,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# count strokes
|
# count strokes
|
||||||
nr_strokes = len(df)
|
nr_strokes = len(df)
|
||||||
|
|
||||||
|
|||||||
35
rowers/templates/alert_stats.html
Normal file
35
rowers/templates/alert_stats.html
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
{% extends "newbase.html" %}
|
||||||
|
{% load staticfiles %}
|
||||||
|
|
||||||
|
{% block title %}Metric Alert{% endblock %}
|
||||||
|
|
||||||
|
{% block main %}
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<a href="/rowers/alerts/{{ alert.id }}/report/{{ nperiod|add:1 }}/user/{{ rower.user.id }}/">Previous</a>
|
||||||
|
{% if nperiod > 0 %}
|
||||||
|
<a href="/rowers/alerts/{{ alert.id }}/report/{{ nperiod|add:-1 }}/user/{{ rower.user.id }}/">Next</a>
|
||||||
|
{% endif %}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ul class="main-content">
|
||||||
|
|
||||||
|
<li class="grid_2">
|
||||||
|
<h2>Alert</h2>
|
||||||
|
<p>{{ alert }}</p>
|
||||||
|
<p>This is a page under construction. Currently with minimal information</p>
|
||||||
|
</li>
|
||||||
|
{% for key, value in stats.items %}
|
||||||
|
<li>
|
||||||
|
<h2>{{ key }}</h2>
|
||||||
|
<p>{{ value }}</p>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block sidebar %}
|
||||||
|
{% include 'menu_analytics.html' %}
|
||||||
|
{% endblock %}
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a class="small"
|
<a class="small"
|
||||||
href="/rowers/alerts/{{ alert.id }}/stats/"
|
href="/rowers/alerts/{{ alert.id }}/report/"
|
||||||
title="Report">
|
title="Report">
|
||||||
<i class="fal fa-table fa-fw"></i>
|
<i class="fal fa-table fa-fw"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -423,6 +423,9 @@ urlpatterns = [
|
|||||||
re_path(r'^alerts/(?P<id>\d+)/edit/user/(?P<userid>\d+)/$',views.alert_edit_view,name='alert_edit_view'),
|
re_path(r'^alerts/(?P<id>\d+)/edit/user/(?P<userid>\d+)/$',views.alert_edit_view,name='alert_edit_view'),
|
||||||
re_path(r'^alerts/(?P<id>\d+)/edit/$',views.alert_edit_view,name='alert_edit_view'),
|
re_path(r'^alerts/(?P<id>\d+)/edit/$',views.alert_edit_view,name='alert_edit_view'),
|
||||||
re_path(r'^alerts/new/$',views.alert_create_view, name='alert_create_view'),
|
re_path(r'^alerts/new/$',views.alert_create_view, name='alert_create_view'),
|
||||||
|
re_path(r'^alerts/(?P<id>\d+)/report/user/(?P<userid>\d+)/$',views.alert_report_view,name='alert_report_view'),
|
||||||
|
re_path(r'^alerts/(?P<id>\d+)/report/(?P<nperiod>\d+)/user/(?P<userid>\d+)/$',views.alert_report_view,name='alert_report_view'),
|
||||||
|
re_path(r'^alerts/(?P<id>\d+)/report/$',views.alert_report_view,name='alert_report_view'),
|
||||||
re_path(r'^user-boxplot/user/(?P<userid>\d+)/$',views.boxplot_view,name='boxplot_view'),
|
re_path(r'^user-boxplot/user/(?P<userid>\d+)/$',views.boxplot_view,name='boxplot_view'),
|
||||||
re_path(r'^user-boxplot/$',views.boxplot_view,name='boxplot_view'),
|
re_path(r'^user-boxplot/$',views.boxplot_view,name='boxplot_view'),
|
||||||
re_path(r'^user-boxplot-data/$',views.boxplot_view_data,name='boxplot_view_data'),
|
re_path(r'^user-boxplot-data/$',views.boxplot_view_data,name='boxplot_view_data'),
|
||||||
|
|||||||
@@ -4421,7 +4421,57 @@ def alert_create_view(request,userid=0):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# alert report view
|
# alert report view
|
||||||
|
@user_passes_test(ispromember, login_url="/rowers/paidplans",
|
||||||
|
message="This functionality requires a Pro plan or higher",
|
||||||
|
redirect_field_name=None)
|
||||||
|
def alert_report_view(request,id=0,userid=0,nperiod=0):
|
||||||
|
r = getrequestrower(request,userid=userid)
|
||||||
|
if userid == 0:
|
||||||
|
userid = request.user.id
|
||||||
|
|
||||||
|
alert = Alert.objects.get(id=id)
|
||||||
|
nperiod = int(nperiod)
|
||||||
|
|
||||||
|
try:
|
||||||
|
alert = Alert.objects.get(id=id)
|
||||||
|
except Alert.DoesNotExist:
|
||||||
|
raise Http404("This alert doesn't exist")
|
||||||
|
|
||||||
|
|
||||||
|
if alert.manager != request.user:
|
||||||
|
raise PermissionDenied('You are not allowed to edit this Alert')
|
||||||
|
|
||||||
|
stats = alert_get_stats(alert,nperiod=nperiod)
|
||||||
|
|
||||||
|
breadcrumbs = [
|
||||||
|
{
|
||||||
|
'url':'/rowers/analysis',
|
||||||
|
'name': 'Analysis'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'url':reverse('alerts_view'),
|
||||||
|
'name':'Alerts',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'url': reverse('alert_edit_view',
|
||||||
|
kwargs={'userid':userid,'id':alert.id}),
|
||||||
|
'name': alert.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'url': reverse('alert_report_view',
|
||||||
|
kwargs={'userid':userid,'id':alert.id}),
|
||||||
|
'name': 'Report',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
return render(request,'alert_stats.html',
|
||||||
|
{
|
||||||
|
'breadcrumbs':breadcrumbs,
|
||||||
|
'stats':stats,
|
||||||
|
'rower':r,
|
||||||
|
'alert':alert,
|
||||||
|
'nperiod':nperiod,
|
||||||
|
})
|
||||||
|
|
||||||
# alert edit view
|
# alert edit view
|
||||||
@user_passes_test(ispromember, login_url="/rowers/paidplans",
|
@user_passes_test(ispromember, login_url="/rowers/paidplans",
|
||||||
message="This functionality requires a Pro plan or higher",
|
message="This functionality requires a Pro plan or higher",
|
||||||
@@ -4429,7 +4479,14 @@ def alert_create_view(request,userid=0):
|
|||||||
def alert_edit_view(request,id=0,userid=0):
|
def alert_edit_view(request,id=0,userid=0):
|
||||||
r = getrequestrower(request,userid=userid)
|
r = getrequestrower(request,userid=userid)
|
||||||
|
|
||||||
alert = Alert.objects.get(id=id)
|
try:
|
||||||
|
alert = Alert.objects.get(id=id)
|
||||||
|
except Alert.DoesNotExist:
|
||||||
|
raise Http404("This alert doesn't exist")
|
||||||
|
|
||||||
|
|
||||||
|
if alert.manager != request.user:
|
||||||
|
raise PermissionDenied('You are not allowed to edit this Alert')
|
||||||
|
|
||||||
FilterFormSet = formset_factory(ConditionEditForm, formset=BaseConditionFormSet,extra=0)
|
FilterFormSet = formset_factory(ConditionEditForm, formset=BaseConditionFormSet,extra=0)
|
||||||
if len(alert.filter.all()) == 0:
|
if len(alert.filter.all()) == 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user