Commit 1d7cacbc authored by krasnal's avatar krasnal
Browse files

Added class names sorting (statistics)

parent cc96cd90
Loading
Loading
Loading
Loading
+12 −0
Changes for stats/admin.py: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@ from elections.models import Election
from vote.models import Participation
from voters.models import Voter, Group

import re

def live_results(request, election_id):
    context = admin.site.each_context(request)
    
@@ -46,6 +48,16 @@ def statistics(request, election_id):
            'percentage': round((voted / total * 100), 2) if total > 0 else 0
        })

    def sort_key(item):
        name = item.get('class_name') or ""

        match = re.search(r'd+', name)
        num = int(match.group()) if match else 0

        return (num, name.lower())
    
    stats_by_class.sort(key=sort_key)

    remote_count = Participation.objects.filter(election=election, is_remote=True).count()
    stationary_count = total_participated - remote_count;