hyf

Context-aware query service for Radroots
git clone https://radroots.dev/git/hyf.git
Log | Files | Refs | README | LICENSE

commit fe6e745c3ba0b4d7bf7475fa0beb31a20b949626
parent bcc682b4b53a315ad1b81bd35ce716a552b28506
Author: triesap <tyson@radroots.org>
Date:   Mon, 21 Sep 2026 13:55:05 +0000

core: group compatible lots by supplier

Diffstat:
Asrc/hyf_application/match_plan.mojo | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/test_application.mojo | 28++++++++++++++++++++++++++++
2 files changed, 82 insertions(+), 0 deletions(-)

diff --git a/src/hyf_application/match_plan.mojo b/src/hyf_application/match_plan.mojo @@ -0,0 +1,54 @@ +from std.collections import List + +from hyf_core.domain.plan import ( + Allocation, + LotCapacity, + MatchPlan, + allocation, + match_plan, + plan_conservation_violations, +) + + +def group_lots_by_supplier( + lot_ids: List[String], supplier_ids: List[String] +) raises -> List[String]: + if len(lot_ids) != len(supplier_ids): + raise Error("lot ids and supplier ids must align") + var suppliers = List[String]() + for supplier in supplier_ids: + if String(supplier).strip().byte_length() == 0: + raise Error("supplier id must not be empty") + var seen = False + for existing in suppliers: + if existing == supplier: + seen = True + if not seen: + suppliers.append(String(supplier)) + return suppliers^ + + +def allocate_single_line( + plan_id: String, + line_id: String, + supplier_id: String, + required_value: Int, + required_scale: Int, + lots: List[LotCapacity], +) raises -> MatchPlan: + var remaining = required_value + var allocations = List[Allocation]() + for lot in lots: + if remaining <= 0: + break + var capacity = lot.value + var take = remaining if remaining < capacity else capacity + allocations.append( + allocation(lot.lot_id, lot.revision, line_id, take, lot.scale) + ) + remaining -= take + return match_plan(plan_id, supplier_id, allocations) + + +def multi_supplier_is_supported() -> Bool: + return False diff --git a/tests/test_application.mojo b/tests/test_application.mojo @@ -508,3 +508,31 @@ def test_compose_applicable_checks_before_ranking() raises: only_unknown.append(constraint_assessment("quantity", "unknown", True, "stock_unknown")) assert_equal(compose_applicable_checks(only_unknown), "conditional") assert_true(not scores_affect_feasibility()) + + +from hyf_application.match_plan import ( + allocate_single_line, + group_lots_by_supplier, + multi_supplier_is_supported, +) +from hyf_core.domain.plan import LotCapacity, plan_conservation_violations + + +def test_supplier_grouping_and_bounded_allocation() raises: + var lots = List[String]() + lots.append("lot-1") + lots.append("lot-2") + var suppliers = List[String]() + suppliers.append("farm-1") + suppliers.append("farm-1") + var grouped = group_lots_by_supplier(lots, suppliers) + assert_equal(len(grouped), 1) + assert_equal(grouped[0], "farm-1") + + var capacities = List[LotCapacity]() + capacities.append(LotCapacity(lot_id="lot-1", revision="l1", value=30, scale=0)) + capacities.append(LotCapacity(lot_id="lot-2", revision="l1", value=40, scale=0)) + var plan = allocate_single_line("p1", "line-1", "farm-1", 50, 0, capacities) + assert_equal(len(plan.allocations), 2) + assert_equal(len(plan_conservation_violations(plan, capacities)), 0) + assert_true(not multi_supplier_is_supported())