Compare commits

..

17 commits

Author SHA1 Message Date
Maxime Bloch
b8614879ba
Merge branch 'master' of ssh://git.zeus.gent:2222/kelder/rubygoldberg-tracker 2019-10-08 18:14:45 +02:00
Maxime Bloch
3dea109886
add persistency, update server url in client and server js 2019-10-08 18:14:07 +02:00
hannes
99bf4e3f2f Merge branch 'live-request-function' into 'master'
added route

See merge request kelder/rubygoldberg-tracker!3
2019-10-08 18:06:43 +02:00
Hannes Klinckaert
40aa56f721 added route 2019-10-08 18:04:42 +02:00
Maxime Bloch
468861d36f
add simple client scripts 2019-10-08 17:29:50 +02:00
flynn
1f172c3b61 Merge branch 'live-request-function' into 'master'
Live request function

See merge request kelder/rubygoldberg-tracker!2
2019-10-08 17:21:23 +02:00
Hannes Klinckaert
7916873589 add live requests to all valid routes 2019-10-02 13:22:51 +02:00
Hannes Klinckaert
f226a4e51a moved socket.emit to the live_request function 2019-10-02 13:12:08 +02:00
Hannes Klinckaert
c89fba9594 updated css 2019-10-02 11:33:28 +02:00
Hannes Klinckaert
833dd271a0 removed example items 2019-10-02 11:30:26 +02:00
Hannes Klinckaert
06ded21847 deleted example file 2019-10-02 11:29:57 +02:00
Hannes Klinckaert
a00d93b632 added checks to make sure runs and indexes are numbers #5 2019-10-02 11:29:01 +02:00
flynn
37c8e13167 Merge branch 'client' into 'master'
Client

See merge request kelder/rubygoldberg-tracker!1
2019-09-27 19:41:52 +02:00
flynn
9a44e83637 Merge branch 'master' into 'client'
# Conflicts:
#   watcher/app.py
2019-09-27 19:41:37 +02:00
Maxime Bloch
a7ddca1d0b
add run instructions for the client 2019-09-27 15:28:30 +02:00
Maxime Bloch
9a9669d87d
add cors to server, fix client requests 2019-09-27 15:20:10 +02:00
Maxime Bloch
5228879c96
start on a simple client with fields and buttons 2019-09-26 18:37:48 +02:00
12 changed files with 175 additions and 68 deletions

View file

@ -37,3 +37,18 @@ Go enjoy the dashboard @ *localhost:5000*
## The client ## The client
This is an example client and will also be used as first link in the machine. This is an example client and will also be used as first link in the machine.
### Requirements
A local http file server of some kind.
for ex the python http server.
### Running
Go into the correct directory with the code
cd client
with python's http server
python -m http.server

8
client/handoff.sh Executable file
View file

@ -0,0 +1,8 @@
#!/bin/bash
RUN_NUMBER=0
LINK_NUMBER=0
SERVER_URL="10.1.0.155:5000"
curl http://${SERVER_URL}/link/handoff/${RUN_NUMBER}/${LINK_NUMBER}

11
client/index.css Normal file
View file

@ -0,0 +1,11 @@
.input-group {
padding: 10px;
}
input {
padding: 5px;
}
label {
margin-right: 10px;
}

33
client/index.html Normal file
View file

@ -0,0 +1,33 @@
<html>
<head>
<link href="index.css" rel="stylesheet" />
<script src="index.js"></script>
</head>
<body>
<form name="link">
<div class="input-group">
<label for="url-field">Watch server url</label>
<input name="url-field" type="text" value="10.1.0.155:5000" required></input>
</div>
<div class="input-group">
<label for="run-field">Run id</label>
<input name="run-field" type="number" value="1" required></input>
</div>
<div class="input-group">
<label for="link-field"> Link id </label>
<input name="link-field" type="number" value="0" required></input>
</div>
<div class="input-group">
<input type="button" name="start" value="Start" onclick="call_backend()" />
<input type="button" name="handoff" value="Handoff" onclick="call_backend()" />
</div>
</form>
<p>Result: <span id="result" style="font-weight: bold;"></span></p>
</body>
</html>

20
client/index.js Normal file
View file

@ -0,0 +1,20 @@
let call_backend = function(e) {
type = event.target.getAttribute('name');
var url_base = document.forms["link"]["url-field"].value;
var run = document.forms["link"]["run-field"].value;
var link = document.forms["link"]["link-field"].value;
x = new XMLHttpRequest();
x.onreadystatechange = function() {
if (x.readyState === 4) {
console.log("response: " + x.responseText);
document.getElementById("result").innerHTML = x.responseText;
};
};
var url = "http://" + url_base + "/link/" + (type === "start" ? "start" : "handoff") + "/" + run + "/" + link;
// console.log(url);
x.open("GET", url, true);
x.send();
};

