Compare commits
No commits in common. "9a48f528458dbb623e28a3d1712ca7e5e2bde4ac" and "d7a1026ad1f8b6809be4f19f2a9d5f8cc2a69f53" have entirely different histories.
9a48f52845
...
d7a1026ad1
9 changed files with 16 additions and 74 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +0,0 @@
|
||||||
/webserver/plots/
|
|
22
shell.nix
22
shell.nix
|
@ -1,14 +1,10 @@
|
||||||
{ pkgs ? import <nixpkgs> {} }:
|
{ pkgs ? import <nixpkgs> {} }:
|
||||||
|
(pkgs.buildFHSUserEnv {
|
||||||
pkgs.mkShell {
|
name = "pipzone";
|
||||||
buildInputs = [
|
targetPkgs = pkgs: (with pkgs; [
|
||||||
(pkgs.python3.withPackages (ps: with ps; [
|
python313
|
||||||
matplotlib
|
python313Packages.pip
|
||||||
numpy
|
python313Packages.virtualenv
|
||||||
]))
|
]);
|
||||||
];
|
runScript = "bash --init-file /etc/profile";
|
||||||
shellHook = ''
|
}).env
|
||||||
export SHELL=${pkgs.zsh}/bin/zsh
|
|
||||||
exec ${pkgs.zsh}/bin/zsh
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
{ pkgs ? import <nixpkgs> {} }:
|
|
||||||
(pkgs.buildFHSUserEnv {
|
|
||||||
name = "venv";
|
|
||||||
targetPkgs = pkgs: (with pkgs; [
|
|
||||||
python312
|
|
||||||
python312Packages.pip
|
|
||||||
python312Packages.virtualenv
|
|
||||||
python312Packages.matplotlib
|
|
||||||
]);
|
|
||||||
runScript = "bash --init-file /etc/profile";
|
|
||||||
# runScript = "zsh";
|
|
||||||
}).env
|
|
|
@ -18,9 +18,7 @@
|
||||||
"readings": [
|
"readings": [
|
||||||
{ "ts": 1747814400, "value": 45.2 },
|
{ "ts": 1747814400, "value": 45.2 },
|
||||||
{ "ts": 1747818000, "value": 47.1 },
|
{ "ts": 1747818000, "value": 47.1 },
|
||||||
{ "ts": 1747821600, "value": 46.8 },
|
{ "ts": 1747821600, "value": 46.8 }
|
||||||
{ "ts": 1747821700, "value": 35.8 },
|
|
||||||
{ "ts": 1747821800, "value": 48.2 }
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 22 KiB |
Binary file not shown.
Before Width: | Height: | Size: 23 KiB |
Binary file not shown.
Before Width: | Height: | Size: 23 KiB |
Binary file not shown.
Before Width: | Height: | Size: 16 KiB |
|
@ -1,10 +1,6 @@
|
||||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import json
|
import json
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
import mimetypes
|
|
||||||
|
|
||||||
mimetypes.add_type("image/png", ".png")
|
|
||||||
|
|
||||||
# Opening JSON file
|
# Opening JSON file
|
||||||
f = open("data.json")
|
f = open("data.json")
|
||||||
|
@ -20,61 +16,26 @@ for i in data["sensors"]:
|
||||||
# Closing file
|
# Closing file
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def create_plot(id: str, unit: str, xaxis: list, yaxis: list):
|
|
||||||
plt.plot(xaxis, yaxis)
|
|
||||||
plt.title(id)
|
|
||||||
plt.xlabel("Time")
|
|
||||||
plt.ylabel(unit)
|
|
||||||
plt.savefig(f"plots/{id}.png") # Save to file
|
|
||||||
plt.close()
|
|
||||||
|
|
||||||
|
|
||||||
htmldata = ""
|
htmldata = ""
|
||||||
|
|
||||||
|
|
||||||
def sortfunc(körber):
|
|
||||||
return körber
|
|
||||||
|
|
||||||
|
|
||||||
for i in sensors:
|
for i in sensors:
|
||||||
type = sensors[i][0]
|
type = sensors[i][0]
|
||||||
unit = sensors[i][1]
|
unit = sensors[i][1]
|
||||||
readings = ""
|
readings = ""
|
||||||
datapoints: list = []
|
sensorrange = len(sensors[i][2]) if len(sensors[i][2]) < 5 else 4
|
||||||
sensorrange = len(sensors[i][2]) if len(sensors[i][2]) < 5 else 5
|
|
||||||
for j in range(sensorrange):
|
for j in range(sensorrange):
|
||||||
datapoints.append([])
|
|
||||||
ts = sensors[i][2][j]["ts"]
|
ts = sensors[i][2][j]["ts"]
|
||||||
value = sensors[i][2][j]["value"]
|
|
||||||
datapoints[j].append(ts)
|
|
||||||
datapoints[j].append(value)
|
|
||||||
datapoints[j].append(unit)
|
|
||||||
datapoints.sort(key=sortfunc, reverse=True)
|
|
||||||
|
|
||||||
graphdata: list = [[], []]
|
|
||||||
for j in datapoints:
|
|
||||||
ts = j[0]
|
|
||||||
time = datetime.fromtimestamp(ts).strftime("%d.%m.%Y %H:%M.%S")
|
time = datetime.fromtimestamp(ts).strftime("%d.%m.%Y %H:%M.%S")
|
||||||
timeNoDate = datetime.fromtimestamp(ts).strftime("%H:%M.%S")
|
value = sensors[i][2][j]["value"]
|
||||||
value = j[1]
|
readings += f"{time}: {value}{unit}<br>"
|
||||||
unit = j[2]
|
|
||||||
# print(f"{time} {j}")
|
|
||||||
readings += f"{time}> {value}{unit}<br>"
|
|
||||||
graphdata[0].append(timeNoDate)
|
|
||||||
graphdata[1].append(value)
|
|
||||||
|
|
||||||
create_plot(i, unit, graphdata[0], graphdata[1])
|
|
||||||
|
|
||||||
htmldata += f"""
|
htmldata += f"""
|
||||||
<p>Id: {i}</p>
|
<p>Id: {i}</p>
|
||||||
<p>Type: {type}</p>
|
<p>Type: {type}</p>
|
||||||
<p>Readings:</p>
|
<p>Readings:</p>
|
||||||
<div style="margin-left: 40px;">
|
<div style="margin-left: 40px;">
|
||||||
{readings}
|
{readings}
|
||||||
<img src="/plots/{i}.png" alt="Graph">
|
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<p>---------------------------------------------</p>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
html = f"""
|
html = f"""
|
||||||
|
@ -85,7 +46,7 @@ html = f"""
|
||||||
<title>Sensor Data</title>
|
<title>Sensor Data</title>
|
||||||
<style>
|
<style>
|
||||||
* {{
|
* {{
|
||||||
font-family: 'Caskaydia Cove NF';
|
font-family: 'Times New Roman';
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
color: white;
|
color: white;
|
||||||
background: #1C1C1C;
|
background: #1C1C1C;
|
||||||
|
@ -102,7 +63,7 @@ html = f"""
|
||||||
class MyHandler(BaseHTTPRequestHandler):
|
class MyHandler(BaseHTTPRequestHandler):
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
# self.send_header("Content-type", "text/html")
|
self.send_header("Content-type", "text/html")
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(html.encode("utf-8"))
|
self.wfile.write(html.encode("utf-8"))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue