diff --git a/rowers/alerts.py b/rowers/alerts.py
index f5bbfec4..76cb2c74 100644
--- a/rowers/alerts.py
+++ b/rowers/alerts.py
@@ -93,6 +93,7 @@ def alert_get_stats(alert,nperiod=0):
ids = [w.id for w in workouts]
df = getsmallrowdata_db(columns,ids=ids,doclean=True,workstrokesonly=workstrokesonly)
+
if df.empty:
return {
'workouts':len(workouts),
@@ -102,25 +103,37 @@ def alert_get_stats(alert,nperiod=0):
'nr_strokes_qualifying':0,
}
+ # check if filters are in columns list
+ pdcolumns = set(df.columns)
# drop strokes through filter
- for condition in alert.filter.all():
- if condition.condition == '>':
- mask = df[condition.metric] > condition.value1
- df.loc[mask,alert.measured.metric] = np.nan
- elif condition.condition == '<':
- mask = df[condition.metric] < condition.value1
- df.loc[mask,alert.measured.metric] = np.nan
- elif condition.condition == 'between':
- mask = df[condition.metric] > condition.value1
- mask2 = df[condition.metric] < condition.value2
- df.loc[mask & mask2,alert.measured.metric] = np.nan
- elif condition.condition == '=':
- mask = df[condition.metric] == condition.value1
- df.loc[mask,alert.measured.metric] = np.nan
+ if set(columns) <= pdcolumns:
+ for condition in alert.filter.all():
+ if condition.condition == '>':
+ mask = df[condition.metric] > condition.value1
+ df.loc[mask,alert.measured.metric] = np.nan
+ elif condition.condition == '<':
+ mask = df[condition.metric] < condition.value1
+ df.loc[mask,alert.measured.metric] = np.nan
+ elif condition.condition == 'between':
+ mask = df[condition.metric] > condition.value1
+ mask2 = df[condition.metric] < condition.value2
+ df.loc[mask & mask2,alert.measured.metric] = np.nan
+ elif condition.condition == '=':
+ mask = df[condition.metric] == condition.value1
+ df.loc[mask,alert.measured.metric] = np.nan
df.dropna(inplace=True,axis=0)
-
+ else:
+ return {
+ 'workouts':len(workouts),
+ 'startdate':startdate,
+ 'enddate':enddate,
+ 'nr_strokes':0,
+ 'nr_strokes_qualifying':0,
+ }
+
+
# count strokes
nr_strokes = len(df)
diff --git a/rowers/templates/alert_stats.html b/rowers/templates/alert_stats.html
new file mode 100644
index 00000000..713716f9
--- /dev/null
+++ b/rowers/templates/alert_stats.html
@@ -0,0 +1,35 @@
+{% extends "newbase.html" %}
+{% load staticfiles %}
+
+{% block title %}Metric Alert{% endblock %}
+
+{% block main %}
+
+
+ Previous
+ {% if nperiod > 0 %}
+ Next
+ {% endif %}
+
+
+
+
+ -
+
Alert
+ {{ alert }}
+ This is a page under construction. Currently with minimal information
+
+ {% for key, value in stats.items %}
+ -
+
{{ key }}
+ {{ value }}
+
+ {% endfor %}
+
+
+
+{% endblock %}
+
+{% block sidebar %}
+{% include 'menu_analytics.html' %}
+{% endblock %}
diff --git a/rowers/templates/alerts.html b/rowers/templates/alerts.html
index 5740d620..0ea4db1c 100644
--- a/rowers/templates/alerts.html
+++ b/rowers/templates/alerts.html
@@ -36,7 +36,7 @@
diff --git a/rowers/urls.py b/rowers/urls.py
index 14e04c6f..6e0c64ec 100644
--- a/rowers/urls.py
+++ b/rowers/urls.py
@@ -423,6 +423,9 @@ urlpatterns = [
re_path(r'^alerts/(?P\d+)/edit/user/(?P\d+)/$',views.alert_edit_view,name='alert_edit_view'),
re_path(r'^alerts/(?P\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/(?P\d+)/report/user/(?P\d+)/$',views.alert_report_view,name='alert_report_view'),
+ re_path(r'^alerts/(?P\d+)/report/(?P\d+)/user/(?P\d+)/$',views.alert_report_view,name='alert_report_view'),
+ re_path(r'^alerts/(?P\d+)/report/$',views.alert_report_view,name='alert_report_view'),
re_path(r'^user-boxplot/user/(?P\d+)/$',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'),
diff --git a/rowers/views/analysisviews.py b/rowers/views/analysisviews.py
index 9d744438..546fb652 100644
--- a/rowers/views/analysisviews.py
+++ b/rowers/views/analysisviews.py
@@ -4421,7 +4421,57 @@ def alert_create_view(request,userid=0):
})
# 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
@user_passes_test(ispromember, login_url="/rowers/paidplans",
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):
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)
if len(alert.filter.all()) == 0:
|