diff --git a/rowers/tasks.py b/rowers/tasks.py index 3aab4fbe..cf0bae49 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -756,6 +756,26 @@ def handle_updatedps(useremail, workoutids, debug=False,**kwargs): return 1 +import math +def sigdig(value, digits = 3): + try: + order = int(math.floor(math.log10(math.fabs(value)))) + except (ValueError,TypeError): + return value + + # return integers as is + if value % 1 == 0: + return value + + places = digits - order - 1 + if places > 0: + fmtstr = "%%.%df" % (places) + else: + fmtstr = "%.0f" + return fmtstr % (round(value, places)) + + + @app.task def handle_send_email_alert( useremail, userfirstname, userlastname, rowerfirstname, alertname, stats, **kwargs): @@ -770,15 +790,26 @@ def handle_send_email_alert( else: othertexts = None - subject = "Your rowing performance on rowsandall.com ({startdate} to {enddate})".format( + report = {} + report['Percentage'] = int(stats['percentage']) + report['Number of workouts'] = int(stats['workouts']) + report['Data set'] = "{a} strokes out of {b}".format( + a = stats['nr_strokes_qualifying'], + b = stats['nr_strokes'] + ) + report['Median'] = sigdig(stats['median']) + report['Median of qualifying strokes'] = sigdig(stats['median_q']) + + subject = "Rowsandall.com: {alertname} ({startdate} to {enddate})".format( startdate = stats['startdate'], enddate = stats['enddate'], + alertname=alertname, ) from_email = 'Rowsandall ' d = { - 'report':stats, + 'report':report, 'first_name':userfirstname, 'last_name':userlastname, 'siteurl':siteurl, diff --git a/rowers/templates/emailbase.html b/rowers/templates/emailbase.html index cb160fb3..417b8d6f 100644 --- a/rowers/templates/emailbase.html +++ b/rowers/templates/emailbase.html @@ -1,14 +1,22 @@ + + + + + Rowsandall + + - - - {% block body %} - - {% endblock %} - + + + {% block body %} + + {% endblock %} +