summaryrefslogtreecommitdiffstats
path: root/parsers/survex.py
diff options
context:
space:
mode:
Diffstat (limited to 'parsers/survex.py')
-rw-r--r--parsers/survex.py101
1 files changed, 71 insertions, 30 deletions
diff --git a/parsers/survex.py b/parsers/survex.py
index 272dc19..4d47d7b 100644
--- a/parsers/survex.py
+++ b/parsers/survex.py
@@ -57,7 +57,7 @@ class LoadingSurvex():
# This interprets the survex "*data normal" command which sets out the order of the fields in the data, e.g.
# *DATA normal from to length gradient bearing ignore ignore ignore ignore
datastardefault = {"type":"normal", "from":0, "to":1, "tape":2, "compass":3, "clino":4}
- flagsdefault = {"duplicate":False, "surface":False, "splay":False, "skiplegs":False}
+ flagsdefault = {"duplicate":False, "surface":False, "splay":False, "skiplegs":False, "splayalias":False}
datastar ={}
flagsstar = {}
@@ -74,6 +74,7 @@ class LoadingSurvex():
stacksvxfiles = []
svxfileslist = []
svxdirs = {}
+ expos = {}
survexdict = {} # each key is a directory, and its value is a list of files
lineno = 0
insp = ""
@@ -93,11 +94,11 @@ class LoadingSurvex():
def LoadSurvexIgnore(self, survexblock, line, cmd):
if cmd == "require":
pass # should we check survex version available for processing?
- elif cmd in ["equate", "fix", "alias", "calibrate", "cs","entrance", "export", "case",
+ elif cmd in ["equate", "fix", "calibrate", "cs", "export", "case",
"declination", "infer","instrument", "sd", "units"]:
pass # we ignore all these, which is fine.
else:
- if cmd in ["include", "data", "flags", "title", "set", "ref"]:
+ if cmd in ["include", "data", "flags", "title", "entrance","set", "units", "alias", "ref"]:
message = "! Unparsed [*{}]: '{}' {}".format(cmd, line, survexblock.survexfile.path)
print((self.insp+message))
models.DataIssue.objects.create(parser='survex', message=message)
@@ -122,18 +123,40 @@ class LoadingSurvex():
personrole.person=personexpedition.person
personrole.save()
+ def LoadSurvexEntrance(self, survexblock, line):
+ # Not using this yet
+ pass
+
+ def LoadSurvexAlias(self, survexblock, line):
+ # *alias station - ..
+ splayalias = re.match("(?i)station\s*\-\s*\.\.\s*$",line)
+ if splayalias:
+ self.flagsstar["splayalias"] = True
+ else:
+ message = "! Bad *ALIAS: '{}' ({}) {}".format(line, survexblock, survexblock.survexfile.path)
+ print((self.insp+message))
+ models.DataIssue.objects.create(parser='survex', message=message)
+
def LoadSurvexDate(self, survexblock, line):
# we should make this a date range for everything
if len(line) == 10:
+ year = line[:4]
+ # make_aware is a django function, and may not be correct to use it like this anyway! We want Austrian time.
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:
+ # cacheing to save DB query on every block and to prepare for django-less troggle in future
+ if year in self.expos:
+ expo = self.expos[year]
+ else:
+ expeditions = models.Expedition.objects.filter(year=year)
assert len(expeditions) == 1
- survexblock.expedition = expeditions[0]
- survexblock.expeditionday = survexblock.expedition.get_expedition_day(survexblock.date)
- survexblock.save()
+ expo= expeditions[0]
+ self.expos[year]= expo
- def LoadSurvexLineLeg(self, survexblock, sline, comment):
+ survexblock.expedition = expo
+ survexblock.expeditionday = survexblock.expedition.get_expedition_day(survexblock.date)
+ survexblock.save()
+
+ def LoadSurvexLeg(self, survexblock, sline, comment):
"""This reads compass, clino and tape data but only keeps the tape lengths,
the rest is discarded after error-checking.
"""
@@ -141,8 +164,9 @@ class LoadingSurvex():
invalid_compass = 720.0
invalid_tape = 0.0
- # if self.flagsstar["skiplegs"]:
- # return
+ if self.flagsstar["skiplegs"]:
+ #print("skip in ", self.flagsstar, survexblock.survexfile.path)
+ return
#print("! LEG datastar type:{}++{}\n{} ".format(self.datastar["type"].upper(), survexblock.survexfile.path, sline))
# SKIP PASSAGES *data passage
@@ -165,7 +189,22 @@ class LoadingSurvex():
survexleg = SurvexLeg()
ls = sline.lower().split()
-
+
+ # skip all splay legs
+ if ls[datastar["from"]] == "..":
+ #print("Splay in ", survexblock.survexfile.path)
+ return
+ if ls[datastar["to"]] == "..":
+ #print("Splay in ", survexblock.survexfile.path)
+ return
+ if self.flagsstar["splayalias"]:
+ if ls[datastar["from"]] == "-":
+ #print("Aliased splay in ", survexblock.survexfile.path)
+ return
+ if ls[datastar["to"]] == "-":
+ #print("Aliased splay in ", survexblock.survexfile.path)
+ return
+
try:
tape = ls[datastar["tape"]]
except:
@@ -176,8 +215,7 @@ class LoadingSurvex():
models.DataIssue.objects.create(parser='survexleg', message=message)
survexleg.tape = invalid_tape
return
- # this next fails for two surface survey svx files which use / for decimal point
- # e.g. '29/09' in the tape measurement, or use decimals but in brackets, e.g. (06.05)
+ # e.g. '29/09' or '(06.05)' in the tape measurement
# tape = tape.replace("(","") # edited original file (only one) instead
# tape = tape.replace(")","") # edited original file (only one) instead
# tape = tape.replace("/",".") # edited original file (only one) instead.
@@ -192,7 +230,7 @@ class LoadingSurvex():
models.DataIssue.objects.create(parser='survexleg', message=message)
survexleg.tape = invalid_tape
try:
- survexblock.totalleglength += survexleg.tape
+ survexblock.legslength += survexleg.tape
self.slength += survexleg.tape
except ValueError:
message = ' ! Value Error: Tape length not added %s in %s' % (ls, survexblock.survexfile.path)
@@ -238,8 +276,6 @@ class LoadingSurvex():
models.DataIssue.objects.create(parser='survexleg', message=message)
survexleg.compass = invalid_compass
- if self.flagsstar["skiplegs"]:
- return
# delete the object to save memory
survexleg = None
@@ -651,6 +687,7 @@ class LoadingSurvex():
# ------------ * FLAGS
self.flagsstack.append(copy.deepcopy(self.flagsstar))
# ------------ * FLAGS
+ pass
def popblock():
nonlocal blkid
@@ -675,7 +712,7 @@ class LoadingSurvex():
if oldflags["skiplegs"] != self.flagsstar["skiplegs"]:
print(" # POP 'any' flag now:'{}' was:{} ".format(self.flagsstar["skiplegs"], oldflags["skiplegs"]))
- def starstatement(mstar):
+ def starstatement(star):
nonlocal survexblock
nonlocal blkid
nonlocal pathlist
@@ -684,7 +721,7 @@ class LoadingSurvex():
nonlocal slengthtotal
nonlocal nlegstotal
- cmd, args = mstar.groups()
+ cmd, args = star.groups()
cmd = cmd.lower()
# ------------------------BEGIN
@@ -702,7 +739,7 @@ class LoadingSurvex():
newsurvexblock = models_survex.SurvexBlock(name=blkid, parent=survexblock,
survexpath=pathlist,
cave=self.currentcave, survexfile=self.currentsurvexfile,
- legsall=0, legssplay=0, legssurfc=0, totalleglength=0.0)
+ legsall=0, legslength=0.0)
newsurvexblock.save()
newsurvexblock.title = "("+survexblock.title+")" # copy parent inititally
survexblock = newsurvexblock
@@ -712,7 +749,7 @@ class LoadingSurvex():
# ---------------------------END
elif re.match("end$(?i)", cmd):
survexblock.legsall = self.legsnumber
- survexblock.totalleglength = self.slength
+ survexblock.legslength = self.slength
printend()
slengthtotal += self.slength
nlegstotal += self.legsnumber
@@ -751,6 +788,10 @@ class LoadingSurvex():
elif re.match("(?i)data$", cmd):
self.LoadSurvexDataCmd(survexblock, args)
+ elif re.match("(?i)alias$", cmd):
+ self.LoadSurvexAlias(survexblock, args)
+ elif re.match("(?i)entrance$", cmd):
+ self.LoadSurvexEntrance(survexblock, args)
elif re.match("(?i)date$", cmd):
self.LoadSurvexDate(survexblock, args)
elif re.match("(?i)team$", cmd):
@@ -777,12 +818,12 @@ class LoadingSurvex():
continue # skip blank lines
# detect a star command
- mstar = self.rx_star.match(sline)
- if mstar:
+ star = self.rx_star.match(sline)
+ if star:
# yes we are reading a *command
- starstatement(mstar)
+ starstatement(star)
else: # not a *cmd so we are reading data OR a ";" rx_comment failed
- self.LoadSurvexLineLeg(survexblock, sline, comment)
+ self.LoadSurvexLeg(survexblock, sline, comment)
self.legsnumber = slengthtotal
self.slength = nlegstotal
@@ -825,9 +866,9 @@ class LoadingSurvex():
fcollate.write("{}\n".format(svxline.strip()))
sline, comment = self.rx_comment.match(svxline.strip()).groups()
- mstar = self.rx_star.match(sline)
- if mstar: # yes we are reading a *cmd
- cmd, args = mstar.groups()
+ star = self.rx_star.match(sline)
+ if star: # yes we are reading a *cmd
+ cmd, args = star.groups()
cmd = cmd.lower()
if re.match("(?i)include$", cmd):
includepath = os.path.normpath(os.path.join(os.path.split(path)[0], re.sub(r"\.svx$", "", args)))
@@ -1043,7 +1084,7 @@ def LoadSurvexBlocks():
survexfileroot = MakeSurvexFileRoot()
# this next makes a block_object assciated with a file_object.path = SURVEX_TOPNAME
survexblockroot = models_survex.SurvexBlock(name=ROOTBLOCK, survexpath="", cave=None, survexfile=survexfileroot,
- legsall=0, legssplay=0, legssurfc=0, totalleglength=0.0)
+ legsall=0, legslength=0.0)
# this is the first so id=1
survexblockroot.save()
@@ -1056,7 +1097,7 @@ def LoadSurvexBlocks():
print(" - MEMORY start:{:.3f} MB end:{:.3f} MB increase={:.3f} MB".format(memstart,memend, memend-memstart))
# Don't do this, it double-counts everything:
- #survexblockroot.totalleglength = slength
+ #survexblockroot.legslength = slength
#survexblockroot.legsall = legsnumber
survexblockroot.save()