FEAT: Apply contact normalization and misclassification discarding mappings during import

This commit is contained in:
2026-06-13 01:45:45 +02:00
parent 396d8f05d8
commit ea760fba06

View File

@@ -37,6 +37,65 @@ def normalize_name(name):
return ""
return "".join(c for c in name.lower() if c.isalnum())
def get_normalized_contact_name(name):
if not name:
return "", False
n = "".join(c for c in name.lower() if c.isalnum())
to_discard = {
"agoutissindnett",
"chevroletcamarooftopolino",
"cindyvprivatzuchtgießen",
"cindyvprivatzuchtgiessen",
"inuschofblackforest",
"stichvonprivatzuchtgießen",
"stichvonprivatzuchtgiessen",
"tarzanofsamsimar",
"hanserennersposeidon",
"livingforcesidefix",
"livingforcesnando"
}
if n in to_discard:
return "", False
norm_map = {
"kleinechaoten": "Zucht der kleinen Chaoten",
"kleinenchaoten": "Zucht der kleinen Chaoten",
"zuchtderkleinenchaoten": "Zucht der kleinen Chaoten",
"schlossmaus": "Schlossmäuse",
"schlossmäuse": "Schlossmäuse",
"schlossmäusen": "Schlossmäuse",
"buntefellnasen": "bunten Fellnasen",
"buntenfellnase": "bunten Fellnasen",
"buntenfellnasen": "bunten Fellnasen",
"kkchaos": "KK-Chaos",
"kkchaosofkkchaos": "KK-Chaos",
"oflennylengo": "Lenny Lengo",
"lennylengo": "Lenny Lengo",
"pzmaintal": "Privatzucht Maintal",
"maintalerpz": "Privatzucht Maintal",
"vonprivatzuchtmaintal": "Privatzucht Maintal",
"pzmücke": "Privatzucht Mücke",
"pzmuecke": "Privatzucht Mücke",
"privatzuchtmücke": "Privatzucht Mücke",
"privatzuchtmuecke": "Privatzucht Mücke",
"pzseligenstadt": "Privatzucht Seligenstadt",
"kriegernmitkrallen": "Krieger mit Krallen",
"littlefellows": "little fellows",
"littlerunners": "little runners",
"colourfulfurrygerbils": "Colorful Furry Gerbils",
"colorfulfurrygerbils": "Colorful Furry Gerbils",
"hanserenners": "Hanse Renner",
"blackforestgv": "Black Forest",
"topol": "Topolino",
}
if n in norm_map:
return norm_map[n], True
return name, True
def get_call_name(name):
if not name:
return ""
@@ -682,14 +741,20 @@ def main():
if not name_val:
continue
norm_name = normalize_name(name_val)
canon_name, should_keep = get_normalized_contact_name(name_val)
scoped_id = rc["_scoped_id"]
if not should_keep:
if scoped_id:
contact_id_map[scoped_id] = None
continue
norm_name = normalize_name(canon_name)
if norm_name not in contact_by_norm_name:
global_guid = generate_guid(f"contact-{norm_name}")
contact_by_norm_name[norm_name] = {
"Id": global_guid,
"Name": name_val,
"Name": canon_name,
"Email": rc.get("Email") or rc.get("email"),
"Phone": rc.get("Phone") or rc.get("phone"),
"Address": rc.get("Address") or rc.get("address"),
@@ -902,8 +967,9 @@ def main():
eff_dob_val = days_to_date(file_dates[filename])
raw_breeder = rg.get("OriginBreeder") or rg.get("originBreeder")
if raw_breeder and "klein" in raw_breeder.lower() and "chaot" in raw_breeder.lower() and "extern" not in raw_breeder.lower():
raw_breeder = "Zucht der kleinen Chaoten"
if raw_breeder:
norm_b, keep_b = get_normalized_contact_name(raw_breeder)
raw_breeder = norm_b if keep_b else None
all_processed_gerbils.append({
"Id": new_guid,
@@ -1005,8 +1071,9 @@ def main():
is_deaf = a["genotype"].get("deaf")
stammbaum_breeder = a.get("breeder") if a.get("breeder") else (a.get("zucht") if a.get("zucht") else None)
if stammbaum_breeder and "klein" in stammbaum_breeder.lower() and "chaot" in stammbaum_breeder.lower() and "extern" not in stammbaum_breeder.lower():
stammbaum_breeder = "Zucht der kleinen Chaoten"
if stammbaum_breeder:
norm_b, keep_b = get_normalized_contact_name(stammbaum_breeder)
stammbaum_breeder = norm_b if keep_b else None
all_processed_gerbils.append({
"Id": scoped_id,