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

stack-based state of *data fixed

This commit is contained in:
Philip Sargent 2020-07-03 17:22:15 +01:00
parent 67f66b72e8
commit fd6f0b0a35

View File

@ -55,18 +55,18 @@ class LoadingSurvex():
# This interprets the survex "*data normal" command which sets out the order of the fields in the data, e.g. # 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 # *DATA normal from to length gradient bearing ignore ignore ignore ignore
stardatadefault = {"type":"normal", "from":0, "to":1, "tape":2, "compass":3, "clino":4} datastardefault = {"type":"normal", "from":0, "to":1, "tape":2, "compass":3, "clino":4}
flagsdefault = {"duplicate":False, "surface":False, "splay":False, "any":False} flagsdefault = {"duplicate":False, "surface":False, "splay":False, "any":False}
stardata ={} datastar ={}
starflags = {} flagsstar = {}
survexlegsalllength = 0.0 survexlegsalllength = 0.0
survexlegsnumber = 0 survexlegsnumber = 0
depthbegin = 0 depthbegin = 0
depthinclude = 0 depthinclude = 0
stackbegin =[] stackbegin =[]
stackflags =[] flagsstack =[]
stackdata =[] datastack =[]
stackinclude = [] stackinclude = []
stacksvxfiles = [] stacksvxfiles = []
svxfileslist = [] svxfileslist = []
@ -134,41 +134,41 @@ class LoadingSurvex():
"""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.
""" """
#print("! LEG stardata type:{}++{}\n{} ".format(self.stardata["type"].upper(), survexblock.survexfile.path, sline)) #print("! LEG datastar type:{}++{}\n{} ".format(self.datastar["type"].upper(), survexblock.survexfile.path, sline))
# SKIP PASSAGES *data passage # SKIP PASSAGES *data passage
if self.stardata["type"] == "passage": if self.datastar["type"] == "passage":
return return
if self.stardata["type"] == "cartesian": if self.datastar["type"] == "cartesian":
return return
if self.stardata["type"] == "nosurvey": if self.datastar["type"] == "nosurvey":
return return
if self.stardata["type"] == "diving": if self.datastar["type"] == "diving":
return return
if self.stardata["type"] == "cylpolar": if self.datastar["type"] == "cylpolar":
return return
#print(" !! LEG data lineno:{}\n !! sline:'{}'\n !! stardata['tape']: {}".format(self.lineno, sline, self.stardata["tape"])) #print(" !! LEG data lineno:{}\n !! sline:'{}'\n !! datastar['tape']: {}".format(self.lineno, sline, self.datastar["tape"]))
# # For speed this should come first. But we are checking validity too. # # For speed this should come first. But we are checking validity too.
# if self.starflags["any"]: # if self.flagsstar["any"]:
# survexleg.tape = invalid_tape # survexleg.tape = invalid_tape
# #return # #return
if self.stardata["type"] != "normal": if self.datastar["type"] != "normal":
return return
invalid_clino = 180.0 invalid_clino = 180.0
invalid_compass = 720.0 invalid_compass = 720.0
invalid_tape = 0.0 invalid_tape = 0.0
stardata = self.stardata datastar = self.datastar # shallow copy: alias but the things inside are the same things
survexleg = SurvexLeg() survexleg = SurvexLeg()
ls = sline.lower().split() ls = sline.lower().split()
try: try:
tape = ls[stardata["tape"]] tape = ls[datastar["tape"]]
except: except:
print(("! stardata parsing incorrect", survexblock.survexfile.path)) print(("! datastar parsing incorrect", survexblock.survexfile.path))
print((" Stardata:", stardata)) print((" datastar:", datastar))
print((" Line:", ls)) print((" Line:", ls))
message = ' ! stardata parsing incorrect in line %s in %s' % (ls, survexblock.survexfile.path) message = ' ! datastar parsing incorrect in line %s in %s' % (ls, survexblock.survexfile.path)
models.DataIssue.objects.create(parser='survexleg', message=message) models.DataIssue.objects.create(parser='survexleg', message=message)
survexleg.tape = invalid_tape survexleg.tape = invalid_tape
return return
@ -182,7 +182,7 @@ class LoadingSurvex():
self.survexlegsnumber += 1 self.survexlegsnumber += 1
except ValueError: except ValueError:
print(("! Tape misread in", survexblock.survexfile.path)) print(("! Tape misread in", survexblock.survexfile.path))
print((" Stardata:", stardata)) print((" datastar:", datastar))
print((" Line:", ls)) print((" Line:", ls))
message = ' ! Value Error: Tape misread in line %s in %s' % (ls, survexblock.survexfile.path) message = ' ! Value Error: Tape misread in line %s in %s' % (ls, survexblock.survexfile.path)
models.DataIssue.objects.create(parser='survexleg', message=message) models.DataIssue.objects.create(parser='survexleg', message=message)
@ -195,20 +195,20 @@ class LoadingSurvex():
models.DataIssue.objects.create(parser='survexleg', message=message) models.DataIssue.objects.create(parser='survexleg', message=message)
try: try:
lcompass = ls[stardata["compass"]] lcompass = ls[datastar["compass"]]
except: except:
print(("! Compass not found in", survexblock.survexfile.path)) print(("! Compass not found in", survexblock.survexfile.path))
print((" Stardata:", stardata)) print((" datastar:", datastar))
print((" Line:", ls)) print((" Line:", ls))
message = ' ! Value Error: Compass not found in line %s in %s' % (ls, survexblock.survexfile.path) message = ' ! Value Error: Compass not found in line %s in %s' % (ls, survexblock.survexfile.path)
models.DataIssue.objects.create(parser='survexleg', message=message) models.DataIssue.objects.create(parser='survexleg', message=message)
lcompass = invalid_compass lcompass = invalid_compass
try: try:
lclino = ls[stardata["clino"]] lclino = ls[datastar["clino"]]
except: except:
print(("! Clino misread in", survexblock.survexfile.path)) print(("! Clino misread in", survexblock.survexfile.path))
print((" Stardata:", stardata)) print((" datastar:", datastar))
print((" Line:", ls)) print((" Line:", ls))
message = ' ! Value Error: Clino misread in line %s in %s' % (ls, survexblock.survexfile.path) message = ' ! Value Error: Clino misread in line %s in %s' % (ls, survexblock.survexfile.path)
models.DataIssue.objects.create(parser='survexleg', message=message) models.DataIssue.objects.create(parser='survexleg', message=message)
@ -227,7 +227,7 @@ class LoadingSurvex():
survexleg.compass = float(lcompass) survexleg.compass = float(lcompass)
except ValueError: except ValueError:
print(("! Compass misread in", survexblock.survexfile.path)) print(("! Compass misread in", survexblock.survexfile.path))
print((" Stardata:", stardata)) print((" datastar:", datastar))
print((" Line:", ls)) print((" Line:", ls))
message = " ! Value Error: lcompass:'{}' line {} in '{}'".format(lcompass, message = " ! Value Error: lcompass:'{}' line {} in '{}'".format(lcompass,
ls, survexblock.survexfile.path) ls, survexblock.survexfile.path)
@ -235,7 +235,7 @@ class LoadingSurvex():
survexleg.compass = invalid_compass survexleg.compass = invalid_compass
# For speed this should come first. But we are checking validity too. # For speed this should come first. But we are checking validity too.
if self.starflags["any"]: if self.flagsstar["any"]:
pass pass
# Comment out until we have the *data commands working! # Comment out until we have the *data commands working!
#survexleg.tape = invalid_tape #survexleg.tape = invalid_tape
@ -336,7 +336,7 @@ class LoadingSurvex():
*data normal from to tape compass clino *data normal from to tape compass clino
We are only collecting length data so we are disinterested in from, to, LRUD etc. We are only collecting length data so we are disinterested in from, to, LRUD etc.
""" """
# stardatadefault = { # included here as reference to help understand the code # datastardefault = { # included here as reference to help understand the code
# "type":"normal", # "type":"normal",
# "t":"leg", # "t":"leg",
# "from":0, # "from":0,
@ -344,39 +344,39 @@ class LoadingSurvex():
# "tape":2, # "tape":2,
# "compass":3, # "compass":3,
# "clino":4} # "clino":4}
stardata = self.stardatadefault datastar = copy.deepcopy(self.datastardefault)
if args == "": if args == "":
# naked '*data' which is relevant only for passages. Ignore. Continue with previous settings. # naked '*data' which is relevant only for passages. Ignore. Continue with previous settings.
return return
# DEFAULT | NORMAL | CARTESIAN| NOSURVEY |PASSAGE | TOPOFIL | CYLPOLAR | DIVING # DEFAULT | NORMAL | CARTESIAN| NOSURVEY |PASSAGE | TOPOFIL | CYLPOLAR | DIVING
ls = args.lower().split() ls = args.lower().split()
if ls[0] == "default": if ls[0] == "default":
self.stardata = self.stardatadefault self.datastar = copy.deepcopy(self.datastardefault)
elif ls[0] == "normal" or ls[0] == "topofil": elif ls[0] == "normal" or ls[0] == "topofil":
if not ("from" in stardata and "to" in stardata): if not ("from" in datastar and "to" in datastar):
message = " ! - Unrecognised *data normal statement '{}' {}|{}".format(args, survexblock.name, survexblock.survexpath) message = " ! - Unrecognised *data normal statement '{}' {}|{}".format(args, survexblock.name, survexblock.survexpath)
print(message) print(message)
print(message,file=sys.stderr) print(message,file=sys.stderr)
models.DataIssue.objects.create(parser='survex', message=message) models.DataIssue.objects.create(parser='survex', message=message)
return return
else: else:
stardata = self.stardatadefault datastar = self.datastardefault
# ls = ["normal", "from", "to", "tape", "compass", "clino" ] # ls = ["normal", "from", "to", "tape", "compass", "clino" ]
for i in range(1, len(ls)): # len[0] is "normal" for i in range(1, len(ls)): # len[0] is "normal"
if ls[i] in ["bearing","compass"]: if ls[i] in ["bearing","compass"]:
stardata["compass"] = i-1 datastar["compass"] = i-1
if ls[i] in ["clino","gradient"]: if ls[i] in ["clino","gradient"]:
stardata["clino"] = i-1 datastar["clino"] = i-1
if ls[i] in ["tape","length"]: if ls[i] in ["tape","length"]:
stardata["tape"] = i-1 datastar["tape"] = i-1
self.stardata = stardata self.datastar = copy.deepcopy(datastar)
return return
elif ls[0] == "cartesian" or ls[0] == "nosurvey" or ls[0] == "diving" or ls[0] == "cylpolar" or ls[0] == "passage": elif ls[0] == "cartesian" or ls[0] == "nosurvey" or ls[0] == "diving" or ls[0] == "cylpolar" or ls[0] == "passage":
message = " ! - *data {} blocks ignored. {}|{}" '{}' .format(ls[0].upper(), survexblock.name, survexblock.survexpath, args) message = " ! - *data {} blocks ignored. {}|{}" '{}' .format(ls[0].upper(), survexblock.name, survexblock.survexpath, args)
print(message) print(message)
#print(message,file=sys.stderr) #print(message,file=sys.stderr)
#models.DataIssue.objects.create(parser='survex', message=message) #models.DataIssue.objects.create(parser='survex', message=message)
self.stardata["type"] = ls[0] self.datastar["type"] = ls[0]
else: else:
message = " ! - Unrecognised *data statement '{}' {}|{}".format(args, survexblock.name, survexblock.survexpath) message = " ! - Unrecognised *data statement '{}' {}|{}".format(args, survexblock.name, survexblock.survexpath)
print(message) print(message)
@ -386,7 +386,7 @@ class LoadingSurvex():
def LoadSurvexFlags(self, args): def LoadSurvexFlags(self, args):
# Valid flags are DUPLICATE, SPLAY, and SURFACE, and a flag may be preceded with NOT to turn it off. # Valid flags are DUPLICATE, SPLAY, and SURFACE, and a flag may be preceded with NOT to turn it off.
# Default values are NOT any of them # Default values are NOT any of them
self.starflags = copy.deepcopy(self.flagsdefault) self.flagsstar = copy.deepcopy(self.flagsdefault)
flags = [] flags = []
args = self.rx_flags.sub("not",args) args = self.rx_flags.sub("not",args)
@ -395,24 +395,24 @@ class LoadingSurvex():
flags.append(s) flags.append(s)
if "duplicate" in flags: if "duplicate" in flags:
self.starflags["duplicate"] = True self.flagsstar["duplicate"] = True
if "surface" in flags: if "surface" in flags:
self.starflags["surface"] = True self.flagsstar["surface"] = True
if "splay" in flags: if "splay" in flags:
self.starflags["splay"] = True self.flagsstar["splay"] = True
if "notduplicate" in flags: if "notduplicate" in flags:
self.starflags["duplicate"] = False self.flagsstar["duplicate"] = False
if "notsurface" in flags: if "notsurface" in flags:
self.starflags["surface"] = False self.flagsstar["surface"] = False
if "notsplay" in flags: if "notsplay" in flags:
self.starflags["splay"] = False self.flagsstar["splay"] = False
# if self.starflags["duplicate"] == True or self.starflags["surface"] == True or self.starflags["splay"] == True: # if self.flagsstar["duplicate"] == True or self.flagsstar["surface"] == True or self.flagsstar["splay"] == True:
# actually we do want to count duplicates as this is for "effort expended in surveying underground" # actually we do want to count duplicates as this is for "effort expended in surveying underground"
if self.starflags["surface"] == True or self.starflags["splay"] == True: if self.flagsstar["surface"] == True or self.flagsstar["splay"] == True:
self.starflags["any"] = True self.flagsstar["any"] = True
def IdentifyCave(self, cavepath): def IdentifyCave(self, cavepath):
if cavepath.lower() in self.caveslist: if cavepath.lower() in self.caveslist:
@ -444,6 +444,7 @@ class LoadingSurvex():
if headpath.lower() not in self.svxdirs: if headpath.lower() not in self.svxdirs:
self.svxdirs[headpath.lower()] = models_survex.SurvexDirectory(path=headpath, primarysurvexfile=self.currentsurvexfile) self.svxdirs[headpath.lower()] = models_survex.SurvexDirectory(path=headpath, primarysurvexfile=self.currentsurvexfile)
self.svxdirs[headpath.lower()].save() self.svxdirs[headpath.lower()].save()
self.survexdict[self.svxdirs[headpath.lower()]] = [] # list of the files in the directory
return self.svxdirs[headpath.lower()] return self.svxdirs[headpath.lower()]
def ReportNonCaveIncludes(self, headpath, includelabel): def ReportNonCaveIncludes(self, headpath, includelabel):
@ -465,7 +466,12 @@ class LoadingSurvex():
Creates a new current survexfile and valid .survexdirectory Creates a new current survexfile and valid .survexdirectory
The survexblock passed-in is not necessarily the parent. FIX THIS. The survexblock passed-in is not necessarily the parent. FIX THIS.
""" """
# self.stardata = self.stardatadefault # self.datastar = self.datastardefault
print(" # datastack in LoadSurvexFile:{} 'type':".format(svxid), end="")
for dict in self.datastack:
print("'{}' ".format(dict["type"].upper()), end="")
print("")
depth = " " * self.depthbegin depth = " " * self.depthbegin
print("{:2}{} - NEW survexfile:'{}'".format(self.depthbegin, depth, svxid)) print("{:2}{} - NEW survexfile:'{}'".format(self.depthbegin, depth, svxid))
@ -477,7 +483,7 @@ class LoadingSurvex():
newdirectory = self.GetSurvexDirectory(headpath) newdirectory = self.GetSurvexDirectory(headpath)
newdirectory.save() newdirectory.save()
newfile.survexdirectory = newdirectory newfile.survexdirectory = newdirectory
self.survexdict[newdirectory] = [newfile,] self.survexdict[newdirectory].append(newfile)
cave = self.IdentifyCave(headpath) # cave already exists in db cave = self.IdentifyCave(headpath) # cave already exists in db
if not newdirectory: if not newdirectory:
@ -505,6 +511,11 @@ class LoadingSurvex():
print(newdirectory, file=sys.stderr) print(newdirectory, file=sys.stderr)
print(newdirectory.primarysurvexfile, file=sys.stderr) print(newdirectory.primarysurvexfile, file=sys.stderr)
raise raise
print(" # datastack end LoadSurvexFile:{} 'type':".format(svxid), end="")
for dict in self.datastack:
print("'{}' ".format(dict["type"].upper()), end="")
print("")
def ProcessIncludeLine(self, included): def ProcessIncludeLine(self, included):
svxid = included.groups()[0] svxid = included.groups()[0]
@ -543,7 +554,7 @@ class LoadingSurvex():
def LoadSurvexSetup(self,survexblock, survexfile): def LoadSurvexSetup(self,survexblock, survexfile):
self.depthbegin = 0 self.depthbegin = 0
self.stardata = self.stardatadefault self.datastar = self.datastardefault
blocklegs = self.survexlegsnumber blocklegs = self.survexlegsnumber
print(self.insp+" - MEM:{:.3f} Reading. parent:{} <> {} ".format(models.get_process_memory(),survexblock.survexfile.path, survexfile.path)) print(self.insp+" - MEM:{:.3f} Reading. parent:{} <> {} ".format(models.get_process_memory(),survexblock.survexfile.path, survexfile.path))
self.lineno = 0 self.lineno = 0
@ -571,11 +582,11 @@ class LoadingSurvex():
self.currentsurvexfile = survexblock.survexfile self.currentsurvexfile = survexblock.survexfile
self.currentsurvexfile.save() # django insists on this although it is already saved !? self.currentsurvexfile.save() # django insists on this although it is already saved !?
self.stardata = copy.deepcopy(self.stardatadefault) self.datastar = copy.deepcopy(self.datastardefault)
#self.stackdata.append(self.stardata) # and extra push will do it ? #self.datastack.append(self.datastar) # and extra push will do it ?
self.starflags = copy.deepcopy(self.flagsdefault) self.flagsstar = copy.deepcopy(self.flagsdefault)
#self.stackflags.append(self.starflags) #self.flagsstack.append(self.flagsstar)
blockcount = 0 blockcount = 0
self.lineno = 0 self.lineno = 0
def tickle(): def tickle():
@ -611,12 +622,18 @@ class LoadingSurvex():
blkid = args.lower() blkid = args.lower()
self.stackbegin.append(blkid) self.stackbegin.append(blkid)
# PUSH state ++++++++++++++ # PUSH state ++++++++++++++
self.stackflags.append(copy.deepcopy(self.starflags)) print(" # datastack at 1 *begin {} 'type':".format(blkid), end="")
self.stackdata.append(copy.deepcopy(self.stardata)) for dict in self.datastack:
print(" # stackDATA after *begin 'type':", end="")
for dict in self.stackdata:
print("'{}' ".format(dict["type"].upper()), end="") print("'{}' ".format(dict["type"].upper()), end="")
print("") print("")
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
self.flagsstack.append(copy.deepcopy(self.flagsstar))
self.datastack.append(copy.deepcopy(self.datastar))
print(" # datastack at 2 *begin {} 'type':".format(blkid), end="")
for dict in self.datastack:
print("'{}' ".format(dict["type"].upper()), end="")
print("")
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
# PUSH state ++++++++++++++ # PUSH state ++++++++++++++
previousnlegs = self.survexlegsnumber previousnlegs = self.survexlegsnumber
@ -654,20 +671,26 @@ class LoadingSurvex():
except: except:
print(survexblock, file=sys.stderr) print(survexblock, file=sys.stderr)
raise raise
print(" # datastack at *end '{} 'type':".format(blkid), end="")
for dict in self.datastack:
print("'{}' ".format(dict["type"].upper()), end="")
print("")
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
# POP state ++++++++++++++
self.datastar = copy.deepcopy(self.datastack.pop())
print(" # datastack after *end '{} 'type':".format(blkid), end="")
for dict in self.datastack:
print("'{}' ".format(dict["type"].upper()), end="")
print("")
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
self.flagsstar = copy.deepcopy(self.flagsstack.pop())
if oldflags["any"] != self.flagsstar["any"]:
print(" # POP 'any' flag now:'{}' was:{} ".format(self.flagsstar["any"], oldflags["any"]))
# POP state ++++++++++++++
self.currentsurvexblock = survexblock.parent self.currentsurvexblock = survexblock.parent
survexblock = survexblock.parent survexblock = survexblock.parent
blkid = self.stackbegin.pop() blkid = self.stackbegin.pop()
oldflags = self.starflags oldflags = self.flagsstar
# POP state ++++++++++++++
self.stardata = copy.deepcopy(self.stackdata.pop())
print(" # stackDATA at *end 'type':", end="")
for dict in self.stackdata:
print("'{}' ".format(dict["type"].upper()), end="")
print("")
self.starflags = copy.deepcopy(self.stackflags.pop())
if oldflags["any"] != self.starflags["any"]:
print(" # POP 'any' flag now:'{}' was:{} ".format(self.starflags["any"], oldflags["any"]))
# POP state ++++++++++++++
self.depthbegin -= 1 self.depthbegin -= 1
# ----------------------------- # -----------------------------
@ -676,10 +699,10 @@ class LoadingSurvex():
elif re.match("(?i)ref$", cmd): elif re.match("(?i)ref$", cmd):
self.LoadSurvexRef(survexblock, args) self.LoadSurvexRef(survexblock, args)
elif re.match("(?i)flags$", cmd): elif re.match("(?i)flags$", cmd):
oldflags = self.starflags oldflags = self.flagsstar
self.LoadSurvexFlags(args) self.LoadSurvexFlags(args)
if oldflags["any"] != self.starflags["any"]: if oldflags["any"] != self.flagsstar["any"]:
print(" # CHANGE 'any' flag now:'{}' was:{} ".format(self.starflags["any"], oldflags["any"])) print(" # CHANGE 'any' flag now:'{}' was:{} ".format(self.flagsstar["any"], oldflags["any"]))
elif re.match("(?i)data$", cmd): elif re.match("(?i)data$", cmd):
self.LoadSurvexDataCmd(survexblock, args) self.LoadSurvexDataCmd(survexblock, args)
@ -900,7 +923,9 @@ def FindAndLoadSurvex(survexblockroot):
print('\n - Loading All Survex Blocks (LinearLoad)',file=sys.stderr) print('\n - Loading All Survex Blocks (LinearLoad)',file=sys.stderr)
svx_load = LoadingSurvex() svx_load = LoadingSurvex()
svx_load.survexdict[survexfileroot.survexdirectory] = []
svx_load.survexdict[survexfileroot.survexdirectory].append(survexfileroot)
svx_load.svxdirs[""] = survexfileroot.survexdirectory svx_load.svxdirs[""] = survexfileroot.survexdirectory
with open(collatefilename, "r") as fcollate: with open(collatefilename, "r") as fcollate:
svxlines = fcollate.read().splitlines() svxlines = fcollate.read().splitlines()