From 0286f25f0f9e036d287274124181192a03e8756d Mon Sep 17 00:00:00 2001 From: Shak Date: Sun, 27 Nov 2022 22:49:12 -0800 Subject: [PATCH] adding voting analyses as an experiment --- cdp_data/instances.py | 3 +++ cdp_data/tests/voting_analysis.py | 37 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 cdp_data/tests/voting_analysis.py diff --git a/cdp_data/instances.py b/cdp_data/instances.py index d0101a2..4e18bb3 100644 --- a/cdp_data/instances.py +++ b/cdp_data/instances.py @@ -31,3 +31,6 @@ class CDPInstances: Richmond = "cdp-richmond-a3d06941" Louisville = "cdp-louisville-6fd32a38" Atlanta = "cdp-atlanta-37e7dd70" + + all_instances = [Seattle, KingCounty, Portland, Missoula, Denver, Alameda, Boston, Oakland, Charlotte, SanJose, + MountainView, Milwaukee, LongBeach, Albuquerque, Richmond, Louisville, Atlanta] diff --git a/cdp_data/tests/voting_analysis.py b/cdp_data/tests/voting_analysis.py new file mode 100644 index 0000000..7424e24 --- /dev/null +++ b/cdp_data/tests/voting_analysis.py @@ -0,0 +1,37 @@ +from cdp_data import CDPInstances, datasets + + +def voting_analysis(cdp_instance:str, start_datetime:str, end_datetime:str,): + ds = datasets.get_vote_dataset(cdp_instance,start_datetime=start_datetime,end_datetime=end_datetime,replace_py_objects=True) + + ds=ds[['matter_id','event_datetime','event_minutes_item_overall_decision','in_majority','decision','person_name']].sort_values(by=['matter_id']) + + #all of the voting in the system + ds_all_votes = ds.groupby(['matter_id','event_datetime','event_minutes_item_overall_decision']) + + #all of the votings that passed + df_passed = ds_all_votes['event_minutes_item_overall_decision'].apply(lambda x: (x == 'Passed').sum()).reset_index(name='count') + + #all of voting that were not unanimous + df_count_objection = ds.groupby(['matter_id'])['in_majority'].apply(lambda x: (x == False).sum()).reset_index(name='count') + df_count_objection = df_count_objection[df_count_objection['count'] != 0] +# print(ds_all_votes) +# print(df_passed) +# print(df_count_objection) + return (len(ds_all_votes),len(df_passed),len(df_count_objection)) + + +""" +f = open("council_vote_data.txt", "a") + + +for instance in CDPInstances.all_instances: + res = voting_analysis(instance, "2022-10-01", "2022-10-31") + f.write(instance + "\t" + str(res[0]) + "\t" + str(res[1]) + "\t" + str(res[2])) + f.write("\n") + +f.close() +""" + +res = voting_analysis(CDPInstances.Oakland, "2022-10-01", "2022-10-30") +print(res)