a2a-source-edit: write agent.py
This commit is contained in:
12
agent.py
12
agent.py
@@ -312,6 +312,16 @@ def _score_higher_is_better(value: float, minimum: float, maximum: float) -> flo
|
||||
return ((value - minimum) / (maximum - minimum)) * 100.0
|
||||
|
||||
|
||||
def _comparison_sort_key(row: dict[str, Any]) -> tuple[Any, ...]:
|
||||
return (
|
||||
-row["weighted_score"],
|
||||
row["total_price"],
|
||||
row["delivery_days"],
|
||||
-row["warranty_months"],
|
||||
row["vendor"].casefold(),
|
||||
)
|
||||
|
||||
|
||||
def _build_comparison(comparison_id: str, quotes: list[QuoteInput], weights: WeightInput) -> dict[str, Any]:
|
||||
prices = [q.unit_price for q in quotes]
|
||||
deliveries = [q.delivery_days for q in quotes]
|
||||
@@ -338,7 +348,7 @@ def _build_comparison(comparison_id: str, quotes: list[QuoteInput], weights: Wei
|
||||
"weighted_score": round(weighted_score, 4),
|
||||
}
|
||||
)
|
||||
rows.sort(key=lambda item: (-item["weighted_score"], item["total_price"], item["delivery_days"], -item["warranty_months"], item["vendor"].casefold()))
|
||||
rows.sort(key=_comparison_sort_key)
|
||||
winner = rows[0]
|
||||
return {
|
||||
"ok": True,
|
||||
|
||||
Reference in New Issue
Block a user