2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-15 04:27:11 +00:00

more fixing bad *ref and null dates on blocks

This commit is contained in:
2023-10-26 22:46:16 +03:00
parent 87d9804864
commit 7672de2dd1

View File

@@ -265,7 +265,7 @@ class LoadingSurvex:
rx_team = re.compile(r"(?i)team$") rx_team = re.compile(r"(?i)team$")
rx_set = re.compile(r"(?i)set$") rx_set = re.compile(r"(?i)set$")
rx_names = re.compile(r"(?i)names") #rx_names = re.compile(r"(?i)names")
rx_flagsnot = re.compile(r"not\s") rx_flagsnot = re.compile(r"not\s")
rx_linelen = re.compile(r"[\d\-+.]+$") rx_linelen = re.compile(r"[\d\-+.]+$")
instruments = "(bitch|bodger|bolt|bolter|bolting|book|clino|comp|compass|consultant|disto|distox|distox2|dog|dogsbody|drawing|drill|gps|helper|inst|instr|instrument|monkey|nagging|nail|nail_polish|nail_polish_bitch|nail_polish_monkey|nail_varnish|nail_varnish_bitch|note|paint|photo|pic|point|polish|powerdrill|rig|rigger|rigging|shoot|sketch|slacker|something|tape|topodroid|unknown|useless|varnish|waiting_patiently)" instruments = "(bitch|bodger|bolt|bolter|bolting|book|clino|comp|compass|consultant|disto|distox|distox2|dog|dogsbody|drawing|drill|gps|helper|inst|instr|instrument|monkey|nagging|nail|nail_polish|nail_polish_bitch|nail_polish_monkey|nail_varnish|nail_varnish_bitch|note|paint|photo|pic|point|polish|powerdrill|rig|rigger|rigging|shoot|sketch|slacker|something|tape|topodroid|unknown|useless|varnish|waiting_patiently)"
@@ -581,9 +581,27 @@ class LoadingSurvex:
stash_data_issue( stash_data_issue(
parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) parser="survex", message=message, url=None, sb=(survexblock.survexfile.path)
) )
def LoadSurvexSet(self, survexblock, line):
"""survex *set can reset the character for space, decinmal point, field separator
and lots of other stuff which would stuff this parser completely. The '*set names ...' is
innocuous, so we ignore that. All the others need swift attention."""
item, *_ = line.strip().split(" ") # unpack tuples idiom in python 3
if item.lower() == "names":
# we don't care as we treat all chars as names anyway.
# print(f"*set names - do not care: '{line}' {survexblock.survexfile.path}", file=sys.stderr)
return
else:
message = (
f"! SERIOUS Warning. Unparsed [*set]: '{line}' {survexblock.survexfile.path} "
)
print(self.insp + message)
stash_data_issue(
parser="survex", message=message, url=None, sb=(survexblock.survexfile.path)
)
def LoadSurvexEntrance(self, survexblock, line): def LoadSurvexEntrance(self, survexblock, line):
# Not using this yet # Not using this
pass pass
def LoadSurvexAlias(self, survexblock, line): def LoadSurvexAlias(self, survexblock, line):
@@ -1763,8 +1781,8 @@ class LoadingSurvex:
self.LoadSurvexUnits(survexblock, args) self.LoadSurvexUnits(survexblock, args)
elif self.rx_team.match(cmd): elif self.rx_team.match(cmd):
self.LoadSurvexTeam(survexblock, args) self.LoadSurvexTeam(survexblock, args)
elif self.rx_set.match(cmd) and self.rx_names.match(cmd): elif self.rx_set.match(cmd): #and self.rx_names.match(cmd):
pass self.LoadSurvexSet(survexblock, args)
elif self.rx_include.match(cmd): elif self.rx_include.match(cmd):
message = f" ! -ERROR *include command not expected here {path}. Re-run a full Survex import." message = f" ! -ERROR *include command not expected here {path}. Re-run a full Survex import."
print(message) print(message)
@@ -2483,41 +2501,49 @@ def MakeFileRoot(svxpath):
return fileroot return fileroot
def set_survexblocks(wallet): def set_survexblocks():
"""Need to find the optimal Django way of doing this query. """Need to find the optimal Django way of doing this query.
It's a mess now""" It's a mess now"""
if svxfiles := wallet.survexfiles(): # reads from JSON, should be cached already
for svx in svxfiles: # for b in SurvexBlock.objects.all():
if svx: # if not b.date:
if svx.endswith(".svx"): # print(f" Block {b} on {b.survexfile} HAS NULL DATE ")
svx = svx.replace(".svx","")
try: cache = {}
# there are survex files we ignore when troggle parses, and some of these are referred to in wallets allsvx = SurvexFile.objects.all()
sfile = SurvexFile.objects.get(path=svx) #.select_related("survexblocks") for s in allsvx:
# print(sfile) if s.path:
except: cache[s.path] = s
continue
blocks = SurvexBlock.objects.filter(survexfile=sfile) wallets = Wallet.objects.all()
for b in blocks: for wallet in wallets:
try:
if b.scanswallet == wallet: if svxfiles := wallet.survexfiles(): # reads from JSON, should be cached already
pass for svx in svxfiles:
elif b.scanswallet: if svx:
if b.date > date(2019, 1, 1) and b.date < date(2020, 1, 1): if svx.endswith(".svx"):
print(f"not set{wallet} on {b.survexfile} : {b} as already set to {b.scanswallet}") svx = svx.replace(".svx","")
else: if svx in cache:
b.scanswallet = wallet sfile = cache[svx]
b.save() # try:
if b.date > date(2019, 1, 1) and b.date < date(2020, 1, 1): # # there are survex files we ignore when troggle parses, and some of these are referred to in wallets
print(f"setting {wallet} on {b.survexfile} : {b}") # sfile = SurvexFile.objects.get(path=svx) #.select_related("survexblocks")
except: # # print(sfile)
if not hasattr(b,"date"): # except:
print(f" Block {b} on {b.survexfile} HAS NO DATE SET ") # continue
elif not b.date: blocks = SurvexBlock.objects.filter(survexfile=sfile)
print(f" Block {b} on {b.survexfile} HAS NULL DATE ") for b in blocks:
else: if b.date: # many are NULL
print(f" exception {wallet} on {b.survexfile} : {b}") if b.scanswallet == wallet:
pass
elif b.scanswallet:
if b.date > date(2019, 1, 1) and b.date < date(2020, 1, 1):
print(f"not set{wallet} on {b.survexfile} : {b} as already set to {b.scanswallet}")
else:
b.scanswallet = wallet
b.save()
if b.date > date(2019, 1, 1) and b.date < date(2020, 1, 1):
print(f"setting {wallet} on {b.survexfile} : {b}")
def survexifywallets(): def survexifywallets():
"""Gets the caves from the list of survexblocks """Gets the caves from the list of survexblocks
@@ -2539,15 +2565,14 @@ def survexifywallets():
print(f" - {duration:7.2f} s to add people to wallets ", file=sys.stderr) print(f" - {duration:7.2f} s to add people to wallets ", file=sys.stderr)
start = time.time() start = time.time()
wallets = Wallet.objects.all()
for w in wallets: set_survexblocks() # reads JSON, sets survexblocks if survexfiles specified on wallet JSON
set_survexblocks(w) # reads JSON, sets survexblocks if survexfiles specified on wallet JSON
duration = time.time() - start duration = time.time() - start
print(f" - {duration:7.2f} s to set survexblock:wallet using JSON survexfiles ", file=sys.stderr) print(f" - {duration:7.2f} s to set survexblock:wallet using JSON survexfiles ", file=sys.stderr)
start = time.time() start = time.time()
for w in wallets: for w in Wallet.objects.all():
blocks = SurvexBlock.objects.filter(scanswallet=w).select_related("survexfile") blocks = SurvexBlock.objects.filter(scanswallet=w).select_related("survexfile")
for b in blocks: for b in blocks:
if b.survexfile.cave: if b.survexfile.cave: