From 400fd8430ef446fdf088064b374c6a7618feb248 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 26 Sep 2025 20:38:18 +0300 Subject: [PATCH] add survey by year to wallets for each cave: Charlotte's request --- core/models/survex.py | 6 ++++++ core/views/scans.py | 14 +++++++++++++- templates/cavewallets.html | 6 +++++- templates/wallet_table.html | 1 - 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/core/models/survex.py b/core/models/survex.py index ea7f617..acf29f0 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -246,6 +246,12 @@ class SurvexBlock(models.Model): def isSurvexBlock(self): # Function used in templates return True + + def year(self): + if self.date: + return self.date.year + else: + return 1970 def DayIndex(self): """This is used to set different colours for the different trips on diff --git a/core/views/scans.py b/core/views/scans.py index 4263c2c..225f18e 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -1,4 +1,5 @@ import datetime +from collections import defaultdict from pathlib import Path from urllib.parse import unquote as urlunquote @@ -327,14 +328,25 @@ def cavewallets(request, caveid): expeditions = Expedition.objects.all() length_ug = 0.0 + length_by_year = defaultdict(int) # initialises values to zero + checksum = 0 for w in manywallets: for sb in w.survexblock_set.all(): length_ug += sb.legslength + length_by_year[sb.year()] += sb.legslength + length_by_year = dict(sorted(length_by_year.items())) + for y in length_by_year: + checksum += length_by_year[y] + print(f"{y} {length_by_year[y]:.0f}") + for key in list(length_by_year.keys()): + if length_by_year[key] < 0.1: + del length_by_year[key] + return render( request, "cavewallets.html", {"manywallets": manywallets, "settings": settings, "cave": cave, "expeditions": expeditions, - "length_ug": length_ug, "year": current_expo()} + "length_ug": length_ug, "length_by_year": length_by_year, "checksum": checksum, "year": current_expo()} ) diff --git a/templates/cavewallets.html b/templates/cavewallets.html index ace826d..a469242 100644 --- a/templates/cavewallets.html +++ b/templates/cavewallets.html @@ -25,7 +25,11 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c
-

Total underground survey length: {{length_ug|floatformat:"1g"}} m
+ {% for year, length in length_by_year.items %} + {{ year }} {{ length|floatformat:"0g" }} m
+ {% endfor %} + +

Total underground survey length: {{length_ug|floatformat:"1g"}} m (checksum: {{length_ug|floatformat:"1g"}} )
Note that this is for all the wallets listed above, which includes those which are surveys of different caves not just {{cave}}.
If you want accurate cave lengths for {{cave}}, go to the primary survex file for this cave diff --git a/templates/wallet_table.html b/templates/wallet_table.html index ba39c05..7989f8e 100644 --- a/templates/wallet_table.html +++ b/templates/wallet_table.html @@ -62,5 +62,4 @@ which is probably more useful.

Note that names in italics are copied from the related survex file block name.
Note also that survex data recently uploaded will not appear in this table until a database reset is done on the server. -

Note that all the Tunneled/Therioned boxes are fuchsia pending a proper method of setting this.