Add monthly and yearly activity counters
This commit is contained in:
parent
8108fb8bf4
commit
cbcf7a365c
2 changed files with 27 additions and 10 deletions
|
@ -42,8 +42,7 @@ def moodstats(user, mindate=None, maxdate=None, days=7):
|
||||||
points.opts(
|
points.opts(
|
||||||
tools=[hover], color='color', cmap='Category20',
|
tools=[hover], color='color', cmap='Category20',
|
||||||
line_color='black', size=25,
|
line_color='black', size=25,
|
||||||
width=600, height=400, show_grid=True,
|
width=600, height=400, show_grid=True)
|
||||||
title='Your Mood Entries')
|
|
||||||
|
|
||||||
pointtuples = [(pointdict["date"][i], pointdict["value"][i]) for i in range(len(pointdict["date"]))]
|
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 = {}
|
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:
|
for activity in status.activity_set:
|
||||||
if activity in output.keys():
|
if not activity in output.keys():
|
||||||
output[activity] += 1
|
output[activity] = {
|
||||||
else:
|
"alltime": 0,
|
||||||
output[activity] = 1
|
"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
|
return output
|
|
@ -31,12 +31,16 @@
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Activity</th>
|
<th>Activity</th>
|
||||||
<th>Count</th>
|
<th>7 days</th>
|
||||||
|
<th>1 month</th>
|
||||||
|
<th>1 year</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for activity, count in activities.items %}
|
{% for activity, counts in activities.items %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="color:{{ activity.color }};"><i class="{{ activity.icon }}"></i><b> {{ activity }}</b></td>
|
<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>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in a new issue