Created
February 1, 2024 14:11
-
-
Save stef/127c0109335b68551604b8670159a35e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run this directly in the db console | |
# for example for hungarian fidesz: | |
# for m, s, e, p in vote_ratio('Fidesz-Magyar Polgári Szövetség-Kereszténydemokrata Néppárt'): print(f"{m} {p:.2f}%") | |
# for more info how to play with parltrack data locally see | |
# https://parltrack.org/blog/playing-with-the-data-locally.html | |
# and other follow-up blogposts | |
def vote_ratio(target): | |
return [(m['Name']['full'], | |
c['start'], | |
c['end'], | |
sum([1 | |
for v in DBS['ep_votes'].values() if v['ts'] >= c['start'] and v['ts'] <= c['end'] | |
for t in v.get('votes',{}).values() | |
for g in t['groups'].values() | |
for mv in g if mv['mepid']==m['UserID']]) | |
/ | |
sum([1 | |
for v in DBS['ep_votes'].values() if v['ts'] >= c['start'] and v['ts'] <= c['end']]) | |
* 100) | |
for m in DBS['ep_meps'].values() | |
for c in m.get('Constituencies',[]) if c and c.get('party') == target and c['start'] >= '2019-07-02T00:00:00'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment