Spaces:
Running
Running
Exclude rejected duplicate quotes and conflicting profile currencies from swap plans
Browse filesPreserve accepted quote identity when rejecting duplicate offer IDs, enforce unique anonymous profiles and country/currency consistency, and match the current offer's contracted power. Nine focused scenario tests passed, including the new duplicate and currency regressions.
Files changed (3)
- resources.zip+2-2
- resources_manifest.json+2-2
- scenarios.py+19-4
123version https://git-lfs.github.com/spec/v1oid sha256:c86c1f011c2b3acab9b9c7966c5244a81888209a07897501e87b3ba189f37845size 2963767123version https://git-lfs.github.com/spec/v1oid sha256:e70d2f5681bb4e2512e8f862ea34d55498c039a137d3b89bc4ef15b01e619067size 2963922
1234584 unmodified lines90919293949596{"archive_sha256": "c86c1f011c2b3acab9b9c7966c5244a81888209a07897501e87b3ba189f37845","files": {"assets/xenowattz-poster.png": "ffe946861e3c9671750b55c1e101a017137974fe933d4ddb53e16c38b826c502","assets/xenowattz_480.mp4": "dfb29c1b1ceaaa5804b273a7e38aaa4d52398581cbac703c9089dd5065d80717",84 unmodified lines"tests/test_billing.py": "7386e0a911028309da2b1e039d71d13980c6b3b68ce52e7e0f2fdb38d030d856","tests/test_bulk.py": "44a3fd530fec0f05f33e5c8a813c8a4303bd60b756f37c8099f2bd126a37d184","tests/test_core.py": "b6aaae17f5d3a0cf8c24d05c327f0a9f760814963a4611c4eafd8b6a42ef778b","tests/test_scenarios.py": "746aaf769257a030a85a43abe9f3680d442ca68901f4035db1b459314adf1b44","tests/test_sources.py": "cc62716a2a7e8cb0677e9c1ac2be736038587c6527bb3f87a2c5eb79db39bafa","scripts/acquire_price_snapshots.py": "47197872de69a61dcaf7d24d7a1492e18957eead556f7b958688fa1303bb68df","scripts/acquire_snapshots.py": "238274834b3ab3efc1ad4e6a44805221edbb7566d2f229cc82a9f7ab4b0eb8fd",1234584 unmodified lines90919293949596{"archive_sha256": "e70d2f5681bb4e2512e8f862ea34d55498c039a137d3b89bc4ef15b01e619067","files": {"assets/xenowattz-poster.png": "ffe946861e3c9671750b55c1e101a017137974fe933d4ddb53e16c38b826c502","assets/xenowattz_480.mp4": "dfb29c1b1ceaaa5804b273a7e38aaa4d52398581cbac703c9089dd5065d80717",84 unmodified lines"tests/test_billing.py": "7386e0a911028309da2b1e039d71d13980c6b3b68ce52e7e0f2fdb38d030d856","tests/test_bulk.py": "44a3fd530fec0f05f33e5c8a813c8a4303bd60b756f37c8099f2bd126a37d184","tests/test_core.py": "b6aaae17f5d3a0cf8c24d05c327f0a9f760814963a4611c4eafd8b6a42ef778b","tests/test_scenarios.py": "a425cab65838fbb34edcbe29d870c5da971504ef10c2afd9a08810b247d6a20c","tests/test_sources.py": "cc62716a2a7e8cb0677e9c1ac2be736038587c6527bb3f87a2c5eb79db39bafa","scripts/acquire_price_snapshots.py": "47197872de69a61dcaf7d24d7a1492e18957eead556f7b958688fa1303bb68df","scripts/acquire_snapshots.py": "238274834b3ab3efc1ad4e6a44805221edbb7566d2f229cc82a9f7ab4b0eb8fd",
79 unmodified lines808182838485861 unmodified line888990919293110 unmodified lines20420520620720820921021121221321421521621721879 unmodified linesfutures = boolean(options.get("assume_future_enrolment", False), "assume_future_enrolment")eligible = consumer_compare({**options, **profile, "as_of": as_of, "offers": offers})ids = {r["offer_id"] for r in eligible["ranked_offers"]}candidates = [{**validate_offer(r), **{k: r[k] for k in ["minimum_term_months", "exit_fee", "credit_vesting_months", "rate_curve", "entry_months"] if k in r}} for r in offers if str(r.get("offer_id")) in ids]if len(candidates) > 12:raise ValueError("Switching plans accept at most 12 eligible offers per profile.")current_provider = str(profile.get("provider", "current provider"))1 unmodified linebaseline = validate_offer(current)if baseline["country"] != profile["country"] or baseline["region"] not in {profile["region"], "ALL"} or not baseline["tax_included"]:raise ValueError("Current offer country, region and VAT basis must match the profile.")baseline.update({k: current[k] for k in ["minimum_term_months", "exit_fee", "credit_vesting_months", "rate_curve"] if k in current})baseline["guaranteed_credit"] = 0current_provider = baseline["provider"]110 unmodified linesstart = month_add(payload.get("start_month", month_add(as_of[:7],1)),0)if start < as_of[:7]:raise ValueError("Start month cannot precede as_of.")output, currencies = [], {}for index, profile in enumerate(profiles):if not isinstance(profile, dict) or profile.get("country") not in MARKETS:raise ValueError("Each profile must declare PT, DE or AU.")if profile.get("needs_review") and not boolean(payload.get("accept_profile_estimates", False), "accept_profile_estimates"):raise ValueError("Imported allocated/annualized bills need review and explicit accept_profile_estimates=true.")pid = str(profile.get("profile_id", f"profile-{index+1}"))if len(pid)>100 or not pid:raise ValueError("Use anonymous profile IDs of at most 100 characters.")plans = []for scenario in scenarios:if not isinstance(scenario,dict) or not isinstance(scenario.get("annual_price_change_pct",{}),dict):79 unmodified lines80818283848586878889909192939495961 unmodified line9899100101102103104105110 unmodified lines21621721821922022122222322422522622722822923023123223379 unmodified linesfutures = boolean(options.get("assume_future_enrolment", False), "assume_future_enrolment")eligible = consumer_compare({**options, **profile, "as_of": as_of, "offers": offers})ids = {r["offer_id"] for r in eligible["ranked_offers"]}candidates=[]selected_ids=set()for r in offers:offer_id=str(r.get("offer_id"))if offer_id not in ids or offer_id in selected_ids:continue# The accepted IDs alone cannot distinguish a rejected duplicate row.if not consumer_compare({**options,**profile,"as_of":as_of,"offers":[r]})["ranked_offers"]:continueselected_ids.add(offer_id)candidates.append({**validate_offer(r), **{k:r[k] for k in ["minimum_term_months","exit_fee","credit_vesting_months","rate_curve","entry_months"] if k in r}})if len(candidates) > 12:raise ValueError("Switching plans accept at most 12 eligible offers per profile.")current_provider = str(profile.get("provider", "current provider"))1 unmodified linebaseline = validate_offer(current)if baseline["country"] != profile["country"] or baseline["region"] not in {profile["region"], "ALL"} or not baseline["tax_included"]:raise ValueError("Current offer country, region and VAT basis must match the profile.")if profile.get("contracted_power_kva") is not None and (baseline.get("contracted_power_kva") is None or not math.isclose(float(profile["contracted_power_kva"]),baseline["contracted_power_kva"],abs_tol=.001)):raise ValueError("Current offer must explicitly match contracted kVA power.")baseline.update({k: current[k] for k in ["minimum_term_months", "exit_fee", "credit_vesting_months", "rate_curve"] if k in current})baseline["guaranteed_credit"] = 0current_provider = baseline["provider"]110 unmodified linesstart = month_add(payload.get("start_month", month_add(as_of[:7],1)),0)if start < as_of[:7]:raise ValueError("Start month cannot precede as_of.")output, currencies, seen_profiles = [], {}, set()for index, profile in enumerate(profiles):if not isinstance(profile, dict) or profile.get("country") not in MARKETS:raise ValueError("Each profile must declare PT, DE or AU.")if profile.get("currency",MARKETS[profile["country"]])!=MARKETS[profile["country"]]:raise ValueError("Profile currency must match its country; no conversion is performed.")if profile.get("needs_review") and not boolean(payload.get("accept_profile_estimates", False), "accept_profile_estimates"):raise ValueError("Imported allocated/annualized bills need review and explicit accept_profile_estimates=true.")pid = str(profile.get("profile_id", f"profile-{index+1}"))if len(pid)>100 or not pid or pid in seen_profiles:raise ValueError("Use unique anonymous profile IDs of at most 100 characters.")seen_profiles.add(pid)plans = []for scenario in scenarios:if not isinstance(scenario,dict) or not isinstance(scenario.get("annual_price_change_pct",{}),dict):
resources.zip+2-2
resources_manifest.json+2-2
scenarios.py+19-4