diff --git a/rowers/alerts.py b/rowers/alerts.py index f33bd3f9..6e9fcd12 100644 --- a/rowers/alerts.py +++ b/rowers/alerts.py @@ -169,6 +169,10 @@ def alert_get_stats(alert,nperiod=0): percentage = int(100.*nr_strokes_qualifying/nr_strokes) else: percentage = 0 + + median_q = df2[alert.measured.metric].median() + median = df[alert.measured.metric].median() + std = df[alert.measured.metric].std() return { 'workouts':len(workouts), @@ -177,7 +181,10 @@ def alert_get_stats(alert,nperiod=0): 'nr_strokes':nr_strokes, 'nr_strokes_qualifying':nr_strokes_qualifying, 'percentage': percentage, - 'nperiod':nperiod, + 'nperiod':nperiod, + 'median':median, + 'median_q':median_q, + 'standard_dev':std, } # run alert report diff --git a/rowers/models.py b/rowers/models.py index f9d2ae9f..3028d064 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -881,9 +881,12 @@ class Rower(models.Model): def save(self, *args, **kwargs): try: for group in self.coachinggroups.all(): - coach = Rower.objects.get(mycoachgroup=group) - if coach.rowerplan == 'freecoach': - self.coachinggroups.remove(group) + try: + coach = Rower.objects.get(mycoachgroup=group) + if coach.rowerplan == 'freecoach': + self.coachinggroups.remove(group) + except Rower.DoesNotExist: + pass except ValueError: pass @@ -1093,6 +1096,11 @@ class Alert(models.Model): return stri + def metricname(self): + metricdict = {key:value for (key,value) in parchoicesy1} + + return metricdict[self.measured.metric] + def description(self): metricdict = {key:value for (key,value) in parchoicesy1} @@ -1115,6 +1123,24 @@ class Alert(models.Model): return description + def shortdescription(self): + metricdict = {key:value for (key,value) in parchoicesy1} + + if self.measured.condition == 'between': + description = '{value1} < {metric} < {value2}'.format( + metric = self.measured.metric, + value1 = self.measured.value1, + value2 = self.measured.value2, + ) + else: + description = '{metric} {condition} {value1}'.format( + metric = self.measured.metric, + value1 = self.measured.value1, + condition = self.measured.condition + ) + + return description + class AlertEditForm(ModelForm): class Meta: diff --git a/rowers/templates/alert_stats.html b/rowers/templates/alert_stats.html index fb950332..400a8dd3 100644 --- a/rowers/templates/alert_stats.html +++ b/rowers/templates/alert_stats.html @@ -1,5 +1,6 @@ {% extends "newbase.html" %} {% load staticfiles %} +{% load rowerfilters %} {% block title %}Metric Alert{% endblock %} @@ -13,19 +14,33 @@
{{ alert }}
{{ alert.description }}
This is a page under construction. Currently with minimal information
{{ value }}
+{{ stats|lookup:'workouts' }} workouts
+{{ stats|lookup:'nr_strokes_qualifying' }} strokes out of {{ stats|lookup:'nr_strokes' }}
+Median {{ alert.metricname }}: {{ stats|lookup:'median'|sigdig }}
+Median {{ alert.metricname }}: {{ stats|lookup:'median_q'|sigdig }} ({{ alert.shortdescription }})