Preliminary dream stat template tags
This commit is contained in:
parent
fc7d56680a
commit
f021f618f8
4 changed files with 162 additions and 10 deletions
26
TODO.md
26
TODO.md
|
@ -1,30 +1,36 @@
|
||||||
# To-Do List
|
# To-Do List
|
||||||
|
|
||||||
|
## General
|
||||||
|
|
||||||
|
[_] Make sure users can't access other users' data
|
||||||
|
[_] Allow configuration as single user instance
|
||||||
|
|
||||||
## mood module
|
## mood module
|
||||||
|
|
||||||
[_] Missing mood views
|
[_] Missing mood views
|
||||||
[ ] Statistics / graphs
|
[_] Statistics / graphs
|
||||||
|
|
||||||
## cbt module
|
## cbt module
|
||||||
|
|
||||||
[ ] Complete thought record creation
|
[_] Complete thought record creation
|
||||||
[ ] Thought record editing (?)
|
[_] Thought record editing (?)
|
||||||
[ ] Thought record deletion
|
[_] Thought record deletion
|
||||||
|
|
||||||
## msgio module
|
## msgio module
|
||||||
|
|
||||||
[ ] Implement Telegram webhooks
|
[_] Implement Telegram webhooks
|
||||||
|
|
||||||
## dreams module
|
## dreams module
|
||||||
|
|
||||||
[x] New dream page
|
[x] New dream page
|
||||||
[x] Edit dream page
|
[x] Edit dream page
|
||||||
[x] Delete dream page
|
[x] Delete dream page
|
||||||
[ ] Statistics / template tags
|
[x] Statistics / template tags
|
||||||
[ ] Check for copy-paste errors in pages
|
[_] Check for copy-paste errors in pages
|
||||||
|
|
||||||
## Frontend
|
## Frontend
|
||||||
|
|
||||||
[ ] Better icons for sidebar items
|
[_] Better icons for sidebar items
|
||||||
[ ] Sidebar auto-generation (?)
|
[_] Sidebar auto-generation (?)
|
||||||
[ ] Fix sidebar highlighting for pages with same name
|
[_] Fix sidebar highlighting for pages with same name
|
||||||
|
[_] Move dashboard components to module templates
|
0
dreams/templatetags/__init__.py
Normal file
0
dreams/templatetags/__init__.py
Normal file
60
dreams/templatetags/dream_stats.py
Normal file
60
dreams/templatetags/dream_stats.py
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
from django import template
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=True)
|
||||||
|
def total_dreams(context):
|
||||||
|
return len(context["user"].dream_set.all())
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=True)
|
||||||
|
def weekly_dreams(context):
|
||||||
|
now = timezone.now()
|
||||||
|
start = now - timezone.timedelta(days=7)
|
||||||
|
|
||||||
|
return len(context["user"].dream_set.filter(timestamp__gte=start, timestamp__lte=now))
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=True)
|
||||||
|
def most_common_theme(context, start, end=None):
|
||||||
|
dream_list = context["user"].dream_set.filter(timestamp__gte=start.date(), timestamp__lte=(end.date() if end else start.date()))
|
||||||
|
themes = list()
|
||||||
|
|
||||||
|
for dream in dream_list:
|
||||||
|
for theme in dream.dreamtheme_set.all():
|
||||||
|
themes.append(theme.theme)
|
||||||
|
|
||||||
|
try:
|
||||||
|
most_common = Counter(themes).most_common(1)[0]
|
||||||
|
return most_common[0], most_common[1]
|
||||||
|
except:
|
||||||
|
return None, None
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=True)
|
||||||
|
def most_common_theme_weekly(context):
|
||||||
|
now = timezone.now()
|
||||||
|
start = now - timezone.timedelta(days=7)
|
||||||
|
|
||||||
|
return most_common_theme(context, start, now)
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=True)
|
||||||
|
def special_dreams(context, start, end=None):
|
||||||
|
dream_list = context["user"].dream_set.filter(timestamp__gte=start.date(), timestamp__lte=(end.date() if end else start.date()))
|
||||||
|
wet = 0
|
||||||
|
lucid = 0
|
||||||
|
|
||||||
|
for dream in dream_list:
|
||||||
|
if dream.lucid:
|
||||||
|
lucid += 1
|
||||||
|
if dream.wet:
|
||||||
|
wet += 1
|
||||||
|
|
||||||
|
return lucid, wet
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=True)
|
||||||
|
def special_dreams_weekly(context):
|
||||||
|
now = timezone.now()
|
||||||
|
start = now - timezone.timedelta(days=7)
|
||||||
|
|
||||||
|
return special_dreams(context, start, now)
|
|
@ -1,7 +1,9 @@
|
||||||
{% extends "frontend/base.html" %}
|
{% extends "frontend/base.html" %}
|
||||||
{% load mood_stats %}
|
{% load mood_stats %}
|
||||||
|
{% load dream_stats %}
|
||||||
{% block "content" %}
|
{% block "content" %}
|
||||||
|
|
||||||
|
<!-- Mood stats -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
<!-- Earnings (Monthly) Card Example -->
|
<!-- Earnings (Monthly) Card Example -->
|
||||||
|
@ -85,4 +87,88 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Dream Stats -->
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
<!-- Earnings (Monthly) Card Example -->
|
||||||
|
<div class="col-xl-3 col-md-6 mb-4">
|
||||||
|
<div class="card border-left-primary shadow h-100 py-2">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row no-gutters align-items-center">
|
||||||
|
<div class="col mr-2">
|
||||||
|
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
|
||||||
|
Dream count (total)</div>
|
||||||
|
<div class="h5 mb-0 font-weight-bold text-gray-800">{% total_dreams %}</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<i class="fas fa-book fa-2x text-gray-300"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Earnings (Monthly) Card Example -->
|
||||||
|
<div class="col-xl-3 col-md-6 mb-4">
|
||||||
|
<div class="card border-left-success shadow h-100 py-2">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row no-gutters align-items-center">
|
||||||
|
<div class="col mr-2">
|
||||||
|
<div class="text-xs font-weight-bold text-success text-uppercase mb-1">
|
||||||
|
Dreams (weekly)</div>
|
||||||
|
<div class="h5 mb-0 font-weight-bold text-gray-800">{% weekly_dreams %}</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<i class="fas fa-calendar fa-2x text-gray-300"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Earnings (Monthly) Card Example -->
|
||||||
|
<div class="col-xl-3 col-md-6 mb-4">
|
||||||
|
<div class="card border-left-info shadow h-100 py-2">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row no-gutters align-items-center">
|
||||||
|
<div class="col mr-2">
|
||||||
|
<div class="text-xs font-weight-bold text-info text-uppercase mb-1">Special Dreams (lucid / wet)
|
||||||
|
</div>
|
||||||
|
<div class="row no-gutters align-items-center">
|
||||||
|
<div class="col-auto">
|
||||||
|
{% special_dreams_weekly as weekly %}
|
||||||
|
<div class="h5 mb-0 mr-3 font-weight-bold text-gray-800">{{ weekly.0 }} / {{ weekly.1 }} <sub><i>(weekly)</i></sub></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<i class="{{ moodobj.icon }} fa-2x text-gray-300"></i>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Pending Requests Card Example -->
|
||||||
|
<div class="col-xl-3 col-md-6 mb-4">
|
||||||
|
<div class="card border-left-warning shadow h-100 py-2">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row no-gutters align-items-center">
|
||||||
|
<div class="col mr-2">
|
||||||
|
<div class="text-xs font-weight-bold text-warning text-uppercase mb-1">
|
||||||
|
Most Common Theme (weekly)</div>
|
||||||
|
{% most_common_theme_weekly as theme %}
|
||||||
|
<div class="h5 mb-0 font-weight-bold text-gray-800">{{ theme.0 }} <sub><i>({{ theme.1 }})</i></sub></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<i class="fas fa-bed fa-2x text-gray-300"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in a new issue