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