mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-25 05:42:23 +00:00
Consider tweaks in notation sheet
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
parent
5261a52401
commit
f1012efcaa
@ -36,4 +36,6 @@ class Command(BaseCommand):
|
|||||||
self.stdout.write(f"Parsing notation sheet for pool {pool.short_name} for {tournament}")
|
self.stdout.write(f"Parsing notation sheet for pool {pool.short_name} for {tournament}")
|
||||||
pool.parse_spreadsheet()
|
pool.parse_spreadsheet()
|
||||||
|
|
||||||
|
tournament.parse_tweaks_spreadskeets()
|
||||||
|
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
@ -439,10 +439,10 @@ class Tournament(models.Model):
|
|||||||
else:
|
else:
|
||||||
worksheet = spreadsheet.worksheet("Classement final")
|
worksheet = spreadsheet.worksheet("Classement final")
|
||||||
|
|
||||||
if worksheet.index < 100:
|
if worksheet.index != self.pools.count():
|
||||||
worksheet.update_index(self.pools.count() + 1)
|
worksheet.update_index(self.pools.count())
|
||||||
|
|
||||||
header = [["Équipe", "Points jour 1", "Points jour 2", "Total", "Harmonisation", "Total final", "Rang"]]
|
header = [["Équipe", "Score jour 1", "Harmonisation 1", "Score jour 2", "Harmonisation 2", "Total", "Rang"]]
|
||||||
lines = []
|
lines = []
|
||||||
participations = self.participations.filter(pools__round=1, pools__tournament=self).all()
|
participations = self.participations.filter(pools__round=1, pools__tournament=self).all()
|
||||||
for i, participation in enumerate(participations):
|
for i, participation in enumerate(participations):
|
||||||
@ -451,13 +451,19 @@ class Tournament(models.Model):
|
|||||||
|
|
||||||
pool1 = self.pools.get(round=1, participations=participation)
|
pool1 = self.pools.get(round=1, participations=participation)
|
||||||
passage1 = pool1.passages.get(defender=participation)
|
passage1 = pool1.passages.get(defender=participation)
|
||||||
|
tweak1_qs = Tweak.objects.filter(pool=pool1, participation=participation)
|
||||||
|
tweak1 = tweak1_qs.get() if tweak1_qs.exists() else None
|
||||||
|
|
||||||
pool2 = self.pools.get(round=2, participations=participation)
|
pool2 = self.pools.get(round=2, participations=participation)
|
||||||
passage2 = pool2.passages.get(defender=participation)
|
passage2 = pool2.passages.get(defender=participation)
|
||||||
|
tweak2_qs = Tweak.objects.filter(pool=pool2, participation=participation)
|
||||||
|
tweak2 = tweak2_qs.get() if tweak2_qs.exists() else None
|
||||||
|
|
||||||
line.append(f"=SIERREUR('Poule {pool1.short_name}'!$D{pool1.juries.count() + 10 + passage1.position}; 0)")
|
line.append(f"=SIERREUR('Poule {pool1.short_name}'!$D{pool1.juries.count() + 10 + passage1.position}; 0)")
|
||||||
|
line.append(tweak1.diff if tweak1 else 0)
|
||||||
line.append(f"=SIERREUR('Poule {pool2.short_name}'!$D{pool2.juries.count() + 10 + passage2.position}; 0)")
|
line.append(f"=SIERREUR('Poule {pool2.short_name}'!$D{pool2.juries.count() + 10 + passage2.position}; 0)")
|
||||||
line.append(f"=$B{i + 2} + $C{i + 2}")
|
line.append(tweak2.diff if tweak2 else 0)
|
||||||
line.append(0)
|
line.append(f"=$B{i + 2} + $C{i + 2} + $D{i + 2} + E{i + 2}")
|
||||||
line.append(f"=$D{i + 2} + $E{i + 2}")
|
|
||||||
line.append(f"=RANG($F{i + 2}; $F$2:$F${participations.count() + 1})")
|
line.append(f"=RANG($F{i + 2}; $F$2:$F${participations.count() + 1})")
|
||||||
|
|
||||||
final_ranking = [["", "", ""], ["", "", ""], ["Équipe", "Score", "Rang"],
|
final_ranking = [["", "", ""], ["", "", ""], ["Équipe", "Score", "Rang"],
|
||||||
@ -475,7 +481,7 @@ class Tournament(models.Model):
|
|||||||
format_requests = []
|
format_requests = []
|
||||||
|
|
||||||
# Set the width of the columns
|
# Set the width of the columns
|
||||||
column_widths = [("A", 250), ("B", 100), ("C", 100), ("D", 100), ("E", 100), ("F", 100), ("G", 100)]
|
column_widths = [("A", 250), ("B", 120), ("C", 120), ("D", 120), ("E", 120), ("F", 120), ("G", 120)]
|
||||||
for column, width in column_widths:
|
for column, width in column_widths:
|
||||||
grid_range = a1_range_to_grid_range(column, worksheet.id)
|
grid_range = a1_range_to_grid_range(column, worksheet.id)
|
||||||
format_requests.append({
|
format_requests.append({
|
||||||
@ -531,7 +537,9 @@ class Tournament(models.Model):
|
|||||||
# Set background color for headers and footers
|
# Set background color for headers and footers
|
||||||
bg_colors = [("A1:AF", (1, 1, 1)),
|
bg_colors = [("A1:AF", (1, 1, 1)),
|
||||||
(f"A1:G1", (0.8, 0.8, 0.8)),
|
(f"A1:G1", (0.8, 0.8, 0.8)),
|
||||||
(f"A2:D{participations.count() + 1}", (0.9, 0.9, 0.9)),
|
(f"A2:B{participations.count() + 1}", (0.9, 0.9, 0.9)),
|
||||||
|
(f"C2:C{participations.count() + 1}", (1, 1, 1)),
|
||||||
|
(f"D2:D{participations.count() + 1}", (0.9, 0.9, 0.9)),
|
||||||
(f"E2:E{participations.count() + 1}", (1, 1, 1)),
|
(f"E2:E{participations.count() + 1}", (1, 1, 1)),
|
||||||
(f"F2:G{participations.count() + 1}", (0.9, 0.9, 0.9)),
|
(f"F2:G{participations.count() + 1}", (0.9, 0.9, 0.9)),
|
||||||
(f"A{participations.count() + 4}:C{participations.count() + 4}", (0.8, 0.8, 0.8)),
|
(f"A{participations.count() + 4}:C{participations.count() + 4}", (0.8, 0.8, 0.8)),
|
||||||
@ -547,13 +555,19 @@ class Tournament(models.Model):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Set number format, display only one decimal
|
# Set number format, display only one decimal
|
||||||
number_format_ranges = [f"B2:D{participations.count() + 1}", f"F2:F{participations.count() + 1}",
|
number_format_ranges = [(f"B2:B{participations.count() + 1}", "0.0"),
|
||||||
f"B{participations.count() + 5}:B{2 * participations.count() + 5}", ]
|
(f"C2:C{participations.count() + 1}", "0"),
|
||||||
for number_format_range in number_format_ranges:
|
(f"D2:D{participations.count() + 1}", "0.0"),
|
||||||
|
(f"E2:E{participations.count() + 1}", "0"),
|
||||||
|
(f"F2:F{participations.count() + 1}", "0.0"),
|
||||||
|
(f"G2:G{participations.count() + 1}", "0"),
|
||||||
|
(f"B{participations.count() + 5}:B{2 * participations.count() + 5}", "0.0"),
|
||||||
|
(f"C{participations.count() + 5}:C{2 * participations.count() + 5}", "0"), ]
|
||||||
|
for number_format_range, pattern in number_format_ranges:
|
||||||
format_requests.append({
|
format_requests.append({
|
||||||
"repeatCell": {
|
"repeatCell": {
|
||||||
"range": a1_range_to_grid_range(number_format_range, worksheet.id),
|
"range": a1_range_to_grid_range(number_format_range, worksheet.id),
|
||||||
"cell": {"userEnteredFormat": {"numberFormat": {"type": "NUMBER", "pattern": "0.0"}}},
|
"cell": {"userEnteredFormat": {"numberFormat": {"type": "NUMBER", "pattern": pattern}}},
|
||||||
"fields": "userEnteredFormat.numberFormat",
|
"fields": "userEnteredFormat.numberFormat",
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -567,7 +581,8 @@ class Tournament(models.Model):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Protect the header, the juries list, the footer and the ranking
|
# Protect the header, the juries list, the footer and the ranking
|
||||||
protected_ranges = [f"A1:G1", f"A2:D{participations.count() + 1}", f"F2:G{participations.count() + 1}",
|
protected_ranges = [f"A1:G1", f"A2:B{participations.count() + 1}",
|
||||||
|
f"D2:D{participations.count() + 1}", f"F2:G{participations.count() + 1}",
|
||||||
f"A{participations.count() + 4}:C{2 * participations.count() + 4}", ]
|
f"A{participations.count() + 4}:C{2 * participations.count() + 4}", ]
|
||||||
for protected_range in protected_ranges:
|
for protected_range in protected_ranges:
|
||||||
format_requests.append({
|
format_requests.append({
|
||||||
@ -584,6 +599,35 @@ class Tournament(models.Model):
|
|||||||
body = {"requests": format_requests}
|
body = {"requests": format_requests}
|
||||||
worksheet.client.batch_update(spreadsheet.id, body)
|
worksheet.client.batch_update(spreadsheet.id, body)
|
||||||
|
|
||||||
|
def parse_tweaks_spreadskeets(self):
|
||||||
|
gc = gspread.service_account_from_dict(settings.GOOGLE_SERVICE_CLIENT)
|
||||||
|
spreadsheet = gc.open_by_key(self.notes_sheet_id)
|
||||||
|
worksheet = spreadsheet.worksheet("Classement final")
|
||||||
|
|
||||||
|
score_cell = worksheet.find("Score")
|
||||||
|
max_row = score_cell.row - 3
|
||||||
|
data = worksheet.get_values(f"A2:E{max_row}")
|
||||||
|
for line in data:
|
||||||
|
trigram = line[0][-4:-1]
|
||||||
|
participation = self.participations.get(team__trigram=trigram)
|
||||||
|
pool1 = self.pools.get(round=1, participations=participation)
|
||||||
|
pool2 = self.pools.get(round=2, participations=participation)
|
||||||
|
tweak1_qs = Tweak.objects.filter(pool=pool1, participation=participation)
|
||||||
|
tweak2_qs = Tweak.objects.filter(pool=pool2, participation=participation)
|
||||||
|
tweak1_nb, tweak2_nb = int(line[2]), int(line[4])
|
||||||
|
if not tweak1_nb:
|
||||||
|
tweak1_qs.delete()
|
||||||
|
else:
|
||||||
|
tweak1_qs.update_or_create(defaults={'diff': tweak1_nb},
|
||||||
|
create_defaults={'diff': tweak1_nb, 'pool': pool1,
|
||||||
|
'participation': participation})
|
||||||
|
if not tweak2_nb:
|
||||||
|
tweak2_qs.delete()
|
||||||
|
else:
|
||||||
|
tweak2_qs.update_or_create(defaults={'diff': tweak2_nb},
|
||||||
|
create_defaults={'diff': tweak2_nb, 'pool': pool2,
|
||||||
|
'participation': participation})
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse_lazy("participation:tournament_detail", args=(self.pk,))
|
return reverse_lazy("participation:tournament_detail", args=(self.pk,))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user