Spaces:
Sleeping
Sleeping
Create ingest/scorecard.py
Browse files- ingest/scorecard.py +34 -0
ingest/scorecard.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def compute_transparency_scorecard(results):
|
| 2 |
+
agencies = {}
|
| 3 |
+
|
| 4 |
+
for r in results:
|
| 5 |
+
a = r["source"]
|
| 6 |
+
agencies.setdefault(a, {
|
| 7 |
+
"documents": 0,
|
| 8 |
+
"exemptions": 0,
|
| 9 |
+
"latest_date": None,
|
| 10 |
+
})
|
| 11 |
+
|
| 12 |
+
agencies[a]["documents"] += 1
|
| 13 |
+
agencies[a]["exemptions"] += len(r.get("exemptions", []))
|
| 14 |
+
|
| 15 |
+
if r.get("date"):
|
| 16 |
+
agencies[a]["latest_date"] = max(
|
| 17 |
+
agencies[a]["latest_date"] or r["date"],
|
| 18 |
+
r["date"],
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
scorecard = []
|
| 22 |
+
for agency, m in agencies.items():
|
| 23 |
+
scorecard.append({
|
| 24 |
+
"agency": agency,
|
| 25 |
+
"doc_count": m["documents"],
|
| 26 |
+
"exemptions_per_doc": round(m["exemptions"] / max(m["documents"], 1), 2),
|
| 27 |
+
"last_release": m["latest_date"],
|
| 28 |
+
"transparency_score": min(
|
| 29 |
+
100,
|
| 30 |
+
m["documents"] * 2 - m["exemptions"]
|
| 31 |
+
),
|
| 32 |
+
})
|
| 33 |
+
|
| 34 |
+
return scorecard
|