Spaces:
Sleeping
Sleeping
jerin
commited on
Commit
•
a650cd7
1
Parent(s):
1af5459
Revert "lstm pipeline"
Browse filesThis reverts commit 1af5459d233d042ff693c634a4dd9d5b7c1f1944.
- MA_temp_model.h5 +0 -3
- buildingdata.csv +0 -3
- energy_model.h5 +0 -3
- energy_model_01.h5 +0 -3
- file_info.ipynb +0 -0
- kmeans_model.pkl +0 -3
- kmeans_model1.pkl +0 -3
- kmeans_model2.pkl +0 -3
- kmeans_model3.pkl +0 -3
- kmeans_model4.pkl +0 -3
- lstm.ipynb +0 -0
- mqttclient.ipynb +6 -13
- mqttpublisher.ipynb +11 -449
- pca_model.pkl +0 -3
- pipeline.ipynb +0 -0
- sample_data.csv +0 -3
- sample_data_01.csv +0 -3
- sample_data_02.csv +0 -3
- sample_data_smooth_01.csv +0 -3
- scaler.pkl +0 -3
- scaler_1.pkl +0 -3
- src/main.py +0 -42
- src/rtu/RTUAnomalizer.py +7 -61
- src/rtu/RTUPipeline.py +8 -129
- src/rtu/models/kmeans_model1.pkl +0 -3
- src/rtu/models/kmeans_model2.pkl +0 -3
- src/rtu/models/kmeans_model3.pkl +0 -3
- src/rtu/models/kmeans_model4.pkl +0 -3
- src/rtu/models/scaler_1.pkl +0 -3
- streamlit.py +11 -206
MA_temp_model.h5
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:ed0c2c96cde21763e2a60597ab8abf0a50bd75ab954525845702014d219027c4
|
3 |
-
size 533080
|
|
|
|
|
|
|
|
buildingdata.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:62e6cb23b7dfca34ca511b0ff99c68009f860968cd0c5688ac97ffa50a6aea8b
|
3 |
-
size 24061812
|
|
|
|
|
|
|
|
energy_model.h5
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:ad1ad8b65c5030e0dc971b3c488335f2f1d93b0b8acc2bfb6af10145237cda87
|
3 |
-
size 780616
|
|
|
|
|
|
|
|
energy_model_01.h5
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:58e7e4823df5c20cd2fb4df23d2399d8b0fcf710147f3e52c9c1f3fcbeaa7cc1
|
3 |
-
size 535480
|
|
|
|
|
|
|
|
file_info.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
kmeans_model.pkl
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:5bddef9e8a8d413136daf6f99dd236fb6c97700d2fa85567de17aacb4a32bce1
|
3 |
-
size 1927225
|
|
|
|
|
|
|
|
kmeans_model1.pkl
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:aaa404e937bf8fe9d52b38aa1e11f87d544530a2d4789b46d20b5a1665e15846
|
3 |
-
size 2064297
|
|
|
|
|
|
|
|
kmeans_model2.pkl
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:9cf710504c910255e59d0609617fecf74ee8ad6710f4ba4109d9de5aae0cd879
|
3 |
-
size 2064297
|
|
|
|
|
|
|
|
kmeans_model3.pkl
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:1fb375913725bf309d514f55b71799daead266db7caad09f02ab9cfdd56bdc0a
|
3 |
-
size 2064297
|
|
|
|
|
|
|
|
kmeans_model4.pkl
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:cfbe4b1a5c1aa4b00e8e932c77dd8ed5ce99fbe5efd4960079d14e380206f9f2
|
3 |
-
size 2064297
|
|
|
|
|
|
|
|
lstm.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
mqttclient.ipynb
CHANGED
@@ -2,14 +2,14 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [
|
8 |
{
|
9 |
"name": "stderr",
|
10 |
"output_type": "stream",
|
11 |
"text": [
|
12 |
-
"C:\\Users\\jerin\\AppData\\Local\\Temp\\
|
13 |
" client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)\n"
|
14 |
]
|
15 |
},
|
@@ -17,13 +17,7 @@
|
|
17 |
"name": "stdout",
|
18 |
"output_type": "stream",
|
19 |
"text": [
|
20 |
-
"{'
|
21 |
-
"{'date': '2018-05-02 00:10:00', 'hp_hws_temp': 97.0, 'rtu_003_sa_temp': 64.1, 'rtu_003_oadmpr_pct': 88.4, 'rtu_003_ra_temp': 72.4, 'rtu_003_oa_temp': 61.9, 'rtu_003_ma_temp': 63.3, 'rtu_003_sf_vfd_spd_fbk_tn': 77.2, 'rtu_003_rf_vfd_spd_fbk_tn': 52.5, 'rtu_004_sa_temp': 68.8, 'rtu_004_oadmpr_pct': 80.6, 'rtu_004_ra_temp': 73.3, 'rtu_004_oa_temp': 68.2, 'rtu_004_ma_temp': 66.1, 'rtu_004_sf_vfd_spd_fbk_tn': 75.6, 'rtu_004_rf_vfd_spd_fbk_tn': 67.3, 'air_temp_set_1': 14.9, 'air_temp_set_2': 14.44, 'dew_point_temperature_set_1d': 7.02, 'relative_humidity_set_1': 59.5, 'solar_radiation_set_1': 335.9}\n",
|
22 |
-
"{'date': '2018-05-02 00:11:00', 'hp_hws_temp': 97.6, 'rtu_003_sa_temp': 64.1, 'rtu_003_oadmpr_pct': 88.4, 'rtu_003_ra_temp': 72.4, 'rtu_003_oa_temp': 62.0, 'rtu_003_ma_temp': 63.8, 'rtu_003_sf_vfd_spd_fbk_tn': 78.2, 'rtu_003_rf_vfd_spd_fbk_tn': 56.7, 'rtu_004_sa_temp': 67.3, 'rtu_004_oadmpr_pct': 76.6, 'rtu_004_ra_temp': 73.4, 'rtu_004_oa_temp': 68.6, 'rtu_004_ma_temp': 64.3, 'rtu_004_sf_vfd_spd_fbk_tn': 78.6, 'rtu_004_rf_vfd_spd_fbk_tn': 77.5, 'air_temp_set_1': 14.9, 'air_temp_set_2': 14.44, 'dew_point_temperature_set_1d': 7.02, 'relative_humidity_set_1': 59.5, 'solar_radiation_set_1': 335.9}\n",
|
23 |
-
"{'date': '2018-05-02 00:12:00', 'hp_hws_temp': 98.3, 'rtu_003_sa_temp': 64.2, 'rtu_003_oadmpr_pct': 88.4, 'rtu_003_ra_temp': 72.4, 'rtu_003_oa_temp': 62.1, 'rtu_003_ma_temp': 64.1, 'rtu_003_sf_vfd_spd_fbk_tn': 76.4, 'rtu_003_rf_vfd_spd_fbk_tn': 52.9, 'rtu_004_sa_temp': 66.7, 'rtu_004_oadmpr_pct': 51.4, 'rtu_004_ra_temp': 73.4, 'rtu_004_oa_temp': 68.9, 'rtu_004_ma_temp': 65.1, 'rtu_004_sf_vfd_spd_fbk_tn': 79.6, 'rtu_004_rf_vfd_spd_fbk_tn': 82.5, 'air_temp_set_1': 14.9, 'air_temp_set_2': 14.44, 'dew_point_temperature_set_1d': 7.02, 'relative_humidity_set_1': 59.5, 'solar_radiation_set_1': 335.9}\n",
|
24 |
-
"{'date': '2018-05-02 00:13:00', 'hp_hws_temp': 98.9, 'rtu_003_sa_temp': 64.3, 'rtu_003_oadmpr_pct': 88.4, 'rtu_003_ra_temp': 72.3, 'rtu_003_oa_temp': 62.2, 'rtu_003_ma_temp': 63.8, 'rtu_003_sf_vfd_spd_fbk_tn': 78.5, 'rtu_003_rf_vfd_spd_fbk_tn': 57.0, 'rtu_004_sa_temp': 67.8, 'rtu_004_oadmpr_pct': 52.4, 'rtu_004_ra_temp': 73.4, 'rtu_004_oa_temp': 68.9, 'rtu_004_ma_temp': 67.8, 'rtu_004_sf_vfd_spd_fbk_tn': 78.3, 'rtu_004_rf_vfd_spd_fbk_tn': 73.9, 'air_temp_set_1': 14.9, 'air_temp_set_2': 14.44, 'dew_point_temperature_set_1d': 7.02, 'relative_humidity_set_1': 59.5, 'solar_radiation_set_1': 335.9}\n",
|
25 |
-
"{'date': '2018-05-02 00:14:00', 'hp_hws_temp': 99.3, 'rtu_003_sa_temp': 64.4, 'rtu_003_oadmpr_pct': 88.4, 'rtu_003_ra_temp': 72.4, 'rtu_003_oa_temp': 62.5, 'rtu_003_ma_temp': 63.9, 'rtu_003_sf_vfd_spd_fbk_tn': 75.9, 'rtu_003_rf_vfd_spd_fbk_tn': 49.8, 'rtu_004_sa_temp': 68.8, 'rtu_004_oadmpr_pct': 52.4, 'rtu_004_ra_temp': 73.3, 'rtu_004_oa_temp': 68.1, 'rtu_004_ma_temp': 68.3, 'rtu_004_sf_vfd_spd_fbk_tn': 76.5, 'rtu_004_rf_vfd_spd_fbk_tn': 74.7, 'air_temp_set_1': 14.9, 'air_temp_set_2': 14.44, 'dew_point_temperature_set_1d': 7.02, 'relative_humidity_set_1': 59.5, 'solar_radiation_set_1': 335.9}\n",
|
26 |
-
"{'date': '2018-05-02 00:15:00', 'hp_hws_temp': 99.0, 'rtu_003_sa_temp': 63.9, 'rtu_003_oadmpr_pct': 88.4, 'rtu_003_ra_temp': 72.3, 'rtu_003_oa_temp': 62.6, 'rtu_003_ma_temp': 63.6, 'rtu_003_sf_vfd_spd_fbk_tn': 74.3, 'rtu_003_rf_vfd_spd_fbk_tn': 53.5, 'rtu_004_sa_temp': 69.1, 'rtu_004_oadmpr_pct': 79.0, 'rtu_004_ra_temp': 73.3, 'rtu_004_oa_temp': 67.2, 'rtu_004_ma_temp': 66.6, 'rtu_004_sf_vfd_spd_fbk_tn': 75.3, 'rtu_004_rf_vfd_spd_fbk_tn': 69.0, 'air_temp_set_1': 16.0, 'air_temp_set_2': 15.48, 'dew_point_temperature_set_1d': 6.63, 'relative_humidity_set_1': 54.0, 'solar_radiation_set_1': 426.3}\n"
|
27 |
]
|
28 |
},
|
29 |
{
|
@@ -33,7 +27,7 @@
|
|
33 |
"traceback": [
|
34 |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
35 |
"\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
|
36 |
-
"Cell \u001b[1;32mIn[
|
37 |
"File \u001b[1;32mc:\\Users\\jerin\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\paho\\mqtt\\client.py:2291\u001b[0m, in \u001b[0;36mClient.loop_forever\u001b[1;34m(self, timeout, retry_first_connection)\u001b[0m\n\u001b[0;32m 2289\u001b[0m rc \u001b[38;5;241m=\u001b[39m MQTTErrorCode\u001b[38;5;241m.\u001b[39mMQTT_ERR_SUCCESS\n\u001b[0;32m 2290\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m rc \u001b[38;5;241m==\u001b[39m MQTTErrorCode\u001b[38;5;241m.\u001b[39mMQTT_ERR_SUCCESS:\n\u001b[1;32m-> 2291\u001b[0m rc \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_loop\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 2292\u001b[0m \u001b[38;5;66;03m# We don't need to worry about locking here, because we've\u001b[39;00m\n\u001b[0;32m 2293\u001b[0m \u001b[38;5;66;03m# either called loop_forever() when in single threaded mode, or\u001b[39;00m\n\u001b[0;32m 2294\u001b[0m \u001b[38;5;66;03m# in multi threaded mode when loop_stop() has been called and\u001b[39;00m\n\u001b[0;32m 2295\u001b[0m \u001b[38;5;66;03m# so no other threads can access _out_packet or _messages.\u001b[39;00m\n\u001b[0;32m 2296\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_thread_terminate \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m 2297\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_out_packet) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m\n\u001b[0;32m 2298\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_out_messages) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m):\n",
|
38 |
"File \u001b[1;32mc:\\Users\\jerin\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\paho\\mqtt\\client.py:1657\u001b[0m, in \u001b[0;36mClient._loop\u001b[1;34m(self, timeout)\u001b[0m\n\u001b[0;32m 1654\u001b[0m rlist \u001b[38;5;241m=\u001b[39m [\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_sock, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_sockpairR]\n\u001b[0;32m 1656\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m-> 1657\u001b[0m socklist \u001b[38;5;241m=\u001b[39m select\u001b[38;5;241m.\u001b[39mselect(rlist, wlist, [], timeout)\n\u001b[0;32m 1658\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[0;32m 1659\u001b[0m \u001b[38;5;66;03m# Socket isn't correct type, in likelihood connection is lost\u001b[39;00m\n\u001b[0;32m 1660\u001b[0m \u001b[38;5;66;03m# ... or we called disconnect(). In that case the socket will\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 1663\u001b[0m \u001b[38;5;66;03m# rc != MQTT_ERR_SUCCESS and we don't want state to change from\u001b[39;00m\n\u001b[0;32m 1664\u001b[0m \u001b[38;5;66;03m# mqtt_cs_disconnecting.\u001b[39;00m\n\u001b[0;32m 1665\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_state \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m (_ConnectionState\u001b[38;5;241m.\u001b[39mMQTT_CS_DISCONNECTING, _ConnectionState\u001b[38;5;241m.\u001b[39mMQTT_CS_DISCONNECTED):\n",
|
39 |
"\u001b[1;31mKeyboardInterrupt\u001b[0m: "
|
@@ -54,9 +48,8 @@
|
|
54 |
"def on_message(client, userdata, message):\n",
|
55 |
" global df\n",
|
56 |
" payload = json.loads(message.payload.decode())\n",
|
57 |
-
"
|
58 |
-
"
|
59 |
-
" \n",
|
60 |
" print(payload)\n",
|
61 |
" # df.loc[len(df)] = {\"sa_temp\": sa_temp, \"ma_temp\": ma_temp}\n",
|
62 |
" \n",
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
"metadata": {},
|
7 |
"outputs": [
|
8 |
{
|
9 |
"name": "stderr",
|
10 |
"output_type": "stream",
|
11 |
"text": [
|
12 |
+
"C:\\Users\\jerin\\AppData\\Local\\Temp\\ipykernel_6272\\1211754903.py:21: DeprecationWarning: Callback API version 1 is deprecated, update to latest version\n",
|
13 |
" client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)\n"
|
14 |
]
|
15 |
},
|
|
|
17 |
"name": "stdout",
|
18 |
"output_type": "stream",
|
19 |
"text": [
|
20 |
+
"{'sa_temp': 68.6, 'ma_temp': 70.0}\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
]
|
22 |
},
|
23 |
{
|
|
|
27 |
"traceback": [
|
28 |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
29 |
"\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
|
30 |
+
"Cell \u001b[1;32mIn[2], line 25\u001b[0m\n\u001b[0;32m 23\u001b[0m client\u001b[38;5;241m.\u001b[39mconnect(broker_address, broker_port)\n\u001b[0;32m 24\u001b[0m client\u001b[38;5;241m.\u001b[39msubscribe(topic)\n\u001b[1;32m---> 25\u001b[0m \u001b[43mclient\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mloop_forever\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
|
31 |
"File \u001b[1;32mc:\\Users\\jerin\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\paho\\mqtt\\client.py:2291\u001b[0m, in \u001b[0;36mClient.loop_forever\u001b[1;34m(self, timeout, retry_first_connection)\u001b[0m\n\u001b[0;32m 2289\u001b[0m rc \u001b[38;5;241m=\u001b[39m MQTTErrorCode\u001b[38;5;241m.\u001b[39mMQTT_ERR_SUCCESS\n\u001b[0;32m 2290\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m rc \u001b[38;5;241m==\u001b[39m MQTTErrorCode\u001b[38;5;241m.\u001b[39mMQTT_ERR_SUCCESS:\n\u001b[1;32m-> 2291\u001b[0m rc \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_loop\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 2292\u001b[0m \u001b[38;5;66;03m# We don't need to worry about locking here, because we've\u001b[39;00m\n\u001b[0;32m 2293\u001b[0m \u001b[38;5;66;03m# either called loop_forever() when in single threaded mode, or\u001b[39;00m\n\u001b[0;32m 2294\u001b[0m \u001b[38;5;66;03m# in multi threaded mode when loop_stop() has been called and\u001b[39;00m\n\u001b[0;32m 2295\u001b[0m \u001b[38;5;66;03m# so no other threads can access _out_packet or _messages.\u001b[39;00m\n\u001b[0;32m 2296\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_thread_terminate \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m 2297\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_out_packet) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m\n\u001b[0;32m 2298\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_out_messages) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m):\n",
|
32 |
"File \u001b[1;32mc:\\Users\\jerin\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\paho\\mqtt\\client.py:1657\u001b[0m, in \u001b[0;36mClient._loop\u001b[1;34m(self, timeout)\u001b[0m\n\u001b[0;32m 1654\u001b[0m rlist \u001b[38;5;241m=\u001b[39m [\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_sock, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_sockpairR]\n\u001b[0;32m 1656\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m-> 1657\u001b[0m socklist \u001b[38;5;241m=\u001b[39m select\u001b[38;5;241m.\u001b[39mselect(rlist, wlist, [], timeout)\n\u001b[0;32m 1658\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[0;32m 1659\u001b[0m \u001b[38;5;66;03m# Socket isn't correct type, in likelihood connection is lost\u001b[39;00m\n\u001b[0;32m 1660\u001b[0m \u001b[38;5;66;03m# ... or we called disconnect(). In that case the socket will\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 1663\u001b[0m \u001b[38;5;66;03m# rc != MQTT_ERR_SUCCESS and we don't want state to change from\u001b[39;00m\n\u001b[0;32m 1664\u001b[0m \u001b[38;5;66;03m# mqtt_cs_disconnecting.\u001b[39;00m\n\u001b[0;32m 1665\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_state \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m (_ConnectionState\u001b[38;5;241m.\u001b[39mMQTT_CS_DISCONNECTING, _ConnectionState\u001b[38;5;241m.\u001b[39mMQTT_CS_DISCONNECTED):\n",
|
33 |
"\u001b[1;31mKeyboardInterrupt\u001b[0m: "
|
|
|
48 |
"def on_message(client, userdata, message):\n",
|
49 |
" global df\n",
|
50 |
" payload = json.loads(message.payload.decode())\n",
|
51 |
+
" sa_temp = payload[\"sa_temp\"]\n",
|
52 |
+
" ma_temp = payload[\"ma_temp\"]\n",
|
|
|
53 |
" print(payload)\n",
|
54 |
" # df.loc[len(df)] = {\"sa_temp\": sa_temp, \"ma_temp\": ma_temp}\n",
|
55 |
" \n",
|
mqttpublisher.ipynb
CHANGED
@@ -2,379 +2,17 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [
|
8 |
{
|
9 |
"name": "stderr",
|
10 |
"output_type": "stream",
|
11 |
"text": [
|
12 |
-
"C:\\Users\\jerin\\AppData\\Local\\Temp\\
|
13 |
" client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, clientId)\n"
|
14 |
]
|
15 |
},
|
16 |
-
{
|
17 |
-
"name": "stdout",
|
18 |
-
"output_type": "stream",
|
19 |
-
"text": [
|
20 |
-
"published!\n",
|
21 |
-
"published!\n",
|
22 |
-
"published!\n",
|
23 |
-
"published!\n",
|
24 |
-
"published!\n",
|
25 |
-
"published!\n",
|
26 |
-
"published!\n",
|
27 |
-
"published!\n",
|
28 |
-
"published!\n",
|
29 |
-
"published!\n",
|
30 |
-
"published!\n",
|
31 |
-
"published!\n",
|
32 |
-
"published!\n",
|
33 |
-
"published!\n",
|
34 |
-
"published!\n",
|
35 |
-
"published!\n",
|
36 |
-
"published!\n",
|
37 |
-
"published!\n",
|
38 |
-
"published!\n",
|
39 |
-
"published!\n",
|
40 |
-
"published!\n",
|
41 |
-
"published!\n",
|
42 |
-
"published!\n",
|
43 |
-
"published!\n",
|
44 |
-
"published!\n",
|
45 |
-
"published!\n",
|
46 |
-
"published!\n",
|
47 |
-
"published!\n",
|
48 |
-
"published!\n",
|
49 |
-
"published!\n",
|
50 |
-
"published!\n",
|
51 |
-
"published!\n",
|
52 |
-
"published!\n",
|
53 |
-
"published!\n",
|
54 |
-
"published!\n",
|
55 |
-
"published!\n",
|
56 |
-
"published!\n",
|
57 |
-
"published!\n",
|
58 |
-
"published!\n",
|
59 |
-
"published!\n",
|
60 |
-
"published!\n",
|
61 |
-
"published!\n",
|
62 |
-
"published!\n",
|
63 |
-
"published!\n",
|
64 |
-
"published!\n",
|
65 |
-
"published!\n",
|
66 |
-
"published!\n",
|
67 |
-
"published!\n",
|
68 |
-
"published!\n",
|
69 |
-
"published!\n",
|
70 |
-
"published!\n",
|
71 |
-
"published!\n",
|
72 |
-
"published!\n",
|
73 |
-
"published!\n",
|
74 |
-
"published!\n",
|
75 |
-
"published!\n",
|
76 |
-
"published!\n",
|
77 |
-
"published!\n",
|
78 |
-
"published!\n",
|
79 |
-
"published!\n",
|
80 |
-
"published!\n",
|
81 |
-
"published!\n",
|
82 |
-
"published!\n",
|
83 |
-
"published!\n",
|
84 |
-
"published!\n",
|
85 |
-
"published!\n",
|
86 |
-
"published!\n",
|
87 |
-
"published!\n",
|
88 |
-
"published!\n",
|
89 |
-
"published!\n",
|
90 |
-
"published!\n",
|
91 |
-
"published!\n",
|
92 |
-
"published!\n",
|
93 |
-
"published!\n",
|
94 |
-
"published!\n",
|
95 |
-
"published!\n",
|
96 |
-
"published!\n",
|
97 |
-
"published!\n",
|
98 |
-
"published!\n",
|
99 |
-
"published!\n",
|
100 |
-
"published!\n",
|
101 |
-
"published!\n",
|
102 |
-
"published!\n",
|
103 |
-
"published!\n",
|
104 |
-
"published!\n",
|
105 |
-
"published!\n",
|
106 |
-
"published!\n",
|
107 |
-
"published!\n",
|
108 |
-
"published!\n",
|
109 |
-
"published!\n",
|
110 |
-
"published!\n",
|
111 |
-
"published!\n",
|
112 |
-
"published!\n",
|
113 |
-
"published!\n",
|
114 |
-
"published!\n",
|
115 |
-
"published!\n",
|
116 |
-
"published!\n",
|
117 |
-
"published!\n",
|
118 |
-
"published!\n",
|
119 |
-
"published!\n",
|
120 |
-
"published!\n",
|
121 |
-
"published!\n",
|
122 |
-
"published!\n",
|
123 |
-
"published!\n",
|
124 |
-
"published!\n",
|
125 |
-
"published!\n",
|
126 |
-
"published!\n",
|
127 |
-
"published!\n",
|
128 |
-
"published!\n",
|
129 |
-
"published!\n",
|
130 |
-
"published!\n",
|
131 |
-
"published!\n",
|
132 |
-
"published!\n",
|
133 |
-
"published!\n",
|
134 |
-
"published!\n",
|
135 |
-
"published!\n",
|
136 |
-
"published!\n",
|
137 |
-
"published!\n",
|
138 |
-
"published!\n",
|
139 |
-
"published!\n",
|
140 |
-
"published!\n",
|
141 |
-
"published!\n",
|
142 |
-
"published!\n",
|
143 |
-
"published!\n",
|
144 |
-
"published!\n",
|
145 |
-
"published!\n",
|
146 |
-
"published!\n",
|
147 |
-
"published!\n",
|
148 |
-
"published!\n",
|
149 |
-
"published!\n",
|
150 |
-
"published!\n",
|
151 |
-
"published!\n",
|
152 |
-
"published!\n",
|
153 |
-
"published!\n",
|
154 |
-
"published!\n",
|
155 |
-
"published!\n",
|
156 |
-
"published!\n",
|
157 |
-
"published!\n",
|
158 |
-
"published!\n",
|
159 |
-
"published!\n",
|
160 |
-
"published!\n",
|
161 |
-
"published!\n",
|
162 |
-
"published!\n",
|
163 |
-
"published!\n",
|
164 |
-
"published!\n",
|
165 |
-
"published!\n",
|
166 |
-
"published!\n",
|
167 |
-
"published!\n",
|
168 |
-
"published!\n",
|
169 |
-
"published!\n",
|
170 |
-
"published!\n",
|
171 |
-
"published!\n",
|
172 |
-
"published!\n",
|
173 |
-
"published!\n",
|
174 |
-
"published!\n",
|
175 |
-
"published!\n",
|
176 |
-
"published!\n",
|
177 |
-
"published!\n",
|
178 |
-
"published!\n",
|
179 |
-
"published!\n",
|
180 |
-
"published!\n",
|
181 |
-
"published!\n",
|
182 |
-
"published!\n",
|
183 |
-
"published!\n",
|
184 |
-
"published!\n",
|
185 |
-
"published!\n",
|
186 |
-
"published!\n",
|
187 |
-
"published!\n",
|
188 |
-
"published!\n",
|
189 |
-
"published!\n",
|
190 |
-
"published!\n",
|
191 |
-
"published!\n",
|
192 |
-
"published!\n",
|
193 |
-
"published!\n",
|
194 |
-
"published!\n",
|
195 |
-
"published!\n",
|
196 |
-
"published!\n",
|
197 |
-
"published!\n",
|
198 |
-
"published!\n",
|
199 |
-
"published!\n",
|
200 |
-
"published!\n",
|
201 |
-
"published!\n",
|
202 |
-
"published!\n",
|
203 |
-
"published!\n",
|
204 |
-
"published!\n",
|
205 |
-
"published!\n",
|
206 |
-
"published!\n",
|
207 |
-
"published!\n",
|
208 |
-
"published!\n",
|
209 |
-
"published!\n",
|
210 |
-
"published!\n",
|
211 |
-
"published!\n",
|
212 |
-
"published!\n",
|
213 |
-
"published!\n",
|
214 |
-
"published!\n",
|
215 |
-
"published!\n",
|
216 |
-
"published!\n",
|
217 |
-
"published!\n",
|
218 |
-
"published!\n",
|
219 |
-
"published!\n",
|
220 |
-
"published!\n",
|
221 |
-
"published!\n",
|
222 |
-
"published!\n",
|
223 |
-
"published!\n",
|
224 |
-
"published!\n",
|
225 |
-
"published!\n",
|
226 |
-
"published!\n",
|
227 |
-
"published!\n",
|
228 |
-
"published!\n",
|
229 |
-
"published!\n",
|
230 |
-
"published!\n",
|
231 |
-
"published!\n",
|
232 |
-
"published!\n",
|
233 |
-
"published!\n",
|
234 |
-
"published!\n",
|
235 |
-
"published!\n",
|
236 |
-
"published!\n",
|
237 |
-
"published!\n",
|
238 |
-
"published!\n",
|
239 |
-
"published!\n",
|
240 |
-
"published!\n",
|
241 |
-
"published!\n",
|
242 |
-
"published!\n",
|
243 |
-
"published!\n",
|
244 |
-
"published!\n",
|
245 |
-
"published!\n",
|
246 |
-
"published!\n",
|
247 |
-
"published!\n",
|
248 |
-
"published!\n",
|
249 |
-
"published!\n",
|
250 |
-
"published!\n",
|
251 |
-
"published!\n",
|
252 |
-
"published!\n",
|
253 |
-
"published!\n",
|
254 |
-
"published!\n",
|
255 |
-
"published!\n",
|
256 |
-
"published!\n",
|
257 |
-
"published!\n",
|
258 |
-
"published!\n",
|
259 |
-
"published!\n",
|
260 |
-
"published!\n",
|
261 |
-
"published!\n",
|
262 |
-
"published!\n",
|
263 |
-
"published!\n",
|
264 |
-
"published!\n",
|
265 |
-
"published!\n",
|
266 |
-
"published!\n",
|
267 |
-
"published!\n",
|
268 |
-
"published!\n",
|
269 |
-
"published!\n",
|
270 |
-
"published!\n",
|
271 |
-
"published!\n",
|
272 |
-
"published!\n",
|
273 |
-
"published!\n",
|
274 |
-
"published!\n",
|
275 |
-
"published!\n",
|
276 |
-
"published!\n",
|
277 |
-
"published!\n",
|
278 |
-
"published!\n",
|
279 |
-
"published!\n",
|
280 |
-
"published!\n",
|
281 |
-
"published!\n",
|
282 |
-
"published!\n",
|
283 |
-
"published!\n",
|
284 |
-
"published!\n",
|
285 |
-
"published!\n",
|
286 |
-
"published!\n",
|
287 |
-
"published!\n",
|
288 |
-
"published!\n",
|
289 |
-
"published!\n",
|
290 |
-
"published!\n",
|
291 |
-
"published!\n",
|
292 |
-
"published!\n",
|
293 |
-
"published!\n",
|
294 |
-
"published!\n",
|
295 |
-
"published!\n",
|
296 |
-
"published!\n",
|
297 |
-
"published!\n",
|
298 |
-
"published!\n",
|
299 |
-
"published!\n",
|
300 |
-
"published!\n",
|
301 |
-
"published!\n",
|
302 |
-
"published!\n",
|
303 |
-
"published!\n",
|
304 |
-
"published!\n",
|
305 |
-
"published!\n",
|
306 |
-
"published!\n",
|
307 |
-
"published!\n",
|
308 |
-
"published!\n",
|
309 |
-
"published!\n",
|
310 |
-
"published!\n",
|
311 |
-
"published!\n",
|
312 |
-
"published!\n",
|
313 |
-
"published!\n",
|
314 |
-
"published!\n",
|
315 |
-
"published!\n",
|
316 |
-
"published!\n",
|
317 |
-
"published!\n",
|
318 |
-
"published!\n",
|
319 |
-
"published!\n",
|
320 |
-
"published!\n",
|
321 |
-
"published!\n",
|
322 |
-
"published!\n",
|
323 |
-
"published!\n",
|
324 |
-
"published!\n",
|
325 |
-
"published!\n",
|
326 |
-
"published!\n",
|
327 |
-
"published!\n",
|
328 |
-
"published!\n",
|
329 |
-
"published!\n",
|
330 |
-
"published!\n",
|
331 |
-
"published!\n",
|
332 |
-
"published!\n",
|
333 |
-
"published!\n",
|
334 |
-
"published!\n",
|
335 |
-
"published!\n",
|
336 |
-
"published!\n",
|
337 |
-
"published!\n",
|
338 |
-
"published!\n",
|
339 |
-
"published!\n",
|
340 |
-
"published!\n",
|
341 |
-
"published!\n",
|
342 |
-
"published!\n",
|
343 |
-
"published!\n",
|
344 |
-
"published!\n",
|
345 |
-
"published!\n",
|
346 |
-
"published!\n",
|
347 |
-
"published!\n",
|
348 |
-
"published!\n",
|
349 |
-
"published!\n",
|
350 |
-
"published!\n",
|
351 |
-
"published!\n",
|
352 |
-
"published!\n",
|
353 |
-
"published!\n",
|
354 |
-
"published!\n",
|
355 |
-
"published!\n",
|
356 |
-
"published!\n",
|
357 |
-
"published!\n",
|
358 |
-
"published!\n",
|
359 |
-
"published!\n",
|
360 |
-
"published!\n",
|
361 |
-
"published!\n",
|
362 |
-
"published!\n",
|
363 |
-
"published!\n",
|
364 |
-
"published!\n",
|
365 |
-
"published!\n",
|
366 |
-
"published!\n",
|
367 |
-
"published!\n",
|
368 |
-
"published!\n",
|
369 |
-
"published!\n",
|
370 |
-
"published!\n",
|
371 |
-
"published!\n",
|
372 |
-
"published!\n",
|
373 |
-
"published!\n",
|
374 |
-
"published!\n",
|
375 |
-
"published!\n"
|
376 |
-
]
|
377 |
-
},
|
378 |
{
|
379 |
"ename": "KeyboardInterrupt",
|
380 |
"evalue": "",
|
@@ -382,8 +20,7 @@
|
|
382 |
"traceback": [
|
383 |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
384 |
"\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
|
385 |
-
"Cell \u001b[1;32mIn[
|
386 |
-
"Cell \u001b[1;32mIn[10], line 90\u001b[0m, in \u001b[0;36mpublish_sensor_data\u001b[1;34m()\u001b[0m\n\u001b[0;32m 55\u001b[0m client\u001b[38;5;241m.\u001b[39mpublish(topic, payload\u001b[38;5;241m=\u001b[39mjson\u001b[38;5;241m.\u001b[39mdumps({\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhp_hws_temp\u001b[39m\u001b[38;5;124m'\u001b[39m:hp_hws_temp,\n\u001b[0;32m 56\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mrtu_003_sa_temp\u001b[39m\u001b[38;5;124m'\u001b[39m:rtu_003_sa_temp,\n\u001b[0;32m 57\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mrtu_003_oadmpr_pct\u001b[39m\u001b[38;5;124m'\u001b[39m: rtu_003_oadmpr_pct,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 87\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mrelative_humidity_set_1\u001b[39m\u001b[38;5;124m'\u001b[39m:relative_humidity_set_1,\n\u001b[0;32m 88\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124msolar_radiation_set_1\u001b[39m\u001b[38;5;124m'\u001b[39m:solar_radiation_set_1}))\n\u001b[0;32m 89\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpublished!\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m---> 90\u001b[0m time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;241m2\u001b[39m)\n",
|
387 |
"\u001b[1;31mKeyboardInterrupt\u001b[0m: "
|
388 |
]
|
389 |
}
|
@@ -399,99 +36,24 @@
|
|
399 |
"broker_address = \"localhost\"\n",
|
400 |
"broker_port = 1883\n",
|
401 |
"\n",
|
402 |
-
"df = pd.read_csv(\"
|
403 |
"\n",
|
404 |
"client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, clientId)\n",
|
405 |
"client.connect(broker_address, broker_port)\n",
|
406 |
"topic = \"sensor_data\"\n",
|
407 |
"\n",
|
408 |
-
"def publish_sensor_data()
|
|
|
|
|
409 |
" for index, row in df.iterrows():\n",
|
410 |
-
"
|
411 |
-
"
|
412 |
-
"
|
413 |
-
" rtu_003_ra_temp = row['rtu_003_ra_temp']\n",
|
414 |
-
" rtu_003_oa_temp = row['rtu_003_oa_temp']\n",
|
415 |
-
" rtu_003_ma_temp = row['rtu_003_ma_temp']\n",
|
416 |
-
" rtu_003_sf_vfd_spd_fbk_tn = row['rtu_003_sf_vfd_spd_fbk_tn']\n",
|
417 |
-
" rtu_003_rf_vfd_spd_fbk_tn =row['rtu_003_rf_vfd_spd_fbk_tn']\n",
|
418 |
-
" rtu_004_sa_temp = row['rtu_004_sa_temp']\n",
|
419 |
-
" rtu_004_oadmpr_pct = row['rtu_004_oadmpr_pct']\n",
|
420 |
-
" rtu_004_ra_temp = row['rtu_004_ra_temp']\n",
|
421 |
-
" rtu_004_oa_temp = row['rtu_004_oa_temp']\n",
|
422 |
-
" rtu_004_ma_temp = row['rtu_004_ma_temp']\n",
|
423 |
-
" rtu_004_sf_vfd_spd_fbk_tn = row['rtu_004_sf_vfd_spd_fbk_tn']\n",
|
424 |
-
" rtu_004_rf_vfd_spd_fbk_tn = row['rtu_004_rf_vfd_spd_fbk_tn']\n",
|
425 |
-
" rtu_001_sa_temp = row['rtu_001_sa_temp']\n",
|
426 |
-
" rtu_001_oadmpr_pct = row['rtu_001_oadmpr_pct']\n",
|
427 |
-
" rtu_001_ra_temp = row['rtu_001_ra_temp']\n",
|
428 |
-
" rtu_001_oa_temp = row['rtu_001_oa_temp']\n",
|
429 |
-
" rtu_001_ma_temp = row['rtu_001_ma_temp']\n",
|
430 |
-
" rtu_001_sf_vfd_spd_fbk_tn = row['rtu_001_sf_vfd_spd_fbk_tn']\n",
|
431 |
-
" rtu_001_rf_vfd_spd_fbk_tn =row['rtu_001_rf_vfd_spd_fbk_tn']\n",
|
432 |
-
" rtu_002_sa_temp = row['rtu_002_sa_temp']\n",
|
433 |
-
" rtu_002_oadmpr_pct = row['rtu_002_oadmpr_pct']\n",
|
434 |
-
" rtu_002_ra_temp = row['rtu_002_ra_temp']\n",
|
435 |
-
" rtu_002_oa_temp = row['rtu_002_oa_temp']\n",
|
436 |
-
" rtu_002_ma_temp = row['rtu_002_ma_temp']\n",
|
437 |
-
" rtu_002_sf_vfd_spd_fbk_tn = row['rtu_002_sf_vfd_spd_fbk_tn']\n",
|
438 |
-
" rtu_002_rf_vfd_spd_fbk_tn = row['rtu_002_rf_vfd_spd_fbk_tn']\n",
|
439 |
-
" rtu_004_sat_sp_tn = row['rtu_004_sat_sp_tn']\n",
|
440 |
-
" rtu_003_sat_sp_tn = row['rtu_003_sat_sp_tn']\n",
|
441 |
-
" rtu_001_sat_sp_tn = row['rtu_001_sat_sp_tn']\n",
|
442 |
-
" rtu_002_sat_sp_tn = row['rtu_002_sat_sp_tn']\n",
|
443 |
-
" air_temp_set_1 = row['air_temp_set_1']\n",
|
444 |
-
" air_temp_set_2 = row['air_temp_set_2']\n",
|
445 |
-
" dew_point_temperature_set_1d = row['dew_point_temperature_set_1d']\n",
|
446 |
-
" relative_humidity_set_1 = row['relative_humidity_set_1']\n",
|
447 |
-
" solar_radiation_set_1 = row['solar_radiation_set_1']\n",
|
448 |
-
" \n",
|
449 |
-
" \n",
|
450 |
-
" client.publish(topic, payload=json.dumps({'hp_hws_temp':hp_hws_temp,\n",
|
451 |
-
" 'rtu_003_sa_temp':rtu_003_sa_temp,\n",
|
452 |
-
" 'rtu_003_oadmpr_pct': rtu_003_oadmpr_pct,\n",
|
453 |
-
" 'rtu_003_ra_temp':rtu_003_ra_temp,\n",
|
454 |
-
" 'rtu_003_oa_temp': rtu_003_oa_temp,\n",
|
455 |
-
" 'rtu_003_ma_temp': rtu_003_ma_temp,\n",
|
456 |
-
" 'rtu_003_sf_vfd_spd_fbk_tn': rtu_003_sf_vfd_spd_fbk_tn,\n",
|
457 |
-
" 'rtu_003_rf_vfd_spd_fbk_tn':rtu_003_rf_vfd_spd_fbk_tn,\n",
|
458 |
-
" 'rtu_004_sa_temp':rtu_004_sa_temp,\n",
|
459 |
-
" 'rtu_004_oadmpr_pct':rtu_004_oadmpr_pct,\n",
|
460 |
-
" 'rtu_004_ra_temp':rtu_004_ra_temp,\n",
|
461 |
-
" 'rtu_004_oa_temp':rtu_004_oa_temp,\n",
|
462 |
-
" 'rtu_004_ma_temp':rtu_004_ma_temp,\n",
|
463 |
-
" 'rtu_004_sf_vfd_spd_fbk_tn':rtu_004_sf_vfd_spd_fbk_tn,\n",
|
464 |
-
" 'rtu_004_rf_vfd_spd_fbk_tn':rtu_004_rf_vfd_spd_fbk_tn,\n",
|
465 |
-
" 'rtu_001_sa_temp':rtu_001_sa_temp,\n",
|
466 |
-
" 'rtu_001_oadmpr_pct': rtu_001_oadmpr_pct,\n",
|
467 |
-
" 'rtu_001_ra_temp':rtu_001_ra_temp,\n",
|
468 |
-
" 'rtu_001_oa_temp': rtu_001_oa_temp,\n",
|
469 |
-
" 'rtu_001_ma_temp': rtu_001_ma_temp,\n",
|
470 |
-
" 'rtu_001_sf_vfd_spd_fbk_tn': rtu_001_sf_vfd_spd_fbk_tn,\n",
|
471 |
-
" 'rtu_001_rf_vfd_spd_fbk_tn':rtu_001_rf_vfd_spd_fbk_tn,\n",
|
472 |
-
" 'rtu_002_sa_temp':rtu_002_sa_temp,\n",
|
473 |
-
" 'rtu_002_oadmpr_pct':rtu_002_oadmpr_pct,\n",
|
474 |
-
" 'rtu_002_ra_temp':rtu_002_ra_temp,\n",
|
475 |
-
" 'rtu_002_oa_temp':rtu_002_oa_temp,\n",
|
476 |
-
" 'rtu_002_ma_temp':rtu_002_ma_temp,\n",
|
477 |
-
" 'rtu_002_sf_vfd_spd_fbk_tn':rtu_002_sf_vfd_spd_fbk_tn,\n",
|
478 |
-
" 'rtu_002_rf_vfd_spd_fbk_tn':rtu_002_rf_vfd_spd_fbk_tn,\n",
|
479 |
-
" 'rtu_004_sat_sp_tn':rtu_004_sat_sp_tn,\n",
|
480 |
-
" 'rtu_003_sat_sp_tn' :rtu_003_sat_sp_tn,\n",
|
481 |
-
" 'rtu_001_sat_sp_tn':rtu_001_sat_sp_tn,\n",
|
482 |
-
" 'rtu_002_sat_sp_tn':rtu_002_sat_sp_tn,\n",
|
483 |
-
" 'air_temp_set_1':air_temp_set_1,\n",
|
484 |
-
" 'air_temp_set_2':air_temp_set_2,\n",
|
485 |
-
" 'dew_point_temperature_set_1d':dew_point_temperature_set_1d,\n",
|
486 |
-
" 'relative_humidity_set_1':relative_humidity_set_1,\n",
|
487 |
-
" 'solar_radiation_set_1':solar_radiation_set_1}))\n",
|
488 |
-
" print(\"published!\")\n",
|
489 |
-
" time.sleep(2)\n",
|
490 |
"\n",
|
491 |
"\n",
|
492 |
"while True:\n",
|
493 |
" publish_sensor_data()\n",
|
494 |
-
"
|
495 |
"client.disconnect()"
|
496 |
]
|
497 |
},
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
"metadata": {},
|
7 |
"outputs": [
|
8 |
{
|
9 |
"name": "stderr",
|
10 |
"output_type": "stream",
|
11 |
"text": [
|
12 |
+
"C:\\Users\\jerin\\AppData\\Local\\Temp\\ipykernel_18680\\2251714346.py:13: DeprecationWarning: Callback API version 1 is deprecated, update to latest version\n",
|
13 |
" client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, clientId)\n"
|
14 |
]
|
15 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
{
|
17 |
"ename": "KeyboardInterrupt",
|
18 |
"evalue": "",
|
|
|
20 |
"traceback": [
|
21 |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
22 |
"\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
|
23 |
+
"Cell \u001b[1;32mIn[1], line 28\u001b[0m\n\u001b[0;32m 26\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[0;32m 27\u001b[0m publish_sensor_data()\n\u001b[1;32m---> 28\u001b[0m time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;241m5\u001b[39m)\n\u001b[0;32m 29\u001b[0m client\u001b[38;5;241m.\u001b[39mdisconnect()\n",
|
|
|
24 |
"\u001b[1;31mKeyboardInterrupt\u001b[0m: "
|
25 |
]
|
26 |
}
|
|
|
36 |
"broker_address = \"localhost\"\n",
|
37 |
"broker_port = 1883\n",
|
38 |
"\n",
|
39 |
+
"df = pd.read_csv(\"buildingdata.csv\")\n",
|
40 |
"\n",
|
41 |
"client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, clientId)\n",
|
42 |
"client.connect(broker_address, broker_port)\n",
|
43 |
"topic = \"sensor_data\"\n",
|
44 |
"\n",
|
45 |
+
"def publish_sensor_data():\n",
|
46 |
+
" # temp = round(random.uniform(20, 30), 2) \n",
|
47 |
+
" # pressure = round(random.uniform(900, 1100), 2) \n",
|
48 |
" for index, row in df.iterrows():\n",
|
49 |
+
" sa_temp = row['rtu_004_sa_temp']\n",
|
50 |
+
" ma_temp = row['rtu_004_ma_temp']\n",
|
51 |
+
" client.publish(topic, payload=json.dumps({\"sa_temp\": sa_temp, \"ma_temp\": ma_temp}))\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
"\n",
|
53 |
"\n",
|
54 |
"while True:\n",
|
55 |
" publish_sensor_data()\n",
|
56 |
+
" time.sleep(5)\n",
|
57 |
"client.disconnect()"
|
58 |
]
|
59 |
},
|
pca_model.pkl
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:225896826ab8bfb9ea32f0f3057c1292ca5bc238d2ea87858c25fa8da5960b46
|
3 |
-
size 1179
|
|
|
|
|
|
|
|
pipeline.ipynb
DELETED
File without changes
|
sample_data.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:aa13789e2460e1b575a63d32ca46615d5df237c62de5da2f4da22c1e8edc945c
|
3 |
-
size 144290729
|
|
|
|
|
|
|
|
sample_data_01.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:8a00542784412e885f2ef707e3dd86b58023e678b35221fefbce5af9ec6cb10d
|
3 |
-
size 59769388
|
|
|
|
|
|
|
|
sample_data_02.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:3fe51d16cfeffdc7df991e0f27da089da5e9f1260e2ab9c316cd6786999d8d29
|
3 |
-
size 119517162
|
|
|
|
|
|
|
|
sample_data_smooth_01.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:efbfdef5e85cb88d20e7e50ac2351f60d20f07a31b2a40cf4c925596097c5cc4
|
3 |
-
size 299846687
|
|
|
|
|
|
|
|
scaler.pkl
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:63d98018c0b4da0c42820e9017c91944d1486e85471cd44a9a6ab121e7d2c64a
|
3 |
-
size 1101
|
|
|
|
|
|
|
|
scaler_1.pkl
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:778df19577ac7a34c16dfda1b32f26800c62ff687130e22e58715b8d495dcb37
|
3 |
-
size 1437
|
|
|
|
|
|
|
|
src/main.py
DELETED
@@ -1,42 +0,0 @@
|
|
1 |
-
import json
|
2 |
-
from rtu.RTUAnomalizer import RTUAnomalizer
|
3 |
-
from rtu.RTUPipeline import RTUPipeline
|
4 |
-
import paho.mqtt.client as mqtt
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
def main():
|
9 |
-
rtu_data_pipeline = RTUPipeline(scaler_path="rtu/models/scaler_1.pkl")
|
10 |
-
rtu_anomalizer = RTUAnomalizer(
|
11 |
-
prediction_model_path="rtu/models/lstm_4rtu_smooth_02.keras",
|
12 |
-
clustering_model_paths=[
|
13 |
-
"rtu/models/kmeans_model1.pkl",
|
14 |
-
"rtu/models/kmeans_model2.pkl",
|
15 |
-
"rtu/models/kmeans_model3.pkl",
|
16 |
-
"rtu/models/kmeans_model4.pkl",
|
17 |
-
],
|
18 |
-
num_inputs=rtu_data_pipeline.num_inputs,
|
19 |
-
num_outputs=rtu_data_pipeline.num_outputs
|
20 |
-
)
|
21 |
-
|
22 |
-
def on_message(client, userdata, message):
|
23 |
-
print(json.loads(message.payload.decode()))
|
24 |
-
df_new, df_trans = rtu_data_pipeline.fit(message)
|
25 |
-
out = rtu_anomalizer.predict(df_new, df_trans, rtu_data_pipeline.scaler)
|
26 |
-
print(out)
|
27 |
-
|
28 |
-
broker_address = "localhost"
|
29 |
-
broker_port = 1883
|
30 |
-
topic = "sensor_data"
|
31 |
-
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)
|
32 |
-
client.on_message = on_message
|
33 |
-
client.connect(broker_address, broker_port)
|
34 |
-
client.subscribe(topic)
|
35 |
-
client.loop_forever()
|
36 |
-
|
37 |
-
|
38 |
-
if __name__=='__main__':
|
39 |
-
#
|
40 |
-
main()
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/rtu/RTUAnomalizer.py
CHANGED
@@ -1,68 +1,14 @@
|
|
1 |
-
import numpy as np
|
2 |
from tensorflow.keras.models import load_model
|
3 |
-
|
4 |
|
5 |
class RTUAnomalizer:
|
6 |
model = None
|
7 |
-
kmeans_models = []
|
8 |
-
|
9 |
-
def __init__(self, prediction_model_path = None, clustering_model_paths= None, num_inputs = None, num_outputs = None):
|
10 |
-
|
11 |
-
self.num_inputs = num_inputs
|
12 |
-
self.num_outputs = num_outputs
|
13 |
-
if not prediction_model_path is None and not clustering_model_paths is None:
|
14 |
-
self.load_models(prediction_model_path, clustering_model_paths)
|
15 |
-
|
16 |
-
def initialize_lists(size=30):
|
17 |
-
initial_values = [0] * size
|
18 |
-
return initial_values.copy(), initial_values.copy(), initial_values.copy()
|
19 |
-
|
20 |
-
def load_models(self, prediction_model_path, clustering_model_paths):
|
21 |
-
self.model = load_model(prediction_model_path)
|
22 |
-
|
23 |
-
for path in clustering_model_paths:
|
24 |
-
self.kmeans_models.append(joblib.load(path))
|
25 |
-
|
26 |
-
def predict(self, df_new):
|
27 |
-
return self.model.predict(df_new)
|
28 |
-
|
29 |
-
def calculate_residuals(self,df_trans, pred):
|
30 |
-
actual = df_trans[30,:self.num_outputs+1]
|
31 |
-
resid = actual - pred
|
32 |
-
return actual, resid
|
33 |
-
|
34 |
-
def resize_prediction(self,pred, df_trans):
|
35 |
-
pred.resize((pred.shape[0], pred.shape[1] + len(df_trans[30,self.num_outputs+1:])))
|
36 |
-
pred[:, -len(df_trans[30,self.num_outputs+1:]):] = df_trans[30,self.num_outputs+1:]
|
37 |
-
return pred
|
38 |
-
|
39 |
-
def inverse_transform(scaler, pred, df_trans):
|
40 |
-
pred = scaler.inverse_transform(np.array(pred))
|
41 |
-
actual = scaler.inverse_transform(np.array([df_trans[30,:]]))
|
42 |
-
return actual, pred
|
43 |
|
44 |
-
def
|
45 |
-
|
46 |
-
pred_list.pop(0)
|
47 |
-
resid_list.pop(0)
|
48 |
-
actual_list.append(actual[0,1])
|
49 |
-
pred_list.append(pred[0,1])
|
50 |
-
resid_list.append(resid[0,1])
|
51 |
-
return actual_list, pred_list, resid_list
|
52 |
|
53 |
-
def
|
54 |
-
|
55 |
-
for i, model in enumerate(self.kmeans_models):
|
56 |
-
dist.append(np.linalg.norm(resid[:,(i*7)+1:(i*7)+8]-model.cluster_centers_[0], ord=2, axis=1))
|
57 |
-
|
58 |
-
return np.array(dist)
|
59 |
|
60 |
-
def pipeline(self,
|
61 |
-
|
62 |
-
pred = self.predict(df_new)
|
63 |
-
actual, resid = self.calculate_residuals(df_trans, pred)
|
64 |
-
pred = self.resize_prediction(pred, df_trans)
|
65 |
-
actual, pred = self.inverse_transform(scaler, pred, df_trans)
|
66 |
-
actual_list, pred_list, resid_list = self.update_lists(actual_list, pred_list, resid_list, actual, pred, resid)
|
67 |
-
dist = self.calculate_distances(resid)
|
68 |
-
return actual_list, pred_list, resid_list, dist
|
|
|
|
|
1 |
from tensorflow.keras.models import load_model
|
2 |
+
|
3 |
|
4 |
class RTUAnomalizer:
|
5 |
model = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
def __init__(self):
|
8 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
def load_model(self, model_path):
|
11 |
+
self.model = load_model(model_path)
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
def pipeline(self, data):
|
14 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/rtu/RTUPipeline.py
CHANGED
@@ -1,140 +1,19 @@
|
|
1 |
-
import json
|
2 |
-
import joblib
|
3 |
-
import pandas as pd
|
4 |
from sklearn.preprocessing import StandardScaler
|
5 |
from pickle import load
|
6 |
-
import numpy as np
|
7 |
|
8 |
|
9 |
class RTUPipeline:
|
10 |
scaler = None
|
11 |
|
12 |
-
def __init__(self
|
13 |
-
self.
|
14 |
-
"hp_hws_temp",
|
15 |
-
"rtu_003_sa_temp",
|
16 |
-
"rtu_003_oadmpr_pct",
|
17 |
-
"rtu_003_ra_temp",
|
18 |
-
"rtu_003_oa_temp",
|
19 |
-
"rtu_003_ma_temp",
|
20 |
-
"rtu_003_sf_vfd_spd_fbk_tn",
|
21 |
-
"rtu_003_rf_vfd_spd_fbk_tn",
|
22 |
-
"rtu_004_sa_temp",
|
23 |
-
"rtu_004_oadmpr_pct",
|
24 |
-
"rtu_004_ra_temp",
|
25 |
-
"rtu_004_oa_temp",
|
26 |
-
"rtu_004_ma_temp",
|
27 |
-
"rtu_004_sf_vfd_spd_fbk_tn",
|
28 |
-
"rtu_004_rf_vfd_spd_fbk_tn",
|
29 |
-
"rtu_001_sa_temp",
|
30 |
-
"rtu_001_oadmpr_pct",
|
31 |
-
"rtu_001_ra_temp",
|
32 |
-
"rtu_001_oa_temp",
|
33 |
-
"rtu_001_ma_temp",
|
34 |
-
"rtu_001_sf_vfd_spd_fbk_tn",
|
35 |
-
"rtu_001_rf_vfd_spd_fbk_tn",
|
36 |
-
"rtu_002_sa_temp",
|
37 |
-
"rtu_002_oadmpr_pct",
|
38 |
-
"rtu_002_ra_temp",
|
39 |
-
"rtu_002_oa_temp",
|
40 |
-
"rtu_002_ma_temp",
|
41 |
-
"rtu_002_sf_vfd_spd_fbk_tn",
|
42 |
-
"rtu_002_rf_vfd_spd_fbk_tn",
|
43 |
-
# "rtu_004_sat_sp_tn",
|
44 |
-
# "rtu_003_sat_sp_tn",
|
45 |
-
# "rtu_001_sat_sp_tn",
|
46 |
-
# "rtu_002_sat_sp_tn",
|
47 |
-
# "air_temp_set_1",
|
48 |
-
# "air_temp_set_2",
|
49 |
-
# "dew_point_temperature_set_1d",
|
50 |
-
# "relative_humidity_set_1",
|
51 |
-
# "solar_radiation_set_1",
|
52 |
-
]
|
53 |
-
|
54 |
-
self.input_col_names = ["air_temp_set_1",
|
55 |
-
"air_temp_set_2",
|
56 |
-
"dew_point_temperature_set_1d",
|
57 |
-
"relative_humidity_set_1",
|
58 |
-
"solar_radiation_set_1",
|
59 |
-
]
|
60 |
-
self.num_inputs = len(self.input_col_names)
|
61 |
-
self.num_outputs = len(self.output_col_names)
|
62 |
-
self.column_names = self.output_col_names+self.input_col_names
|
63 |
-
|
64 |
-
if scaler_path:
|
65 |
-
self.scaler = self.get_scaler(scaler_path)
|
66 |
-
self.df = pd.DataFrame(columns = self.column_names)
|
67 |
|
68 |
def get_scaler(self, scaler_path):
|
69 |
-
|
70 |
-
|
71 |
-
def get_window(self, df):
|
72 |
-
len_df = np.len(df)
|
73 |
-
if len_df > 30:
|
74 |
-
return df[len_df - 31 : len_df].astype("float32")
|
75 |
-
else:
|
76 |
-
return None
|
77 |
|
78 |
-
def
|
79 |
-
|
80 |
|
81 |
-
def
|
82 |
-
|
83 |
-
|
84 |
-
def extract_data_from_message(self, message):
|
85 |
-
payload = json.loads(message.payload.decode())
|
86 |
-
|
87 |
-
len_df = len(self.df)
|
88 |
-
# self.df.loc[len_df] = {'hp_hws_temp':payload['hp_hws_temp'],
|
89 |
-
# 'rtu_003_sa_temp':payload['rtu_003_sa_temp'],
|
90 |
-
# 'rtu_003_oadmpr_pct': payload["rtu_003_oadmpr_pct"],
|
91 |
-
# 'rtu_003_ra_temp':payload["rtu_003_ra_temp"],
|
92 |
-
# 'rtu_003_oa_temp': payload["rtu_003_oa_temp"],
|
93 |
-
# 'rtu_003_ma_temp': payload["rtu_003_ma_temp"],
|
94 |
-
# 'rtu_003_sf_vfd_spd_fbk_tn': payload["rtu_003_sf_vfd_spd_fbk_tn"],
|
95 |
-
# 'rtu_003_rf_vfd_spd_fbk_tn':payload["rtu_003_rf_vfd_spd_fbk_tn"],
|
96 |
-
# 'rtu_004_sa_temp':payload["rtu_004_sa_temp"],
|
97 |
-
# 'rtu_004_oadmpr_pct':payload["rtu_004_oadmpr_pct"],
|
98 |
-
# 'rtu_004_ra_temp':payload["rtu_004_ra_temp"],
|
99 |
-
# 'rtu_004_oa_temp':payload["rtu_004_oa_temp"],
|
100 |
-
# 'rtu_004_ma_temp':payload["rtu_004_ma_temp"],
|
101 |
-
# 'rtu_004_sf_vfd_spd_fbk_tn':payload["rtu_004_sf_vfd_spd_fbk_tn"],
|
102 |
-
# 'rtu_004_rf_vfd_spd_fbk_tn':payload["rtu_004_rf_vfd_spd_fbk_tn"],
|
103 |
-
# 'rtu_001_sa_temp':payload["rtu_001_sa_temp"],
|
104 |
-
# 'rtu_001_oadmpr_pct': payload["rtu_001_oadmpr_pct"],
|
105 |
-
# 'rtu_001_ra_temp':payload["rtu_001_ra_temp"],
|
106 |
-
# 'rtu_001_oa_temp': payload["rtu_001_oa_temp"],
|
107 |
-
# 'rtu_001_ma_temp': payload["rtu_001_ma_temp"],
|
108 |
-
# 'rtu_001_sf_vfd_spd_fbk_tn': payload["rtu_001_sf_vfd_spd_fbk_tn"],
|
109 |
-
# 'rtu_001_rf_vfd_spd_fbk_tn':payload["rtu_001_rf_vfd_spd_fbk_tn"],
|
110 |
-
# 'rtu_002_sa_temp':payload["rtu_002_sa_temp"],
|
111 |
-
# 'rtu_002_oadmpr_pct':payload["rtu_002_oadmpr_pct"],
|
112 |
-
# 'rtu_002_ra_temp':payload["rtu_002_ra_temp"],
|
113 |
-
# 'rtu_002_oa_temp':payload["rtu_002_oa_temp"],
|
114 |
-
# 'rtu_002_ma_temp':payload["rtu_002_ma_temp"],
|
115 |
-
# 'rtu_002_sf_vfd_spd_fbk_tn':payload["rtu_002_sf_vfd_spd_fbk_tn"],
|
116 |
-
# 'rtu_002_rf_vfd_spd_fbk_tn':payload["rtu_002_rf_vfd_spd_fbk_tn"],
|
117 |
-
# 'rtu_004_sat_sp_tn':payload["rtu_004_sat_sp_tn"],
|
118 |
-
# 'rtu_003_sat_sp_tn' :payload["rtu_003_sat_sp_tn"],
|
119 |
-
# 'rtu_001_sat_sp_tn':payload["rtu_001_sat_sp_tn"],
|
120 |
-
# 'rtu_002_sat_sp_tn':payload["rtu_002_sat_sp_tn"],
|
121 |
-
# 'air_temp_set_1':payload["air_temp_set_1"],
|
122 |
-
# 'air_temp_set_2':payload["air_temp_set_2"],
|
123 |
-
# 'dew_point_temperature_set_1d':payload["dew_point_temperature_set_1d"],
|
124 |
-
# 'relative_humidity_set_1':payload["relative_humidity_set_1"],
|
125 |
-
# 'solar_radiation_set_1':payload["solar_radiation_set_1"]}
|
126 |
-
|
127 |
-
self.df.loc[len_df] = {}
|
128 |
-
for col in self.column_names:
|
129 |
-
self.df.loc[len_df][col] = payload[col]
|
130 |
-
return self.df
|
131 |
-
|
132 |
-
|
133 |
-
def fit(self,message):
|
134 |
-
len_df = np.len(df)
|
135 |
-
df = self.extract_data_from_message(message)
|
136 |
-
df_window = self.get_window(df, len_df)
|
137 |
-
if df_window is not None:
|
138 |
-
df_trans = self.transform_window(df_window, self.scaler)
|
139 |
-
df_new = self.prepare_input(df_trans)
|
140 |
-
return df_new,df_trans
|
|
|
|
|
|
|
|
|
1 |
from sklearn.preprocessing import StandardScaler
|
2 |
from pickle import load
|
|
|
3 |
|
4 |
|
5 |
class RTUPipeline:
|
6 |
scaler = None
|
7 |
|
8 |
+
def __init__(self):
|
9 |
+
self.column_names = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def get_scaler(self, scaler_path):
|
12 |
+
self.scaler = StandardScaler()
|
13 |
+
self.scaler = load(open(scaler_path, "rb"))
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
def get_data(self, data):
|
16 |
+
pass
|
17 |
|
18 |
+
def pipeline(self, data):
|
19 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/rtu/models/kmeans_model1.pkl
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:aaa404e937bf8fe9d52b38aa1e11f87d544530a2d4789b46d20b5a1665e15846
|
3 |
-
size 2064297
|
|
|
|
|
|
|
|
src/rtu/models/kmeans_model2.pkl
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:9cf710504c910255e59d0609617fecf74ee8ad6710f4ba4109d9de5aae0cd879
|
3 |
-
size 2064297
|
|
|
|
|
|
|
|
src/rtu/models/kmeans_model3.pkl
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:1fb375913725bf309d514f55b71799daead266db7caad09f02ab9cfdd56bdc0a
|
3 |
-
size 2064297
|
|
|
|
|
|
|
|
src/rtu/models/kmeans_model4.pkl
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:cfbe4b1a5c1aa4b00e8e932c77dd8ed5ce99fbe5efd4960079d14e380206f9f2
|
3 |
-
size 2064297
|
|
|
|
|
|
|
|
src/rtu/models/scaler_1.pkl
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:778df19577ac7a34c16dfda1b32f26800c62ff687130e22e58715b8d495dcb37
|
3 |
-
size 1437
|
|
|
|
|
|
|
|
streamlit.py
CHANGED
@@ -6,21 +6,9 @@ import plotly.express as px # interactive charts
|
|
6 |
import paho.mqtt.client as mqtt
|
7 |
import json
|
8 |
import warnings
|
9 |
-
from tensorflow.keras.models import load_model
|
10 |
-
import joblib
|
11 |
-
import plotly.graph_objects as go
|
12 |
warnings.filterwarnings('ignore')
|
13 |
|
14 |
-
|
15 |
-
model = load_model("lstm_4rtu_smooth_02.keras")
|
16 |
-
scaler = joblib.load('scaler_1.pkl')
|
17 |
-
# kmeans = joblib.load('kmeans_model.pkl')
|
18 |
-
kmeans1 = joblib.load('kmeans_model1.pkl')
|
19 |
-
kmeans2 = joblib.load('kmeans_model2.pkl')
|
20 |
-
kmeans3 = joblib.load('kmeans_model3.pkl')
|
21 |
-
kmeans4 = joblib.load('kmeans_model4.pkl')
|
22 |
-
pca = joblib.load('pca_model.pkl')
|
23 |
-
|
24 |
st.set_page_config(
|
25 |
page_title = 'Real-Time Data Buliding 59',
|
26 |
page_icon = '✅',
|
@@ -34,209 +22,26 @@ broker_address = "localhost"
|
|
34 |
broker_port = 1883
|
35 |
topic = "sensor_data"
|
36 |
|
37 |
-
df = pd.DataFrame(
|
38 |
-
'rtu_003_sa_temp',
|
39 |
-
'rtu_003_oadmpr_pct',
|
40 |
-
'rtu_003_ra_temp',
|
41 |
-
'rtu_003_oa_temp',
|
42 |
-
'rtu_003_ma_temp',
|
43 |
-
'rtu_003_sf_vfd_spd_fbk_tn',
|
44 |
-
'rtu_003_rf_vfd_spd_fbk_tn',
|
45 |
-
'rtu_004_sa_temp',
|
46 |
-
'rtu_004_oadmpr_pct',
|
47 |
-
'rtu_004_ra_temp',
|
48 |
-
'rtu_004_oa_temp',
|
49 |
-
'rtu_004_ma_temp',
|
50 |
-
'rtu_004_sf_vfd_spd_fbk_tn',
|
51 |
-
'rtu_004_rf_vfd_spd_fbk_tn',
|
52 |
-
'rtu_001_sa_temp',
|
53 |
-
'rtu_001_oadmpr_pct',
|
54 |
-
'rtu_001_ra_temp',
|
55 |
-
'rtu_001_oa_temp',
|
56 |
-
'rtu_001_ma_temp',
|
57 |
-
'rtu_001_sf_vfd_spd_fbk_tn',
|
58 |
-
'rtu_001_rf_vfd_spd_fbk_tn',
|
59 |
-
'rtu_002_sa_temp',
|
60 |
-
'rtu_002_oadmpr_pct',
|
61 |
-
'rtu_002_ra_temp',
|
62 |
-
'rtu_002_oa_temp',
|
63 |
-
'rtu_002_ma_temp',
|
64 |
-
'rtu_002_sf_vfd_spd_fbk_tn',
|
65 |
-
'rtu_002_rf_vfd_spd_fbk_tn',
|
66 |
-
'rtu_004_sat_sp_tn',
|
67 |
-
'rtu_003_sat_sp_tn',
|
68 |
-
'rtu_001_sat_sp_tn',
|
69 |
-
'rtu_002_sat_sp_tn',
|
70 |
-
'air_temp_set_1',
|
71 |
-
'air_temp_set_2',
|
72 |
-
'dew_point_temperature_set_1d',
|
73 |
-
'relative_humidity_set_1',
|
74 |
-
'solar_radiation_set_1'])
|
75 |
-
actual_list = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
76 |
-
pred_list = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
77 |
-
resid_list = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
78 |
-
distance = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
79 |
-
pca_x = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
80 |
-
pca_y = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
81 |
|
82 |
def on_message(client, userdata, message):
|
83 |
global df
|
84 |
payload = json.loads(message.payload.decode())
|
85 |
-
|
86 |
-
|
87 |
-
rtu_003_sa_temp = payload['rtu_003_sa_temp']
|
88 |
-
rtu_003_oadmpr_pct = payload['rtu_003_oadmpr_pct']
|
89 |
-
rtu_003_ra_temp = payload['rtu_003_ra_temp']
|
90 |
-
rtu_003_oa_temp = payload['rtu_003_oa_temp']
|
91 |
-
rtu_003_ma_temp = payload['rtu_003_ma_temp']
|
92 |
-
rtu_003_sf_vfd_spd_fbk_tn = payload['rtu_003_sf_vfd_spd_fbk_tn']
|
93 |
-
rtu_003_rf_vfd_spd_fbk_tn =payload['rtu_003_rf_vfd_spd_fbk_tn']
|
94 |
-
rtu_004_sa_temp = payload['rtu_004_sa_temp']
|
95 |
-
rtu_004_oadmpr_pct = payload['rtu_004_oadmpr_pct']
|
96 |
-
rtu_004_ra_temp = payload['rtu_004_ra_temp']
|
97 |
-
rtu_004_oa_temp = payload['rtu_004_oa_temp']
|
98 |
-
rtu_004_ma_temp = payload['rtu_004_ma_temp']
|
99 |
-
rtu_004_sf_vfd_spd_fbk_tn = payload['rtu_004_sf_vfd_spd_fbk_tn']
|
100 |
-
rtu_004_rf_vfd_spd_fbk_tn = payload['rtu_004_rf_vfd_spd_fbk_tn']
|
101 |
-
rtu_001_sa_temp = payload['rtu_001_sa_temp']
|
102 |
-
rtu_001_oadmpr_pct = payload['rtu_001_oadmpr_pct']
|
103 |
-
rtu_001_ra_temp = payload['rtu_001_ra_temp']
|
104 |
-
rtu_001_oa_temp = payload['rtu_001_oa_temp']
|
105 |
-
rtu_001_ma_temp = payload['rtu_001_ma_temp']
|
106 |
-
rtu_001_sf_vfd_spd_fbk_tn = payload['rtu_001_sf_vfd_spd_fbk_tn']
|
107 |
-
rtu_001_rf_vfd_spd_fbk_tn =payload['rtu_001_rf_vfd_spd_fbk_tn']
|
108 |
-
rtu_002_sa_temp = payload['rtu_002_sa_temp']
|
109 |
-
rtu_002_oadmpr_pct = payload['rtu_002_oadmpr_pct']
|
110 |
-
rtu_002_ra_temp = payload['rtu_002_ra_temp']
|
111 |
-
rtu_002_oa_temp = payload['rtu_002_oa_temp']
|
112 |
-
rtu_002_ma_temp = payload['rtu_002_ma_temp']
|
113 |
-
rtu_002_sf_vfd_spd_fbk_tn = payload['rtu_002_sf_vfd_spd_fbk_tn']
|
114 |
-
rtu_002_rf_vfd_spd_fbk_tn = payload['rtu_002_rf_vfd_spd_fbk_tn']
|
115 |
-
rtu_004_sat_sp_tn = payload['rtu_004_sat_sp_tn']
|
116 |
-
rtu_003_sat_sp_tn = payload['rtu_003_sat_sp_tn']
|
117 |
-
rtu_001_sat_sp_tn = payload['rtu_001_sat_sp_tn']
|
118 |
-
rtu_002_sat_sp_tn = payload['rtu_002_sat_sp_tn']
|
119 |
-
air_temp_set_1 = payload['air_temp_set_1']
|
120 |
-
air_temp_set_2 = payload['air_temp_set_2']
|
121 |
-
dew_point_temperature_set_1d = payload['dew_point_temperature_set_1d']
|
122 |
-
relative_humidity_set_1 = payload['relative_humidity_set_1']
|
123 |
-
solar_radiation_set_1 = payload['solar_radiation_set_1']
|
124 |
-
|
125 |
len_df = len(df)
|
126 |
-
df.loc[len_df] = {
|
127 |
-
|
128 |
-
'rtu_003_oadmpr_pct': rtu_003_oadmpr_pct,
|
129 |
-
'rtu_003_ra_temp':rtu_003_ra_temp,
|
130 |
-
'rtu_003_oa_temp': rtu_003_oa_temp,
|
131 |
-
'rtu_003_ma_temp': rtu_003_ma_temp,
|
132 |
-
'rtu_003_sf_vfd_spd_fbk_tn': rtu_003_sf_vfd_spd_fbk_tn,
|
133 |
-
'rtu_003_rf_vfd_spd_fbk_tn':rtu_003_rf_vfd_spd_fbk_tn,
|
134 |
-
'rtu_004_sa_temp':rtu_004_sa_temp,
|
135 |
-
'rtu_004_oadmpr_pct':rtu_004_oadmpr_pct,
|
136 |
-
'rtu_004_ra_temp':rtu_004_ra_temp,
|
137 |
-
'rtu_004_oa_temp':rtu_004_oa_temp,
|
138 |
-
'rtu_004_ma_temp':rtu_004_ma_temp,
|
139 |
-
'rtu_004_sf_vfd_spd_fbk_tn':rtu_004_sf_vfd_spd_fbk_tn,
|
140 |
-
'rtu_004_rf_vfd_spd_fbk_tn':rtu_004_rf_vfd_spd_fbk_tn,
|
141 |
-
'rtu_001_sa_temp':rtu_001_sa_temp,
|
142 |
-
'rtu_001_oadmpr_pct': rtu_001_oadmpr_pct,
|
143 |
-
'rtu_001_ra_temp':rtu_001_ra_temp,
|
144 |
-
'rtu_001_oa_temp': rtu_001_oa_temp,
|
145 |
-
'rtu_001_ma_temp': rtu_001_ma_temp,
|
146 |
-
'rtu_001_sf_vfd_spd_fbk_tn': rtu_001_sf_vfd_spd_fbk_tn,
|
147 |
-
'rtu_001_rf_vfd_spd_fbk_tn':rtu_001_rf_vfd_spd_fbk_tn,
|
148 |
-
'rtu_002_sa_temp':rtu_002_sa_temp,
|
149 |
-
'rtu_002_oadmpr_pct':rtu_002_oadmpr_pct,
|
150 |
-
'rtu_002_ra_temp':rtu_002_ra_temp,
|
151 |
-
'rtu_002_oa_temp':rtu_002_oa_temp,
|
152 |
-
'rtu_002_ma_temp':rtu_002_ma_temp,
|
153 |
-
'rtu_002_sf_vfd_spd_fbk_tn':rtu_002_sf_vfd_spd_fbk_tn,
|
154 |
-
'rtu_002_rf_vfd_spd_fbk_tn':rtu_002_rf_vfd_spd_fbk_tn,
|
155 |
-
'rtu_004_sat_sp_tn':rtu_004_sat_sp_tn,
|
156 |
-
'rtu_003_sat_sp_tn' :rtu_003_sat_sp_tn,
|
157 |
-
'rtu_001_sat_sp_tn':rtu_001_sat_sp_tn,
|
158 |
-
'rtu_002_sat_sp_tn':rtu_002_sat_sp_tn,
|
159 |
-
'air_temp_set_1':air_temp_set_1,
|
160 |
-
'air_temp_set_2':air_temp_set_2,
|
161 |
-
'dew_point_temperature_set_1d':dew_point_temperature_set_1d,
|
162 |
-
'relative_humidity_set_1':relative_humidity_set_1,
|
163 |
-
'solar_radiation_set_1':solar_radiation_set_1}
|
164 |
-
|
165 |
-
if len_df>30:
|
166 |
-
df_window = df[len_df-31:len_df]
|
167 |
-
df_window = df_window.astype('float32')
|
168 |
-
df_trans = scaler.transform(df_window)
|
169 |
-
df_new = df_trans[:30,:].reshape((1,30,34))#
|
170 |
-
pred = model.predict(df_new)
|
171 |
-
pred_copy = pred.copy()
|
172 |
-
actual = df_trans[30,:29]#
|
173 |
-
resid = actual - pred
|
174 |
-
#---------
|
175 |
-
pred.resize((pred.shape[0], pred.shape[1] + len(df_trans[30,29:])))#
|
176 |
-
pred[:, -len(df_trans[30,29:]):] = df_trans[30,29:]#
|
177 |
-
pred = scaler.inverse_transform(np.array(pred))
|
178 |
-
actual = scaler.inverse_transform(np.array([df_trans[30,:]]))
|
179 |
-
#---------
|
180 |
-
actual_list.pop(0)
|
181 |
-
pred_list.pop(0)
|
182 |
-
resid_list.pop(0)
|
183 |
-
# distance.pop(0)
|
184 |
-
# pca_x.pop(0)
|
185 |
-
# pca_y.pop(0)
|
186 |
-
actual_list.append(actual[0,1])
|
187 |
-
pred_list.append(pred[0,1])
|
188 |
-
resid_list.append(resid[0,1])
|
189 |
-
# distance.append(np.linalg.norm(pred_copy-kmeans.cluster_centers_[0], ord=2, axis = 1))
|
190 |
-
# dist_color = [1 if num >= 5 else 0 for num in distance]
|
191 |
-
dist = []
|
192 |
-
dist.append(np.linalg.norm(resid[:,1:8]-kmeans1.cluster_centers_[0], ord=2, axis = 1))
|
193 |
-
dist.append(np.linalg.norm(resid[:,8:15]-kmeans2.cluster_centers_[0], ord=2, axis = 1))
|
194 |
-
dist.append(np.linalg.norm(resid[:,15:22]-kmeans3.cluster_centers_[0], ord=2, axis = 1))
|
195 |
-
dist.append(np.linalg.norm(resid[:,22:29]-kmeans4.cluster_centers_[0], ord=2, axis = 1))
|
196 |
-
dist = np.array(dist)
|
197 |
-
# dist_color = [1 if num >= 2 else 0 for num in dist]
|
198 |
-
|
199 |
-
# pca_cord = pca.transform(resid)
|
200 |
-
# pca_x.append(pca_cord[0,0])
|
201 |
-
# pca_y.append(pca_cord[0,1])
|
202 |
-
# clust_center = pca.transform(kmeans.cluster_centers_)
|
203 |
-
# theta = np.linspace(0, 2*np.pi, 100)
|
204 |
-
# radius = 2
|
205 |
-
# x_circle = clust_center[0, 0] + radius * np.cos(theta)
|
206 |
-
# y_circle = clust_center[0, 1] + radius * np.sin(theta)
|
207 |
-
|
208 |
-
ind = np.linspace(1, 30, 30)
|
209 |
-
|
210 |
with placeholder.container():
|
211 |
-
|
212 |
-
with col1:
|
213 |
-
st.header("RTU Status")
|
214 |
-
for i in range(4):
|
215 |
-
rtu = ['RTU 1', 'RTU 2', 'RTU 3', 'RTU 4']
|
216 |
-
tol = [2,2,2,0.1]#[4.5,4,5,5]
|
217 |
-
status_icon = "🔧" if dist[i,0] > tol[i] else "🔄"
|
218 |
-
status = "Damper or Fan issue" if dist[i,0] > tol[i] else "Normal"
|
219 |
-
status_markdown = f"**{rtu[i]} {status_icon}**\n\nSA Temp: {int(actual[0,1])}°C\nRA Temp: {int(actual[0,3])}°C\n\nStatus: {status}"
|
220 |
-
st.markdown(status_markdown, unsafe_allow_html=True)
|
221 |
with fig_col1:
|
222 |
-
|
223 |
-
|
224 |
-
fig1 = go.Figure()
|
225 |
-
# fig1.add_trace(go.Scatter(x=ind, y=resid_list, mode='lines', name='Actual',line=dict(color='blue')))
|
226 |
-
# fig1 = px.scatter(x=pca_x, y=pca_y,color=dist_color,color_discrete_map={'1': 'red', '0': 'green'})
|
227 |
-
# fig1.add_trace(go.Scatter(x=x_circle, y=y_circle, mode='lines',line=dict(color='green')))
|
228 |
-
colors = ['red' if value > 0.1 else 'blue' for value in dist[:, 0]]
|
229 |
-
fig1 = fig1.add_trace(go.Bar(x=['RTU 1', 'RTU 2', 'RTU 3', 'RTU 4'],y=dist[:, 0],marker_color=colors,width=0.4))
|
230 |
-
fig1.update_layout(width=500,height=400 )
|
231 |
st.write(fig1)
|
232 |
with fig_col2:
|
233 |
-
st.
|
234 |
-
fig2 =
|
235 |
-
fig2.add_trace(go.Scatter(x=ind, y=actual_list, mode='lines', name='Actual',line=dict(color='blue')))
|
236 |
-
fig2.add_trace(go.Scatter(x=ind, y=pred_list, mode='lines', name='Predicted',line=dict(color='red', dash='dot')))
|
237 |
-
fig2.update_layout(yaxis_range=[50, 80],width=500,height=400 )
|
238 |
st.write(fig2)
|
239 |
-
|
240 |
st.markdown("### Detailed Data View")
|
241 |
st.dataframe(df[len_df-5:len_df])
|
242 |
# time.sleep(1)
|
|
|
6 |
import paho.mqtt.client as mqtt
|
7 |
import json
|
8 |
import warnings
|
|
|
|
|
|
|
9 |
warnings.filterwarnings('ignore')
|
10 |
|
11 |
+
# df = pd.read_csv('buildingdata.csv')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
st.set_page_config(
|
13 |
page_title = 'Real-Time Data Buliding 59',
|
14 |
page_icon = '✅',
|
|
|
22 |
broker_port = 1883
|
23 |
topic = "sensor_data"
|
24 |
|
25 |
+
df = pd.DataFrame({"sa_temp":[60, 56, 66,69,70],"ma_temp":[30,40,50,60,65]})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
def on_message(client, userdata, message):
|
28 |
global df
|
29 |
payload = json.loads(message.payload.decode())
|
30 |
+
sa_temp = payload["sa_temp"]
|
31 |
+
ma_temp = payload["ma_temp"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
len_df = len(df)
|
33 |
+
df.loc[len_df] = {"sa_temp": sa_temp, "ma_temp": ma_temp}
|
34 |
+
if len_df>5:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
with placeholder.container():
|
36 |
+
fig_col1, fig_col2 = st.columns(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
with fig_col1:
|
38 |
+
st.markdown("### Supply Air temperature")
|
39 |
+
fig1 = px.line(data_frame=df[len_df-5:len_df], y = 'sa_temp', x = df[len_df-5:len_df].index)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
st.write(fig1)
|
41 |
with fig_col2:
|
42 |
+
st.markdown("### Mixed Air temperature")
|
43 |
+
fig2 = px.line(data_frame=df[len_df-5:len_df], y = 'ma_temp', x = df[len_df-5:len_df].index)
|
|
|
|
|
|
|
44 |
st.write(fig2)
|
|
|
45 |
st.markdown("### Detailed Data View")
|
46 |
st.dataframe(df[len_df-5:len_df])
|
47 |
# time.sleep(1)
|