-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsponsorship_stats.py
35 lines (32 loc) · 1.11 KB
/
sponsorship_stats.py
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
27
28
29
30
31
32
33
34
35
from openstates.data.models import BillSponsorship, LegislativeSession
from openstates.metadata import STATES_BY_NAME
import csv
out = csv.writer(open("sponsorships.csv", "w"))
out.writerow(("state", "session", "total", "unmatched", "percent_matched", "distinct"))
for state in STATES_BY_NAME.values():
session = (
LegislativeSession.objects.filter(jurisdiction_id=state.jurisdiction_id).exclude(classification="special")
.order_by("start_date")
.last()
)
print(state.name, session)
qs = BillSponsorship.objects.filter(bill__legislative_session=session)
total_sponsorships = qs.count()
unmatched_sponsorships = qs.filter(person_id=None).count()
distinct = qs.filter(person_id=None).distinct("name").count()
if total_sponsorships:
percent = (
(total_sponsorships - unmatched_sponsorships) / total_sponsorships * 100
)
else:
percent = 100
out.writerow(
(
state.name,
session.name,
total_sponsorships,
unmatched_sponsorships,
percent,
distinct,
)
)