-
Notifications
You must be signed in to change notification settings - Fork 15
/
server.py
78 lines (60 loc) · 2.44 KB
/
server.py
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
from flask import Flask, request, render_template, jsonify
from flask_cors import CORS
import os
import glob
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as sts
import seaborn as sns
import simulation
from networkx.readwrite import json_graph
app = Flask(__name__, static_url_path='')
CORS(app)
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
def jsonifyNetwork(network):
obj = json_graph.node_link_data(network)
return obj
@app.route('/')
def root():
return app.send_static_file('index.html')
@app.route('/api/cadcad', methods=['POST'])
def cadcad():
try:
params = request.get_json()
hatchers = int(params['hatchers'])
proposals = int(params['proposals'])
hatch_tribute = float(params['hatch_tribute'])
vesting_80p_unlocked = int(params['vesting_80p_unlocked'])
exit_tribute = float(params['exit_tribute'])
kappa = float(params['kappa'])
days_to_80p_of_max_voting_weight = int(
params['days_to_80p_of_max_voting_weight'])
max_proposal_request = float(params['max_proposal_request'])
except Exception as err:
return str(err), 422
c = simulation.simulation.CommonsSimulationConfiguration(hatchers=hatchers, proposals=proposals, days_to_80p_of_max_voting_weight=days_to_80p_of_max_voting_weight,
max_proposal_request=max_proposal_request, exit_tribute=exit_tribute)
result, df = simulation.simrunner.run_simulation(c)
for ind in range(len(df)):
r = results[ind]['result']
# print(results[ind]['simulation_parameters'])
r.plot(x='timestep', y='funds')
plt.savefig('static/plot8-'+str(ind)+'.png')
plt.clf()
fig, ax1 = plt.subplots()
ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis
df = r
rdf = df[df.substep == 4].copy()
rdf.plot(x='timestep', y=['funds', 'reserve', 'supply'], ax=ax1)
rdf.plot(x='timestep', y='spot_price', style='--',
color='red', ax=ax2, legend=False)
ax2.set_ylabel('Price in xDAI per Token', color='red')
ax1.set_ylabel('Quantity of Assets')
ax2.tick_params(axis='y', labelcolor='red')
plt.title('Summary of Local Economy')
plt.savefig('static/plot9-'+str(ind)+'.png')
plt.clf()
return jsonify({
'results': ['plot8-0.png', 'plot9-0.png']
})