summaryrefslogtreecommitdiffstats
path: root/parsers/survex.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2020-06-24 14:49:39 +0100
committerPhilip Sargent <philip.sargent@klebos.com>2020-06-24 14:49:39 +0100
commit45bbfce4d35917cbdbc68b903fc4eb7b3108b411 (patch)
tree999572814f2d76c3f1096dbf04a033a44d9736cf /parsers/survex.py
parentbb69cc073a7cc26a3da6840841b6ec6eca665a51 (diff)
downloadtroggle-45bbfce4d35917cbdbc68b903fc4eb7b3108b411.tar.gz
troggle-45bbfce4d35917cbdbc68b903fc4eb7b3108b411.tar.bz2
troggle-45bbfce4d35917cbdbc68b903fc4eb7b3108b411.zip
extract *ref, ;ref and ;QMs to functions
Diffstat (limited to 'parsers/survex.py')
-rw-r--r--parsers/survex.py153
1 files changed, 77 insertions, 76 deletions
diff --git a/parsers/survex.py b/parsers/survex.py
index c4d9609..959bd26 100644
--- a/parsers/survex.py
+++ b/parsers/survex.py
@@ -67,7 +67,7 @@ class LoadSurvex():
def __init__(self):
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,
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.
- 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
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):
"""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
mref = comment and self.rx_ref.match(comment)
if mref:
- yr, letterx, wallet = mref.groups()
- 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)
+ self.LoadSurvexRef(insp, survexblock, mref)
- # 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)
if 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)
-
- # 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
+ self.LoadSurvexQM(insp, qmline)
if not sline:
continue
@@ -252,25 +271,7 @@ class LoadSurvex():
# detect the star ref command
mstar = self.rx_starref.match(sline)
if mstar:
- 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()
- 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
+ self.LoadSurvexRef(insp, survexblock, mstar)
# detect the star command
mstar = self.rx_star.match(sline)
@@ -495,7 +496,7 @@ def LoadAllSurvexBlocks():
memstart = models.get_process_memory()
survexlegsnumber, survexlegsalllength = FindAndLoadAllSurvex(survexblockroot, survexfileroot)
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.legsall = survexlegsnumber