feat(import): resolve color variety ID mappings mismatch, support unnamed parents in virtual litters, and implement SaleContract updates
This commit is contained in:
@@ -71,15 +71,38 @@ def main():
|
||||
|
||||
# Load color variety seeds
|
||||
print("Loading color variety seeds...")
|
||||
variety_map = {}
|
||||
|
||||
# Load from C# ApplicationContext.cs catalog for stable database GUIDs (index + 1)
|
||||
app_context_path = os.path.abspath(os.path.join(HERE, "..", "..", "GerbilManagerWebAPI", "ApplicationContext.cs"))
|
||||
cs_name_to_id = {}
|
||||
if os.path.exists(app_context_path):
|
||||
with open(app_context_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
catalog_match = re.search(r'catalog\s*=\s*\{(.*?)\};', content, re.DOTALL)
|
||||
if catalog_match:
|
||||
block = catalog_match.group(1)
|
||||
entries = re.findall(r'\(\s*"([^"]+)"\s*,\s*"([^"]+)"\s*,\s*(\d+)\s*\)', block)
|
||||
for idx, (name, genotype, sort_order) in enumerate(entries):
|
||||
variety_id = f"00000000-0000-0000-0000-{idx + 1:012d}"
|
||||
cs_name_to_id[name.strip().lower()] = variety_id
|
||||
variety_map[name.strip().lower()] = variety_id
|
||||
else:
|
||||
print(f"Warning: ApplicationContext.cs not found at {app_context_path}")
|
||||
|
||||
with open(SEEDS_PATH, "r", encoding="utf-8") as f:
|
||||
seeds = json.load(f)
|
||||
|
||||
# Map variety name -> Guid
|
||||
variety_map = {}
|
||||
for v in seeds:
|
||||
# UUID is based on SortOrder + 1
|
||||
variety_id = f"00000000-0000-0000-0000-{v['sortOrder'] + 1:012d}"
|
||||
variety_map[v["name"].strip().lower()] = variety_id
|
||||
name_lower = v["name"].strip().lower()
|
||||
variety_id = cs_name_to_id.get(name_lower)
|
||||
if not variety_id:
|
||||
variety_id = f"00000000-0000-0000-0000-{v['sortOrder'] + 1:012d}"
|
||||
variety_map[name_lower] = variety_id
|
||||
|
||||
# Map English name if present
|
||||
if "english" in v and v["english"]:
|
||||
variety_map[v["english"].strip().lower()] = variety_id
|
||||
|
||||
# 1. Establish stable Guid maps
|
||||
animal_guid_map = {a["id"]: generate_guid(f"animal-{a['id']}") for a in animals}
|
||||
@@ -297,12 +320,12 @@ def main():
|
||||
elif not is_resident:
|
||||
status = "GivenAway"
|
||||
else:
|
||||
# Age presumed deceased (>7 years)
|
||||
# Age presumed deceased (>6 years)
|
||||
if dob:
|
||||
dt_dob = datetime.strptime(dob, "%Y-%m-%d")
|
||||
dt_now = datetime.now()
|
||||
age_years = (dt_now - dt_dob).days / 365.25
|
||||
if age_years >= 7.0:
|
||||
if age_years >= 6.0:
|
||||
status = "Deceased"
|
||||
else:
|
||||
status = "Breeding" # default to breeding for resident stock
|
||||
|
||||
Reference in New Issue
Block a user