Files
AI-on-the-edge-device/docs/sd-card/html/graph.html
2022-10-30 21:48:06 +01:00

62 lines
1.5 KiB
HTML

<html>
<head>
<script src='https://cdn.plot.ly/plotly-2.14.0.min.js'></script>
<style>
textarea {
width: 600px;
height: 300px;
}
</style>
<script>
function run() {
var el = document.getElementById('cnsl');
el && eval(el.value);
}
</script>
</head>
<body>
<div id='chart'></div>
<button onclick="document.getElementById('editor').hidden = false; this.hidden = true;" >Editor</button>
<div id='editor' hidden='true'>
<textarea id="cnsl">
const d = new Date();
var date = d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate();
fetch('/fileserver/log/message/log_'+date+'.txt')
.then(response => {
// handle the response
response.text()
.then( result => {
var lines = result.split("\n");
var trace = {
x: [],
y: [],
type: 'scatter'
};
var timex = 1;
for (let line of lines) {
if (line.includes("PostProcessing - Raw")) {
console.log(line);
var value = line.split(" ")[6];
var time = line.split(" ")[0];
console.log("> "+time+" "+value+"\n");
trace.x.push(timex);
timex += 1;
trace.y.push(value);
}
}
console.log(trace);
var data = [trace];
Plotly.newPlot('chart', data);
});
})
.catch(error => {
// handle the error
out.value = "error";
});
</textarea><br />
<button onclick="run();">run</button>
</div>
<script>run();</script>
</body>
</html>