2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 07:11:52 +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
ignored-files.log
tunnel-import.log
posnotfound
troggle.sqlite-journal

View File

@ -10,7 +10,7 @@ from django.utils.timezone import make_aware
import re
import os
from datetime import datetime
from datetime import datetime, timedelta
line_leg_regex = re.compile(r"[\d\-+.]+$")
@ -405,20 +405,25 @@ def LoadPos():
updtsvx = os.path.getmtime(topdata + ".svx")
updtcache = os.path.getmtime(cachefile)
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 :
print " cache is stale."
os.remove(cachefile)
else:
print " cache is fresh."
print " cache is fresh. Reading..."
try:
f = open(cachefile, "r")
for line in f:
notfoundbefore[line] +=1 # should not be duplicates
with open(cachefile, "r") as f:
for line in f:
l = line.rstrip()
if l in notfoundbefore:
notfoundbefore[l] +=1 # should not be duplicates
print " DUPLICATE ", line, notfoundbefore[l]
else:
notfoundbefore[l] =1
except:
print " FAILURE READ opening cache file %s" % (cachefile)
f.close()
raise
notfoundnow =[]
found = 0
@ -434,7 +439,7 @@ def LoadPos():
if r:
x, y, z, name = r.groups() # easting, northing, altitude
if name in notfoundbefore:
skip[name] += 1
skip[name] = 1
else:
try:
ss = models.SurvexStation.objects.lookup(name)
@ -446,16 +451,18 @@ def LoadPos():
except:
#print "%s in %s.pos not found in lookup of SurvexStation.objects" % (name, settings.SURVEX_TOPNAME)
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
try:
with open(cachefile, "w") as f:
print " cache file opened"
c = len(notfoundnow)+len(skip)
for i in notfoundnow:
f.write("%s\n" % i)
for j in skip:
f.write("%s\n" % j) # NB skip not notfoundbefore
print(' Not-found cache file written: %s entries' % c)
except:
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__))
# Django settings for troggle project.
DEBUG = True
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = [u'expo.survex.com']