moved aliases to people module, faster db too

This commit is contained in:
Philip Sargent 2023-01-28 14:03:46 +00:00
parent 9e71be8169
commit d9a4069662
2 changed files with 21 additions and 30 deletions

View File

@ -125,24 +125,7 @@ def GetTripPersons(trippeople, expedition, logtime_underground, tid=None):
if tripperson and tripperson[0] != "*": if tripperson and tripperson[0] != "*":
tripperson = re.sub(rx_round_bracket, "", tripperson).strip() tripperson = re.sub(rx_round_bracket, "", tripperson).strip()
# these aliases should be moved to people.py GetPersonExpeditionNameLookup(expedition) # Whacky aliases all handled in GetPersonExpeditionNameLookup()
if tripperson == "Wiggy":
tripperson = "Phil Wigglesworth"
if tripperson == "Animal":
tripperson = "Mike Richardson"
if tripperson == "MikeTA":
tripperson = "Mike Richardson"
if tripperson == "CavingPig":
tripperson = "Elaine Oliver"
if tripperson == "nobrotson":
tripperson = "Rob Watson"
if tripperson == "Tinywoman":
tripperson = "Nadia"
if tripperson == "tcacrossley":
tripperson = "Tom Crossley"
if tripperson == "Samouse1":
tripperson = "Todd Rye"
personyear = GetPersonExpeditionNameLookup(expedition).get(tripperson.lower()) personyear = GetPersonExpeditionNameLookup(expedition).get(tripperson.lower())
if not personyear: if not personyear:
message = f" ! - {expedition.year} No name match for: '{tripperson}' in entry {tid=} for this expedition year." message = f" ! - {expedition.year} No name match for: '{tripperson}' in entry {tid=} for this expedition year."

View File

@ -8,7 +8,6 @@ from django.conf import settings
from unidecode import unidecode from unidecode import unidecode
from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition
from troggle.core.utils import save_carefully
"""These functions do not match how the stand-alone folk script works. So the script produces an HTML file which has """These functions do not match how the stand-alone folk script works. So the script produces an HTML file which has
href links to pages in troggle which troggle does not think are right. href links to pages in troggle which troggle does not think are right.
@ -74,17 +73,15 @@ def load_people_expos():
headers = next(personreader) headers = next(personreader)
header = dict(list(zip(headers, list(range(len(headers)))))) header = dict(list(zip(headers, list(range(len(headers))))))
# make expeditions
print(" - Loading expeditions")
years = headers[5:] years = headers[5:]
nexpos = Expedition.objects.count()
if nexpos <= 0:
print(" - Creating expeditions")
for year in years: for year in years:
lookupAttribs = {"year": year} lookupAttribs = {"year": year}
nonLookupAttribs = {"name": f"CUCC expo {year}"} nonLookupAttribs = {"name": f"CUCC expo {year}"}
e = Expedition.objects.create(**nonLookupAttribs, **lookupAttribs)
save_carefully(Expedition, lookupAttribs, nonLookupAttribs)
# make persons
print(" - Loading personexpeditions") print(" - Loading personexpeditions")
for personline in personreader: for personline in personreader:
@ -116,7 +113,7 @@ def load_people_expos():
lookupAttribs = {"first_name": firstname, "last_name": (lastname or "")} lookupAttribs = {"first_name": firstname, "last_name": (lastname or "")}
nonLookupAttribs = {"is_vfho": vfho, "fullname": fullname, "nickname": nickname} nonLookupAttribs = {"is_vfho": vfho, "fullname": fullname, "nickname": nickname}
person, created = save_carefully(Person, lookupAttribs, nonLookupAttribs) person = Person.objects.create(**nonLookupAttribs, **lookupAttribs)
parse_blurb(personline=personline, header=header, person=person) parse_blurb(personline=personline, header=header, person=person)
@ -126,7 +123,7 @@ def load_people_expos():
if attended == "1" or attended == "-1": if attended == "1" or attended == "-1":
lookupAttribs = {"person": person, "expedition": expedition} lookupAttribs = {"person": person, "expedition": expedition}
nonLookupAttribs = {"nickname": nickname, "is_guest": (personline[header["Guest"]] == "1")} nonLookupAttribs = {"nickname": nickname, "is_guest": (personline[header["Guest"]] == "1")}
save_carefully(PersonExpedition, lookupAttribs, nonLookupAttribs) pe = PersonExpedition.objects.create(**nonLookupAttribs, **lookupAttribs)
print("", flush=True) print("", flush=True)
@ -289,8 +286,19 @@ def GetPersonExpeditionNameLookup(expedition):
possnames.append("eric c. landgraf") possnames.append("eric c. landgraf")
possnames.append("eric c landgraf") possnames.append("eric c landgraf")
if f"{f} {l}" == "Nadia Raeburn".lower(): if f"{f} {l}" == "Nadia Raeburn".lower():
possnames.append("tinywoman")
possnames.append("nadia rc") possnames.append("nadia rc")
possnames.append("nadia raeburn-cherradi") possnames.append("nadia raeburn-cherradi")
if f"{f} {l}" == "Phil Wigglesworth".lower():
possnames.append("wiggy")
if f"{f} {l}" == "Elaine Oliver".lower():
possnames.append("cavingpig")
if f"{f} {l}" == "Tom Crossley".lower():
possnames.append("tcacrossley")
if f"{f} {l}" == "Rob Watson".lower():
possnames.append("nobrotson")
if f"{f} {l}" == "Todd Rye".lower():
possnames.append("samouse1")
for i in [3, 4, 5, 6]: for i in [3, 4, 5, 6]:
lim = min(i, len(f) + 1) # short form, e.g. Dan for Daniel. lim = min(i, len(f) + 1) # short form, e.g. Dan for Daniel.