diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2023-03-14 02:12:28 +0000 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2023-03-14 02:12:28 +0000 |
commit | 85fab88ac9cc6f2098bf0b1146a4b0503bc90979 (patch) | |
tree | af7ed9af76ec884ac58623837e161713fa5b4587 /parsers/survex.py | |
parent | b428a87f1a7f70c4ae7540e07ccf9fceb247f1b0 (diff) | |
download | troggle-85fab88ac9cc6f2098bf0b1146a4b0503bc90979.tar.gz troggle-85fab88ac9cc6f2098bf0b1146a4b0503bc90979.tar.bz2 troggle-85fab88ac9cc6f2098bf0b1146a4b0503bc90979.zip |
Fixing inherited *date into sub-blocks
Diffstat (limited to 'parsers/survex.py')
-rw-r--r-- | parsers/survex.py | 57 |
1 files changed, 41 insertions, 16 deletions
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, |