MCPcopy Create free account
hub / github.com/google/adk-samples / compute_aggregate_stats

Function compute_aggregate_stats

python/agents/invoice-processing/eval/eval.py:1024–1067  ·  view source on GitHub ↗

Compute aggregate statistics across all evaluated cases. When master data is provided, dynamically computes per-group and per-field accuracy from eval_schema.comparison_groups instead of hardcoded field names.

(
    results: list[dict], master: MasterData | None = None
)

Source from the content-addressed store, hash-verified

1022
1023
1024def compute_aggregate_stats(
1025 results: list[dict], master: MasterData | None = None
1026) -> dict:
1027 """Compute aggregate statistics across all evaluated cases.
1028
1029 When master data is provided, dynamically computes per-group and per-field
1030 accuracy from eval_schema.comparison_groups instead of hardcoded field names.
1031 """
1032 evaluated = [r for r in results if r.get("status") != "ERROR"]
1033 errors = [r for r in results if r.get("status") == "ERROR"]
1034
1035 if not evaluated:
1036 return {"total": len(results), "evaluated": 0, "errors": len(errors)}
1037
1038 total = len(evaluated)
1039 passed = sum(1 for r in evaluated if r["all_correct"])
1040
1041 decision_correct = sum(1 for r in evaluated if r["decision"]["match"])
1042 decision_matrix = _compute_decision_matrix(evaluated)
1043
1044 if master:
1045 group_accuracy, field_stats = _compute_group_and_field_stats_schema(
1046 evaluated, master, total
1047 )
1048 else:
1049 group_accuracy, field_stats = _compute_group_and_field_stats_legacy(
1050 evaluated, total
1051 )
1052
1053 llm_stats = _compute_llm_stats(evaluated)
1054
1055 return {
1056 "total": len(results),
1057 "evaluated": total,
1058 "errors": len(errors),
1059 "passed": passed,
1060 "failed": total - passed,
1061 "pass_rate": passed / total,
1062 "decision_accuracy": decision_correct / total,
1063 "decision_matrix": decision_matrix,
1064 "group_accuracy": group_accuracy,
1065 "field_stats": field_stats,
1066 "llm_alignment": llm_stats,
1067 }
1068
1069
1070def _print_decision_stats(stats: dict) -> None:

Callers 1

mainFunction · 0.85

Calls 5

_compute_decision_matrixFunction · 0.85
_compute_llm_statsFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected