2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-01-19 09:22:32 +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
insp = ""
callcount = 0
stardata ={}
def __init__(self):
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):
"""This reads compass, clino and tape data but only keeps the tape lengths,
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
pass
def LoadSurvexRef(self, insp, survexblock, mstar):
def LoadSurvexRef(self, survexblock, mstar):
# *REF but also ; Ref
yr,letterx,wallet = mstar.groups()
if not letterx:
@ -165,15 +177,15 @@ class LoadSurvex():
survexblock.save()
if len(manyscansfolders) > 1:
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)
else:
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)
def LoadSurvexQM(self, insp, qmline):
def LoadSurvexQM(self, insp, survexblock, qmline):
qm_no = qmline.group(1)
qm_grade = qmline.group(2)
qm_from_section = qmline.group(3)
@ -210,11 +222,13 @@ class LoadSurvex():
grade=qm_grade.upper(),
location_description=qm_notes)
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)
models.DataIssue.objects.create(parser='survex', message=message)
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
@ -222,7 +236,7 @@ class LoadSurvex():
"""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
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
text = [ ]
@ -256,14 +270,13 @@ class LoadSurvex():
lineno += 1
# break the line at the comment
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)
if mref:
self.LoadSurvexRef(insp, survexblock, mref)
self.LoadSurvexRef(survexblock, mref)
qmline = comment and self.rx_qm.match(comment)
if qmline:
self.LoadSurvexQM(insp, qmline)
self.LoadSurvexQM(insp, survexblock, qmline)
if not sline:
continue
@ -271,7 +284,7 @@ class LoadSurvex():
# detect the star ref command
mstar = self.rx_starref.match(sline)
if mstar:
self.LoadSurvexRef(insp, survexblock, mstar)
self.LoadSurvexRef(survexblock, mstar)
# detect the star command
mstar = self.rx_star.match(sline)
@ -368,19 +381,10 @@ class LoadSurvex():
print(insp+" - LEGS: {} (previous: {}, now:{})".format(legsinblock,previousnlegs,self.survexlegsnumber))
survexblock.legsall = legsinblock
survexblock.save()
endstamp = datetime.now()
timetaken = endstamp - stamp
return
elif re.match("date$(?i)", cmd):
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()
self.LoadSurvexDate(survexblock, line)
elif re.match("team$(?i)", cmd):
pass
@ -411,6 +415,7 @@ class LoadSurvex():
stardata = { "type":ls[0] }
for i in range(0, len(ls)):
stardata[self.stardataparamconvert.get(ls[i], ls[i])] = i - 1
self.stardata = stardata
if ls[0] in ["normal", "cartesian", "nosurvey"]:
assert (("from" in stardata and "to" in stardata) or "station" in stardata), line
elif ls[0] == "default":