diff options
author | Martin Green <martin.speleo@gmail.com> | 2011-07-11 00:01:12 +0100 |
---|---|---|
committer | Martin Green <martin.speleo@gmail.com> | 2011-07-11 00:01:12 +0100 |
commit | a128401d49691337365222d9e91929be03a4060d (patch) | |
tree | 44ca180af8fd3cb3737a3d54de2b71741488f43c /parsers/survex.py | |
parent | 5075ded032150872641bc51afa34696a4c8370eb (diff) | |
download | troggle-a128401d49691337365222d9e91929be03a4060d.tar.gz troggle-a128401d49691337365222d9e91929be03a4060d.tar.bz2 troggle-a128401d49691337365222d9e91929be03a4060d.zip |
Added parsing of all.svx, along side parsing individual caves.
Added the making and parsing of all.pos to determine the location of stations.
Mare work is required so the caves are parsed and stored only once.
Survex parsing appears to include bugs, that print out errors.
Diffstat (limited to 'parsers/survex.py')
-rw-r--r-- | parsers/survex.py | 72 |
1 files changed, 65 insertions, 7 deletions
diff --git a/parsers/survex.py b/parsers/survex.py index f8ec6d4..2e0b8d3 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -1,5 +1,8 @@ import troggle.settings as settings import troggle.core.models as models +import troggle.settings as settings + +from subprocess import call, Popen, PIPE from troggle.parsers.people import GetPersonExpeditionNameLookup import re @@ -14,7 +17,13 @@ def LoadSurvexLineLeg(survexblock, stardata, sline, comment): survexleg = models.SurvexLeg(block=survexblock, stationfrom=ssfrom, stationto=ssto) if stardata["type"] == "normal": - survexleg.tape = float(ls[stardata["tape"]]) + try: + survexleg.tape = float(ls[stardata["tape"]]) + except ValueError: + print "Tape misread in", survexblock.survexfile.path + print "Stardata:", stardata + print "Line:", ls + survexleg.tape = 1000 lclino = ls[stardata["clino"]] lcompass = ls[stardata["compass"]] if lclino == "up": @@ -24,7 +33,13 @@ def LoadSurvexLineLeg(survexblock, stardata, sline, comment): survexleg.compass = 0.0 survexleg.clino = -90.0 elif lclino == "-" or lclino == "level": - survexleg.compass = float(lcompass) + try: + survexleg.compass = float(lcompass) + except ValueError: + print "Compass misread in", survexblock.survexfile.path + print "Stardata:", stardata + print "Line:", ls + survexleg.compass = 1000 survexleg.clino = -90.0 else: assert re.match("[\d\-+.]+$", lcompass), ls @@ -37,7 +52,10 @@ def LoadSurvexLineLeg(survexblock, stardata, sline, comment): itape = stardata.get("tape") if itape: - survexblock.totalleglength += float(ls[itape]) + try: + survexblock.totalleglength += float(ls[itape]) + except ValueError: + print "Length not added" survexblock.save() def LoadSurvexEquate(survexblock, sline): @@ -86,6 +104,7 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines): LoadSurvexLineLeg(survexblock, stardata, sline, comment) elif stardata["type"] == "passage": LoadSurvexLinePassage(survexblock, stardata, sline, comment) + #Missing "station" in stardata. continue # detect the star command @@ -151,8 +170,7 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines): for i in range(0, len(ls)): stardata[stardataparamconvert.get(ls[i], ls[i])] = i - 1 if ls[0] in ["normal", "cartesian", "nosurvey"]: - assert "from" in stardata, line - assert "to" in stardata, line + assert (("from" in stardata and "to" in stardata) or "station" in stardata), line elif ls[0] == "default": stardata = stardatadefault else: @@ -162,7 +180,7 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines): LoadSurvexEquate(survexblock, sline) else: - assert cmd.lower() in [ "sd", "equate", "include", "units", "entrance", "fix", "data", "flags", "title", "export", "instrument", "calibrate", ], (cmd, line, survexblock) + assert cmd.lower() in [ "sd", "equate", "include", "units", "entrance", "fix", "data", "flags", "title", "export", "instrument", "calibrate", "set", "infer"], (cmd, line, survexblock) @@ -186,6 +204,30 @@ def ReloadSurvexCave(survex_cave): def LoadAllSurvexBlocks(): + models.SurvexBlock.objects.all().delete() + models.SurvexFile.objects.all().delete() + models.SurvexDirectory.objects.all().delete() + models.SurvexEquate.objects.all().delete() + models.SurvexLeg.objects.all().delete() + models.SurvexTitle.objects.all().delete() + models.SurvexPersonRole.objects.all().delete() + + survexfile = models.SurvexFile(path="all", cave=None) + survexfile.save() + survexfile.SetDirectory() + + #Load all + survexblockroot = models.SurvexBlock(name="root", survexpath="", begin_char=0, cave=None, survexfile=survexfile, totalleglength=0.0) + survexblockroot.save() + fin = survexfile.OpenFile() + textlines = [ ] + RecursiveLoad(survexblockroot, survexfile, fin, textlines) + survexblockroot.text = "".join(textlines) + survexblockroot.save() + + + #Load each cave, + #FIXME this should be dealt with load all above caves = models.Cave.objects.all() for cave in caves: if cave.kataster_number and os.path.isdir(os.path.join(settings.SURVEX_DATA, "caves", cave.kataster_number)): @@ -193,4 +235,20 @@ def LoadAllSurvexBlocks(): print "loading", cave ReloadSurvexCave(cave.kataster_number) - +poslineregex = re.compile("^\(\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*)\s*\)\s*([^\s]+)$") +def LoadPos(): + call([settings.CAVERN, "--output=%s/all.3d" % settings.SURVEX_DATA, "%s/all.svx" % settings.SURVEX_DATA]) + call([settings.THREEDTOPOS, '%sall.3d' % settings.SURVEX_DATA], cwd = settings.SURVEX_DATA) + posfile = open("%sall.pos" % settings.SURVEX_DATA) + posfile.readline()#Drop header + for line in posfile.readlines(): + r = poslineregex.match(line) + if r: + x, y, z, name = r.groups() + try: + ss = models.SurvexStation.objects.lookup(name) + except: + pass + ss.x = float(x) + ss.y = float(y) + ss.z = float(z) |