Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion kos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.db.models import Max, Q, Count
from django.db.models import Count, Max, Q
from django.utils.timezone import now
from unidecode import unidecode

Expand Down Expand Up @@ -399,6 +399,9 @@ def submit_solution(self, team_solution: str):
if is_correct:
self.solve_puzzle()

def count_hints(self):
return self.team.hints_taken.filter(puzzle=self.puzzle).count()


class Submission(models.Model):
"""Pokus o odovzdanie odpovede na šifru"""
Expand Down
86 changes: 86 additions & 0 deletions kos/templates/kos/statistics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{% extends "kos/base.html" %}

{% block header %}
{% load static %}
<script src="{% static 'kos/results.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'kos/results.css' %}">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
{% endblock %}

{% block title %}Štatistiky - {{year.name}}{% endblock %}

{% block content %}

<h1>Štatistiky šifier</h1>

<!-- <div class="dropdown">
<button class="dropdown__button main-button" onclick="toggle()">
{{year.name}}
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content" id="dropdown-content">
{% for year in years %}
<a href="{% url 'kos:results' pk=year.pk %}">{{year.name}}</a>
{% endfor %}
</div>
</div> -->

{% if not games %}
Táto hra nemá zverejnené štatistiky.
{% endif %}

{% for game in games %}
<h2>{{game.name}}</h2>

{% if game.online_teams %}
<h3>Online:</h3>

<table>
<tr>
<th>Poradie</th>
<th>Názov tímu</th>
<th>Členovia tímu</th>
<th>Počet vyriešených šifier</th>
<th>Posledné správne odovzdanie</th>
</tr>
{% for team in game.online_teams %}
<tr>
<td>{{ team.place }}.</td>
<td>{{ team.name }}</td>
<td>{{ team.members_joined }}</td>
<td>{{ team.solved_puzzles }}</td>
<!-- This needs to be displayed in the client's timezone -->
<td>{% if team.last_correct_submission %}{{ team.last_correct_submission|date:'H:i:s' }}{% else %}-{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% endif %}

{% if game.offline_teams %}
<h3>Terénna:</h3>

<table>
<tr>
<th>Poradie</th>
<th>Názov tímu</th>
<th>Členovia tímu</th>
<th>Počet vyriešených šifier</th>
<th>Posledné správne odovzdanie</th>
</tr>
{% for team in game.offline_teams %}
<tr>
<td>{{ team.place }}.</td>
<td>{{ team.name }}</td>
<td>{{ team.members_joined }}</td>
</td>
<td>{{ team.solved_puzzles }}</td>
<!-- This needs to be displayed in the client's timezone -->
<td>{% if team.last_correct_submission %}{{ team.last_correct_submission|date:'H:i:s' }}{% else %}-{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% endif %}
{% endfor %}
{% endblock %}
3 changes: 3 additions & 0 deletions kos/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
path(r'poradie/<int:pk>', views.ResultsView.as_view(), name='results'),
path('poradie/aktualne', views.ResultsLatestView.as_view(),
name='results-latest'),
path(r'statistiky/<int:pk>', views.StatisticsView.as_view(), name='statistics'),
# path('statistiky/aktualne', views.StatisticsView.as_view,
# name='statistics-latest'),
path(r'poradie-latex/<int:pk>',
views.ResultsLatexExportView.as_view(), name='results-latex'),
path('pravidla', flatpage, {'url': '/pravidla/'}, name='rules'),
Expand Down
43 changes: 42 additions & 1 deletion kos/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


import json
from typing import Optional
from typing import Any, Optional

from allauth.account.models import EmailAddress
from allauth.account.signals import email_confirmed
Expand Down Expand Up @@ -465,3 +465,44 @@ def form_valid(self, form):
team.save()

return super().form_valid(form)


class StatisticsView(DetailView):
model = Year
template_name = 'kos/statistics.html'

def generate_statistics_matrix(self, game: Game):

num_puzzles = game.puzzle_set.count()
return [
{
'team': team.name,
'puzzles': [
{
'solved_at': state.ended_at,
'solving_time': state.ended_at-state.started_at if state.ended_at else None,
'skipped': state.skipped,
'hints': state.count_hints()
}
for state in team.states.all()
] + [
{
'solved_at': None,
'solving_time': None,
'skipped': None,
'hints': None
}
]*(num_puzzles-team.states.count())
}
for team in game.team_set.all()
]

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['stats'] = []
for game in self.object.games:
context['stats'].append(
{'game': game.name,
'matrix': self.generate_statistics_matrix(game)
})
return context