mirror of
https://git.roussel.pro/telecom-paris/GIN206.git
synced 2026-02-09 02:30:17 +01:00
added a practical implementation of the algorithm in python
This commit is contained in:
18
README.md
18
README.md
@@ -1,2 +1,20 @@
|
||||
# gin206-iot
|
||||
IOT Project for the GIN206 course of Télécom Paris
|
||||
|
||||
# Description
|
||||
The main.py file contains the code generating the graphs seen on the document submitted for the project. The implementation.py file contains the code that sends the data to the Thingsboard server.
|
||||
|
||||
# How to setup the implementation
|
||||
Install the requirements
|
||||
```
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
Create a .env file in the root directory of the project with the following content:
|
||||
```
|
||||
SENSOR_API_URL= # URL of the sensor API
|
||||
THINGSBOARD_URL = # URL of the Thingsboard server
|
||||
```
|
||||
Run the application
|
||||
```
|
||||
python implementation.py
|
||||
```
|
||||
63
implementation.py
Normal file
63
implementation.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import time
|
||||
import requests
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
|
||||
dT = 0.5
|
||||
|
||||
RATE_OF_CHANGE = [
|
||||
0.609164,
|
||||
0.533102,
|
||||
0.490007,
|
||||
0.441728,
|
||||
0.422819,
|
||||
0.397558,
|
||||
0.381043,
|
||||
0.459887,
|
||||
1.095440,
|
||||
2.825424,
|
||||
3.922974,
|
||||
3.454793,
|
||||
2.309282,
|
||||
1.671112,
|
||||
1.513777,
|
||||
1.621256,
|
||||
2.043299,
|
||||
2.568422,
|
||||
2.934706,
|
||||
2.461657,
|
||||
2.166300,
|
||||
1.601714,
|
||||
1.058227,
|
||||
0.778290,
|
||||
]
|
||||
|
||||
load_dotenv()
|
||||
|
||||
def poll_data():
|
||||
# make a api call to http://quentin.com/api/temperature
|
||||
res = requests.get(os.getenv("SENSOR_API_URL")).json()
|
||||
return res["temperature"]
|
||||
|
||||
def push_data(temperature):
|
||||
print(f"Pushed data: {temperature}")
|
||||
requests.post(os.getenv("API_URL"), json={"temperature": temperature})
|
||||
|
||||
def main():
|
||||
temperature = poll_data()
|
||||
push_data(temperature)
|
||||
while True:
|
||||
#get hour of the day
|
||||
current_hour = time.localtime().tm_hour
|
||||
#get the rate of change for the current hour
|
||||
rate_of_change = RATE_OF_CHANGE[current_hour]
|
||||
#calculate the wait before the next poll
|
||||
wait_time = 3600 * dT / rate_of_change
|
||||
#wait
|
||||
time.sleep(wait_time)
|
||||
#poll data
|
||||
new_temperature = poll_data()
|
||||
print(f"New temperature: {new_temperature}")
|
||||
#push data
|
||||
push_data(new_temperature)
|
||||
|
||||
9
main.py
9
main.py
@@ -192,8 +192,9 @@ def histogram_sample_every_kth_point(k=10):
|
||||
# comparaison_mean(df)
|
||||
|
||||
# Temperature rate of change over the day
|
||||
# df = generate_greenhouse_data("datasets/greenhouse.csv")
|
||||
# hcor = hourly_rate_of_change(df)
|
||||
df = generate_greenhouse_data("datasets/greenhouse.csv")
|
||||
hcor = hourly_rate_of_change(df)
|
||||
print(hcor)
|
||||
# hcor.plot()
|
||||
# plt.xlabel("Hour of the day")
|
||||
# plt.ylabel("Average absolute rate of change (°C/hour)")
|
||||
@@ -202,8 +203,8 @@ def histogram_sample_every_kth_point(k=10):
|
||||
# plt.xlabel("Hour of the day")
|
||||
# plt.show()
|
||||
|
||||
df = generate_greenhouse_data("datasets/greenhouse.csv")
|
||||
comparaison_mean(df, 1000)
|
||||
# df = generate_greenhouse_data("datasets/greenhouse.csv")
|
||||
# comparaison_mean(df, 1000)
|
||||
|
||||
# example_sample_every_kth_point(1)
|
||||
# example_sample_every_kth_point(10)
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
pandas
|
||||
noise
|
||||
noise
|
||||
requests
|
||||
python-dotenv
|
||||
Reference in New Issue
Block a user