2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 08:41:51 +00:00

bin Makesurvexstation, survextitle, survexEquate

This commit is contained in:
Philip Sargent 2020-06-24 01:57:20 +01:00
parent d6c4ffca5a
commit 6bf762b72f
5 changed files with 52 additions and 51 deletions

View File

@ -52,8 +52,8 @@ class SurvexFile(models.Model):
self.save() self.save()
class SurvexEquate(models.Model): #class SurvexEquate(models.Model):
cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.CASCADE) # cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.CASCADE)
class SurvexStationLookUpManager(models.Manager): class SurvexStationLookUpManager(models.Manager):
def lookup(self, name): def lookup(self, name):
@ -64,7 +64,7 @@ class SurvexStationLookUpManager(models.Manager):
class SurvexStation(models.Model): class SurvexStation(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
block = models.ForeignKey('SurvexBlock',on_delete=models.CASCADE) block = models.ForeignKey('SurvexBlock',on_delete=models.CASCADE)
equate = models.ForeignKey('SurvexEquate', blank=True, null=True,on_delete=models.CASCADE) # equate = models.ForeignKey('SurvexEquate', blank=True, null=True,on_delete=models.CASCADE)
objects = SurvexStationLookUpManager() objects = SurvexStationLookUpManager()
x = models.FloatField(blank=True, null=True) x = models.FloatField(blank=True, null=True)
y = models.FloatField(blank=True, null=True) y = models.FloatField(blank=True, null=True)
@ -140,22 +140,21 @@ class SurvexBlock(models.Model):
res.append({'person':personrole.personexpedition.person, 'expeditionyear':personrole.personexpedition.expedition.year, 'roles':str(personrole.role)}) res.append({'person':personrole.personexpedition.person, 'expeditionyear':personrole.personexpedition.expedition.year, 'roles':str(personrole.role)})
return res return res
def MakeSurvexStation(self, name): # def MakeSurvexStation(self, name):
ssl = self.survexstation_set.filter(name=name) # ssl = self.survexstation_set.filter(name=name)
if ssl: # if ssl:
assert len(ssl) == 1 # assert len(ssl) == 1
return ssl[0] # return ssl[0]
#print name # ss = SurvexStation(name=name, block=self)
ss = SurvexStation(name=name, block=self) # #ss.save()
#ss.save() # return ss
return ss
def DayIndex(self): def DayIndex(self):
return list(self.expeditionday.survexblock_set.all()).index(self) return list(self.expeditionday.survexblock_set.all()).index(self)
class SurvexTitle(models.Model): class SurvexTitle(models.Model):
survexblock = models.ForeignKey('SurvexBlock',on_delete=models.CASCADE) survexblock = models.ForeignKey('SurvexBlock',on_delete=models.CASCADE)
title = models.CharField(max_length=200) title = models.CharField(max_length=200) # needed by svxcavesingle.html template
cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.CASCADE) cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.CASCADE)
# #
@ -217,14 +216,14 @@ class TunnelFile(models.Model):
tunnelpath = models.CharField(max_length=200) tunnelpath = models.CharField(max_length=200)
tunnelname = models.CharField(max_length=200) tunnelname = models.CharField(max_length=200)
bfontcolours = models.BooleanField(default=False) bfontcolours = models.BooleanField(default=False)
manyscansfolders = models.ManyToManyField("ScansFolder") manyscansfolders = models.ManyToManyField("ScansFolder") # implicitly links to SVX files
scans = models.ManyToManyField("SingleScan") scans = models.ManyToManyField("SingleScan") # implicitly links to SVX files
survexblocks = models.ManyToManyField("SurvexBlock") # survexblocks = models.ManyToManyField("SurvexBlock")
tunnelcontains = models.ManyToManyField("TunnelFile") # case when its a frame type tunnelcontains = models.ManyToManyField("TunnelFile") # case when its a frame type
filesize = models.IntegerField(default=0) filesize = models.IntegerField(default=0)
npaths = models.IntegerField(default=0) npaths = models.IntegerField(default=0)
survextitles = models.ManyToManyField("SurvexTitle") # survextitles = models.ManyToManyField("SurvexTitle")
survexfiles = models.ManyToManyField("SurvexFile") # direct link to SVX files
class Meta: class Meta:
ordering = ('tunnelpath',) ordering = ('tunnelpath',)

