-
Notifications
You must be signed in to change notification settings - Fork 0
/
maintainer.py
55 lines (43 loc) · 1.3 KB
/
maintainer.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
'''
sudo chmod a+rw /dev/ttyUSB0
python3 maintainer.py
'''
import time
import numpy as np
import sqlite3
from joblib import load
print('Import successfully!')
# Init
ID = 0
TABLE_NAME = 'sinamicv20'
DATABASE_PATH = 'data/inverter.db'
SLEEPING_TIME = 2
SPEED_DICT = {0:'stopped',
1:'low_speed',
2:'normal_speed',
3:'high_speed'}
if __name__ == "__main__":
# Connect to database
conn = sqlite3.connect(DATABASE_PATH)
c = conn.cursor()
# Load model
model = load('notebooks/model.joblib')
while True:
query = """SELECT * FROM sinamicv20 WHERE ID = 0"""
c.execute(query)
x = c.fetchone()
#print(x)
# x_drop_index = x[1:]
# print(len(x_drop_index),SPEED_DICT[int(model.predict([np.array(x_drop_index)]))])
speed = x[24] * 8.10/242
if speed != 0:
if speed < 7:
print('SPEED =',speed,'=> WARNING SLOW SPEED!')
elif speed > 13:
print('SPEED =',speed,'=> WARNING HIGH SPEED!')
else:
print('SPEED =',speed,'=> NORMAL SPEED')
else:
print('SPEED =',speed,'=> MOTOR STOPPED')
conn.commit()
time.sleep(SLEEPING_TIME)