Skip to content

Instantly share code, notes, and snippets.

@stef
Created February 1, 2024 14:11
Show Gist options
  • Save stef/127c0109335b68551604b8670159a35e to your computer and use it in GitHub Desktop.
Save stef/127c0109335b68551604b8670159a35e to your computer and use it in GitHub Desktop.
# 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