ambiguous aliases removed more thoroughly

This commit is contained in:
Philip Sargent 2023-07-27 00:38:47 +03:00
parent a86f251423
commit d93133c338

View File

@ -473,6 +473,8 @@ def GetCaveLookup():
fall back on doing the actual database query it wants rather thna using this cache shortcut fall back on doing the actual database query it wants rather thna using this cache shortcut
""" """
duplicates = {}
def checkcaveid(cave, id): def checkcaveid(cave, id):
global Gcavelookup global Gcavelookup
if id not in Gcavelookup: if id not in Gcavelookup:
@ -482,10 +484,10 @@ def GetCaveLookup():
if cave == Gcavelookup[id]: if cave == Gcavelookup[id]:
pass # same id, same cave pass # same id, same cave
else: # same id but different cave else: # same id but different cave
message = f" - Warning: same alias id '{id:3}' for two caves '{Gcavelookup[id]}' and '{cave}'. Removing this shorthand alias entirely." # message = f" - Warning: ignoring alias id '{id:3}'. Caves '{Gcavelookup[id]}' and '{cave}'. "
Gcavelookup.pop(id) # print(message)
print(message) # DataIssue.objects.create(parser="aliases", message=message)
DataIssue.objects.create(parser="aliases", message=message) duplicates[id] = 1
global Gcavelookup global Gcavelookup
if Gcavelookup: if Gcavelookup:
@ -499,6 +501,12 @@ def GetCaveLookup():
for cave in Cave.objects.all(): for cave in Cave.objects.all():
key = cave.official_name.lower() key = cave.official_name.lower()
if key != "" and key != "unamed" and key != "unnamed": if key != "" and key != "unamed" and key != "unnamed":
if Gcave_count[key] > 0:
# message = f" - Warning: ignoring alias id '{id:3}'. Caves '{Gcavelookup[id]}' and '{cave}'. "
# print(message)
# DataIssue.objects.create(parser="aliases", message=message)
duplicates[key] = 1
else:
Gcavelookup[key] = cave Gcavelookup[key] = cave
Gcave_count[key] += 1 Gcave_count[key] += 1
if cave.kataster_number: if cave.kataster_number:
@ -665,11 +673,20 @@ def GetCaveLookup():
addmore = {} addmore = {}
ldup = []
for d in duplicates:
Gcavelookup.pop(d)
Gcave_count.pop(d)
ldup.append(d)
if ldup:
message = f" - Ambiguous aliases removed: {ldup}"
print(message)
DataIssue.objects.create(parser="aliases", message=message)
for c in Gcave_count: for c in Gcave_count:
if Gcave_count[c] > 1: if Gcave_count[c] > 1:
message = f" ** Duplicate cave id count={Gcave_count[c]} id:'{Gcavelookup[c]}' cave __str__:'{c}'" message = f" ** Duplicate cave id count={Gcave_count[c]} id:'{Gcavelookup[c]}' cave __str__:'{c}'"
print(message) print(message)
DataIssue.objects.create(parser="aliases", message=message) DataIssue.objects.create(parser="aliases", message=message)
# logdataissues[Gcavelookup[c]]=message # pending troggle-wide issues logging system
return Gcavelookup return Gcavelookup