Skip to content

Commit

Permalink
Merge pull request #38 from DanLaRoche/master
Browse files Browse the repository at this point in the history
Added relativeDiff endpoint to allow for heatmap
  • Loading branch information
DanLaRoche committed Dec 7, 2018
2 parents 0e7e75c + 481a832 commit 7929e89
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cerp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ def topic_diff(topic, precinctNum):
diff_data = diff_data[['diff']].copy()
return jsonify(result=True, data=json.loads(diff_data.to_json())['diff'])

@app.route('/api/<topic>/<precinctNum>/relativeDiff')
def topic_relativeDiff(topic, precinctNum):
comp1 = request.args.get('comp1', 'YES/FOR')
comp2 = request.args.get('comp2', 'NO/AGAINST')

if precinctNum != 'all':
d = data.ELECTION_DATA[topic]['data'].loc[precinctNum]
diff_data = ((-1 * d[comp1]) + d[comp2])/(d[comp1] + d[comp2])
return jsonify(result=True, data=int(diff_data))

d = data.ELECTION_DATA[topic]['data']
diff_data = d[[comp1, comp2]].copy()
diff_data['diff'] = diff_data.apply(
lambda row: ((-1 * row[comp1]) + row[comp2])/(row[comp1] + row[comp2]),
axis=1
)
diff_data = diff_data[['diff']].copy()
return jsonify(result=True, data=json.loads(diff_data.to_json())['diff'])

@app.route('/api/<topic>/<precinctNum>/meta')
def topic_meta(topic, precinctNum):
Expand All @@ -134,3 +152,7 @@ def topic_meta(topic, precinctNum):
result=True,
data=data.ELECTION_DATA[topic]['meta']
)

@app.route('/api/<topic>/<precinctNum>/heatmap')
def topic_heatmap(topic, precinctNum):
pass

0 comments on commit 7929e89

Please sign in to comment.