2019-09-20 14:27:07 +02:00
|
|
|
from flask import Flask,render_template
|
2019-09-20 14:15:20 +02:00
|
|
|
import datetime
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
# We request users to send the run number to prevent accidentially getting old requests from a previous run
|
|
|
|
# This maybe will give to much errors from people forgetting to change their number
|
|
|
|
# Remove it?
|
|
|
|
|
|
|
|
# TODO
|
|
|
|
# Save and read from a file to persist over reboots
|
|
|
|
# Save progress through time during 1 run
|
|
|
|
# Save result of different runs
|
|
|
|
|
|
|
|
db = {
|
|
|
|
"current_run": 0,
|
|
|
|
"run_start_timer": None,
|
|
|
|
"run_data": {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@app.route("/")
|
|
|
|
def index():
|
2019-09-20 14:27:07 +02:00
|
|
|
return render_template("index.html")
|
2019-09-20 14:15:20 +02:00
|
|
|
|
|
|
|
@app.route("/start_run/<run_index>")
|
|
|
|
def start_run(run_index):
|
|
|
|
db["current_run"] = run_index
|
|
|
|
starttime = datetime.datetime.now()
|
|
|
|
db["run_data"][run_index] = {
|
|
|
|
"starttime": starttime,
|
|
|
|
"data": {}
|
|
|
|
}
|
|
|
|
# TODO send start request to the first person in the chain. Probably a zeus part already written as example
|
|
|
|
return f'Run {run_index} started at {starttime}'
|
|
|
|
|
|
|
|
@app.route("/checkpoint/start/<run>/<index>")
|
|
|
|
def checkpoint_start(run, index):
|
|
|
|
if db["current_run"] != run:
|
|
|
|
return "Wrong run number, you are probably behind.", 404
|
|
|
|
else:
|
|
|
|
db["run_data"][run]["data"][index]["start"] = datetime.datetime.now()
|
|
|
|
return "Success."
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/checkpoint/handoff/<run>/<index>")
|
|
|
|
def checkpoint_handoff(run, index):
|
|
|
|
if db["current_run"] != run:
|
|
|
|
return "Wrong run number, you are probably behind.", 404
|
|
|
|
else:
|
|
|
|
db["run_data"][run]["data"][index]["handoff"] = datetime.datetime.now()
|
|
|
|
return "Success."
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app.run(debug=True)
|