From ab1f4c2ebae1f101dadc997d81dbe6c56edce685 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 18 Nov 2021 19:17:54 +0100 Subject: [PATCH] Add script to generate Wordpress results Signed-off-by: Yohann D'ANELLO --- .../management/commands/export_results.py | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 apps/participation/management/commands/export_results.py diff --git a/apps/participation/management/commands/export_results.py b/apps/participation/management/commands/export_results.py new file mode 100644 index 0000000..d1982b7 --- /dev/null +++ b/apps/participation/management/commands/export_results.py @@ -0,0 +1,86 @@ +# Copyright (C) 2021 by Animath +# SPDX-License-Identifier: GPL-3.0-or-later + +import os + +from django.contrib.auth.models import User +from django.core.management import BaseCommand +from django.utils.formats import date_format +from django.utils.translation import activate + +from participation.models import Tournament + + +class Command(BaseCommand): + def handle(self, *args, **kwargs): + activate('fr') + + tournaments = Tournament.objects.order_by('-date_start', 'name') + for tournament in tournaments: + self.handle_tournament(tournament) + self.w("") + self.w("") + + def w(self, msg): + self.stdout.write(msg) + + def handle_tournament(self, tournament): + name = tournament.name + date_start = date_format(tournament.date_start, "DATE_FORMAT") + date_end = date_format(tournament.date_end, "DATE_FORMAT") + + notes = dict() + for participation in tournament.participations.filter(valid=True).all(): + note = sum(pool.average(participation) + for pool in tournament.pools.filter(participations=participation).all()) + notes[participation] = note + notes = sorted(notes.items(), key=lambda x: x[1], reverse=True) + + self.w("") + self.w(f"

{name}

") + self.w("") + self.w("") + self.w("") + if tournament.final: + self.w(f"

La finale a eu lieu le weekend du {date_start} au {date_end} et a été remporté par l'équipe {notes[0][0].team.name} suivie de l'équipe {notes[1][0].team.name}. Les deux premières équipes sont sélectionnées pour représenter la France lors de l'ITYM.

") + else: + self.w(f"

Le tournoi de {name} a eu lieu le weekend du {date_start} au {date_end} et a été remporté par l'équipe {notes[0][0].team.name}.

") + self.w("") + self.w("") + self.w("") + self.w("") + self.w("
") + self.w("") + self.w("") + self.w("") + self.w("\t") + self.w("\t") + self.w("\t") + self.w("\t") + self.w("\t") + self.w("") + self.w("") + self.w("") + for i, (participation, note) in enumerate(notes): + self.w("") + if i < (2 if len(notes) >= 7 else 1): + self.w(f"\t") + for pool in tournament.pools.filter(participations=participation).all(): + pool_note = pool.average(participation) + self.w(f"\t") + self.w(f"\t") + if i == 0: + self.w("\t") + elif i < (5 if tournament.final else 3): + self.w(f"\t") + elif i < 2 * len(notes) / 3: + self.w("\t") + else: + self.w("\t") + self.w("") + self.w("") + self.w("
ÉquipeScore Tour 1Score Tour 2TotalPrix
{participation.team.name} ({participation.team.trigram})") + else: + self.w(f"\t{participation.team.name} ({participation.team.trigram}){pool_note:.01f}{note:.01f}1er prix{i + 1}ème prixMention très honorableMention honorable
") + self.w("
") + self.w("")