-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.py
65 lines (50 loc) · 1.57 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
from datetime import datetime
from io import BytesIO
import json
from flask import Flask
from flask import jsonify
from flask import render_template
from flask import request
from flask import send_file
import matplotlib
from analysis import classify_coin
from analysis import normalize
from analysis import raw_to_dataframe
matplotlib.use('svg')
from matplotlib import pyplot
matplotlib.pyplot.style.use('seaborn')
server = Flask(__name__)
last_coin = {}
last_coin['curve'] = None
last_coin['coin'] = 'unknown'
last_coin['datetime'] = datetime.today().isoformat()
@server.route("/", methods=['GET'])
def view():
return render_template('view.html')
@server.route('/analyze', methods=['POST'])
def analyze():
raw = request.get_data()
curve = raw_to_dataframe(raw)
curve = normalize(curve)
last_coin['curve'] = curve
last_coin['datetime'] = datetime.today().isoformat()
coin = classify_coin(curve)
last_coin['coin'] = coin
if last_coin['coin'] == -1:
last_coin['coin'] = 'unknown'
return 'ok'
@server.route('/curve')
def curve():
if last_coin['curve'] is None:
return send_file('static/insert_coin.svg', mimetype='image/svg+xml')
figure = last_coin['curve'].plot().get_figure()
img = BytesIO()
figure.savefig(img)
img.seek(0)
return send_file(img, mimetype='image/svg+xml')
@server.route('/result', methods=['GET'])
def result():
return jsonify(coin=last_coin['coin'], datetime=last_coin['datetime'])
config = json.load(open('config.json'))
x = config['server']
server.run(host=x['host'],port=int(x['port']))