forked from expo/troggle
rename variables and leglength calc
This commit is contained in:
@@ -48,7 +48,8 @@ class LoadingSurvex():
|
|||||||
rx_comminc = re.compile(r'(?i)^\*include[\s]*([-\w/]*).*$') # inserted by linear collate ;*include
|
rx_comminc = re.compile(r'(?i)^\*include[\s]*([-\w/]*).*$') # inserted by linear collate ;*include
|
||||||
rx_commcni = re.compile(r'(?i)^\*edulcni[\s]*([-\w/]*).*$') # inserted by linear collate ;*edulcni
|
rx_commcni = re.compile(r'(?i)^\*edulcni[\s]*([-\w/]*).*$') # inserted by linear collate ;*edulcni
|
||||||
rx_include = re.compile(r'(?i)^\s*(\*include[\s].*)$')
|
rx_include = re.compile(r'(?i)^\s*(\*include[\s].*)$')
|
||||||
rx_ref = re.compile(r'(?i)^\s*ref[\s.:]*(\d+)\s*#\s*(X)?\s*(\d+)')
|
rx_ref = re.compile(r'(?i)^\s*ref(erence)?[\s.:]*(\d+)\s*#\s*(X)?\s*(\d+)')
|
||||||
|
rx_ref_text= re.compile(r'(?i)^\s*\"[^"]*\"\s*$')
|
||||||
rx_star = re.compile(r'(?i)\s*\*[\s,]*(\w+)\s*(.*?)\s*(?:;.*)?$')
|
rx_star = re.compile(r'(?i)\s*\*[\s,]*(\w+)\s*(.*?)\s*(?:;.*)?$')
|
||||||
rx_starref = re.compile(r'(?i)^\s*\*ref[\s.:]*((?:19[6789]\d)|(?:20[0123]\d))\s*#?\s*(X)?\s*(.*?\d+.*?)$')
|
rx_starref = re.compile(r'(?i)^\s*\*ref[\s.:]*((?:19[6789]\d)|(?:20[0123]\d))\s*#?\s*(X)?\s*(.*?\d+.*?)$')
|
||||||
rx_argsref = re.compile(r'(?i)^[\s.:]*((?:19[6789]\d)|(?:20[0123]\d))\s*#?\s*(X)?\s*(.*?\d+.*?)$')
|
rx_argsref = re.compile(r'(?i)^[\s.:]*((?:19[6789]\d)|(?:20[0123]\d))\s*#?\s*(X)?\s*(.*?\d+.*?)$')
|
||||||
@@ -56,14 +57,16 @@ 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
|
||||||
datastardefault = {"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, "skiplegs":False}
|
||||||
|
|
||||||
datastar ={}
|
datastar ={}
|
||||||
flagsstar = {}
|
flagsstar = {}
|
||||||
survexlegsalllength = 0.0
|
slength = 0.0
|
||||||
survexlegsnumber = 0
|
legsnumber = 0
|
||||||
depthbegin = 0
|
depthbegin = 0
|
||||||
depthinclude = 0
|
depthinclude = 0
|
||||||
|
legsnumberstack = []
|
||||||
|
slengthstack = []
|
||||||
stackbegin =[]
|
stackbegin =[]
|
||||||
flagsstack =[]
|
flagsstack =[]
|
||||||
datastack =[]
|
datastack =[]
|
||||||
@@ -134,6 +137,13 @@ 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.
|
||||||
"""
|
"""
|
||||||
|
invalid_clino = 180.0
|
||||||
|
invalid_compass = 720.0
|
||||||
|
invalid_tape = 0.0
|
||||||
|
|
||||||
|
# if self.flagsstar["skiplegs"]:
|
||||||
|
# return
|
||||||
|
|
||||||
#print("! LEG datastar type:{}++{}\n{} ".format(self.datastar["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.datastar["type"] == "passage":
|
if self.datastar["type"] == "passage":
|
||||||
@@ -146,20 +156,14 @@ class LoadingSurvex():
|
|||||||
return
|
return
|
||||||
if self.datastar["type"] == "cylpolar":
|
if self.datastar["type"] == "cylpolar":
|
||||||
return
|
return
|
||||||
#print(" !! LEG data lineno:{}\n !! sline:'{}'\n !! datastar['tape']: {}".format(self.lineno, sline, self.datastar["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.flagsstar["any"]:
|
|
||||||
# survexleg.tape = invalid_tape
|
|
||||||
# #return
|
|
||||||
if self.datastar["type"] != "normal":
|
if self.datastar["type"] != "normal":
|
||||||
return
|
return
|
||||||
|
|
||||||
invalid_clino = 180.0
|
|
||||||
invalid_compass = 720.0
|
|
||||||
invalid_tape = 0.0
|
|
||||||
datastar = self.datastar # shallow copy: alias but the things inside are the same things
|
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:
|
||||||
@@ -174,12 +178,12 @@ class LoadingSurvex():
|
|||||||
return
|
return
|
||||||
# this next fails for two surface survey svx files which use / for decimal point
|
# 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' in the tape measurement, or use decimals but in brackets, e.g. (06.05)
|
||||||
tape = tape.replace("(","")
|
# tape = tape.replace("(","") # edited original file (only one) instead
|
||||||
tape = tape.replace(")","")
|
# tape = tape.replace(")","") # edited original file (only one) instead
|
||||||
tape = tape.replace("/",".")
|
# tape = tape.replace("/",".") # edited original file (only one) instead.
|
||||||
try:
|
try:
|
||||||
survexleg.tape = float(tape)
|
survexleg.tape = float(tape)
|
||||||
self.survexlegsnumber += 1
|
self.legsnumber += 1
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print(("! Tape misread in", survexblock.survexfile.path))
|
print(("! Tape misread in", survexblock.survexfile.path))
|
||||||
print((" datastar:", datastar))
|
print((" datastar:", datastar))
|
||||||
@@ -189,7 +193,7 @@ class LoadingSurvex():
|
|||||||
survexleg.tape = invalid_tape
|
survexleg.tape = invalid_tape
|
||||||
try:
|
try:
|
||||||
survexblock.totalleglength += survexleg.tape
|
survexblock.totalleglength += survexleg.tape
|
||||||
self.survexlegsalllength += survexleg.tape
|
self.slength += survexleg.tape
|
||||||
except ValueError:
|
except ValueError:
|
||||||
message = ' ! Value Error: Tape length not added %s in %s' % (ls, survexblock.survexfile.path)
|
message = ' ! Value Error: Tape length not added %s in %s' % (ls, survexblock.survexfile.path)
|
||||||
models.DataIssue.objects.create(parser='survexleg', message=message)
|
models.DataIssue.objects.create(parser='survexleg', message=message)
|
||||||
@@ -234,20 +238,23 @@ class LoadingSurvex():
|
|||||||
models.DataIssue.objects.create(parser='survexleg', message=message)
|
models.DataIssue.objects.create(parser='survexleg', message=message)
|
||||||
survexleg.compass = invalid_compass
|
survexleg.compass = invalid_compass
|
||||||
|
|
||||||
# For speed this should come first. But we are checking validity too.
|
if self.flagsstar["skiplegs"]:
|
||||||
if self.flagsstar["any"]:
|
return
|
||||||
pass
|
# delete the object to save memory
|
||||||
# Comment out until we have the *data commands working!
|
|
||||||
#survexleg.tape = invalid_tape
|
|
||||||
#return
|
|
||||||
|
|
||||||
# delete the object to save memory
|
|
||||||
survexleg = None
|
survexleg = None
|
||||||
|
|
||||||
def LoadSurvexRef(self, survexblock, args):
|
def LoadSurvexRef(self, survexblock, args):
|
||||||
|
print(self.insp+ "*REF ---- '"+ args +"'")
|
||||||
|
|
||||||
# *REF but also ; Ref years from 1960 to 2039
|
# *REF but also ; Ref years from 1960 to 2039
|
||||||
|
refline = self.rx_ref_text.match(args)
|
||||||
|
if refline:
|
||||||
|
# a textual reference such as "1996-1999 Not-KH survey book pp 92-95"
|
||||||
|
print(self.insp+ "*REF quoted text so ignored:"+ args)
|
||||||
|
return
|
||||||
|
|
||||||
if len(args)< 4:
|
if len(args)< 4:
|
||||||
message = " ! Empty or BAD *REF command '{}' in '{}'".format(args, survexblock.survexfile.path)
|
message = " ! Empty or BAD *REF statement '{}' in '{}'".format(args, survexblock.survexfile.path)
|
||||||
print((self.insp+message))
|
print((self.insp+message))
|
||||||
models.DataIssue.objects.create(parser='survex', message=message)
|
models.DataIssue.objects.create(parser='survex', message=message)
|
||||||
return
|
return
|
||||||
@@ -256,8 +263,8 @@ class LoadingSurvex():
|
|||||||
if argsgps:
|
if argsgps:
|
||||||
yr, letterx, wallet = argsgps.groups()
|
yr, letterx, wallet = argsgps.groups()
|
||||||
else:
|
else:
|
||||||
message = " ! BAD *REF command '{}' in '{}'".format(args, survexblock.survexfile.path)
|
message = " ! BAD *REF statement '{}' in '{}'".format(args, survexblock.survexfile.path)
|
||||||
print((self.insp+message))
|
print(self.insp+message)
|
||||||
models.DataIssue.objects.create(parser='survex', message=message)
|
models.DataIssue.objects.create(parser='survex', message=message)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -372,10 +379,10 @@ class LoadingSurvex():
|
|||||||
self.datastar = copy.deepcopy(datastar)
|
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.datastar["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)
|
||||||
@@ -412,7 +419,7 @@ class LoadingSurvex():
|
|||||||
# if self.flagsstar["duplicate"] == True or self.flagsstar["surface"] == True or self.flagsstar["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.flagsstar["surface"] == True or self.flagsstar["splay"] == True:
|
if self.flagsstar["surface"] == True or self.flagsstar["splay"] == True:
|
||||||
self.flagsstar["any"] = True
|
self.flagsstar["skiplegs"] = True
|
||||||
|
|
||||||
def IdentifyCave(self, cavepath):
|
def IdentifyCave(self, cavepath):
|
||||||
if cavepath.lower() in self.caveslist:
|
if cavepath.lower() in self.caveslist:
|
||||||
@@ -459,18 +466,17 @@ class LoadingSurvex():
|
|||||||
print("\n"+message)
|
print("\n"+message)
|
||||||
print("\n"+message,file=sys.stderr)
|
print("\n"+message,file=sys.stderr)
|
||||||
models.DataIssue.objects.create(parser='survex', message=message)
|
models.DataIssue.objects.create(parser='survex', message=message)
|
||||||
|
|
||||||
def LoadSurvexFile(self, svxid):
|
def LoadSurvexFile(self, svxid):
|
||||||
"""Creates SurvexFile in the database, and SurvexDirectory if needed
|
"""Creates SurvexFile in the database, and SurvexDirectory if needed
|
||||||
with links to 'cave'
|
with links to 'cave'
|
||||||
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.datastar = self.datastardefault
|
# print(" # datastack in LoadSurvexFile:{} 'type':".format(svxid), end="")
|
||||||
print(" # datastack in LoadSurvexFile:{} 'type':".format(svxid), end="")
|
# for dict in self.datastack:
|
||||||
for dict in self.datastack:
|
# print("'{}' ".format(dict["type"].upper()), end="")
|
||||||
print("'{}' ".format(dict["type"].upper()), end="")
|
# print("")
|
||||||
print("")
|
|
||||||
|
|
||||||
|
|
||||||
depth = " " * self.depthbegin
|
depth = " " * self.depthbegin
|
||||||
@@ -512,10 +518,11 @@ class LoadingSurvex():
|
|||||||
print(newdirectory.primarysurvexfile, file=sys.stderr)
|
print(newdirectory.primarysurvexfile, file=sys.stderr)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
print(" # datastack end LoadSurvexFile:{} 'type':".format(svxid), end="")
|
# print(" # datastack end LoadSurvexFile:{} 'type':".format(svxid), end="")
|
||||||
for dict in self.datastack:
|
# for dict in self.datastack:
|
||||||
print("'{}' ".format(dict["type"].upper()), end="")
|
# print("'{}' ".format(dict["type"].upper()), end="")
|
||||||
print("")
|
# print("")
|
||||||
|
pass
|
||||||
|
|
||||||
def ProcessIncludeLine(self, included):
|
def ProcessIncludeLine(self, included):
|
||||||
svxid = included.groups()[0]
|
svxid = included.groups()[0]
|
||||||
@@ -555,7 +562,7 @@ class LoadingSurvex():
|
|||||||
def LoadSurvexSetup(self,survexblock, survexfile):
|
def LoadSurvexSetup(self,survexblock, survexfile):
|
||||||
self.depthbegin = 0
|
self.depthbegin = 0
|
||||||
self.datastar = self.datastardefault
|
self.datastar = self.datastardefault
|
||||||
blocklegs = self.survexlegsnumber
|
blocklegs = self.legsnumber
|
||||||
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
|
||||||
sys.stderr.flush();
|
sys.stderr.flush();
|
||||||
@@ -576,6 +583,14 @@ class LoadingSurvex():
|
|||||||
"""Loads a single survex file. Usually used to import all the survex files which have been collated
|
"""Loads a single survex file. Usually used to import all the survex files which have been collated
|
||||||
into a single file. Loads the begin/end blocks using a stack for labels.
|
into a single file. Loads the begin/end blocks using a stack for labels.
|
||||||
"""
|
"""
|
||||||
|
blkid = None
|
||||||
|
pathlist = None
|
||||||
|
args = None
|
||||||
|
oldflags = None
|
||||||
|
blockcount = 0
|
||||||
|
self.lineno = 0
|
||||||
|
slengthtotal = 0.0
|
||||||
|
nlegstotal = 0
|
||||||
self.relativefilename = path
|
self.relativefilename = path
|
||||||
cave = self.IdentifyCave(path) # this will produce null for survex files which are geographic collections
|
cave = self.IdentifyCave(path) # this will produce null for survex files which are geographic collections
|
||||||
|
|
||||||
@@ -584,13 +599,6 @@ class LoadingSurvex():
|
|||||||
|
|
||||||
self.datastar = copy.deepcopy(self.datastardefault)
|
self.datastar = copy.deepcopy(self.datastardefault)
|
||||||
self.flagsstar = copy.deepcopy(self.flagsdefault)
|
self.flagsstar = copy.deepcopy(self.flagsdefault)
|
||||||
blkid = None
|
|
||||||
pathlist = None
|
|
||||||
args = None
|
|
||||||
previousnlegs = None
|
|
||||||
oldflags = None
|
|
||||||
blockcount = 0
|
|
||||||
self.lineno = 0
|
|
||||||
|
|
||||||
def tickle():
|
def tickle():
|
||||||
nonlocal blockcount
|
nonlocal blockcount
|
||||||
@@ -609,6 +617,7 @@ class LoadingSurvex():
|
|||||||
nonlocal pathlist
|
nonlocal pathlist
|
||||||
|
|
||||||
depth = " " * self.depthbegin
|
depth = " " * self.depthbegin
|
||||||
|
self.insp = depth
|
||||||
print("{:2}{} - Begin for :'{}'".format(self.depthbegin,depth, blkid))
|
print("{:2}{} - Begin for :'{}'".format(self.depthbegin,depth, blkid))
|
||||||
pathlist = ""
|
pathlist = ""
|
||||||
for id in self.stackbegin:
|
for id in self.stackbegin:
|
||||||
@@ -617,31 +626,28 @@ class LoadingSurvex():
|
|||||||
|
|
||||||
def printend():
|
def printend():
|
||||||
nonlocal args
|
nonlocal args
|
||||||
nonlocal previousnlegs
|
|
||||||
|
|
||||||
depth = " " * self.depthbegin
|
depth = " " * self.depthbegin
|
||||||
print("{:2}{} - End from:'{}'".format(self.depthbegin,depth,args))
|
print("{:2}{} - End from:'{}'".format(self.depthbegin,depth,args))
|
||||||
legsinblock = self.survexlegsnumber - previousnlegs
|
print("{:2}{} - LEGS: {} (n: {}, length:{})".format(self.depthbegin,
|
||||||
print("{:2}{} - LEGS: {} (previous: {}, now:{})".format(self.depthbegin,
|
depth, self.slength, self.slength, self.legsnumber))
|
||||||
depth, legsinblock, previousnlegs, self.survexlegsnumber))
|
|
||||||
survexblock.legsall = legsinblock
|
|
||||||
|
|
||||||
def pushblock():
|
def pushblock():
|
||||||
nonlocal blkid
|
nonlocal blkid
|
||||||
|
|
||||||
print(" # datastack at 1 *begin {} 'type':".format(blkid), end="")
|
# print(" # datastack at 1 *begin {} 'type':".format(blkid), end="")
|
||||||
for dict in self.datastack:
|
# for dict in self.datastack:
|
||||||
print("'{}' ".format(dict["type"].upper()), end="")
|
# print("'{}' ".format(dict["type"].upper()), end="")
|
||||||
print("")
|
# print("")
|
||||||
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
# print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
||||||
# ------------ * DATA
|
# ------------ * DATA
|
||||||
self.datastack.append(copy.deepcopy(self.datastar))
|
self.datastack.append(copy.deepcopy(self.datastar))
|
||||||
# ------------ * DATA
|
# ------------ * DATA
|
||||||
print(" # datastack at 2 *begin {} 'type':".format(blkid), end="")
|
# print(" # datastack at 2 *begin {} 'type':".format(blkid), end="")
|
||||||
for dict in self.datastack:
|
# for dict in self.datastack:
|
||||||
print("'{}' ".format(dict["type"].upper()), end="")
|
# print("'{}' ".format(dict["type"].upper()), end="")
|
||||||
print("")
|
# print("")
|
||||||
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
# print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
||||||
# ------------ * FLAGS
|
# ------------ * FLAGS
|
||||||
self.flagsstack.append(copy.deepcopy(self.flagsstar))
|
self.flagsstack.append(copy.deepcopy(self.flagsstar))
|
||||||
# ------------ * FLAGS
|
# ------------ * FLAGS
|
||||||
@@ -650,32 +656,33 @@ class LoadingSurvex():
|
|||||||
nonlocal blkid
|
nonlocal blkid
|
||||||
nonlocal oldflags
|
nonlocal oldflags
|
||||||
|
|
||||||
print(" # datastack at *end '{} 'type':".format(blkid), end="")
|
# print(" # datastack at *end '{} 'type':".format(blkid), end="")
|
||||||
for dict in self.datastack:
|
# for dict in self.datastack:
|
||||||
print("'{}' ".format(dict["type"].upper()), end="")
|
# print("'{}' ".format(dict["type"].upper()), end="")
|
||||||
print("")
|
# print("")
|
||||||
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
# print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
||||||
# ------------ * DATA
|
# ------------ * DATA
|
||||||
self.datastar = copy.deepcopy(self.datastack.pop())
|
self.datastar = copy.deepcopy(self.datastack.pop())
|
||||||
# ------------ * DATA
|
# ------------ * DATA
|
||||||
print(" # datastack after *end '{} 'type':".format(blkid), end="")
|
# print(" # datastack after *end '{} 'type':".format(blkid), end="")
|
||||||
for dict in self.datastack:
|
# for dict in self.datastack:
|
||||||
print("'{}' ".format(dict["type"].upper()), end="")
|
# print("'{}' ".format(dict["type"].upper()), end="")
|
||||||
print("")
|
# print("")
|
||||||
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
# print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
||||||
# ------------ * FLAGS
|
# ------------ * FLAGS
|
||||||
self.flagsstar = copy.deepcopy(self.flagsstack.pop())
|
self.flagsstar = copy.deepcopy(self.flagsstack.pop())
|
||||||
# ------------ * FLAGS
|
# ------------ * FLAGS
|
||||||
if oldflags["any"] != self.flagsstar["any"]:
|
if oldflags["skiplegs"] != self.flagsstar["skiplegs"]:
|
||||||
print(" # POP 'any' flag now:'{}' was:{} ".format(self.flagsstar["any"], oldflags["any"]))
|
print(" # POP 'any' flag now:'{}' was:{} ".format(self.flagsstar["skiplegs"], oldflags["skiplegs"]))
|
||||||
|
|
||||||
def starstatement(mstar):
|
def starstatement(mstar):
|
||||||
nonlocal survexblock
|
nonlocal survexblock
|
||||||
nonlocal blkid
|
nonlocal blkid
|
||||||
nonlocal pathlist
|
nonlocal pathlist
|
||||||
nonlocal args
|
nonlocal args
|
||||||
nonlocal previousnlegs
|
|
||||||
nonlocal oldflags
|
nonlocal oldflags
|
||||||
|
nonlocal slengthtotal
|
||||||
|
nonlocal nlegstotal
|
||||||
|
|
||||||
cmd, args = mstar.groups()
|
cmd, args = mstar.groups()
|
||||||
cmd = cmd.lower()
|
cmd = cmd.lower()
|
||||||
@@ -685,9 +692,12 @@ class LoadingSurvex():
|
|||||||
blkid = args.lower()
|
blkid = args.lower()
|
||||||
# PUSH state ++++++++++++++
|
# PUSH state ++++++++++++++
|
||||||
self.stackbegin.append(blkid)
|
self.stackbegin.append(blkid)
|
||||||
|
self.legsnumberstack.append(self.legsnumber)
|
||||||
|
self.slengthstack.append(self.slength)
|
||||||
pushblock()
|
pushblock()
|
||||||
# PUSH state ++++++++++++++
|
# PUSH state ++++++++++++++
|
||||||
previousnlegs = self.survexlegsnumber
|
self.legsnumber = 0
|
||||||
|
self.slength = 0.0
|
||||||
printbegin()
|
printbegin()
|
||||||
newsurvexblock = models_survex.SurvexBlock(name=blkid, parent=survexblock,
|
newsurvexblock = models_survex.SurvexBlock(name=blkid, parent=survexblock,
|
||||||
survexpath=pathlist,
|
survexpath=pathlist,
|
||||||
@@ -701,7 +711,12 @@ class LoadingSurvex():
|
|||||||
|
|
||||||
# ---------------------------END
|
# ---------------------------END
|
||||||
elif re.match("end$(?i)", cmd):
|
elif re.match("end$(?i)", cmd):
|
||||||
|
survexblock.legsall = self.legsnumber
|
||||||
|
survexblock.totalleglength = self.slength
|
||||||
printend()
|
printend()
|
||||||
|
slengthtotal += self.slength
|
||||||
|
nlegstotal += self.legsnumber
|
||||||
|
|
||||||
try:
|
try:
|
||||||
survexblock.parent.save() # django insists on this although it is already saved !?
|
survexblock.parent.save() # django insists on this although it is already saved !?
|
||||||
except:
|
except:
|
||||||
@@ -714,12 +729,14 @@ class LoadingSurvex():
|
|||||||
raise
|
raise
|
||||||
# POP state ++++++++++++++
|
# POP state ++++++++++++++
|
||||||
popblock()
|
popblock()
|
||||||
|
self.legsnumber = self.legsnumberstack.pop()
|
||||||
|
self.slength = self.slengthstack.pop()
|
||||||
blkid = self.stackbegin.pop()
|
blkid = self.stackbegin.pop()
|
||||||
# POP state ++++++++++++++
|
|
||||||
self.currentsurvexblock = survexblock.parent
|
self.currentsurvexblock = survexblock.parent
|
||||||
survexblock = survexblock.parent
|
survexblock = survexblock.parent
|
||||||
oldflags = self.flagsstar
|
oldflags = self.flagsstar
|
||||||
self.depthbegin -= 1
|
self.depthbegin -= 1
|
||||||
|
# POP state ++++++++++++++
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
elif re.match("(?i)title$", cmd):
|
elif re.match("(?i)title$", cmd):
|
||||||
@@ -729,8 +746,8 @@ class LoadingSurvex():
|
|||||||
elif re.match("(?i)flags$", cmd):
|
elif re.match("(?i)flags$", cmd):
|
||||||
oldflags = self.flagsstar
|
oldflags = self.flagsstar
|
||||||
self.LoadSurvexFlags(args)
|
self.LoadSurvexFlags(args)
|
||||||
if oldflags["any"] != self.flagsstar["any"]:
|
if oldflags["skiplegs"] != self.flagsstar["skiplegs"]:
|
||||||
print(" # CHANGE 'any' flag now:'{}' was:{} ".format(self.flagsstar["any"], oldflags["any"]))
|
print(" # CHANGE 'any' flag now:'{}' was:{} ".format(self.flagsstar["skiplegs"], oldflags["skiplegs"]))
|
||||||
|
|
||||||
elif re.match("(?i)data$", cmd):
|
elif re.match("(?i)data$", cmd):
|
||||||
self.LoadSurvexDataCmd(survexblock, args)
|
self.LoadSurvexDataCmd(survexblock, args)
|
||||||
@@ -761,11 +778,14 @@ class LoadingSurvex():
|
|||||||
|
|
||||||
# detect a star command
|
# detect a star command
|
||||||
mstar = self.rx_star.match(sline)
|
mstar = self.rx_star.match(sline)
|
||||||
if mstar: # yes we are reading a *cmd
|
if mstar:
|
||||||
|
# yes we are reading a *command
|
||||||
starstatement(mstar)
|
starstatement(mstar)
|
||||||
else: # not a *cmd so we are reading data OR rx_comment failed
|
else: # not a *cmd so we are reading data OR a ";" rx_comment failed
|
||||||
self.LoadSurvexLineLeg(survexblock, sline, comment)
|
self.LoadSurvexLineLeg(survexblock, sline, comment)
|
||||||
|
|
||||||
|
self.legsnumber = slengthtotal
|
||||||
|
self.slength = nlegstotal
|
||||||
|
|
||||||
def RecursiveScan(self, survexblock, path, fin, flinear, fcollate):
|
def RecursiveScan(self, survexblock, path, fin, flinear, fcollate):
|
||||||
"""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
|
||||||
@@ -783,7 +803,7 @@ class LoadingSurvex():
|
|||||||
|
|
||||||
|
|
||||||
if path in self.svxfileslist:
|
if path in self.svxfileslist:
|
||||||
message = " * Warning. Duplicate in *include list at:{} depth:{} file:{}".format(self.callcount, self.depthinclude, path)
|
message = " * Warning. Duplicate detected in *include list at callcount:{} depth:{} file:{}".format(self.callcount, self.depthinclude, path)
|
||||||
print(message)
|
print(message)
|
||||||
print(message,file=flinear)
|
print(message,file=flinear)
|
||||||
print("\n"+message,file=sys.stderr)
|
print("\n"+message,file=sys.stderr)
|
||||||
@@ -879,7 +899,7 @@ class LoadingSurvex():
|
|||||||
svx_t = now - 365*24*3600
|
svx_t = now - 365*24*3600
|
||||||
|
|
||||||
def runcavern():
|
def runcavern():
|
||||||
print(" - Regenerating stale (or chaos-monkeyed) cavern .log and .3d for '{}'\n days svx old: {:.1f} cav old:{:.1f} log old: {:.1f}".
|
print(" - Regenerating stale (or chaos-monkeyed) cavern .log and .3d for '{}'\n days svx old: {:.1f} cav:{:.1f} log old: {:.1f}".
|
||||||
format(fullpath, (svx_t - log_t)/(24*3600), (cav_t - log_t)/(24*3600), (now - log_t)/(24*3600)))
|
format(fullpath, (svx_t - log_t)/(24*3600), (cav_t - log_t)/(24*3600), (now - log_t)/(24*3600)))
|
||||||
call([settings.CAVERN, "--log", "--output={}".format(fullpath), "{}.svx".format(fullpath)])
|
call([settings.CAVERN, "--log", "--output={}".format(fullpath), "{}.svx".format(fullpath)])
|
||||||
|
|
||||||
@@ -919,7 +939,7 @@ def FindAndLoadSurvex(survexblockroot):
|
|||||||
# Redirect sys.stdout to the file
|
# Redirect sys.stdout to the file
|
||||||
sys.stdout = open('svxblks.log', 'w')
|
sys.stdout = open('svxblks.log', 'w')
|
||||||
|
|
||||||
print(' - SCANNING All Survex Blocks...',file=sys.stderr)
|
print(' - Scanning Survex Blocks tree from {}.svx ...'.format(settings.SURVEX_TOPNAME),file=sys.stderr)
|
||||||
survexfileroot = survexblockroot.survexfile # i.e. SURVEX_TOPNAME only
|
survexfileroot = survexblockroot.survexfile # i.e. SURVEX_TOPNAME only
|
||||||
collatefilename = "_" + survexfileroot.path + ".svx"
|
collatefilename = "_" + survexfileroot.path + ".svx"
|
||||||
|
|
||||||
@@ -980,8 +1000,8 @@ def FindAndLoadSurvex(survexblockroot):
|
|||||||
print("\n - MEM:{:7.2f} MB STOP".format(mem1),file=sys.stderr)
|
print("\n - MEM:{:7.2f} MB STOP".format(mem1),file=sys.stderr)
|
||||||
print(" - MEM:{:7.3f} MB USED".format(mem1-mem0),file=sys.stderr)
|
print(" - MEM:{:7.3f} MB USED".format(mem1-mem0),file=sys.stderr)
|
||||||
|
|
||||||
survexlegsnumber = svx_load.survexlegsnumber
|
legsnumber = svx_load.legsnumber
|
||||||
survexlegsalllength = svx_load.survexlegsalllength
|
slength = svx_load.slength
|
||||||
mem1 = models.get_process_memory()
|
mem1 = models.get_process_memory()
|
||||||
|
|
||||||
print(" - Number of SurvexDirectories: {}".format(len(svx_load.survexdict)))
|
print(" - Number of SurvexDirectories: {}".format(len(svx_load.survexdict)))
|
||||||
@@ -996,7 +1016,7 @@ def FindAndLoadSurvex(survexblockroot):
|
|||||||
print("+", file=sys.stderr)
|
print("+", file=sys.stderr)
|
||||||
sys.stderr.flush();
|
sys.stderr.flush();
|
||||||
sys.stdout = stdout_orig
|
sys.stdout = stdout_orig
|
||||||
return (survexlegsnumber, survexlegsalllength)
|
return (legsnumber, slength)
|
||||||
|
|
||||||
def MakeSurvexFileRoot():
|
def MakeSurvexFileRoot():
|
||||||
"""Returns a file_object.path = SURVEX_TOPNAME associated with directory_object.path = SURVEX_DATA
|
"""Returns a file_object.path = SURVEX_TOPNAME associated with directory_object.path = SURVEX_DATA
|
||||||
@@ -1030,22 +1050,23 @@ def LoadSurvexBlocks():
|
|||||||
print(' - Loading Survex Blocks...')
|
print(' - Loading Survex Blocks...')
|
||||||
memstart = models.get_process_memory()
|
memstart = models.get_process_memory()
|
||||||
#----------------------------------------------------------------
|
#----------------------------------------------------------------
|
||||||
survexlegsnumber, survexlegsalllength = FindAndLoadSurvex(survexblockroot)
|
legsnumber, slength = FindAndLoadSurvex(survexblockroot)
|
||||||
#----------------------------------------------------------------
|
#----------------------------------------------------------------
|
||||||
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
|
# Don't do this, it double-counts everything:
|
||||||
survexblockroot.legsall = survexlegsnumber
|
#survexblockroot.totalleglength = slength
|
||||||
|
#survexblockroot.legsall = legsnumber
|
||||||
survexblockroot.save()
|
survexblockroot.save()
|
||||||
|
|
||||||
print(" - total number of survex legs: {}".format(survexlegsnumber))
|
print(" - total number of survex legs: {}".format(legsnumber))
|
||||||
print(" - total leg lengths loaded: {}m".format(survexlegsalllength))
|
print(" - total leg lengths loaded: {}m".format(slength))
|
||||||
print(' - Loaded All Survex Blocks.')
|
print(' - Loaded All Survex Blocks.')
|
||||||
|
|
||||||
poslineregex = re.compile(r"^\(\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*)\s*\)\s*([^\s]+)$")
|
poslineregex = re.compile(r"^\(\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*)\s*\)\s*([^\s]+)$")
|
||||||
|
|
||||||
def LoadPos():
|
def LoadPositions():
|
||||||
"""First load the survex stations for entrances and fixed points (about 600) into the database.
|
"""First load the survex stations for entrances and fixed points (about 600) into the database.
|
||||||
Run cavern to produce a complete .3d file, then run 3dtopos to produce a table of
|
Run cavern to produce a complete .3d file, then run 3dtopos to produce a table of
|
||||||
all survey point positions. Then lookup each position by name to see if we have it in the database
|
all survey point positions. Then lookup each position by name to see if we have it in the database
|
||||||
@@ -1074,6 +1095,7 @@ def LoadPos():
|
|||||||
|
|
||||||
svxpath = topdata + ".svx"
|
svxpath = topdata + ".svx"
|
||||||
d3dpath = topdata + ".3d"
|
d3dpath = topdata + ".3d"
|
||||||
|
pospath = topdata + ".pos"
|
||||||
|
|
||||||
svx_t = os.path.getmtime(svxpath)
|
svx_t = os.path.getmtime(svxpath)
|
||||||
|
|
||||||
@@ -1082,11 +1104,13 @@ def LoadPos():
|
|||||||
d3d_t = os.path.getmtime(d3dpath)
|
d3d_t = os.path.getmtime(d3dpath)
|
||||||
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
|
if not os.path.isfile(pospath):
|
||||||
|
runcavern3d()
|
||||||
if not os.path.isfile(d3dpath):
|
if not os.path.isfile(d3dpath):
|
||||||
runcavern3d()
|
runcavern3d()
|
||||||
elif svx_t - d3d_t > 0: # stale, 3d older than svx file
|
elif d3d_t - svx_t > 0: # stale, 3d older than svx file
|
||||||
runcavern3d()
|
runcavern3d()
|
||||||
elif now - d3d_t > 60 *24*60*60: # >60 days old, re-run anyway
|
elif now - d3d_t> 60 *24*60*60: # >60 days old, re-run anyway
|
||||||
runcavern3d()
|
runcavern3d()
|
||||||
elif cav_t - d3d_t > 0: # new version of cavern
|
elif cav_t - d3d_t > 0: # new version of cavern
|
||||||
runcavern3d()
|
runcavern3d()
|
||||||
|
|||||||
Reference in New Issue
Block a user