Spaces:
Sleeping
Sleeping
| def compute_transparency_scorecard(results): | |
| agencies = {} | |
| for r in results: | |
| a = r["source"] | |
| agencies.setdefault(a, { | |
| "documents": 0, | |
| "exemptions": 0, | |
| "latest_date": None, | |
| }) | |
| agencies[a]["documents"] += 1 | |
| agencies[a]["exemptions"] += len(r.get("exemptions", [])) | |
| if r.get("date"): | |
| agencies[a]["latest_date"] = max( | |
| agencies[a]["latest_date"] or r["date"], | |
| r["date"], | |
| ) | |
| scorecard = [] | |
| for agency, m in agencies.items(): | |
| scorecard.append({ | |
| "agency": agency, | |
| "doc_count": m["documents"], | |
| "exemptions_per_doc": round(m["exemptions"] / max(m["documents"], 1), 2), | |
| "last_release": m["latest_date"], | |
| "transparency_score": min( | |
| 100, | |
| m["documents"] * 2 - m["exemptions"] | |
| ), | |
| }) | |
| return scorecard |