2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-02-18 05:00:13 +00:00

getting the LoadPos to work better

This commit is contained in:
Philip Sargent 2020-04-28 21:50:53 +01:00
parent b4c0c4d219
commit ecf92e2079
3 changed files with 21 additions and 12 deletions

2
.gitignore vendored
View File

@ -31,3 +31,5 @@ import_profile.json
import_times.json import_times.json
ignored-files.log ignored-files.log
tunnel-import.log tunnel-import.log
posnotfound
troggle.sqlite-journal

View File

@ -10,7 +10,7 @@ from django.utils.timezone import make_aware
import re import re
import os import os
from datetime import datetime from datetime import datetime, timedelta
line_leg_regex = re.compile(r"[\d\-+.]+$") line_leg_regex = re.compile(r"[\d\-+.]+$")
@ -405,19 +405,24 @@ def LoadPos():
updtsvx = os.path.getmtime(topdata + ".svx") updtsvx = os.path.getmtime(topdata + ".svx")
updtcache = os.path.getmtime(cachefile) updtcache = os.path.getmtime(cachefile)
age = updtcache - updtsvx age = updtcache - updtsvx
print(' svx: %s cache: %s cache age: %s' % (updtsvx, updtcache, age )) print(' svx: %s cache: %s cache age: %s' % (updtsvx, updtcache, str(timedelta(seconds=age) )))
if age < 0 : if age < 0 :
print " cache is stale." print " cache is stale."
os.remove(cachefile) os.remove(cachefile)
else: else:
print " cache is fresh." print " cache is fresh. Reading..."
try: try:
f = open(cachefile, "r") with open(cachefile, "r") as f:
for line in f: for line in f:
notfoundbefore[line] +=1 # should not be duplicates l = line.rstrip()
if l in notfoundbefore:
notfoundbefore[l] +=1 # should not be duplicates
print " DUPLICATE ", line, notfoundbefore[l]
else:
notfoundbefore[l] =1
except: except:
print " FAILURE READ opening cache file %s" % (cachefile) print " FAILURE READ opening cache file %s" % (cachefile)
f.close() raise
notfoundnow =[] notfoundnow =[]
@ -434,7 +439,7 @@ def LoadPos():
if r: if r:
x, y, z, name = r.groups() # easting, northing, altitude x, y, z, name = r.groups() # easting, northing, altitude
if name in notfoundbefore: if name in notfoundbefore:
skip[name] += 1 skip[name] = 1
else: else:
try: try:
ss = models.SurvexStation.objects.lookup(name) ss = models.SurvexStation.objects.lookup(name)
@ -446,16 +451,18 @@ def LoadPos():
except: except:
#print "%s in %s.pos not found in lookup of SurvexStation.objects" % (name, settings.SURVEX_TOPNAME) #print "%s in %s.pos not found in lookup of SurvexStation.objects" % (name, settings.SURVEX_TOPNAME)
notfoundnow.append(name) notfoundnow.append(name)
print " - %s stations NOT found in lookup of SurvexStation.objects. %s found. %s skipper." % (len(notfoundnow),found, skip) print " - %s stations NOT found in lookup of SurvexStation.objects. %s found. %s skipped." % (len(notfoundnow),found, len(skip))
if found > 10: # i.e. a previous cave import has been done if found > 10: # i.e. a previous cave import has been done
try: try:
with open(cachefile, "w") as f: with open(cachefile, "w") as f:
print " cache file opened" c = len(notfoundnow)+len(skip)
for i in notfoundnow: for i in notfoundnow:
f.write("%s\n" % i) f.write("%s\n" % i)
for j in skip: for j in skip:
f.write("%s\n" % j) # NB skip not notfoundbefore f.write("%s\n" % j) # NB skip not notfoundbefore
print(' Not-found cache file written: %s entries' % c)
except: except:
print " FAILURE WRITE opening cache file %s" % (cachefile) print " FAILURE WRITE opening cache file %s" % (cachefile)
raise

View File

@ -7,7 +7,7 @@ import django
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Django settings for troggle project. # Django settings for troggle project.
DEBUG = True DEBUG = False
TEMPLATE_DEBUG = DEBUG TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = [u'expo.survex.com'] ALLOWED_HOSTS = [u'expo.survex.com']