diff --git a/mood/statistics.py b/mood/statistics.py index 6125e94..6f2b442 100644 --- a/mood/statistics.py +++ b/mood/statistics.py @@ -8,7 +8,7 @@ from dateutil.relativedelta import relativedelta from .models import Status -def moodstats(mindate=None, maxdate=None, days=7): +def moodstats(user, mindate=None, maxdate=None, days=7): hv.extension('bokeh') maxdate = maxdate or timezone.now() @@ -27,7 +27,7 @@ def moodstats(mindate=None, maxdate=None, days=7): pointdict = {"date": [], "value": [], "color": []} - for status in Status.objects.filter(timestamp__gte=mindate, timestamp__lte=maxdate): + for status in Status.objects.filter(user=user, timestamp__gte=mindate, timestamp__lte=maxdate): if status.mood: pointdict["date"].append(status.timestamp) pointdict["value"].append(status.mood.value) @@ -48,6 +48,21 @@ def moodstats(mindate=None, maxdate=None, days=7): line = hv.Curve(pointtuples) output = points * line - output.opts(tools=["xwheel_zoom"]) + output.opts(tools=["xwheel_zoom"], ylim=(0, 5)) + + return output + +def activitystats(user, mindate=None, maxdate=None, days=7): + maxdate = maxdate or timezone.now() + mindate = mindate or (maxdate - relativedelta(days=days)) + + output = {} + + for status in Status.objects.filter(user=user, timestamp__gte=mindate, timestamp__lte=maxdate): + for activity in status.activity_set: + if activity in output.keys(): + output[activity] += 1 + else: + output[activity] = 1 return output \ No newline at end of file diff --git a/mood/templates/mood/statistics.html b/mood/templates/mood/statistics.html index 0990120..f62820f 100644 --- a/mood/templates/mood/statistics.html +++ b/mood/templates/mood/statistics.html @@ -19,6 +19,31 @@ + +
Activity | +Count | +
---|---|
{{ activity }} | +{{ count }} | +