Sfoglia il codice sorgente

add influx calibration script, readme note.

Thomas Buck 3 anni fa
parent
commit
f685f39044
2 ha cambiato i file con 77 aggiunte e 0 eliminazioni
  1. 13
    0
      README.md
  2. 64
    0
      influx/influx-calibration.py

+ 13
- 0
README.md Vedi File

@@ -56,6 +56,19 @@ When an ESP is used, a webinterface and OTA updater will be included as well.
56 56
 For the ESP32, you can upload a new firmware using a webbrowser.
57 57
 Simply use the link on the main page of the web ui, then upload the '.pio/build/esp32_main/firmware.bin' file from the project directory after building.
58 58
 
59
+Writing events to InfluxDB is also supported.
60
+Configure the server and database in 'include/config.h'.
61
+It will store the valve-open duration (in seconds) with the following measurement types:
62
+
63
+    fertilizer
64
+    plant
65
+    calibrated_filling
66
+    calibrated_watering
67
+
68
+Fertilizer shows each time a fertilizer pump has been running.
69
+Plant shows when multiple plants have been watered at the same time.
70
+Additionally, calibrated_filling can be used to determine the inlet flowrate and calibrated_watering can be used to determine each outlet flowrate, as long as the tank size is known.
71
+
59 72
 ## License
60 73
 
61 74
     Copyright (c) 2021 Thomas Buck <thomas@xythobuz.de>

+ 64
- 0
influx/influx-calibration.py Vedi File

@@ -0,0 +1,64 @@
1
+#!/usr/bin/env python
2
+
3
+from influxdb import InfluxDBClient
4
+import matplotlib.pyplot as plt
5
+import matplotlib
6
+from datetime import datetime
7
+
8
+# config
9
+host = '10.23.42.14'
10
+port = 8086
11
+user = 'root'
12
+password = 'root'
13
+dbname = 'giessomat'
14
+
15
+# data
16
+client = InfluxDBClient(host, port, user, password, dbname)
17
+print("Querying DB " + dbname + " on " + host)
18
+result = client.query('SELECT "duration" FROM "calibrated_filling";')
19
+#print("Result: {0}".format(result))
20
+
21
+data = list(result.get_points())
22
+print("Got " + str(len(data)) + " datapoints")
23
+#print(data)
24
+
25
+times = ([datetime.strptime(d['time'], '%Y-%m-%dT%H:%M:%S.%fZ') for d in data])
26
+durations = ([d['duration'] for d in data])
27
+
28
+max_t = max(durations)
29
+min_t = min(durations)
30
+
31
+simple_average = min_t + ((max_t - min_t) / 2)
32
+average = 0
33
+for d in durations:
34
+    average += d
35
+average /= len(durations)
36
+
37
+sorted_durations = sorted(durations)
38
+median = sorted_durations[int(len(sorted_durations) / 2)]
39
+
40
+print("Min. Filling Time: " + str(min_t))
41
+print("Max. Filling Time: " + str(max_t))
42
+print("Average Filling Time:")
43
+print("  Simple = " + str(simple_average))
44
+print("  Average = " + str(average))
45
+print("  Median = " + str(median))
46
+
47
+# plot results
48
+plt.ioff()
49
+
50
+# ---------------------------
51
+
52
+fig, ax = plt.subplots()
53
+
54
+dates = matplotlib.dates.date2num(times)
55
+ax.plot_date(dates, durations, '-', label='filling')
56
+
57
+ax.set_xlabel('Time')
58
+ax.set_ylabel('Duration')
59
+ax.set_title('Filling Durations')
60
+ax.legend()
61
+
62
+# ---------------------------
63
+
64
+plt.show()

Loading…
Annulla
Salva