From 85fab88ac9cc6f2098bf0b1146a4b0503bc90979 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Tue, 14 Mar 2023 02:12:28 +0000 Subject: [PATCH] Fixing inherited *date into sub-blocks --- core/models/logbooks.py | 5 ++-- core/views/survex.py | 7 +++-- parsers/survex.py | 57 +++++++++++++++++++++++++++++------------ templates/cave_qms.html | 2 ++ templates/svxfile.html | 6 +++-- 5 files changed, 55 insertions(+), 22 deletions(-) diff --git a/core/models/logbooks.py b/core/models/logbooks.py index 4932a57..5933848 100644 --- a/core/models/logbooks.py +++ b/core/models/logbooks.py @@ -162,8 +162,9 @@ class QM(TroggleModel): ("B", "B: Average lead"), ("C", "C: Tight unpromising lead"), ("D", "D: Dig"), - ("X", "X: Unclimbable aven"), - ) # also seen "?" and "V" in imported data - see urls.py + ("X", "X: Unclimbable or horrid"), + ("V", "V: Vertical"), + ) # also seen "?" in imported data - see urls.py grade = models.CharField(max_length=1, choices=GRADE_CHOICES) location_description = models.TextField(blank=True) nearest_station_description = models.CharField(max_length=400, blank=True, null=True) diff --git a/core/views/survex.py b/core/views/survex.py index 2a750aa..5115cb7 100644 --- a/core/views/survex.py +++ b/core/views/survex.py @@ -344,6 +344,7 @@ def svx(request, survex_file): # collect all the survex blocks which actually have a valid date if svxfile: + has_3d = (Path(survexdatasetpath) / Path(survex_file + ".3d")).is_file() try: svxblocks = svxfile.survexblock_set.filter(date__isnull=False).order_by('date') except: @@ -353,12 +354,14 @@ def svx(request, survex_file): svxlength = 0.0 for b in svxblocksall: svxlength += b.legslength - print(svxlength,b, b.legsall) + # print(svxlength,b, b.legsall) except AttributeError: # some survexfiles just *include files and have no blocks themselves svxblocksall = [] else: svxblocks = [] svxblocksall = [] + svxlength = 0.0 + has_3d = False if not difflist: difflist = ["Survex file does not exist yet"] @@ -368,7 +371,7 @@ def svx(request, survex_file): vmap = { "settings": settings, "warning": warning, - "has_3d": (Path(survexdatasetpath) / Path(survex_file + ".3d")).is_file(), + "has_3d": has_3d, "title": survex_file, "svxlength": svxlength, "svxblocks": svxblocks, diff --git a/parsers/survex.py b/parsers/survex.py index 45384e3..81500a8 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -333,8 +333,8 @@ class LoadingSurvex: caverndate = None currentteam = set() inheritteam = set() - currentdate = set() - inheritdate = set() + currentdate = None + inheritdate = None pending = [] adhocload = False @@ -381,12 +381,13 @@ class LoadingSurvex: return self.inheritteam def fix_undated(self, survexblock): - """Called when we reach *end of a block + """Called when we reach *end of a block OR when a QM is seen. Checks to see if the block has no *date, in which case it uses the inherited date. This is fine if the inherited date is from the same SurvexFile, but inheriting dates across *include files is almost certainly NOT - expected behaviour, even though it is syntactically "correct". + expected behaviour, even though it is syntactically "correct", + so triggers a Warning. """ if survexblock.parent.name == "troggle_unseens": # Bolluxed up if we try to inherit from this random junk, so don't. @@ -394,19 +395,38 @@ class LoadingSurvex: if self.currentdate: # already set + if not survexblock.date: + # error + message = ( + f"! no survexblock.date but currentdate is set. ({survexblock})-{survexblock.survexfile.path} {self.currentdate=}" + ) + print(self.insp + message) + stash_data_issue( + parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) + ) return if self.inheritdate: + survexblock.date = self.inheritdate + self.currentdate = self.inheritdate # unecessary duplication # Not an error, so not put in DataIssues, but is printed to debug output message = ( - f"- No *date. INHERITING date from ({survexblock})-{survexblock.survexfile.path} to ({survexblock.parent}) to {self.inheritdate:%Y-%m-%d}" + f"- No *date. INHERITING date from ({survexblock.parent})-{survexblock.parent.survexfile.path} to ({survexblock})-{survexblock.survexfile.path} {self.inheritdate:%Y-%m-%d}" ) print(self.insp + message) # stash_data_issue( - # parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) + # parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) # child # ) - survexblock.date = self.inheritdate - self.currentdate = self.inheritdate # unecessary duplication + if survexblock.survexfile != survexblock.parent.survexfile: + # This is noteworthy, however. + message = ( + f"- Warning *date INHERITED from DIFFERENT file:\n ({survexblock.parent})-{survexblock.parent.survexfile.path} to ({survexblock})-{survexblock.survexfile.path} {self.inheritdate:%Y-%m-%d}\n {self.stackbegin} {self.inheritdate:%Y-%m-%d}" + ) + print(self.insp + message) + stash_data_issue( + parser="survex", message=message, url=None, sb=(survexblock.parent.survexfile.path) # PARENT + ) + return self.inheritdate else: # This is not an error in the Expo dataset. @@ -583,7 +603,7 @@ class LoadingSurvex: print(self.insp + message) stash_data_issue(parser="survexunits", message=message) - def get_expo_from_year(self, year): + def get_expo_from_year(self, year, line, survexblock): # cacheing to save DB query on every block if year in self.expos: expo = self.expos[year] @@ -597,9 +617,14 @@ class LoadingSurvex: stash_data_issue( parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) ) - - expo = expeditions[0] - self.expos[year] = expo + if expeditions: + expo = expeditions[0] + self.expos[year] = expo + else: + expo = Expedition.objects.get(year="1976") + message = f"! DATE INCORRECT. There is no expedition for the year {year}. {survexblock.survexfile.path} ({survexblock}) - set to 1976." + print(self.insp + message) + stash_data_issue(parser='survex', message=message, url=None, sb=(survexblock.survexfile.path)) return expo def LoadSurvexDate(self, survexblock, line): @@ -615,9 +640,8 @@ class LoadingSurvex: *team came before this *date, in which case the names are only in 'pending'""" global trip_person_record - expo = self.get_expo_from_year(year) + expo = self.get_expo_from_year(year, line, survexblock) survexblock.expedition = expo - survexblock.save() team = get_team_on_trip(survexblock) # should be empty, should only be in 'pending' # team = SurvexPersonRole.objects.filter(survexblock=survexblock) @@ -645,6 +669,7 @@ class LoadingSurvex: message=message, url=None, sb=(survexblock.survexfile.path), ) + oline = line if len(line) > 10: message = "! DATE Warning LONG DATE '{}' ({}) {}".format(oline, survexblock, survexblock.survexfile.path) @@ -694,7 +719,7 @@ class LoadingSurvex: if survexblock.date: # do not actually need a distict variable 'currentdate' but it makes the code clearer self.currentdate = survexblock.date - + survexblock.save() def LoadSurvexLeg(self, survexblock, sline, comment, svxline): """This reads compass, clino and tape data but only keeps the tape lengths, @@ -1585,7 +1610,7 @@ class LoadingSurvex: self.inheritteam = self.currentteam self.currentteam = set() # zero the current team when we start a new block self.inheritdate = self.currentdate - self.currentdate = set() # zero the current date when we start a new block + self.currentdate = None # zero the current date when we start a new block printbegin() newsurvexblock = SurvexBlock( name=blkid, diff --git a/templates/cave_qms.html b/templates/cave_qms.html index 47dcea5..8b042d3 100644 --- a/templates/cave_qms.html +++ b/templates/cave_qms.html @@ -40,6 +40,8 @@ {% for QM in cave.get_QMs %} {% if QM.ticked %}
  • {{QM}} + {% if QM.nearest_station %}⋮{{QM.nearest_station}}⋮{% endif %} + {% if QM.nearest_station_name %}⋮{{QM.nearest_station_name}}⋮{% endif %} {% if QM.nearest_station_description %}⋮{{QM.nearest_station_description}}⋮{% endif %} {{QM.location_description}} {{QM.grade}} {% if QM.block %} {{QM.block}}.svx {{QM.block.date}} {% endif %} diff --git a/templates/svxfile.html b/templates/svxfile.html index ccd9749..97dcfe2 100644 --- a/templates/svxfile.html +++ b/templates/svxfile.html @@ -80,14 +80,16 @@ LOGMESSAGES --> {% endif %} -undergound survey length: {{svxlength|floatformat:2}} metres - +underground survey length: {{svxlength|floatformat:2}} metres
    + {% for sb in svxblocks %} +block:({{sb}}) has parent block:({{sb.parent}}) {% empty %} Cannot find any dated survex blocks in this survex file (not looking at *include files).
    Report this to a nerd if you think this is incorrect.
    {% endfor %} + {% for key, value in events.items %} {% with trips=value.0 svxothers=value.1 wallets=value.2 blocks=value.3 %}