From 861980a8e9f9d58e6327e8e1a98f7f8c5fec7048 Mon Sep 17 00:00:00 2001
From: Philip Sargent <philip.sargent@klebos.com>
Date: Sun, 9 Oct 2022 23:50:32 +0300
Subject: [PATCH] More fixes to name resolution checking

---
 core/views/statistics.py | 12 +++++-----
 parsers/people.py        | 47 +++++++++++++++++++++++++++-------------
 2 files changed, 39 insertions(+), 20 deletions(-)

diff --git a/core/views/statistics.py b/core/views/statistics.py
index fb26254..14205b7 100644
--- a/core/views/statistics.py
+++ b/core/views/statistics.py
@@ -181,12 +181,14 @@ def aliases(request, year):
     personexpeditions = PersonExpedition.objects.filter(expedition=expo)
     persons = Person.objects.all()
     
-    aliasdict = GetPersonExpeditionNameLookup(expo)
-    res = aliasdict
-        # invert
+    aliases = GetPersonExpeditionNameLookup(expo)
+    
+    aliasdict = {key: val for key, val in sorted(aliases.items(), key = lambda ele: ele[0])}
+    
+    aliasdict={}
+    for i in sorted(aliases):
+       aliasdict[i]=aliases[i]
     invert ={}
-    for p in res:
-        invert[res[p]].append(p)
 
  
     return render(request,'aliases.html',  {'year': year, 'aliasdict': aliasdict, 'invert': invert,'personexpeditions': personexpeditions, 'persons': persons})
diff --git a/parsers/people.py b/parsers/people.py
index a58167e..b61ba0a 100644
--- a/parsers/people.py
+++ b/parsers/people.py
@@ -147,6 +147,7 @@ def GetPersonExpeditionNameLookup(expedition):
         variations = []
         variations.append(f)
         variations.append(l)
+        variations.append(f + l)
         variations.append(f + " " + l)
         variations.append(f + " " + l[0])
         variations.append(f + l[0])
@@ -183,6 +184,7 @@ def GetPersonExpeditionNameLookup(expedition):
 
             if n:
                 possnames += apply_variations(n, l)
+                
             if f == "Robert".lower():
                 possnames += apply_variations("Bob", l)
             if f == "Andrew".lower():
@@ -193,34 +195,49 @@ def GetPersonExpeditionNameLookup(expedition):
                 possnames += apply_variations("Mike", l)
             if f == "David".lower():
                 possnames += apply_variations("Dave", l)
+            if f == "Dave".lower():
+                possnames += apply_variations("David", l)
             if f == "Peter".lower():
                 possnames += apply_variations("Pete", l)
-                
+            if f == "Pete".lower():
+                possnames += apply_variations("Peter", l)
+            if f == "Olly".lower():
+                possnames += apply_variations("Oliver", l)
+            if f == "Oliver".lower():
+                possnames += apply_variations("Olly", l)
+               
             if f == "Becka".lower():
                 possnames += apply_variations("Rebecca", l)
          
             if f'{f} {l}' == "Andy Waddington".lower():
-                possnames += apply_variations("AER", "Waddington")
+                possnames += apply_variations("aer", "waddington")
             if f'{f} {l}' == "Phil Underwood".lower():
-                possnames += apply_variations("Phil", "Underpants")
+                possnames += apply_variations("phil", "underpants")
             if f'{f} {l}' == "Naomi Griffiths".lower():
-                possnames += apply_variations("Naomi", "Makin")
+                possnames += apply_variations("naomi", "makins")
+            if f'{f} {l}' == "Tina White".lower():
+                possnames += apply_variations("tina", "richardson")
             if f'{f} {l}' == "Cat Hulse".lower():
-                possnames += apply_variations("Catherine", "Hulse")
-                possnames += apply_variations("Cat", "Henry")
+                possnames += apply_variations("catherine", "hulse")
+                possnames += apply_variations("cat", "henry")
             if f'{f} {l}' == "Jess Stirrups".lower():
-                possnames += apply_variations("Jessica", "Stirrups")
+                possnames += apply_variations("jessica", "stirrups")
             if f'{f} {l}' == "Nat Dalton".lower():
-                possnames += apply_variations("Nathaniel", "Dalton")
+                possnames += apply_variations("nathanael", "dalton") # correct. He has a weird spelling.
             if f'{f} {l}' == "Mike Richardson".lower():
-                possnames.append("MTA")
-                possnames.append("Mike the Animal")
-                possnames.append("Animal")
+                possnames.append("mta")
+                possnames.append("miketa")
+                possnames.append("mike the animal")
+                possnames.append("animal")
             if f'{f} {l}' == "Eric Landgraf".lower():
-                 possnames.append("Eric C.Landgraf")
-                 possnames.append("Eric C. Landgraf")
-              
-        for i in [4, 5, 6]:
+                possnames.append("eric c.landgraf")
+                possnames.append("eric c. landgraf")
+                possnames.append("eric c landgraf")
+            if f'{f} {l}' == "Nadia Raeburn".lower():
+                possnames.append("nadia rc")
+                possnames.append("nadia raeburn-cherradi")
+             
+        for i in [3, 4, 5, 6]:
             lim = min(i, len(f)+1)  # short form, e.g. Dan for Daniel. 
             if f[:lim] not in short:
                 short[f[:lim]]= personexpedition