handle shortform months and days in svx file

This commit is contained in:
Expo laptop Crowley 2023-07-10 12:49:14 +02:00
parent b3e2f34960
commit 8ff438942d

View File

@ -695,12 +695,15 @@ class LoadingSurvex:
) )
oline = line oline = line
perps = get_people_on_trip(survexblock) # What, you don't know Judge Dredd slang ?
if len(line) > 10: if len(line) > 10:
message = "! DATE Warning LONG DATE '{}' ({}) {}".format(oline, survexblock, survexblock.survexfile.path) message = "! DATE Warning LONG DATE '{}' ({}) {}".format(oline, survexblock, survexblock.survexfile.path)
print(self.insp+message) print(self.insp+message)
stash_data_issue(parser='svxdate', message=message, url=None, sb=(survexblock.survexfile.path)) stash_data_issue(parser='svxdate', message=message, url=None, sb=(survexblock.survexfile.path))
if line[10] == "-": # ie a range, just look at first date if line[10] == "-": # ie a range, just look at first date
line = line[0:10] line = line[0:10]
if len(line) == 10: if len(line) == 10:
year = line[:4] year = line[:4]
# TO DO set to correct Austrian timezone Europe/Vienna ? # TO DO set to correct Austrian timezone Europe/Vienna ?
@ -708,7 +711,6 @@ class LoadingSurvex:
survexblock.date = datetime.strptime(line.replace(".", "-"), "%Y-%m-%d") survexblock.date = datetime.strptime(line.replace(".", "-"), "%Y-%m-%d")
elif len(line) == 7: elif len(line) == 7:
year = line[:4] year = line[:4]
perps = get_people_on_trip(survexblock) # What, you don't know Judge Dredd slang ?
message = f"! DATE Warning only accurate to the month, setting to 1st '{oline}' ({survexblock}) {survexblock.survexfile.path} {perps}" message = f"! DATE Warning only accurate to the month, setting to 1st '{oline}' ({survexblock}) {survexblock.survexfile.path} {perps}"
print(self.insp + message) print(self.insp + message)
stash_data_issue( stash_data_issue(
@ -717,13 +719,36 @@ class LoadingSurvex:
survexblock.date = datetime.strptime(line.replace(".", "-"), "%Y-%m") # sets to first of month survexblock.date = datetime.strptime(line.replace(".", "-"), "%Y-%m") # sets to first of month
elif len(line) == 4: elif len(line) == 4:
year = line[:4] year = line[:4]
perps = get_people_on_trip(survexblock)
message = f"! DATE WARNING only accurate to the YEAR, setting to 1st January '{oline}' ({survexblock}) {survexblock.survexfile.path} {perps}" message = f"! DATE WARNING only accurate to the YEAR, setting to 1st January '{oline}' ({survexblock}) {survexblock.survexfile.path} {perps}"
print(self.insp + message) print(self.insp + message)
stash_data_issue( stash_data_issue(
parser="svxdate", message=message, url=None, sb=(survexblock.survexfile.path) parser="svxdate", message=message, url=None, sb=(survexblock.survexfile.path)
) )
survexblock.date = datetime.strptime(line, "%Y") # sets to January 1st survexblock.date = datetime.strptime(line, "%Y") # sets to January 1st
elif len(line) == 9 or len(line) == 8:
year = line[:4]
message = f"! DATE format WARNING, single digit day or month number,'{oline}' [{line[-5]}][{line[-2]}] ({survexblock}) {survexblock.survexfile.path}"
print(self.insp + message)
stash_data_issue(
parser="svxdate", message=message, url=None, sb=(survexblock.survexfile.path)
)
if line[-2] == "-" or line[-2] == ".":
line = line[:-1] + '0' + line[-1]
survexblock.date = datetime.strptime(line.replace(".", "-"), "%Y-%m-%d")
print(f"! DATE -2 '{line}' '{survexblock.date}'")
elif line[-5] == "-" or line[-5] == ".":
line = line[:-4] + '0' + line[-4:]
survexblock.date = datetime.strptime(line.replace(".", "-"), "%Y-%m-%d")
print(f"! DATE -5 '{line}' '{survexblock.date}'")
else:
year = line[:4]
message = (
f"! DATE Error SHORT LINE '{line}' '{oline}-{survexblock}' ({type(survexblock)}) {survexblock.survexfile.path}"
)
print(self.insp + message)
stash_data_issue(
parser="svxdate", message=message, url=None, sb=(survexblock.survexfile.path)
)
else: else:
# these errors are reporting the wrong survexblock, which is actually a SurvexFile (!) # these errors are reporting the wrong survexblock, which is actually a SurvexFile (!)
# see To Do notes on how to trigger this. Still needs investigating.. # see To Do notes on how to trigger this. Still needs investigating..
@ -737,13 +762,16 @@ class LoadingSurvex:
print(f" {type(survexblock)=}") # survexblock.parent fails as a SurvexFile has no .parent ...ugh. print(f" {type(survexblock)=}") # survexblock.parent fails as a SurvexFile has no .parent ...ugh.
print(f" {survexblock.survexpath=}") print(f" {survexblock.survexpath=}")
print(f" {survexblock.survexfile=}") print(f" {survexblock.survexfile=}")
# Not setting 'year' crashes entire import on databaseReset.
year = line[:4]
perps = get_people_on_trip(survexblock)
# raise # raise
try: try:
setdate_on_survexblock(year) setdate_on_survexblock(year)
except NameError: except NameError:
print(">> why is year not set ?! {survexblock.survexfile.path}") print(f">> why is year not set ?! {survexblock.survexfile.path}")
setdate_on_survexblock("1970") setdate_on_survexblock("1976")
if survexblock.date: if survexblock.date:
# do not actually need a distict variable 'currentdate' but it makes the code clearer # do not actually need a distict variable 'currentdate' but it makes the code clearer
self.currentdate = survexblock.date self.currentdate = survexblock.date
@ -1383,8 +1411,8 @@ class LoadingSurvex:
self.fix_undated(survexblock) # null-op if already set self.fix_undated(survexblock) # null-op if already set
try: try:
expoyear = str(survexblock.date.year) expoyear = str(survexblock.date.year)
except NameError: except:
print(">> why is survexblock.date.year not set ?! in LoadSurvexQM()/n {survexblock.survexfile.path}") print(f">> why is survexblock not set ?! in LoadSurvexQM()/n {survexblock.survexfile.path}")
expoyear = "1970" expoyear = "1970"