Spaces:
Running
Running
File size: 750 Bytes
3eae4cc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | """
utils.py — Shared pure-function helpers.
No imports from env.py or simulator.py (prevents circular imports).
"""
from __future__ import annotations
from app.models import ServiceType
def completion_fairness_gap(
arrived_by_service: dict,
completed_by_service: dict,
) -> float:
"""
Fairness gap = max completion rate difference across services.
Returns 0.0 if only one service, 1.0 if perfectly unfair.
"""
rates = []
for svc in arrived_by_service:
arrived = arrived_by_service.get(svc, 0)
completed = completed_by_service.get(svc, 0)
if arrived > 0:
rates.append(completed / arrived)
if len(rates) < 2:
return 0.0
return round(max(rates) - min(rates), 4)
|