-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_queries.py
44 lines (39 loc) · 1.23 KB
/
database_queries.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
from mysql_tools.mysql_tools import SQLObject
from utils import timeout, TimeoutError
import pandas as pd
def get_stations():
DB = SQLObject()
df = DB.getStations()
df_sub = df[['Name','Lat','Long','display','devices']]
print(df_sub)
def get_station(ID):
DB = SQLObject()
df = DB.getSingleStation(ID)
print(df)
def get_station_hash(ID):
DB = SQLObject()
hash = DB.getHashFromDB(ID)
print(hash)
def station_update(ID,column,value):
DB = SQLObject()
#UPDATE `dosimeter_network`.`stations` SET `Long` = '8.668740' WHERE (`ID` ='48') and (`Name` = 'Westend');
DB.sendSingleStationChange(ID,column,value)
def get_all_data(ID,data_type,max_time):
retry_counter = 0
DB = SQLObject()
while retry_counter < 3:
try:
with timeout(max_time*(retry_counter+1)):
DB.refresh()
df = DB.getAll(ID,data_type,True)
print(df)
except (TimeoutError) as e:
retry_counter = retry_counter + 1
print(e)
print("Timed out on try {}".format(retry_counter))
pass
except (Exception) as e:
print(e)
print(pd.DataFrame({}))
break
print(pd.DataFrame({}))