Add monthly and yearly activity counters

This commit is contained in:
Kumi 2021-02-25 15:33:28 +01:00
parent 8108fb8bf4
commit cbcf7a365c
2 changed files with 27 additions and 10 deletions

View file

@ -42,8 +42,7 @@ def moodstats(user, mindate=None, maxdate=None, days=7):
points.opts(
tools=[hover], color='color', cmap='Category20',
line_color='black', size=25,
width=600, height=400, show_grid=True,
title='Your Mood Entries')
width=600, height=400, show_grid=True)
pointtuples = [(pointdict["date"][i], pointdict["value"][i]) for i in range(len(pointdict["date"]))]
@ -66,11 +65,25 @@ def activitystats(user, mindate=None, maxdate=None, days=7):
output = {}
for status in Status.objects.filter(user=user, timestamp__gte=mindate, timestamp__lte=maxdate):
for status in Status.objects.filter(user=user):
for activity in status.activity_set:
if activity in output.keys():
output[activity] += 1
else:
output[activity] = 1
if not activity in output.keys():
output[activity] = {
"alltime": 0,
"yearly": 0,
"monthly": 0,
"weekly": 0
}
output[activity]["alltime"] += 1
if status.timestamp > timezone.now() - relativedelta(years=1):
output[activity]["yearly"] += 1
if status.timestamp > timezone.now() - relativedelta(months=1):
output[activity]["monthly"] += 1
if status.timestamp > timezone.now() - relativedelta(weeks=1):
output[activity]["weekly"] += 1
return output

View file

@ -31,12 +31,16 @@
<table>
<tr>
<th>Activity</th>
<th>Count</th>
<th>7 days</th>
<th>1 month</th>
<th>1 year</th>
</tr>
{% for activity, count in activities.items %}
{% for activity, counts in activities.items %}
<tr>
<td style="color:{{ activity.color }};"><i class="{{ activity.icon }}"></i><b> {{ activity }}</b></td>
<td style="text-align: right;">{{ count }}</td>
<td style="text-align: right;">{{ counts.weekly }}</td>
<td style="text-align: right;">{{ counts.monthly }}</td>
<td style="text-align: right;">{{ counts.yearly }}</td>
</tr>
{% endfor %}
</table>