2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-01-19 17:32:31 +00:00

extract *date function

This commit is contained in:
Philip Sargent 2020-06-24 17:55:42 +01:00
parent 45bbfce4d3
commit 3645c98685

View File

@ -63,10 +63,22 @@ class LoadSurvex():
survexlegsnumber = 0 survexlegsnumber = 0
insp = "" insp = ""
callcount = 0 callcount = 0
stardata ={}
def __init__(self): def __init__(self):
pass pass
def LoadSurvexDate(self, survexblock, line):
# we should make this a date range for everything
if len(line) == 10:
survexblock.date = make_aware(datetime.strptime(re.sub(r"\.", "-", line), '%Y-%m-%d'), get_current_timezone())
expeditions = models.Expedition.objects.filter(year=line[:4])
if expeditions:
assert len(expeditions) == 1
survexblock.expedition = expeditions[0]
survexblock.expeditionday = survexblock.expedition.get_expedition_day(survexblock.date)
survexblock.save()
def LoadSurvexLineLeg(self, survexblock, stardata, sline, comment): def LoadSurvexLineLeg(self, survexblock, stardata, sline, comment):
"""This reads compass, clino and tape data but only keeps the tape lengths, """This reads compass, clino and tape data but only keeps the tape lengths,
the rest is discarded after error-checking. the rest is discarded after error-checking.
@ -147,7 +159,7 @@ class LoadSurvex():
# do not import this: *data passage.. data which is LRUD not tape/compass/clino # do not import this: *data passage.. data which is LRUD not tape/compass/clino
pass pass
def LoadSurvexRef(self, insp, survexblock, mstar): def LoadSurvexRef(self, survexblock, mstar):
# *REF but also ; Ref # *REF but also ; Ref
yr,letterx,wallet = mstar.groups() yr,letterx,wallet = mstar.groups()
if not letterx: if not letterx:
@ -165,15 +177,15 @@ class LoadSurvex():
survexblock.save() survexblock.save()
if len(manyscansfolders) > 1: if len(manyscansfolders) > 1:
message = ' ! Wallet *REF {} - multiple scan folders found {}'.format(refscan, survexblock.survexfile.path) message = ' ! Wallet *REF {} - multiple scan folders found {}'.format(refscan, survexblock.survexfile.path)
print((insp+message)) print((self.insp+message))
models.DataIssue.objects.create(parser='survex', message=message) models.DataIssue.objects.create(parser='survex', message=message)
else: else:
message = ' ! Wallet *REF {} - NOT found in manyscansfolders {}'.format(refscan, survexblock.survexfile.path) message = ' ! Wallet *REF {} - NOT found in manyscansfolders {}'.format(refscan, survexblock.survexfile.path)
print((insp+message)) print((self.insp+message))
models.DataIssue.objects.create(parser='survex', message=message) models.DataIssue.objects.create(parser='survex', message=message)
def LoadSurvexQM(self, insp, qmline): def LoadSurvexQM(self, insp, survexblock, qmline):
qm_no = qmline.group(1) qm_no = qmline.group(1)
qm_grade = qmline.group(2) qm_grade = qmline.group(2)
qm_from_section = qmline.group(3) qm_from_section = qmline.group(3)
@ -210,11 +222,13 @@ class LoadSurvex():
grade=qm_grade.upper(), grade=qm_grade.upper(),
location_description=qm_notes) location_description=qm_notes)
else: else:
message = ' ! QM in svx file NOT resolved and NOT found {}'.format(qm_notes) message = ' ! QM {} in {} NOT resolved and NOT found'.format(qm_no, survexblock.survexfile.path)
print(insp+message) print(insp+message)
models.DataIssue.objects.create(parser='survex', message=message) models.DataIssue.objects.create(parser='survex', message=message)
else: else:
print(insp+' - QM found but resolved {}'.format(qm_notes)) message = ' ! QM {} in {} found and resolved as {}'.format(qm_no, survexblock.survexfile.path,qm_resolve_section)
print(insp+message)
models.DataIssue.objects.create(parser='survex', message=message)
pass pass
@ -222,7 +236,7 @@ class LoadSurvex():
"""Follows the *include links in all the survex files from the root file 1623.svx """Follows the *include links in all the survex files from the root file 1623.svx
and reads in the survex blocks, other data and the wallet references (scansfolder) as it and reads in the survex blocks, other data and the wallet references (scansfolder) as it
goes. This part of the data import process is where the maximum memory is used and where it goes. This part of the data import process is where the maximum memory is used and where it
crashes on memory-constrained machines. crashes on memory-constrained machines. Begin-end blocks may also be nested.
""" """
iblankbegins = 0 iblankbegins = 0
text = [ ] text = [ ]
@ -256,14 +270,13 @@ class LoadSurvex():
lineno += 1 lineno += 1
# break the line at the comment # break the line at the comment
sline, comment = self.rx_comment.match(svxline.strip()).groups() sline, comment = self.rx_comment.match(svxline.strip()).groups()
# detect ref line pointing to the scans directory
mref = comment and self.rx_ref.match(comment) mref = comment and self.rx_ref.match(comment)
if mref: if mref:
self.LoadSurvexRef(insp, survexblock, mref) self.LoadSurvexRef(survexblock, mref)
qmline = comment and self.rx_qm.match(comment) qmline = comment and self.rx_qm.match(comment)
if qmline: if qmline:
self.LoadSurvexQM(insp, qmline) self.LoadSurvexQM(insp, survexblock, qmline)
if not sline: if not sline:
continue continue
@ -271,7 +284,7 @@ class LoadSurvex():
# detect the star ref command # detect the star ref command
mstar = self.rx_starref.match(sline) mstar = self.rx_starref.match(sline)
if mstar: if mstar:
self.LoadSurvexRef(insp, survexblock, mstar) self.LoadSurvexRef(survexblock, mstar)
# detect the star command # detect the star command
mstar = self.rx_star.match(sline) mstar = self.rx_star.match(sline)
@ -368,19 +381,10 @@ class LoadSurvex():
print(insp+" - LEGS: {} (previous: {}, now:{})".format(legsinblock,previousnlegs,self.survexlegsnumber)) print(insp+" - LEGS: {} (previous: {}, now:{})".format(legsinblock,previousnlegs,self.survexlegsnumber))
survexblock.legsall = legsinblock survexblock.legsall = legsinblock
survexblock.save() survexblock.save()
endstamp = datetime.now()
timetaken = endstamp - stamp
return return
elif re.match("date$(?i)", cmd): elif re.match("date$(?i)", cmd):
if len(line) == 10: self.LoadSurvexDate(survexblock, line)
survexblock.date = make_aware(datetime.strptime(re.sub(r"\.", "-", line), '%Y-%m-%d'), get_current_timezone())
expeditions = models.Expedition.objects.filter(year=line[:4])
if expeditions:
assert len(expeditions) == 1
survexblock.expedition = expeditions[0]
survexblock.expeditionday = survexblock.expedition.get_expedition_day(survexblock.date)
survexblock.save()
elif re.match("team$(?i)", cmd): elif re.match("team$(?i)", cmd):
pass pass
@ -411,6 +415,7 @@ class LoadSurvex():
stardata = { "type":ls[0] } stardata = { "type":ls[0] }
for i in range(0, len(ls)): for i in range(0, len(ls)):
stardata[self.stardataparamconvert.get(ls[i], ls[i])] = i - 1 stardata[self.stardataparamconvert.get(ls[i], ls[i])] = i - 1
self.stardata = stardata
if ls[0] in ["normal", "cartesian", "nosurvey"]: if ls[0] in ["normal", "cartesian", "nosurvey"]:
assert (("from" in stardata and "to" in stardata) or "station" in stardata), line assert (("from" in stardata and "to" in stardata) or "station" in stardata), line
elif ls[0] == "default": elif ls[0] == "default":