forked from sujay1844/override
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensor.py
55 lines (42 loc) · 991 Bytes
/
sensor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
SERVER_URL = 'http://localhost:8000'
import pandas as pd
import numpy as np
from fastapi import FastAPI
import requests
import asyncio
import time
df = pd.read_csv('train.csv')
len_df = df.shape[0]
frac = 1
idx = 0
async def send_data_periodically():
while True:
await asyncio.sleep(1)
global idx
if idx >= len_df:
return
row = df.iloc[idx].copy()
row.pressure = row.pressure * frac
data = {
"date_time": row.date_time,
"pressure": row.pressure
}
print("sending", row.date_time)
requests.post(SERVER_URL+'/new', json=data)
idx += 1
loop = asyncio.get_event_loop()
loop.create_task(send_data_periodically())
app = FastAPI()
@app.get("/ping")
def read_root():
return {"message": "pong"}
@app.get("/leak")
def leak():
global frac
frac = 0.7
return {"frac": frac}
@app.get("/fix")
def fix():
global frac
frac = 1
return {"frac": frac}