-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
30 lines (24 loc) · 850 Bytes
/
app.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
from flask import Flask, request, render_template
import json
app = Flask(__name__)
app.debug = True
@app.route("/")
def home():
return render_template('index.html')
@app.route("/spaceship/optimize", methods=["POST"])
def spaceship():
data = json.loads(request.form['payload'])
contracts = data['data']
contracts.sort(key=lambda x: x["start"] + x["duration"])
curr_time = 0
curr_profit = 0
path = []
for contract in contracts:
if contract["start"] >= curr_time:
curr_time = contract["start"] + contract["duration"]
curr_profit += contract["price"]
path.append(contract["name"])
response = {"income": curr_profit, "path": path}
return render_template('response.html', response=response)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)