client.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import pandas as pd
  2. # from pycaret.classification import *
  3. import librosa as fe
  4. data = pd.read_csv('data/data_all.csv')
  5. data.timestamp = data.timestamp.apply(lambda x: pd.Timestamp(x))
  6. data['month'] = data.timestamp.dt.month
  7. data['hour'] = data.timestamp.dt.hour
  8. data['dayofweek'] = data.timestamp.dt.dayofweek
  9. def f_e(df, cn='hum'):
  10. # delta feature
  11. df[f'd_{cn}'] = fe.feature.delta(df[f'{cn}'])
  12. df[f'dd_{cn}'] = fe.feature.delta(df[f'd_{cn}'], order=2)
  13. return df
  14. f_e(data, 'hum')
  15. f_e(data, 'temp')
  16. data.to_csv('data/data_all_feature_eng.csv', index=False)
  17. tmp = (data[data['timestamp'] == '2021-08-30 08:09:00'])
  18. out = tmp[['hum', 'd_hum', 'dd_hum', 'temp', 'd_temp', 'dd_temp', 'door', 'motion', 'illum', 'dayofweek', 'month', 'hour']]
  19. v = out.values.tolist()[0]
  20. print(v)
  21. v = ["{}".format(x) for x in v]
  22. print(v)
  23. import requests
  24. URL = f'http://localhost:8000/predict?hum={v[0]}&d_hum={v[1]}&dd_hum={v[2]}&temp={v[3]}&d_temp={v[4]}&dd_temp={v[5]}&door={v[6]}&motion={v[7]}&illum={v[8]}&dayofweek={v[9]}&month={v[10]}&hour={v[11]}'
  25. response = requests.get(URL)
  26. print(response.status_code)
  27. print(response.text)