Compare commits
No commits in common. "9a44e8363725e7851fc6f38ab3db3051ec59d0f0" and "a7ddca1d0b5a680d667289e1002b24a0dee74f55" have entirely different histories.
9a44e83637
...
a7ddca1d0b
|
@ -1,14 +1,7 @@
|
||||||
import asyncio
|
from time import time
|
||||||
import atexit
|
|
||||||
import datetime
|
|
||||||
import socket
|
|
||||||
from functools import lru_cache
|
|
||||||
from time import sleep, time
|
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
import socketio
|
import socketio
|
||||||
from apscheduler.schedulers.background import BackgroundScheduler
|
from flask import Flask, render_template
|
||||||
from flask import Flask, render_template, request
|
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
|
|
||||||
sio = socketio.Server()
|
sio = socketio.Server()
|
||||||
|
@ -27,9 +20,6 @@ app.wsgi_app = socketio.WSGIApp(sio, app.wsgi_app)
|
||||||
|
|
||||||
db = {"current_run": None, "run_start_timer": None, "run_data": {}}
|
db = {"current_run": None, "run_start_timer": None, "run_data": {}}
|
||||||
|
|
||||||
function_times = []
|
|
||||||
function_data = []
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
|
@ -48,26 +38,18 @@ def start_run(run_index):
|
||||||
return f'Run {run_index} started at {starttime}'
|
return f'Run {run_index} started at {starttime}'
|
||||||
|
|
||||||
|
|
||||||
@app.route("/link/start/<run>/<link_index>")
|
@app.route("/link/start/<run>/<index>")
|
||||||
def link_start(run, link_index):
|
def link_start(run, index):
|
||||||
start = time()
|
|
||||||
request_data = live_request(run, link_index)
|
|
||||||
sio.emit('live_request', request_data)
|
|
||||||
|
|
||||||
if db["current_run"] != run:
|
if db["current_run"] != run:
|
||||||
response = "Wrong run number, check that you update your run", 404
|
return "Wrong run number, check that you update your run", 404
|
||||||
else:
|
else:
|
||||||
run_data = db["run_data"][run]["data"]
|
run_data = db["run_data"][run]["data"]
|
||||||
if link_index in run_data:
|
if index in run_data:
|
||||||
response = "you already started in this run. Ignoring this request."
|
return "you already started in this run. Ignoring this request."
|
||||||
else:
|
else:
|
||||||
run_data[link_index] = {"id": link_index, "start": time()}
|
run_data[index] = {"id": index, "start": time()}
|
||||||
sio.emit('link_start', run_data[link_index])
|
sio.emit('link_start', run_data[index])
|
||||||
response = "Success."
|
return "Success."
|
||||||
stop = time()
|
|
||||||
function_data.append(stop - start)
|
|
||||||
function_times.append(len(function_times))
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/link/handoff/<run>/<index>")
|
@app.route("/link/handoff/<run>/<index>")
|
||||||
|
@ -91,34 +73,5 @@ def connect(sid, data):
|
||||||
sio.emit('sync_current_run', current_run, room=sid)
|
sio.emit('sync_current_run', current_run, room=sid)
|
||||||
|
|
||||||
|
|
||||||
def live_request(run, index):
|
|
||||||
ip = request.remote_addr
|
|
||||||
request_data = {}
|
|
||||||
request_data["hostname"] = lookup_hostname(ip)
|
|
||||||
request_data["time"] = time()
|
|
||||||
return request_data
|
|
||||||
|
|
||||||
|
|
||||||
@lru_cache()
|
|
||||||
def lookup_hostname(ip):
|
|
||||||
return socket.gethostbyaddr(ip)[0].split(".")[0]
|
|
||||||
|
|
||||||
|
|
||||||
# def plot_graph():
|
|
||||||
# try:
|
|
||||||
# x = function_times
|
|
||||||
# y = function_data
|
|
||||||
|
|
||||||
# plt.plot(x, y)
|
|
||||||
# plt.show()
|
|
||||||
# except:
|
|
||||||
# pass
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# scheduler = BackgroundScheduler()
|
|
||||||
# scheduler.add_job(func=plot_graph, trigger="interval", seconds=5)
|
|
||||||
# scheduler.start()
|
|
||||||
app.run(host="0.0.0.0", debug=True)
|
app.run(host="0.0.0.0", debug=True)
|
||||||
|
|
||||||
# shut down the scheduler when exiting the app
|
|
||||||
# atexit.register(lambda: scheduler.shutdown())
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
flask
|
flask
|
||||||
flask-cors
|
flask-cors
|
||||||
python-socketio
|
python-socketio
|
||||||
apscheduler
|
|
||||||
matplotlib
|
|
||||||
|
|
|
@ -43,31 +43,8 @@ require(['jquery', 'socket.io'], function(jq, io) {
|
||||||
addLink(link_id, run_data["data"][link_id]);
|
addLink(link_id, run_data["data"][link_id]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
socket.on('live_request', function(request_data) {
|
|
||||||
console.log("live request");
|
|
||||||
request_time = new Date(request_data["time"] * 1000);
|
|
||||||
addLiveRequest(request_data["hostname"], request_time);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function addLiveRequest(request_host, request_time) {
|
|
||||||
let hostname = request_host;
|
|
||||||
let timesting = request_time.getHours() + ":" + request_time.getMinutes();
|
|
||||||
|
|
||||||
let html = `
|
|
||||||
<div class="item">
|
|
||||||
<div>
|
|
||||||
${hostname}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
${timesting}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
$('#live_requests').prepend($(html));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function addLink(link_id, link_data) {
|
function addLink(link_id, link_data) {
|
||||||
let stop = "handoff" in link_data;
|
let stop = "handoff" in link_data;
|
||||||
|
|
||||||
|
|
|
@ -64,26 +64,11 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="live_requests" class="card">
|
<div class="card">
|
||||||
<div class="item">
|
<div class="item">live requests</div>
|
||||||
<div>
|
|
||||||
Hostname
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
Time
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="card__title">
|
<div class="card__title">
|
||||||
Live Requests
|
Live Requests
|
||||||
</div>
|
</div>
|
||||||
<div class="item">
|
|
||||||
<div>
|
|
||||||
Hostname
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue