from app.routers.lab import parse_date_fast, fetch_samples_light, fetch_orders_light, build_order_lookups, find_matches_in_memory from app.models import get_db from datetime import datetime, timedelta # Test Date Parsing d_str = "20250702.0" parsed = parse_date_fast(d_str) print(f"Parsing '{d_str}': {parsed}") if not parsed: print("CRITICAL: Date parsing failed!") # Test Data Fetching db = next(get_db()) start_date = (datetime.now() - timedelta(days=365)).strftime("%Y-%m-%d") print(f"Testing with Start Date: {start_date}") print("Fetching samples...") samples = fetch_samples_light(db, start_date=start_date) print(f"Fetched {len(samples)} samples.") if samples: print("Sample 0:", samples[0]) print("Fetching orders...") orders = fetch_orders_light(db, start_date=start_date) print(f"Fetched {len(orders)} orders.") # Test Matching lookups = build_order_lookups(orders) matches_found = 0 for s in samples: if not s['date']: continue matches = find_matches_in_memory(s, lookups) if matches: print(f"Match found for: {s['customer']} {s['pn']}") for m in matches: print(f" -> Order Date: {m['date']}, Sample Date: {s['date']}") if m['date'] >= s['date']: matches_found += 1 else: print(" -> INVALID (Order before Sample)") print(f"Total Matches Found: {matches_found}")