View File

@ -14,12 +14,11 @@ from django.http import HttpResponse, Http404
import troggle.settings as settings import troggle.settings as settings
import parsers.survex import parsers.survex
from troggle.core.models import Expedition, Person, PersonExpedition from troggle.core.models import Expedition, Person, PersonExpedition
from troggle.core.models_survex import SurvexBlock, SurvexPersonRole, SurvexFile, SurvexDirectory, SurvexTitle from troggle.core.models_survex import SurvexBlock, SurvexPersonRole, SurvexFile, SurvexDirectory #, SurvexTitle
from troggle.core.models_caves import Cave, PersonTrip, LogbookEntry from troggle.core.models_caves import Cave, PersonTrip, LogbookEntry
from troggle.parsers.people import GetPersonExpeditionNameLookup from troggle.parsers.people import GetPersonExpeditionNameLookup
survextemplatefile = """; *** DO NOT SAVE THIS FILE WITHOUT RENAMING IT !! *** survextemplatefile = """; *** DO NOT SAVE THIS FILE WITHOUT RENAMING IT !! ***
;[Stuff in square brackets is example text to be replaced with real data, ;[Stuff in square brackets is example text to be replaced with real data,
; removing the square brackets] ; removing the square brackets]
@ -184,7 +183,6 @@ def svx(request, survex_file):
if "diff" in rform.data: if "diff" in rform.data:
form.data['code'] = rcode form.data['code'] = rcode
#process(survex_file) #process(survex_file)
if 'code' not in form.data: if 'code' not in form.data:
form.data['code'] = form.GetDiscCode() form.data['code'] = form.GetDiscCode()
@ -231,19 +229,19 @@ def threed(request, survex_file):
log = open(settings.SURVEX_DATA + survex_file + ".log", "rt",encoding='utf8') log = open(settings.SURVEX_DATA + survex_file + ".log", "rt",encoding='utf8')
return HttpResponse(log, content_type="text") return HttpResponse(log, content_type="text")
def log(request, survex_file): def log(request, survex_file):
process(survex_file) process(survex_file)
log = open(settings.SURVEX_DATA + survex_file + ".log", "rt",encoding='utf8') log = open(settings.SURVEX_DATA + survex_file + ".log", "rt",encoding='utf8')
return HttpResponse(log, content_type="text") return HttpResponse(log, content_type="text")
def err(request, survex_file): def err(request, survex_file):
process(survex_file) process(survex_file)
err = open(settings.SURVEX_DATA + survex_file + ".err", "rt",encoding='utf8') err = open(settings.SURVEX_DATA + survex_file + ".err", "rt",encoding='utf8')
return HttpResponse(err, content_type="text") return HttpResponse(err, content_type="text")
def identifycavedircontents(gcavedir): def identifycavedircontents(gcavedir):
# find the primary survex file in each cave directory # find the primary survex file in each cave directory
name = os.path.split(gcavedir)[1] name = os.path.split(gcavedir)[1]
@ -339,6 +337,8 @@ def survexcaveslist(request):
# parsing all the survex files of a single cave and showing that it's consistent and can find all the files and people # parsing all the survex files of a single cave and showing that it's consistent and can find all the files and people
# doesn't use recursion. just writes it twice # doesn't use recursion. just writes it twice
# currently produces title and blank page.. link test is "dates and explorers"
def survexcavesingle(request, survex_cave): def survexcavesingle(request, survex_cave):
breload = False breload = False
cave = Cave.objects.get(kataster_number=survex_cave) cave = Cave.objects.get(kataster_number=survex_cave)

View File

@ -5,6 +5,13 @@ import urllib.parse
# link 'localsettings.py' to localsettingsWSL.py for use on a Windows 10 machine running WSL1 # link 'localsettings.py' to localsettingsWSL.py for use on a Windows 10 machine running WSL1
print(" * importing troggle/localsettings.py") print(" * importing troggle/localsettings.py")
#-----------------------------------------------------------------
# THINK before you push this to a repo
# - have you checked that this file is in .gitignore ?
# - have you run pre-push.sh to copy files and remove passwords?
# - we don't want to have to change the expo system password !
#-----------------------------------------------------------------
SERVERPORT = '3777' SERVERPORT = '3777'
LIBDIR = '/mnt/d/CUCC-Expo/t37/lib/python3.7/' LIBDIR = '/mnt/d/CUCC-Expo/t37/lib/python3.7/'

