extract *ref, ;ref and ;QMs to functions

This commit is contained in:
Philip Sargent 2020-06-24 14:49:39 +01:00
parent bb69cc073a
commit 45bbfce4d3

View File

@ -67,7 +67,7 @@ class LoadSurvex():
def __init__(self): def __init__(self):
pass pass
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.
""" """
@ -143,9 +143,80 @@ class LoadSurvex():
# No need to save as we are measuring lengths only on parsing now. # No need to save as we are measuring lengths only on parsing now.
def LoadSurvexLinePassage(self,survexblock, stardata, sline, comment): def LoadSurvexLinePassage(self, survexblock, stardata, sline, comment):
# 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):
# *REF but also ; Ref
yr,letterx,wallet = mstar.groups()
if not letterx:
letterx = ""
else:
letterx = "X"
if len(wallet)<2:
wallet = "0" + wallet
assert (int(yr)>1960 and int(yr)<2039), "Wallet year out of bounds: %s" % yr
assert (int(wallet)<100), "Wallet number more than 100: %s" % wallet
refscan = "%s#%s%s" % (yr, letterx, wallet)
manyscansfolders = models_survex.ScansFolder.objects.filter(walletname=refscan)
if manyscansfolders:
survexblock.scansfolder = manyscansfolders[0]
survexblock.save()
if len(manyscansfolders) > 1:
message = ' ! Wallet *REF {} - multiple scan folders found {}'.format(refscan, survexblock.survexfile.path)
print((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))
models.DataIssue.objects.create(parser='survex', message=message)
def LoadSurvexQM(self, insp, qmline):
qm_no = qmline.group(1)
qm_grade = qmline.group(2)
qm_from_section = qmline.group(3)
qm_from_station = qmline.group(4)
qm_resolve_section = qmline.group(6)
qm_resolve_station = qmline.group(7)
qm_notes = qmline.group(8)
# This whole section should be moved if we can have *QM become a proper survex command
# Spec of QM in SVX files, currently commented out need to add to survex
# needs to match self.rx_qm
# ;Serial number grade(A/B/C/D/X) nearest-station resolution-station description
# ;QM1 a hobnob_hallway_2.42 hobnob-hallway_3.42 junction of keyhole passage
# ;QM1 a hobnob_hallway_2.42 - junction of keyhole passage
# print(insp+'Cave - %s' % survexfile.cave)
# print(insp+'QM no %d' % int(qm_no))
# print(insp+'QM grade %s' % qm_grade)
# print(insp+'QM section %s' % qm_from_section)
# print(insp+'QM station %s' % qm_from_station)
# print(insp+'QM res section %s' % qm_resolve_section)
# print(insp+'QM res station %s' % qm_resolve_station)
# print(insp+'QM notes %s' % qm_notes)
# If the QM isn't resolved (has a resolving station) then load it
if not qm_resolve_section or qm_resolve_section != '-' or qm_resolve_section != 'None':
from_section = models_survex.SurvexBlock.objects.filter(name=qm_from_section)
# If we can find a section (survex note chunk, named)
if len(from_section) > 0:
from_station = models_survex.SurvexStation.objects.filter(block=from_section[0], name=qm_from_station)
# If we can find a from station then we have the nearest station and can import it
if len(from_station) > 0:
qm = models_caves.QM.objects.create(number=qm_no,
nearest_station=from_station[0],
grade=qm_grade.upper(),
location_description=qm_notes)
else:
message = ' ! QM in svx file NOT resolved and NOT found {}'.format(qm_notes)
print(insp+message)
models.DataIssue.objects.create(parser='survex', message=message)
else:
print(insp+' - QM found but resolved {}'.format(qm_notes))
pass
def RecursiveLoad(self,survexblock, survexfile, fin): def RecursiveLoad(self,survexblock, survexfile, fin):
"""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
@ -188,63 +259,11 @@ class LoadSurvex():
# detect ref line pointing to the scans directory # 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:
yr, letterx, wallet = mref.groups() self.LoadSurvexRef(insp, survexblock, mref)
if not letterx:
letterx = ""
else:
letterx = "X"
if len(wallet)<2:
wallet = "0" + wallet
refscan = "%s#%s%s" % (yr, letterx, wallet )
manyscansfolders = models_survex.ScansFolder.objects.filter(walletname=refscan)
if manyscansfolders:
survexblock.scansfolder = manyscansfolders[0]
survexblock.save()
else:
message = ' ! Wallet ; ref {} - NOT found in manyscansfolders {}'.format(refscan, survexblock.survexfile.path)
print((insp+message))
models.DataIssue.objects.create(parser='survex', message=message)
# This whole section should be moved if we can have *QM become a proper survex command
# Spec of QM in SVX files, currently commented out need to add to survex
# needs to match self.rx_qm
# ;Serial number grade(A/B/C/D/X) nearest-station resolution-station description
# ;QM1 a hobnob_hallway_2.42 hobnob-hallway_3.42 junction of keyhole passage
# ;QM1 a hobnob_hallway_2.42 - junction of keyhole passage
qmline = comment and self.rx_qm.match(comment) qmline = comment and self.rx_qm.match(comment)
if qmline: if qmline:
qm_no = qmline.group(1) self.LoadSurvexQM(insp, qmline)
qm_grade = qmline.group(2)
qm_from_section = qmline.group(3)
qm_from_station = qmline.group(4)
qm_resolve_section = qmline.group(6)
qm_resolve_station = qmline.group(7)
qm_notes = qmline.group(8)
# print(insp+'Cave - %s' % survexfile.cave)
# print(insp+'QM no %d' % int(qm_no))
# print(insp+'QM grade %s' % qm_grade)
# print(insp+'QM section %s' % qm_from_section)
# print(insp+'QM station %s' % qm_from_station)
# print(insp+'QM res section %s' % qm_resolve_section)
# print(insp+'QM res station %s' % qm_resolve_station)
# print(insp+'QM notes %s' % qm_notes)
# If the QM isn't resolved (has a resolving station) then load it
if not qm_resolve_section or qm_resolve_section != '-' or qm_resolve_section != 'None':
from_section = models_survex.SurvexBlock.objects.filter(name=qm_from_section)
# If we can find a section (survex note chunck, named)
if len(from_section) > 0:
from_station = models_survex.SurvexStation.objects.filter(block=from_section[0], name=qm_from_station)
# If we can find a from station then we have the nearest station and can import it
if len(from_station) > 0:
qm = models_caves.QM.objects.create(number=qm_no,
nearest_station=from_station[0],
grade=qm_grade.upper(),
location_description=qm_notes)
else:
# print(insp+' - QM found but resolved')
pass
if not sline: if not sline:
continue continue
@ -252,25 +271,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:
yr,letterx,wallet = mstar.groups() self.LoadSurvexRef(insp, survexblock, mstar)
if not letterx:
letterx = ""
else:
letterx = "X"
if len(wallet)<2:
wallet = "0" + wallet
assert (int(yr)>1960 and int(yr)<2039), "Wallet year out of bounds: %s" % yr
assert (int(wallet)<100), "Wallet number more than 100: %s" % wallet
refscan = "%s#%s%s" % (yr, letterx, wallet)
manyscansfolders = models_survex.ScansFolder.objects.filter(walletname=refscan)
if manyscansfolders:
survexblock.scansfolder = manyscansfolders[0]
survexblock.save()
else:
message = ' ! Wallet *REF {} - NOT found in manyscansfolders {}'.format(refscan, survexblock.survexfile.path)
print((insp+message))
models.DataIssue.objects.create(parser='survex', message=message)
continue
# detect the star command # detect the star command
mstar = self.rx_star.match(sline) mstar = self.rx_star.match(sline)
@ -495,7 +496,7 @@ def LoadAllSurvexBlocks():
memstart = models.get_process_memory() memstart = models.get_process_memory()
survexlegsnumber, survexlegsalllength = FindAndLoadAllSurvex(survexblockroot, survexfileroot) survexlegsnumber, survexlegsalllength = FindAndLoadAllSurvex(survexblockroot, survexfileroot)
memend = models.get_process_memory() memend = models.get_process_memory()
print(" - MEMORY start:{:.3f} MB end:{:.3f} MB increase={:.3f} MB",format(memstart,memend,memend-memstart)) print(" - MEMORY start:{:.3f} MB end:{:.3f} MB increase={:.3f} MB".format(memstart,memend, memend-memstart))
survexblockroot.totalleglength = survexlegsalllength survexblockroot.totalleglength = survexlegsalllength
survexblockroot.legsall = survexlegsnumber survexblockroot.legsall = survexlegsnumber