Skip to content
Snippets Groups Projects
Commit e66510a3 authored by Ben Adida's avatar Ben Adida
Browse files

added more stats

parent f8af2a0f
No related branches found
No related tags found
No related merge requests found
......@@ -12,4 +12,5 @@ urlpatterns = patterns(
'',
(r'^$', home),
(r'^elections$', elections),
(r'^recent-votes$', recent_votes),
)
......@@ -7,9 +7,12 @@ from django.core.mail import send_mail
from django.core.paginator import Paginator
from django.http import *
from django.db import transaction
from django.db.models import *
from security import *
from auth.security import get_user, save_in_session_across_logouts
from view_utils import *
def require_admin(request):
user = get_user(request)
......@@ -19,7 +22,8 @@ def require_admin(request):
return user
def home(request):
return HttpResponse("foo")
user = require_admin(request)
return render_template(request, 'stats', {})
def elections(request):
user = require_admin(request)
......@@ -31,6 +35,14 @@ def elections(request):
elections_paginator = Paginator(elections, limit)
elections_page = elections_paginator.page(page)
return render_template(request, "stats", {'elections' : elections_page.object_list, 'elections_page': elections_page,
'limit' : limit})
return render_template(request, "stats_elections", {'elections' : elections_page.object_list, 'elections_page': elections_page,
'limit' : limit})
def recent_votes(request):
user = require_admin(request)
# elections with a vote in the last 24 hours, ordered by most recent cast vote time
# also annotated with number of votes cast in last 24 hours
elections_with_votes_in_24hours = Election.objects.filter(voter__castvote__cast_at__gt= datetime.datetime.utcnow() - datetime.timedelta(days=1)).annotate(last_cast_vote = Max('voter__castvote__cast_at'), num_recent_cast_votes = Count('voter__castvote')).order_by('-last_cast_vote')
return render_template(request, "stats_recent_votes", {'elections' : elections_with_votes_in_24hours})
......@@ -4,22 +4,9 @@
{% block content %}
<h1>Statistics</h1>
<p>
{% if elections_page.has_previous %}
<a href="?page={{elections_page.previous_page_number}}&limit={{limit}}">previous {{limit}}</a> &nbsp;&nbsp;
{% endif %}
Elections {{elections_page.start_index}} - {{elections_page.end_index}}&nbsp;&nbsp;
{% if elections_page.has_next %}
<a href="?page={{elections_page.next_page_number}}&limit={{limit}}">next {{limit}}</a> &nbsp;&nbsp;
{% endif %}
</p>
{% for election in elections %}
<p>
<b><a href="{% url helios.views.one_election_view election.uuid %}">{{election.name}}</a></b> -- {{election.num_voters}} voters
</p>
{% endfor %}
<ul>
<li> <a href="{% url helios.stats_views.elections %}">elections</a></li>
<li> <a href="{% url helios.stats_views.recent_votes %}">recent votes</a></li>
</ul>
{% endblock %}
{% extends TEMPLATE_BASE %}
{% block title %}Statistics{% endblock %}
{% block content %}
<h1>Elections</h1>
<p>
{% if elections_page.has_previous %}
<a href="?page={{elections_page.previous_page_number}}&limit={{limit}}">previous {{limit}}</a> &nbsp;&nbsp;
{% endif %}
Elections {{elections_page.start_index}} - {{elections_page.end_index}}&nbsp;&nbsp;
{% if elections_page.has_next %}
<a href="?page={{elections_page.next_page_number}}&limit={{limit}}">next {{limit}}</a> &nbsp;&nbsp;
{% endif %}
</p>
{% for election in elections %}
<p>
<b><a href="{% url helios.views.one_election_view election.uuid %}">{{election.name}}</a></b> -- {{election.num_voters}} voters / {{election.num_cast_votes}} cast votes
</p>
{% endfor %}
{% endblock %}
{% extends TEMPLATE_BASE %}
{% block title %}Statistics{% endblock %}
{% block content %}
<h1>Recent Votes</h1>
Last 24 hours
{% for election in elections %}
<p>
<b><a href="{% url helios.views.one_election_view election.uuid %}">{{election.name}}</a></b> -- {{election.last_cast_vote}} {{election.num_recent_cast_votes}} recently cast votes
</p>
{% endfor %}
{% endblock %}
......@@ -60,7 +60,9 @@ not logged in. [<a href="{{settings.SECURE_URL_HOST}}{% url auth.views.index %}?
| <a href="{{ footer_link.url }}">{{footer_link.text}}</a>
{% endfor %}
| <a href="mailto:help@heliosvoting.org">Help!</a>
{% if user and user.admin_p %}
| <a href="{% url helios.stats_views.home %}">Statistics</a>
{% endif %}
<br clear="right" />
</div>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment