-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.py
executable file
·35 lines (25 loc) · 868 Bytes
/
api.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
#! /usr/bin/env python2
import json
from flask import Flask, request, abort, redirect
from flask_cors import CORS
PORT = 8090
app = Flask(__name__)
CORS(app)
def tofloat(val):
"""Convert passed variable to float if possible, otherwise return 0."""
try:
return float(val)
except ValueError:
return 0.0
@app.route('/normaliz/<string:v1>/<string:v2>', methods=['GET'])
def normaliz(v1, v2):
"""Get the hilbert basis for the two passed vectors."""
v1 = list(map(tofloat, v1.split(',')))[:2]
v2 = list(map(tofloat, v2.split(',')))[:2]
# TODO: Calculate Hilber Basis
# cone = PyNormaliz.NmzCone('cone', [v1, v2])
# hb = PyNormaliz.NmzResult(cone, 'HilbertBasis')
# TODO: Return Hilbert Basis for visualization on client side.
return json.dumps([v1, v2])
if __name__ == '__main__':
app.run(port=PORT)