View File

@ -111,12 +111,12 @@ def LoadSurvexLineLeg(survexblock, stardata, sline, comment, cave):
# No need to save as we are measuring lengths only on parsing now. # No need to save as we are measuring lengths only on parsing now.
def LoadSurvexEquate(survexblock, sline): # def LoadSurvexEquate(survexblock, sline):
#print sline # # #print sline #
stations = sline.split() # stations = sline.split()
assert len(stations) > 1 # assert len(stations) > 1
for station in stations: # for station in stations:
survexblock.MakeSurvexStation(station) # survexblock.MakeSurvexStation(station)
def LoadSurvexLinePassage(survexblock, stardata, sline, comment): def LoadSurvexLinePassage(survexblock, stardata, sline, comment):
@ -317,7 +317,7 @@ def RecursiveLoad(survexblock, survexfile, fin):
elif re.match("begin$(?i)", cmd): elif re.match("begin$(?i)", cmd):
# On a *begin statement we start a new survexblock. # On a *begin statement we start a new survexblock.
# There should not be any *include inside a begin-end block, so this is a simple # There should not be any *include inside a begin-end block, so this is a simple
# load not a recursive load. But there may be many blocks in one file. # load not a recursive fileload. But there may be many blocks nested to any depth in one file.
if line: if line:
newsvxpath = os.path.join(os.path.split(survexfile.path)[0], re.sub(r"\.svx$", "", line)) newsvxpath = os.path.join(os.path.split(survexfile.path)[0], re.sub(r"\.svx$", "", line))
# Try to find the cave in the DB if not use the string as before # Try to find the cave in the DB if not use the string as before
@ -334,8 +334,10 @@ def RecursiveLoad(survexblock, survexfile, fin):
previousnlegs = survexlegsnumber previousnlegs = survexlegsnumber
name = line.lower() name = line.lower()
print(insp+' - Begin found for:{}, creating new SurvexBlock '.format(name)) print(insp+' - Begin found for:{}, creating new SurvexBlock '.format(name))
survexblockdown = models_survex.SurvexBlock(name=name, parent=survexblock, survexpath=survexblock.survexpath+"."+name, survexblockdown = models_survex.SurvexBlock(name=name, parent=survexblock,
cave=survexfile.cave, survexfile=survexfile, legsall=0, legssplay=0, legssurfc=0, totalleglength=0.0) survexpath=survexblock.survexpath+"."+name,
cave=survexfile.cave, survexfile=survexfile,
legsall=0, legssplay=0, legssurfc=0, totalleglength=0.0)
survexblockdown.save() survexblockdown.save()
survexblock.save() survexblock.save()
survexblock = survexblockdown survexblock = survexblockdown
@ -386,8 +388,9 @@ def RecursiveLoad(survexblock, survexfile, fin):
personrole.save() personrole.save()
elif cmd == "title": elif cmd == "title":
survextitle = models_survex.SurvexTitle(survexblock=survexblock, title=line.strip('"'), cave=survexfile.cave) # unused in troggle.
survextitle.save() #survextitle = models_survex.SurvexTitle(survexblock=survexblock, title=line.strip('"'), cave=survexfile.cave)
#survextitle.save()
pass pass
elif cmd == "require": elif cmd == "require":
@ -407,7 +410,8 @@ def RecursiveLoad(survexblock, survexfile, fin):
assert ls[0] == "passage", line assert ls[0] == "passage", line
elif cmd == "equate": elif cmd == "equate":
LoadSurvexEquate(survexblock, line) #LoadSurvexEquate(survexblock, line)
pass
elif cmd == "set" and re.match("names(?i)", line): elif cmd == "set" and re.match("names(?i)", line):
pass pass
@ -416,7 +420,9 @@ def RecursiveLoad(survexblock, survexfile, fin):
# but this data is only used for sense-checking not to actually calculate anything important # but this data is only used for sense-checking not to actually calculate anything important
pass pass
elif cmd == "fix": elif cmd == "fix":
survexblock.MakeSurvexStation(line.split()[0]) # troggle does not use survex stations
#survexblock.MakeSurvexStation(line.split()[0])
pass
elif cmd in ["alias", "calibrate", "cs","entrance", "export", "case", elif cmd in ["alias", "calibrate", "cs","entrance", "export", "case",
"declination", "infer","instrument", "sd", "units"]: "declination", "infer","instrument", "sd", "units"]:
# we ignore all these, which is fine. # we ignore all these, which is fine.
@ -469,8 +475,8 @@ def LoadAllSurvexBlocks():
models_survex.SurvexBlock.objects.all().delete() models_survex.SurvexBlock.objects.all().delete()
models_survex.SurvexFile.objects.all().delete() models_survex.SurvexFile.objects.all().delete()
models_survex.SurvexDirectory.objects.all().delete() models_survex.SurvexDirectory.objects.all().delete()
models_survex.SurvexEquate.objects.all().delete() # models_survex.SurvexEquate.objects.all().delete()
models_survex.SurvexTitle.objects.all().delete() # models_survex.SurvexTitle.objects.all().delete()
models_survex.SurvexPersonRole.objects.all().delete() models_survex.SurvexPersonRole.objects.all().delete()
models_survex.SurvexStation.objects.all().delete() models_survex.SurvexStation.objects.all().delete()
@ -516,7 +522,6 @@ def LoadPos():
# cavern defaults to using same cwd as supplied input file # cavern defaults to using same cwd as supplied input file
call([settings.CAVERN, "--output=%s.3d" % (topdata), "%s.svx" % (topdata)]) call([settings.CAVERN, "--output=%s.3d" % (topdata), "%s.svx" % (topdata)])
call([settings.THREEDTOPOS, '%s.3d' % (topdata)], cwd = settings.SURVEX_DATA) call([settings.THREEDTOPOS, '%s.3d' % (topdata)], cwd = settings.SURVEX_DATA)
#print(" - This next bit takes a while. Matching ~32,000 survey positions. Be patient...")
mappoints = {} mappoints = {}
for pt in MapLocations().points(): for pt in MapLocations().points():
@ -525,7 +530,6 @@ def LoadPos():
posfile = open("%s.pos" % (topdata)) posfile = open("%s.pos" % (topdata))
posfile.readline() #Drop header posfile.readline() #Drop header
try: try:
survexblockroot = models_survex.SurvexBlock.objects.get(name=ROOTBLOCK) survexblockroot = models_survex.SurvexBlock.objects.get(name=ROOTBLOCK)
except: except:
@ -540,17 +544,8 @@ def LoadPos():
r = poslineregex.match(line) r = poslineregex.match(line)
if r: if r:
x, y, z, id = r.groups() x, y, z, id = r.groups()
# if id in notfoundbefore:
# skip[id] = 1
# else:
for sid in mappoints: for sid in mappoints:
if id.endswith(sid): if id.endswith(sid):
# notfoundnow.append(id)
# Now that we don't import any stations, we create it rather than look it up
# ss = models_survex.SurvexStation.objects.lookup(id)
# need to set block_id which means doing a search on all the survex blocks..
# remove dot at end and add one at beginning
blockpath = "." + id[:-len(sid)].strip(".") blockpath = "." + id[:-len(sid)].strip(".")
try: try:
sbqs = models_survex.SurvexBlock.objects.filter(survexpath=blockpath) sbqs = models_survex.SurvexBlock.objects.filter(survexpath=blockpath)
@ -582,6 +577,5 @@ def LoadPos():
print(message) print(message)
models.DataIssue.objects.create(parser='survex', message=message) models.DataIssue.objects.create(parser='survex', message=message)
raise raise
print(" - {} SurvexStation entrances found.".format(found)) print(" - {} SurvexStation entrances found.".format(found))

View File

@ -27,6 +27,7 @@ sed -i '/SECRET_KEY/ s/^.*$/SECRET_KEY = "not-the-real-secret-key-a#vaeozn0---^f
echo " " reset: SECRET_KEY = \"not-the-real-secret-key-a#vaeozn0---^fj!355qki*vj2\" echo " " reset: SECRET_KEY = \"not-the-real-secret-key-a#vaeozn0---^fj!355qki*vj2\"
# #
# Do these before final testing, *not* just before pushing: # Do these before final testing, *not* just before pushing:
# in ./pre-run.sh
# python reset-django.py # python reset-django.py
# python manage.py makemigrations # python manage.py makemigrations
# python manage.py test # python manage.py test