Fixing inherited *date into sub-blocks

This commit is contained in:
2023-03-14 02:12:28 +00:00
parent b428a87f1a
commit 85fab88ac9
5 changed files with 55 additions and 22 deletions

View File

@@ -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,