8
client/start.sh Normal file → Executable file
View file

@ -0,0 +1,8 @@
#!/bin/bash
RUN_NUMBER=0
LINK_NUMBER=0
SERVER_URL="10.1.0.155:5000"
curl http://${SERVER_URL}/link/start/${RUN_NUMBER}/${LINK_NUMBER}

View file

@ -1,17 +1,22 @@
import asyncio import asyncio
import atexit import atexit
import datetime import datetime
import json
import os.path
import socket import socket
from functools import lru_cache from functools import lru_cache
from pathlib import Path
from time import sleep, time from time import sleep, time
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import socketio import socketio
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
from flask import Flask, render_template, request from flask import Flask, render_template, request
from flask_cors import CORS
sio = socketio.Server() sio = socketio.Server()
app = Flask(__name__) app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "*"}})
app.wsgi_app = socketio.WSGIApp(sio, app.wsgi_app) app.wsgi_app = socketio.WSGIApp(sio, app.wsgi_app)
# We request users to send the run number to prevent accidentially getting old requests from a previous run # We request users to send the run number to prevent accidentially getting old requests from a previous run
@ -29,6 +34,21 @@ function_times = []
function_data = [] function_data = []
def save_data():
with open('data.json', 'w') as outfile:
json.dump(db, outfile)
def load_data():
with open('data.json', 'r') as infile:
db = json.load(infile)
data_file = Path("data.json")
if data_file.is_file():
load_data()
@app.route("/") @app.route("/")
def index(): def index():
return render_template('index.html') return render_template('index.html')
@ -36,11 +56,22 @@ def index():
@app.route("/start_run/<run_index>") @app.route("/start_run/<run_index>")
def start_run(run_index): def start_run(run_index):
db["current_run"] = run_index if "Authorization" not in request.headers or request.headers[
starttime = time() 'Authorization'] != "dsfqlkjmlkjls,,n":
return "Unauthorized"
request_data = live_request(
f'/start_run/{run_index}') #make request show up on the live requests
if not run_index.isdigit():
return f'{run_index} is not a number'
if run_index in db["run_data"]: if run_index in db["run_data"]:
return "This run is already ran, take another number." return "This run is already ran, take another number."
db["current_run"] = run_index
starttime = time()
db["run_data"][run_index] = {"starttime": starttime, "data": {}} db["run_data"][run_index] = {"starttime": starttime, "data": {}}
save_data()
# TODO send start request to the first person in the chain. Probably a zeus part already written as example # TODO send start request to the first person in the chain. Probably a zeus part already written as example
sio.emit('start_run', run_index) sio.emit('start_run', run_index)
return f'Run {run_index} started at {starttime}' return f'Run {run_index} started at {starttime}'
@ -48,9 +79,13 @@ def start_run(run_index):
@app.route("/link/start/<run>/<link_index>") @app.route("/link/start/<run>/<link_index>")
def link_start(run, link_index): def link_start(run, link_index):
request_data = live_request(f'/link/start/{run}/{link_index}'
) #make request show up on the live requests
if not run.isdigit() or not link_index.isdigit():
return f'{run} and/or {link_index} is not a number'
start = time() 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 response = "Wrong run number, check that you update your run", 404
@ -60,6 +95,7 @@ def link_start(run, link_index):
response = "you already started in this run. Ignoring this request." response = "you already started in this run. Ignoring this request."
else: else:
run_data[link_index] = {"id": link_index, "start": time()} run_data[link_index] = {"id": link_index, "start": time()}
save_data()
sio.emit('link_start', run_data[link_index]) sio.emit('link_start', run_data[link_index])
response = "Success." response = "Success."
stop = time() stop = time()
@ -68,12 +104,21 @@ def link_start(run, link_index):
return response return response
@app.route("/link/handoff/<run>/<index>") @app.route("/link/handoff/<run>/<link_index>")
def link_handoff(run, index): def link_handoff(run, link_index):
request_data = live_request(f'/link/handoff/{run}/{link_index}'
) #make request show up on the live requests
if not run.isdigit() or not link_index.isdigit():
return f'{run} and/or {link_index} is not a number'
if db["current_run"] != run: if db["current_run"] != run:
return "Wrong run number, check that you updated you run", 404 return "Wrong run number, check that you updated you run", 404
else: else:
link_data = db["run_data"][run]["data"][index] if index not in db["run_data"][run]["data"]:
return "This link did not start yet..."
link_data = db["run_data"][run]["data"][link_index]
save_data()
if "handoff" in link_data: if "handoff" in link_data:
return "you already handed off control during this run. Ignoring this request" return "you already handed off control during this run. Ignoring this request"
else: else:
@ -89,12 +134,14 @@ 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): def live_request(route_data):
ip = request.remote_addr ip = request.remote_addr
request_data = {} request_data = {}
request_data["hostname"] = lookup_hostname(ip) request_data["hostname"] = lookup_hostname(ip)
request_data["time"] = time() request_data["time"] = time()
return request_data request_data["route"] = route_data
sio.emit('live_request', request_data)
@lru_cache() @lru_cache()
@ -116,7 +163,7 @@ if __name__ == '__main__':
# scheduler = BackgroundScheduler() # scheduler = BackgroundScheduler()
# scheduler.add_job(func=plot_graph, trigger="interval", seconds=5) # scheduler.add_job(func=plot_graph, trigger="interval", seconds=5)
# scheduler.start() # scheduler.start()
app.run(host="0.0.0.0", debug=True) app.run(host="10.1.0.155", debug=True)
# shut down the scheduler when exiting the app # shut down the scheduler when exiting the app
# atexit.register(lambda: scheduler.shutdown()) # atexit.register(lambda: scheduler.shutdown())

View file

@ -1,4 +1,5 @@
flask flask
flask-cors
python-socketio python-socketio
apscheduler apscheduler
matplotlib matplotlib

View file

@ -1,3 +0,0 @@
function sayHello() {
alert("Hello World");
}

View file

@ -46,7 +46,8 @@ h1 {
padding: 5px; padding: 5px;
padding-left: 12px; padding-left: 12px;
padding-right: 12; padding-right: 12;
height: 5%; min-height: 5%;
max-height: 5%;
border: 1px solid rgba(0, 0, 0, 0.2); border: 1px solid rgba(0, 0, 0, 0.2);
border-radius: 6px; border-radius: 6px;
background: #fff; background: #fff;

View file

@ -23,7 +23,7 @@ require(['jquery', 'socket.io'], function(jq, io) {
$(function() { $(function() {
const socket = io('localhost:5000'); const socket = io('10.1.0.155:5000');
socket.on('start_run', function(run_index) {}); socket.on('start_run', function(run_index) {});
socket.on('link_start', function(link_data) { socket.on('link_start', function(link_data) {
@ -46,19 +46,23 @@ require(['jquery', 'socket.io'], function(jq, io) {
socket.on('live_request', function(request_data) { socket.on('live_request', function(request_data) {
console.log("live request"); console.log("live request");
request_time = new Date(request_data["time"] * 1000); request_time = new Date(request_data["time"] * 1000);
addLiveRequest(request_data["hostname"], request_time); addLiveRequest(request_data["hostname"], request_time, request_data["route"]);
}); });
}); });
function addLiveRequest(request_host, request_time) { function addLiveRequest(request_host, request_time, link_route) {
let hostname = request_host; let hostname = request_host;
let timesting = request_time.getHours() + ":" + request_time.getMinutes(); let timesting = request_time.getHours() + ":" + request_time.getMinutes();
let route = link_route;
let html = ` let html = `
<div class="item"> <div class="item">
<div> <div>
${hostname} ${hostname}
</div> </div>
<div>
${route}
</div>
<div> <div>
${timesting} ${timesting}
</div> </div>

View file

@ -21,69 +21,31 @@
<body> <body>
<div class="container"> <div class="container">
<div id="current_run" class="card"> <div id="current_run" class="card">
<div class="item"> <!-- <div class="item">
<div> <div>
0 0
</div> </div>
<div> <div>
<button type="button">Start</button> <button type="button" onclick="$.get('10.1.0.155:5000/start_run/0')">Start</button>
</div> </div>
<div> <div>
<i class="fas fa-question" style="color:grey"></i> <i class="fas fa-question" style="color:grey"></i>
</div> </div>
</div> </div> -->
<div class="item"> <div class="card__title">
<div> Links
1
</div>
<div>
Time: ...
</div>
<div>
<i class="fas fa-check" style="color:green"></i>
</div>
</div>
<div class="card__title">
Links
</div> </div>
</div> </div>
<div class="card"> <div class="card">
<div class="item">
<div>
1
</div>
<div>
total time
</div>
<div>
max fase
</div>
</div>
<div class="card__title"> <div class="card__title">
Runs Runs
</div> </div>
</div> </div>
<div id="live_requests" class="card"> <div id="live_requests" class="card">
<div class="item">
<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>