From 7a9bcd02f7f9e36290239447b9d0f5f33a701831 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Tue, 29 Jul 2025 19:42:59 +0200 Subject: [PATCH] Adding SUrvexFix class --- core/models/survex.py | 16 ++++++++++++++++ parsers/locations.py | 4 +++- parsers/survex.py | 24 +++++++++--------------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/core/models/survex.py b/core/models/survex.py index db1b9a9..ea7f617 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -195,6 +195,22 @@ class SurvexBlockLookUpManager(models.Manager): block = SurvexBlock.objects.get(parent=block, name__iexact=blockname) return block +class SurvexFix(models.Model): + """a *fix line in a survexfile. New at the end of expo in July 2025 + This is used to detect *fix stations which are not attached to a *entrance and thus to a cave + i.e. it is used to discover potential cave entrances + + But this does not include the virtual *fix locations which are + in locations.py + """ + objects = SurvexBlockLookUpManager() # overwrites Survexfix.objects and enables lookup() + name = models.CharField(max_length=100) + class Meta: + ordering = ("name",) + + def __str__(self): + return self.name + str(self.id) + class SurvexBlock(models.Model): """One begin..end block within a survex file. The basic element of a survey trip. diff --git a/parsers/locations.py b/parsers/locations.py index 740880e..083a5da 100644 --- a/parsers/locations.py +++ b/parsers/locations.py @@ -60,7 +60,7 @@ class MapLocations(object): # but not in troggle reports unless we include them here nullent = Entrance.objects.all()[0] - # These pending entrnces have been added to the fixedpts but no Cave Description page has been created yet, + # These pending entrances have been added to the fixedpts but no Cave Description page has been created yet, # nor are they on the pendingcaves.txt list - yet - as they really need a proper name, # /walletedit/2013:02 # so probably 2013-BL-02,03 etc. @@ -393,5 +393,7 @@ def LoadPositions(): print(f" - {found} distinct SurvexStation entrance stations identified in {lineno:,} lines in {positions_filename}.") if dups > 0: print(f" - {dups} Duplicated SurvexStation entrances found") + + store_data_issues() diff --git a/parsers/survex.py b/parsers/survex.py index dd4fcd3..75b9bda 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -10,7 +10,7 @@ from pathlib import Path import troggle.settings as settings from troggle.core.models.caves import Cave, Entrance, GetCaveLookup from troggle.core.models.logbooks import QM -from troggle.core.models.survex import SurvexBlock, SurvexFile, SurvexPersonRole, SurvexStation +from troggle.core.models.survex import SurvexBlock, SurvexFile, SurvexPersonRole, SurvexStation, SurvexFix from troggle.core.models.troggle import DataIssue, Expedition from troggle.core.models.wallets import Wallet from troggle.core.utils import chaosmonkey, get_process_memory @@ -2544,30 +2544,24 @@ def FindAndLoadSurvex(): print(f" - Number of SurvexFiles: {tf:,}") print(f" - Number of Survex *fix: {fixnumber:,}") print(f" - Number of Survex legs: {legsnumber:,}") - - for f in svx_load.fixes: + + fixlist = [] + for f in svx_load.fixes: survexblock, name, altitude, comment = svx_load.fixes[f] + fixlist.append(SurvexFix(name=name)) + # this loses the survex context, e.g. 1623. or 1626. is lost + # we would need to track teh *begin/*end labels to do that s = survexblock spath = s.parent.survexfile - # sprevious = None - # while s.parent != sprevious: - # spath += str(s.parent) + ":" + spath - # sprevious = s - # if not s.parent: - # break - # s = s.parent ff = survexblock.survexfile + # print(f"FIX {name} : {ff} {survexblock} ; {comment}") if comment: - # print(f"FIX {survexblock} {altitude} {comment}") if re.match(r"(?i)[^s]*srtm[\s\S]*", comment.lower()): print(f"SRTM {ff}.svx::{survexblock} - {spath}.svx - alt={altitude} '{comment}'") if re.match(r"(?i)[^s]*radost[\s\S]*", comment.lower()): print(f"RDST {ff}.svx::{survexblock} - {spath}.svx - alt={altitude} '{comment}'") - + SurvexFix.objects.bulk_create(fixlist) svx_load = None - - - return legsnumber def display_contents(blocks):