-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
88 lines (71 loc) · 2.51 KB
/
Copy pathserver.py
File metadata and controls
88 lines (71 loc) · 2.51 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from flask import Flask, jsonify, request
import hashlib
import random
from datetime import datetime
app = Flask(__name__)
# Mock Database
judges = [
{"id": 1, "name": "Judge A", "conflicts": ["CorpX"], "wealth_reports": []},
{"id": 2, "name": "Judge B", "conflicts": [], "wealth_reports": []},
{"id": 3, "name": "Judge C", "conflicts": ["PolPartyY"], "wealth_reports": []},
]
cases = [
{"id": 101, "defendant": "CorpX", "category": "corporate"},
{"id": 102, "defendant": "John Doe", "category": "criminal"},
{"id": 103, "defendant": "PolPartyY", "category": "political"},
]
assignments = []
# Helper: Hash wealth reports for immutability
def hash_wealth_report(judge_id, year, assets):
data = f"{judge_id}-{year}-{assets}"
return hashlib.sha256(data.encode()).hexdigest()
# API 1: Assign a judge to a case (conflict-check + random selection)
@app.route('/assign', methods=['POST'])
def assign_judge():
case_id = request.json.get('case_id')
case = next((c for c in cases if c['id'] == case_id), None)
if not case:
return jsonify({"error": "Case not found"}), 404
# Filter judges with no conflicts
eligible_judges = [
j for j in judges
if case['defendant'] not in j['conflicts']
]
if not eligible_judges:
return jsonify({"error": "No eligible judges"}), 400
# Random assignment
selected_judge = random.choice(eligible_judges)
assignment = {
"case_id": case_id,
"judge_id": selected_judge['id'],
"timestamp": datetime.now().isoformat()
}
assignments.append(assignment)
return jsonify(assignment)
# API 2: Submit a wealth report (stored as hash)
@app.route('/wealth', methods=['POST'])
def submit_wealth():
judge_id = request.json.get('judge_id')
year = request.json.get('year')
assets = request.json.get('assets')
judge = next((j for j in judges if j['id'] == judge_id), None)
if not judge:
return jsonify({"error": "Judge not found"}), 404
# Store hashed report
report_hash = hash_wealth_report(judge_id, year, assets)
judge['wealth_reports'].append({
"year": year,
"assets": assets,
"hash": report_hash
})
return jsonify({"status": "success", "hash": report_hash})
# API 3: Get all data for dashboard
@app.route('/data', methods=['GET'])
def get_data():
return jsonify({
"judges": judges,
"cases": cases,
"assignments": assignments
})
if __name__ == '__main__':
app.run(debug=True)