Initial commit
This commit is contained in:
commit
4182d49adb
2133
Aktuelle_Temperaturwerte.svg
Normal file
2133
Aktuelle_Temperaturwerte.svg
Normal file
File diff suppressed because it is too large
Load diff
After Width: | Height: | Size: 79 KiB |
7223
Temperaturverlauf.svg
Normal file
7223
Temperaturverlauf.svg
Normal file
File diff suppressed because it is too large
Load diff
After Width: | Height: | Size: 302 KiB |
2151
Temperaturverlauf_Tank2.svg
Normal file
2151
Temperaturverlauf_Tank2.svg
Normal file
File diff suppressed because it is too large
Load diff
After Width: | Height: | Size: 80 KiB |
22
change.py
Executable file
22
change.py
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
# SQLite-Datenbankverbindung herstellen
|
||||||
|
conn = sqlite3.connect('temperaturen.db')
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Funktion zum Aktualisieren der Tanknamen in der Datenbank
|
||||||
|
def update_tankname(table_name, old_name, new_name):
|
||||||
|
cursor.execute(f"UPDATE {table_name} SET messstelle = ? WHERE messstelle = ?",
|
||||||
|
(new_name, old_name))
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
# Korrektur durchführen (Tabelle "istwert")
|
||||||
|
update_tankname("istwert", "Tank 1", "1")
|
||||||
|
update_tankname("istwert", "Tank 2", "2")
|
||||||
|
|
||||||
|
# Korrektur durchführen (Tabelle "sollwert")
|
||||||
|
update_tankname("sollwert", "Tank 1", "1")
|
||||||
|
update_tankname("sollwert", "Tank 2", "2")
|
||||||
|
|
||||||
|
# Die Datenbankverbindung schließen
|
||||||
|
conn.close()
|
60
cron_temp.py
Executable file
60
cron_temp.py
Executable file
|
@ -0,0 +1,60 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
# URL der HTML-Seite, die Sie abrufen möchten
|
||||||
|
url = "http://localhost:5010"
|
||||||
|
|
||||||
|
# HTTP-Anfrage senden und den HTML-Inhalt abrufen
|
||||||
|
response = requests.get(url)
|
||||||
|
html = response.text
|
||||||
|
|
||||||
|
# HTML-Dokument in BeautifulSoup-Objekt umwandeln
|
||||||
|
soup = BeautifulSoup(html, 'html.parser')
|
||||||
|
|
||||||
|
# Die Daten in der Tabelle extrahieren
|
||||||
|
table = soup.find('table')
|
||||||
|
rows = table.find_all('tr')
|
||||||
|
|
||||||
|
# Initialisieren der Tanknummern mit 1 und 2
|
||||||
|
tank1_nummer = 1
|
||||||
|
tank2_nummer = 2
|
||||||
|
|
||||||
|
# SQLite-Datenbankverbindung herstellen
|
||||||
|
db_path = '/home/divers/datenbank/temperaturen.db'
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Funktion zum Einfügen von Tanknummern und Temperaturwerten in die Datenbank
|
||||||
|
def insert_temperature(table_name, tanknummer, temperatur):
|
||||||
|
cursor.execute(f"INSERT INTO {table_name} (messstelle, temperatur) VALUES (?, ?)",
|
||||||
|
(tanknummer, temperatur))
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
# Daten in die Datenbank eintragen (Tabelle "istwert")
|
||||||
|
for row in rows[1:-1]:
|
||||||
|
columns = row.find_all('td')
|
||||||
|
if len(columns) >= 3:
|
||||||
|
tank_name = columns[0].text
|
||||||
|
istwert_text = columns[1].text.strip() # Temperaturwert ohne Leerzeichen am Anfang/Ende
|
||||||
|
if istwert_text: # Nur wenn die Zeichenfolge nicht leer ist
|
||||||
|
istwert = float(istwert_text.split('°')[0]) # Extrahieren des Istwertes und Konvertieren in Float
|
||||||
|
tank_nummer = int(tank_name.split()[-1]) # Extrahieren der Tanknummer aus dem Namen
|
||||||
|
insert_temperature("istwert", tank_nummer, istwert)
|
||||||
|
|
||||||
|
# Daten in die Datenbank eintragen (Tabelle "sollwert")
|
||||||
|
for row in rows[1:-1]:
|
||||||
|
columns = row.find_all('td')
|
||||||
|
if len(columns) >= 3:
|
||||||
|
tank_name = columns[0].text
|
||||||
|
sollwert_text = columns[2].text.strip() # Temperaturwert ohne Leerzeichen am Anfang/Ende
|
||||||
|
if sollwert_text: # Nur wenn die Zeichenfolge nicht leer ist
|
||||||
|
sollwert = float(sollwert_text.split('°')[0]) # Extrahieren des Sollwertes und Konvertieren in Float
|
||||||
|
tank_nummer = int(tank_name.split()[-1]) # Extrahieren der Tanknummer aus dem Namen
|
||||||
|
insert_temperature("sollwert", tank_nummer, sollwert)
|
||||||
|
|
||||||
|
# Die Datenbankverbindung schließen
|
||||||
|
conn.close()
|
||||||
|
|
168
data.csv
Normal file
168
data.csv
Normal file
|
@ -0,0 +1,168 @@
|
||||||
|
id,temperature,Timestamp
|
||||||
|
1,13.25,"2023-09-04 21:52:27"
|
||||||
|
2,13.38,"2023-09-04 21:54:24"
|
||||||
|
3,13.38,"2023-09-04 22:05:01"
|
||||||
|
4,13.5,"2023-09-04 22:07:01"
|
||||||
|
5,13.5,"2023-09-04 22:10:01"
|
||||||
|
6,13.5,"2023-09-04 22:15:02"
|
||||||
|
7,13.63,"2023-09-04 22:20:01"
|
||||||
|
8,13.63,"2023-09-04 22:25:02"
|
||||||
|
9,13.75,"2023-09-04 22:30:01"
|
||||||
|
10,13.75,"2023-09-04 22:35:02"
|
||||||
|
11,13.88,"2023-09-04 22:40:01"
|
||||||
|
12,13.88,"2023-09-04 22:45:01"
|
||||||
|
13,14.0,"2023-09-04 22:50:02"
|
||||||
|
14,14.0,"2023-09-04 22:55:01"
|
||||||
|
15,14.0,"2023-09-04 23:00:02"
|
||||||
|
16,14.13,"2023-09-04 23:05:02"
|
||||||
|
17,14.13,"2023-09-04 23:10:01"
|
||||||
|
18,14.13,"2023-09-04 23:15:02"
|
||||||
|
19,14.13,"2023-09-04 23:20:02"
|
||||||
|
20,14.25,"2023-09-04 23:25:01"
|
||||||
|
21,14.25,"2023-09-04 23:30:02"
|
||||||
|
22,14.25,"2023-09-04 23:35:01"
|
||||||
|
23,14.38,"2023-09-04 23:40:02"
|
||||||
|
24,14.5,"2023-09-04 23:45:02"
|
||||||
|
25,14.38,"2023-09-04 23:50:01"
|
||||||
|
26,14.38,"2023-09-04 23:55:02"
|
||||||
|
27,14.5,"2023-09-05 00:00:01"
|
||||||
|
28,14.5,"2023-09-05 00:05:02"
|
||||||
|
29,14.63,"2023-09-05 00:10:01"
|
||||||
|
30,14.63,"2023-09-05 00:15:01"
|
||||||
|
31,14.63,"2023-09-05 00:20:02"
|
||||||
|
32,14.63,"2023-09-05 00:25:02"
|
||||||
|
33,14.75,"2023-09-05 00:30:01"
|
||||||
|
34,14.63,"2023-09-05 00:35:02"
|
||||||
|
35,14.75,"2023-09-05 00:40:01"
|
||||||
|
36,14.75,"2023-09-05 00:45:01"
|
||||||
|
37,14.75,"2023-09-05 00:50:02"
|
||||||
|
38,14.88,"2023-09-05 00:55:01"
|
||||||
|
39,14.88,"2023-09-05 01:00:02"
|
||||||
|
40,14.88,"2023-09-05 01:05:01"
|
||||||
|
41,14.88,"2023-09-05 01:10:02"
|
||||||
|
42,15.0,"2023-09-05 01:15:02"
|
||||||
|
43,14.88,"2023-09-05 01:20:01"
|
||||||
|
44,15.0,"2023-09-05 01:25:02"
|
||||||
|
45,15.0,"2023-09-05 01:30:02"
|
||||||
|
46,15.0,"2023-09-05 01:35:01"
|
||||||
|
47,15.13,"2023-09-05 01:40:02"
|
||||||
|
48,15.0,"2023-09-05 01:45:02"
|
||||||
|
49,15.13,"2023-09-05 01:50:01"
|
||||||
|
50,15.13,"2023-09-05 01:55:02"
|
||||||
|
51,15.13,"2023-09-05 02:00:01"
|
||||||
|
52,15.13,"2023-09-05 02:05:02"
|
||||||
|
53,15.13,"2023-09-05 02:10:02"
|
||||||
|
54,15.25,"2023-09-05 02:15:01"
|
||||||
|
55,15.25,"2023-09-05 02:20:02"
|
||||||
|
56,15.25,"2023-09-05 02:25:01"
|
||||||
|
57,15.25,"2023-09-05 02:30:02"
|
||||||
|
58,15.25,"2023-09-05 02:35:02"
|
||||||
|
59,15.38,"2023-09-05 02:40:02"
|
||||||
|
60,15.38,"2023-09-05 02:45:01"
|
||||||
|
61,15.38,"2023-09-05 02:50:02"
|
||||||
|
62,15.38,"2023-09-05 02:55:01"
|
||||||
|
63,15.38,"2023-09-05 03:00:02"
|
||||||
|
64,15.5,"2023-09-05 03:05:02"
|
||||||
|
65,15.5,"2023-09-05 03:10:01"
|
||||||
|
66,15.5,"2023-09-05 03:15:02"
|
||||||
|
67,15.63,"2023-09-05 03:20:01"
|
||||||
|
68,15.5,"2023-09-05 03:25:01"
|
||||||
|
69,15.63,"2023-09-05 03:30:02"
|
||||||
|
70,15.63,"2023-09-05 03:35:01"
|
||||||
|
71,15.63,"2023-09-05 03:40:01"
|
||||||
|
72,15.75,"2023-09-05 03:45:01"
|
||||||
|
73,15.75,"2023-09-05 03:50:02"
|
||||||
|
74,15.75,"2023-09-05 03:55:01"
|
||||||
|
75,15.75,"2023-09-05 04:00:02"
|
||||||
|
76,15.75,"2023-09-05 04:05:01"
|
||||||
|
77,15.75,"2023-09-05 04:10:02"
|
||||||
|
78,15.75,"2023-09-05 04:15:02"
|
||||||
|
79,15.75,"2023-09-05 04:20:01"
|
||||||
|
80,15.88,"2023-09-05 04:25:02"
|
||||||
|
81,15.88,"2023-09-05 04:30:01"
|
||||||
|
82,15.88,"2023-09-05 04:35:01"
|
||||||
|
83,15.88,"2023-09-05 04:40:02"
|
||||||
|
84,15.88,"2023-09-05 04:45:02"
|
||||||
|
85,16.0,"2023-09-05 04:50:01"
|
||||||
|
86,15.88,"2023-09-05 04:55:01"
|
||||||
|
87,15.88,"2023-09-05 05:00:02"
|
||||||
|
88,16.0,"2023-09-05 05:05:01"
|
||||||
|
89,16.0,"2023-09-05 05:10:02"
|
||||||
|
90,16.0,"2023-09-05 05:15:02"
|
||||||
|
91,16.0,"2023-09-05 05:20:01"
|
||||||
|
92,16.0,"2023-09-05 05:25:02"
|
||||||
|
93,16.12,"2023-09-05 05:30:01"
|
||||||
|
94,16.12,"2023-09-05 05:35:02"
|
||||||
|
95,16.12,"2023-09-05 05:40:02"
|
||||||
|
96,16.12,"2023-09-05 05:45:01"
|
||||||
|
97,16.12,"2023-09-05 05:50:01"
|
||||||
|
98,16.12,"2023-09-05 05:55:02"
|
||||||
|
99,16.25,"2023-09-05 06:00:02"
|
||||||
|
100,16.12,"2023-09-05 06:05:01"
|
||||||
|
101,16.25,"2023-09-05 06:10:02"
|
||||||
|
102,16.25,"2023-09-05 06:15:02"
|
||||||
|
103,16.25,"2023-09-05 06:20:01"
|
||||||
|
104,16.25,"2023-09-05 06:25:02"
|
||||||
|
105,16.37,"2023-09-05 06:30:02"
|
||||||
|
106,16.37,"2023-09-05 06:35:01"
|
||||||
|
107,16.37,"2023-09-05 06:40:02"
|
||||||
|
108,16.37,"2023-09-05 06:45:01"
|
||||||
|
109,16.5,"2023-09-05 06:50:02"
|
||||||
|
110,16.5,"2023-09-05 06:55:02"
|
||||||
|
111,16.5,"2023-09-05 07:00:01"
|
||||||
|
112,16.5,"2023-09-05 07:05:02"
|
||||||
|
113,16.62,"2023-09-05 07:10:02"
|
||||||
|
114,16.62,"2023-09-05 07:15:01"
|
||||||
|
115,16.62,"2023-09-05 07:20:02"
|
||||||
|
116,16.62,"2023-09-05 07:25:02"
|
||||||
|
117,16.62,"2023-09-05 07:30:02"
|
||||||
|
118,16.62,"2023-09-05 07:35:02"
|
||||||
|
119,16.62,"2023-09-05 07:40:02"
|
||||||
|
120,16.75,"2023-09-05 07:45:02"
|
||||||
|
121,16.75,"2023-09-05 07:50:02"
|
||||||
|
122,16.75,"2023-09-05 07:55:02"
|
||||||
|
123,16.87,"2023-09-05 08:00:01"
|
||||||
|
124,16.75,"2023-09-05 08:05:01"
|
||||||
|
125,16.87,"2023-09-05 08:10:02"
|
||||||
|
126,16.87,"2023-09-05 08:15:02"
|
||||||
|
127,16.87,"2023-09-05 08:20:02"
|
||||||
|
128,16.87,"2023-09-05 08:25:02"
|
||||||
|
129,17.0,"2023-09-05 08:30:02"
|
||||||
|
130,17.0,"2023-09-05 08:37:18"
|
||||||
|
131,17.0,"2023-09-05 08:45:02"
|
||||||
|
132,17.12,"2023-09-05 08:50:01"
|
||||||
|
133,17.12,"2023-09-05 08:55:02"
|
||||||
|
134,17.12,"2023-09-05 09:00:02"
|
||||||
|
135,17.12,"2023-09-05 09:05:02"
|
||||||
|
136,17.12,"2023-09-05 09:10:02"
|
||||||
|
137,17.25,"2023-09-05 09:15:02"
|
||||||
|
138,17.25,"2023-09-05 09:20:02"
|
||||||
|
139,17.25,"2023-09-05 09:25:01"
|
||||||
|
140,17.25,"2023-09-05 09:30:02"
|
||||||
|
141,17.37,"2023-09-05 09:35:02"
|
||||||
|
142,17.37,"2023-09-05 09:40:01"
|
||||||
|
143,17.37,"2023-09-05 09:45:01"
|
||||||
|
144,17.5,"2023-09-05 09:50:02"
|
||||||
|
145,17.37,"2023-09-05 09:55:02"
|
||||||
|
146,17.37,"2023-09-05 10:00:02"
|
||||||
|
147,17.5,"2023-09-05 10:05:02"
|
||||||
|
148,17.5,"2023-09-05 10:10:02"
|
||||||
|
149,17.5,"2023-09-05 10:15:02"
|
||||||
|
150,17.5,"2023-09-05 10:20:02"
|
||||||
|
151,17.5,"2023-09-05 10:25:24"
|
||||||
|
152,17.5,"2023-09-05 10:30:02"
|
||||||
|
153,17.62,"2023-09-05 10:35:02"
|
||||||
|
154,17.62,"2023-09-05 10:40:02"
|
||||||
|
155,17.62,"2023-09-05 10:45:01"
|
||||||
|
156,17.62,"2023-09-05 10:50:01"
|
||||||
|
157,17.75,"2023-09-05 10:55:01"
|
||||||
|
158,17.75,"2023-09-05 11:00:01"
|
||||||
|
159,17.75,"2023-09-05 11:05:02"
|
||||||
|
160,17.75,"2023-09-05 11:10:02"
|
||||||
|
161,17.87,"2023-09-05 11:15:02"
|
||||||
|
162,17.87,"2023-09-05 11:20:02"
|
||||||
|
163,17.87,"2023-09-05 11:25:01"
|
||||||
|
164,17.87,"2023-09-05 11:30:01"
|
||||||
|
165,18.0,"2023-09-05 11:35:02"
|
||||||
|
166,17.87,"2023-09-05 11:40:02"
|
||||||
|
167,18.0,"2023-09-05 11:45:02"
|
|
31
datenbank.py
Executable file
31
datenbank.py
Executable file
|
@ -0,0 +1,31 @@
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
# SQLite-Datenbankverbindung herstellen oder erstellen (temperatursteuerung.db)
|
||||||
|
conn = sqlite3.connect('temperaturen.db')
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Tabelle "istwert" erstellen
|
||||||
|
cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS istwert (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
messstelle INTEGER,
|
||||||
|
temperatur REAL,
|
||||||
|
zeitstempel TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
|
||||||
|
# Tabelle "sollwert" erstellen
|
||||||
|
cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS sollwert (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
messstelle INTEGER,
|
||||||
|
temperatur REAL,
|
||||||
|
zeitstempel TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
|
||||||
|
# Änderungen in der Datenbank speichern
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
# Die Datenbankverbindung schließen
|
||||||
|
conn.close()
|
5499
diagramm.svg
Normal file
5499
diagramm.svg
Normal file
File diff suppressed because it is too large
Load diff
After Width: | Height: | Size: 210 KiB |
30
import.py
Normal file
30
import.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import sqlite3
|
||||||
|
import csv
|
||||||
|
|
||||||
|
# Pfad zur CSV-Datei
|
||||||
|
csv_file = 'data.csv'
|
||||||
|
|
||||||
|
# Pfad zur SQLite-Datenbank
|
||||||
|
db_path = '/home/divers/datenbank/temperaturen.db'
|
||||||
|
|
||||||
|
# Verbindung zur SQLite-Datenbank herstellen
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# CSV-Datei öffnen und Daten einfügen
|
||||||
|
with open(csv_file, 'r') as file:
|
||||||
|
csv_reader = csv.DictReader(file)
|
||||||
|
for row in csv_reader:
|
||||||
|
temperature = float(row['temperature']) # Temperaturwert aus der CSV-Datei
|
||||||
|
timestamp = row['Timestamp'] # Zeitstempel aus der CSV-Datei
|
||||||
|
|
||||||
|
# SQL-Abfrage zum Einfügen des Datensatzes in die Tabelle "istwert"
|
||||||
|
cursor.execute("INSERT INTO istwert (messstelle, temperatur, zeitstempel) VALUES (?, ?, ?)",
|
||||||
|
(1, temperature, timestamp))
|
||||||
|
|
||||||
|
# Änderungen in der Datenbank speichern
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
# Datenbankverbindung schließen
|
||||||
|
conn.close()
|
1301
istwert_tank1.svg
Normal file
1301
istwert_tank1.svg
Normal file
File diff suppressed because it is too large
Load diff
After Width: | Height: | Size: 43 KiB |
50
plotact.py
Executable file
50
plotact.py
Executable file
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
# Pfad zur Datenbank
|
||||||
|
db_path = '/home/divers/datenbank/temperaturen.db'
|
||||||
|
|
||||||
|
# SQLite-Datenbankverbindung herstellen
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# SQL-Abfrage, um die letzten 10 Istwerte von Tank 1 abzurufen
|
||||||
|
cursor.execute("SELECT zeitstempel, temperatur FROM istwert WHERE messstelle = 1 ORDER BY zeitstempel ASC LIMIT 30")
|
||||||
|
rows_tank1_istwert = cursor.fetchall()
|
||||||
|
datetimes_tank1_istwert = [row[0] for row in rows_tank1_istwert]
|
||||||
|
temperaturen_tank1_istwert = [row[1] for row in rows_tank1_istwert]
|
||||||
|
|
||||||
|
# SQL-Abfrage, um die letzten 10 Istwerte von Tank 2 abzurufen
|
||||||
|
cursor.execute("SELECT zeitstempel, temperatur FROM istwert WHERE messstelle = 2 ORDER BY zeitstempel ASC LIMIT 30")
|
||||||
|
rows_tank2_istwert = cursor.fetchall()
|
||||||
|
datetimes_tank2_istwert = [row[0] for row in rows_tank2_istwert]
|
||||||
|
temperaturen_tank2_istwert = [row[1] for row in rows_tank2_istwert]
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
# Grafik erstellen
|
||||||
|
plt.figure(figsize=(12, 8))
|
||||||
|
|
||||||
|
# Plot für Istwert (Tank 1)
|
||||||
|
plt.plot(datetimes_tank1_istwert, temperaturen_tank1_istwert, label='Istwert Tank 1', color='blue')
|
||||||
|
|
||||||
|
# Plot für Istwert (Tank 2)
|
||||||
|
plt.plot(datetimes_tank2_istwert, temperaturen_tank2_istwert, label='Istwert Tank 2', color='green')
|
||||||
|
|
||||||
|
plt.xlabel('Zeitstempel')
|
||||||
|
plt.ylabel('Temperatur (°C)')
|
||||||
|
plt.title('Aktuelle Temperaturwerte von Tank 1 und Tank 2')
|
||||||
|
|
||||||
|
# Vertikale Ausrichtung der x-Achsenbeschriftung
|
||||||
|
plt.xticks(rotation='vertical')
|
||||||
|
|
||||||
|
plt.legend()
|
||||||
|
plt.grid(True)
|
||||||
|
|
||||||
|
# Speichern Sie die Grafik als SVG-Datei
|
||||||
|
plt.savefig('AktuellT1T2.svg', format='svg', bbox_inches='tight')
|
||||||
|
|
||||||
|
# Grafik anzeigen (optional)
|
||||||
|
plt.show()
|
54
plott1.py
Executable file
54
plott1.py
Executable file
|
@ -0,0 +1,54 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
# Pfad zur Datenbank
|
||||||
|
db_path = '/home/divers/datenbank/temperaturen.db'
|
||||||
|
|
||||||
|
# SQLite-Datenbankverbindung herstellen
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# SQL-Abfrage, um die Zeitstempel und Temperaturen zu erhalten (Tabelle "istwert" für Tank 1)
|
||||||
|
cursor.execute("SELECT zeitstempel, temperatur FROM istwert WHERE messstelle = 1")
|
||||||
|
rows_istwert = cursor.fetchall()
|
||||||
|
|
||||||
|
# SQL-Abfrage, um die Zeitstempel und Temperaturen zu erhalten (Tabelle "sollwert" für Tank 1)
|
||||||
|
cursor.execute("SELECT zeitstempel, temperatur FROM sollwert WHERE messstelle = 1")
|
||||||
|
rows_sollwert = cursor.fetchall()
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
# Die Zeitstempel und Temperaturen in separate Listen aufteilen (Istwert)
|
||||||
|
datetimes_istwert = [row[0] for row in rows_istwert]
|
||||||
|
temperaturen_istwert = [row[1] for row in rows_istwert]
|
||||||
|
|
||||||
|
# Die Zeitstempel und Temperaturen in separate Listen aufteilen (Sollwert)
|
||||||
|
datetimes_sollwert = [row[0] for row in rows_sollwert]
|
||||||
|
temperaturen_sollwert = [row[1] for row in rows_sollwert]
|
||||||
|
|
||||||
|
# Grafik erstellen
|
||||||
|
plt.figure(figsize=(10, 8)) # Vergrößern Sie die Höhe des Grafikbereichs
|
||||||
|
|
||||||
|
# Plot für Istwert (Tank 1)
|
||||||
|
plt.plot(datetimes_istwert, temperaturen_istwert, label='Istwert Tank 1', color='blue')
|
||||||
|
|
||||||
|
# Plot für Sollwert (Tank 1)
|
||||||
|
plt.plot(datetimes_sollwert, temperaturen_sollwert, label='Sollwert Tank 1', color='red', linestyle='--')
|
||||||
|
|
||||||
|
plt.xlabel('Zeitstempel')
|
||||||
|
plt.ylabel('Temperatur (°C)')
|
||||||
|
plt.title('Temperaturverlauf Tank 1 (Istwert und Sollwert)')
|
||||||
|
|
||||||
|
# Vertikale Ausrichtung der x-Achsenbeschriftung
|
||||||
|
plt.xticks(rotation='vertical')
|
||||||
|
|
||||||
|
plt.legend()
|
||||||
|
plt.grid(True)
|
||||||
|
|
||||||
|
# Speichern Sie die Grafik als SVG-Datei
|
||||||
|
plt.savefig('Temperaturverlauf.svg', format='svg', bbox_inches='tight')
|
||||||
|
|
||||||
|
# Grafik anzeigen (optional)
|
||||||
|
plt.show()
|
52
plott2.py
Executable file
52
plott2.py
Executable file
|
@ -0,0 +1,52 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
# Pfad zur Datenbank
|
||||||
|
db_path = '/home/divers/datenbank/temperaturen.db'
|
||||||
|
|
||||||
|
# SQLite-Datenbankverbindung herstellen
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# SQL-Abfrage, um die Zeitstempel und Temperaturen zu erhalten (Tabelle "istwert" für Tank 2)
|
||||||
|
cursor.execute("SELECT zeitstempel, temperatur FROM istwert WHERE messstelle = 2")
|
||||||
|
rows_istwert_tank2 = cursor.fetchall()
|
||||||
|
|
||||||
|
# SQL-Abfrage, um die Zeitstempel und Temperaturen zu erhalten (Tabelle "sollwert" für Tank 2)
|
||||||
|
cursor.execute("SELECT zeitstempel, temperatur FROM sollwert WHERE messstelle = 2")
|
||||||
|
rows_sollwert_tank2 = cursor.fetchall()
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
# Die Zeitstempel und Temperaturen in separate Listen aufteilen (Istwert und Sollwert Tank 2)
|
||||||
|
datetimes_istwert_tank2 = [row[0] for row in rows_istwert_tank2]
|
||||||
|
temperaturen_istwert_tank2 = [row[1] for row in rows_istwert_tank2]
|
||||||
|
datetimes_sollwert_tank2 = [row[0] for row in rows_sollwert_tank2]
|
||||||
|
temperaturen_sollwert_tank2 = [row[1] for row in rows_sollwert_tank2]
|
||||||
|
|
||||||
|
# Grafik erstellen
|
||||||
|
plt.figure(figsize=(10, 8)) # Vergrößern Sie die Höhe des Grafikbereichs
|
||||||
|
|
||||||
|
# Plot für Istwert (Tank 2)
|
||||||
|
plt.plot(datetimes_istwert_tank2, temperaturen_istwert_tank2, label='Istwert Tank 2', color='green')
|
||||||
|
|
||||||
|
# Plot für Sollwert (Tank 2)
|
||||||
|
plt.plot(datetimes_sollwert_tank2, temperaturen_sollwert_tank2, label='Sollwert Tank 2', color='orange', linestyle='--')
|
||||||
|
|
||||||
|
plt.xlabel('Zeitstempel')
|
||||||
|
plt.ylabel('Temperatur (°C)')
|
||||||
|
plt.title('Temperaturverlauf Tank 2 (Istwert und Sollwert)')
|
||||||
|
|
||||||
|
# Vertikale Ausrichtung der x-Achsenbeschriftung
|
||||||
|
plt.xticks(rotation='vertical')
|
||||||
|
|
||||||
|
plt.legend()
|
||||||
|
plt.grid(True)
|
||||||
|
|
||||||
|
# Speichern Sie die Grafik als SVG-Datei
|
||||||
|
plt.savefig('Temperaturverlauf_Tank2.svg', format='svg', bbox_inches='tight')
|
||||||
|
|
||||||
|
# Grafik anzeigen (optional)
|
||||||
|
plt.show()
|
72
plottemp.py
Executable file
72
plottemp.py
Executable file
|
@ -0,0 +1,72 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
# Pfad zur Datenbank
|
||||||
|
db_path = '/home/divers/datenbank/temperaturen.db'
|
||||||
|
|
||||||
|
# SQLite-Datenbankverbindung herstellen
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# SQL-Abfrage, um die Zeitstempel und Temperaturen zu erhalten (Tabelle "istwert" für Tank 1)
|
||||||
|
cursor.execute("SELECT zeitstempel, temperatur FROM istwert WHERE messstelle = 1")
|
||||||
|
rows_istwert_tank1 = cursor.fetchall()
|
||||||
|
|
||||||
|
# SQL-Abfrage, um die Zeitstempel und Temperaturen zu erhalten (Tabelle "sollwert" für Tank 1)
|
||||||
|
cursor.execute("SELECT zeitstempel, temperatur FROM sollwert WHERE messstelle = 1")
|
||||||
|
rows_sollwert_tank1 = cursor.fetchall()
|
||||||
|
|
||||||
|
# SQL-Abfrage, um die Zeitstempel und Temperaturen zu erhalten (Tabelle "istwert" für Tank 2)
|
||||||
|
cursor.execute("SELECT zeitstempel, temperatur FROM istwert WHERE messstelle = 2")
|
||||||
|
rows_istwert_tank2 = cursor.fetchall()
|
||||||
|
|
||||||
|
# SQL-Abfrage, um die Zeitstempel und Temperaturen zu erhalten (Tabelle "sollwert" für Tank 2)
|
||||||
|
cursor.execute("SELECT zeitstempel, temperatur FROM sollwert WHERE messstelle = 2")
|
||||||
|
rows_sollwert_tank2 = cursor.fetchall()
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
# Die Zeitstempel und Temperaturen in separate Listen aufteilen (Istwert und Sollwert Tank 1)
|
||||||
|
datetimes_istwert_tank1 = [row[0] for row in rows_istwert_tank1]
|
||||||
|
temperaturen_istwert_tank1 = [row[1] for row in rows_istwert_tank1]
|
||||||
|
datetimes_sollwert_tank1 = [row[0] for row in rows_sollwert_tank1]
|
||||||
|
temperaturen_sollwert_tank1 = [row[1] for row in rows_sollwert_tank1]
|
||||||
|
|
||||||
|
# Die Zeitstempel und Temperaturen in separate Listen aufteilen (Istwert und Sollwert Tank 2)
|
||||||
|
datetimes_istwert_tank2 = [row[0] for row in rows_istwert_tank2]
|
||||||
|
temperaturen_istwert_tank2 = [row[1] for row in rows_istwert_tank2]
|
||||||
|
datetimes_sollwert_tank2 = [row[0] for row in rows_sollwert_tank2]
|
||||||
|
temperaturen_sollwert_tank2 = [row[1] for row in rows_sollwert_tank2]
|
||||||
|
|
||||||
|
# Grafik erstellen
|
||||||
|
plt.figure(figsize=(10, 8)) # Vergrößern Sie die Höhe des Grafikbereichs
|
||||||
|
|
||||||
|
# Plot für Istwert (Tank 1)
|
||||||
|
plt.plot(datetimes_istwert_tank1, temperaturen_istwert_tank1, label='Istwert Tank 1', color='blue')
|
||||||
|
|
||||||
|
# Plot für Sollwert (Tank 1)
|
||||||
|
plt.plot(datetimes_sollwert_tank1, temperaturen_sollwert_tank1, label='Sollwert Tank 1', color='red', linestyle='--')
|
||||||
|
|
||||||
|
# Plot für Istwert (Tank 2)
|
||||||
|
plt.plot(datetimes_istwert_tank2, temperaturen_istwert_tank2, label='Istwert Tank 2', color='green')
|
||||||
|
|
||||||
|
# Plot für Sollwert (Tank 2)
|
||||||
|
plt.plot(datetimes_sollwert_tank2, temperaturen_sollwert_tank2, label='Sollwert Tank 2', color='orange', linestyle='--')
|
||||||
|
|
||||||
|
plt.xlabel('Zeitstempel')
|
||||||
|
plt.ylabel('Temperatur (°C)')
|
||||||
|
plt.title('Temperaturverlauf Tank 1 und Tank 2 (Istwert und Sollwert)')
|
||||||
|
|
||||||
|
# Vertikale Ausrichtung der x-Achsenbeschriftung
|
||||||
|
plt.xticks(rotation='vertical')
|
||||||
|
|
||||||
|
plt.legend()
|
||||||
|
plt.grid(True)
|
||||||
|
|
||||||
|
# Speichern Sie die Grafik als SVG-Datei
|
||||||
|
plt.savefig('Temperaturverlauf.svg', format='svg', bbox_inches='tight')
|
||||||
|
|
||||||
|
# Grafik anzeigen (optional)
|
||||||
|
plt.show()
|
22
show.py
Executable file
22
show.py
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
# SQLite-Datenbankverbindung herstellen
|
||||||
|
conn = sqlite3.connect('temperaturen.db')
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Funktion zum Auslesen und Ausgeben der Werte
|
||||||
|
def read_and_print_table(table_name):
|
||||||
|
print(f"Auslesen der Tabelle '{table_name}':")
|
||||||
|
cursor.execute(f"SELECT * FROM {table_name}")
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
for row in rows:
|
||||||
|
print(row)
|
||||||
|
|
||||||
|
# Tabellen "istwert" und "sollwert" auslesen und ausgeben
|
||||||
|
read_and_print_table("istwert")
|
||||||
|
read_and_print_table("sollwert")
|
||||||
|
|
||||||
|
# Die Datenbankverbindung schließen
|
||||||
|
conn.close()
|
24
temp.py
Executable file
24
temp.py
Executable file
|
@ -0,0 +1,24 @@
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
# Pfad zur Datenbank
|
||||||
|
db_path = '/home/divers/datenbank/temperaturen.db'
|
||||||
|
|
||||||
|
# SQLite-Datenbankverbindung herstellen
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# SQL-Update-Statement zum Entfernen von "°C" aus der Temperaturspalte
|
||||||
|
update_query = """
|
||||||
|
UPDATE sollwert
|
||||||
|
SET temperatur = REPLACE(temperatur, '°C', '')
|
||||||
|
WHERE temperatur LIKE '%°C'
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Führen Sie das Update-Statement aus
|
||||||
|
cursor.execute(update_query)
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
# Die Datenbankverbindung schließen
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
print("°C-Symbole in der Temperaturspalte entfernt.")
|
BIN
temperaturen.db
Normal file
BIN
temperaturen.db
Normal file
Binary file not shown.
1564
temperaturverlauf.svg
Normal file
1564
temperaturverlauf.svg
Normal file
File diff suppressed because it is too large
Load diff
After Width: | Height: | Size: 56 KiB |
81
trend.py
Executable file
81
trend.py
Executable file
|
@ -0,0 +1,81 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import cgi
|
||||||
|
import sqlite3
|
||||||
|
import mpld3
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
import csv
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
# Parse the form data
|
||||||
|
form = cgi.FieldStorage()
|
||||||
|
|
||||||
|
# Get the current date and time
|
||||||
|
current_datetime = datetime.now()
|
||||||
|
|
||||||
|
# Calculate one day before and after the current date at 22:22
|
||||||
|
start_datetime_default = current_datetime - timedelta(days=1, hours=current_datetime.hour, minutes=current_datetime.minute, seconds=current_datetime.second)
|
||||||
|
start_datetime_default = start_datetime_default.replace(hour=22, minute=22, second=0)
|
||||||
|
|
||||||
|
end_datetime_default = current_datetime + timedelta(days=1, hours=1, minutes=38) # Assuming you want 24 hours + 1 hour and 38 minutes
|
||||||
|
end_datetime_default = end_datetime_default.replace(hour=22, minute=22, second=0)
|
||||||
|
|
||||||
|
# Get the selected start and end dates with times from the form, or use the defaults
|
||||||
|
start_datetime = form.getvalue("start_datetime", start_datetime_default.strftime("%Y-%m-%dT%H:%M"))
|
||||||
|
end_datetime = form.getvalue("end_datetime", end_datetime_default.strftime("%Y-%m-%dT%H:%M"))
|
||||||
|
|
||||||
|
# Establish a connection to the database (please adjust the database path)
|
||||||
|
conn = sqlite3.connect('/home/divers/datenbank/temperaturen.db')
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Create a function to generate the temperature plot and CSV data
|
||||||
|
def generate_temperature_plot_and_csv(start_datetime, end_datetime):
|
||||||
|
cursor.execute("SELECT zeitstempel, temperatur FROM istwert WHERE messstelle = 1 AND zeitstempel BETWEEN ? AND ?", (start_datetime, end_datetime))
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
|
timestamps = [datetime.strptime(row[0], "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d %H:%M:%S") for row in rows]
|
||||||
|
temperaturen = [row[1] for row in rows]
|
||||||
|
|
||||||
|
# Generate CSV data
|
||||||
|
csv_data = "Zeitstempel,Temperatur (°C)\n"
|
||||||
|
csv_data += "\n".join([f"{timestamps[i]},{temperaturen[i]}" for i in range(len(timestamps))])
|
||||||
|
|
||||||
|
plt.figure(figsize=(10, 5))
|
||||||
|
plt.plot(timestamps, temperaturen, marker='o', linestyle='-', color='b')
|
||||||
|
plt.xlabel('Zeitstempel')
|
||||||
|
plt.ylabel('Temperatur (°C)')
|
||||||
|
plt.title('Temperaturverlauf Tank 1')
|
||||||
|
plt.grid(True)
|
||||||
|
|
||||||
|
plot_html = mpld3.fig_to_html(plt.gcf())
|
||||||
|
plt.close()
|
||||||
|
|
||||||
|
return plot_html, csv_data
|
||||||
|
|
||||||
|
# Generate the temperature plot and CSV data
|
||||||
|
temperature_plot, csv_data = generate_temperature_plot_and_csv(start_datetime, end_datetime)
|
||||||
|
|
||||||
|
# Generate the HTML page with the temperature plot and CSV data
|
||||||
|
print("Content-type: text/html\n")
|
||||||
|
print("<html>")
|
||||||
|
print("<head>")
|
||||||
|
print("<title>Temperaturverlauf</title>")
|
||||||
|
print("</head>")
|
||||||
|
print("<body>")
|
||||||
|
print("<h1>Temperaturverlauf Tank 1</h1>")
|
||||||
|
print("<form method='POST'>")
|
||||||
|
print("Startdatum und Uhrzeit: <input type='datetime-local' name='start_datetime' value='{}'><br>".format(start_datetime))
|
||||||
|
print("Enddatum und Uhrzeit: <input type='datetime-local' name='end_datetime' value='{}'><br>".format(end_datetime))
|
||||||
|
print("<input type='submit' value='Anzeigen'>")
|
||||||
|
print("</form>")
|
||||||
|
print(temperature_plot)
|
||||||
|
print("<h2>Dargestellte Werte als CSV</h2>")
|
||||||
|
print("<pre>")
|
||||||
|
print(csv_data)
|
||||||
|
print("</pre>")
|
||||||
|
print("</body>")
|
||||||
|
print("</html>")
|
||||||
|
|
||||||
|
# Close the database connection
|
||||||
|
conn.close()
|
Loading…
Reference in a new issue