added graph with fake data on each miner page, and added basic formatting to it.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import datetime
|
||||
import os
|
||||
import asyncio
|
||||
import uvicorn
|
||||
@@ -37,6 +38,22 @@ def miner(request: Request, miner_ip):
|
||||
return get_miner
|
||||
|
||||
|
||||
@app.websocket("/miner/{miner_ip}/ws")
|
||||
async def miner_websocket(websocket: WebSocket, miner_ip):
|
||||
await websocket.accept()
|
||||
try:
|
||||
while True:
|
||||
# print(miner_ip)
|
||||
await asyncio.sleep(.1)
|
||||
data = {"hashrate": 1.11, "datetime": datetime.datetime.now().isoformat()}
|
||||
await websocket.send_json(data)
|
||||
|
||||
except WebSocketDisconnect:
|
||||
print("Websocket disconnected.")
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@app.get("/miner/{miner_ip}")
|
||||
def get_miner(request: Request, miner_ip):
|
||||
return templates.TemplateResponse("miner.html", {
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
from tools.web_monitor.app import sio
|
||||
import json
|
||||
|
||||
|
||||
async def scan_found_miner(miner):
|
||||
"""Send data to client that a miner was scanned.
|
||||
|
||||
:param miner: The miner object that was scanned.
|
||||
"""
|
||||
await sio.emit('scan_found_miner', json.dumps(
|
||||
{
|
||||
"ip": str(miner.ip),
|
||||
"model": str(miner.model),
|
||||
"api": str(miner.api_type)
|
||||
}
|
||||
))
|
||||
@@ -1,4 +1,62 @@
|
||||
{% extends 'navbar.html'%}
|
||||
{% block content %}
|
||||
{{miner}}
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/luxon@2.3.1/build/global/luxon.min.js"></script>
|
||||
<h2 class="mt-2 ms-4">{{miner}}</h2>
|
||||
<canvas id="line-chart" width="600" height="360" class="mt-3"></canvas>
|
||||
|
||||
<script>
|
||||
var ws = new WebSocket("ws://localhost:80/miner/{{miner}}/ws");
|
||||
let all_data = []
|
||||
let all_labels = []
|
||||
ws.onmessage = function(event) {
|
||||
var new_data = JSON.parse(event.data)
|
||||
datetime = luxon.DateTime.fromISO(new_data["datetime"]).toLocal();
|
||||
if (minerDataChart.data.labels.length > 49) minerDataChart.data.labels.shift();
|
||||
if (minerDataChart.data.datasets[0].data.length > 49) minerDataChart.data.datasets[0].data.shift();
|
||||
minerDataChart.data.labels.push(datetime.toLocaleString(luxon.DateTime.TIME_WITH_SECONDS));
|
||||
minerDataChart.data.datasets[0].data.push(new_data["hashrate"]);
|
||||
minerDataChart.update();
|
||||
};
|
||||
|
||||
var ctx = document.getElementById("line-chart").getContext("2d");
|
||||
var width = window.innerWidth || document.body.clientWidth;
|
||||
var chartGradient = ctx.createLinearGradient(0, 0, width, 0)
|
||||
chartGradient.addColorStop(0, '#D0368A');
|
||||
chartGradient.addColorStop(1, '#708AD4');
|
||||
|
||||
var minerDataChart = new Chart(document.getElementById("line-chart"), {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: [
|
||||
],
|
||||
datasets: [{
|
||||
label: "Hashrate",
|
||||
borderColor: chartGradient,
|
||||
pointBorderColor: chartGradient,
|
||||
pointBackgroundColor: chartGradient,
|
||||
pointHoverBackgroundColor: chartGradient,
|
||||
pointHoverBorderColor: chartGradient,
|
||||
data: [
|
||||
],
|
||||
}
|
||||
]
|
||||
},
|
||||
options: {
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
ticks: {
|
||||
maxTicksLimit: 8,
|
||||
maxRotation: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock content %}
|
||||
|
||||
Reference in New Issue
Block a user