Skip to content

Commit 0ab59f2

Browse files
author
Sebastian
committed
release 2.0.3
1 parent 1d0467d commit 0ab59f2

File tree

14 files changed

+310
-180
lines changed

14 files changed

+310
-180
lines changed

RTOC/RTLogger/DeviceFunctions.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def getPluginParameter(self, name, parameter, *args):
231231
return False
232232
except Exception:
233233
tb = traceback.format_exc()
234-
logging.debug(tb)
234+
logging.error(tb)
235235
logging.warning(
236236
"PLUGIN FAILURE\nCould not get/set/call Plugin parameter/function'"+str(name)+"'\n")
237237
return False
@@ -249,28 +249,30 @@ def callPluginFunction(self, name, function, *args, **kwargs):
249249
kwargs (\*any): Keyworded parameters transmitted to the function
250250
251251
Returns:
252-
parameter (any): The value of the requested/setted parameter(s).
252+
bool: True, if call was successfull
253253
254-
False, if any error occured, while trying to get/set parameter
254+
parameter (any): The value of the requested/setted parameter(s).
255255
'''
256256
try:
257257
if name in self.pluginObjects.keys() and type(function) == str:
258258
logging.debug(function)
259259
logging.debug(name)
260-
logging.debug(*args)
261-
logging.debug(*kwargs)
260+
# logging.debug(*args)
261+
# logging.debug(*kwargs)
262262
exec('self.func = self.pluginObjects["' +
263263
name+'"].'+function)
264-
return self.func(*args, **kwargs)
264+
265+
ans = self.func(*args, **kwargs)
266+
return True, ans
265267
else:
266268
logging.warning("Plugin "+name+" not found or started")
267-
return False
269+
return False, "Plugin "+name+" not found or started"
268270
except Exception:
269271
tb = traceback.format_exc()
270-
logging.debug(tb)
272+
logging.error(tb)
271273
logging.warning(
272274
"PLUGIN FAILURE\nCould not get/set/call Plugin parameter/function'"+str(name)+"'\n")
273-
return False
275+
return False, tb
274276

275277
def stopPlugin(self, name, remote=True):
276278
'''

RTOC/RTLogger/EventActionFunctions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def loadGlobalActions(self):
143143
Loads global actions from file and stores them in dict 'self.globalActions'
144144
"""
145145
print('Loading global actions from file')
146-
userpath = os.path.expanduser('~/.RTOC')
146+
userpath = self.config['global']['documentfolder']
147147
if not os.path.exists(userpath):
148148
os.mkdir(userpath)
149149
if os.path.exists(userpath+"/globalActions.json"):

RTOC/RTLogger/RTLogger.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"token": "",
8585
"default_eventlevel": 0,
8686
"default_permission": 'blocked', # or 'read' or 'write' or 'admin'
87-
"chat_ids": {},
87+
# "chat_ids": {},
8888
"inlineMenu": False,
8989
"onlyAdmin": False
9090
},
@@ -103,6 +103,7 @@
103103
"autoOnClose": True,
104104
"loadOnOpen": True,
105105
"intervall": 240,
106+
"resample": 0,
106107
},
107108
}
108109

@@ -356,19 +357,20 @@ def _load_config(self):
356357

357358
self.__config['global']['documentfolder'] = userpath
358359

359-
if type(self.__config['telegram']['chat_ids']) == list:
360-
newdict = {}
361-
for id in self.__config['telegram']['chat_ids']:
362-
newdict[id] = self.__config['telegram']['eventlevel']
363-
self.__config['telegram']['chat_ids'] = newdict
364-
logging.warning('Telegram chat ids were saved as list, changed to dict.')
365-
elif type(self.__config['telegram']['chat_ids']) == dict:
366-
for id in self.__config['telegram']['chat_ids'].keys():
367-
if type(self.__config['telegram']['chat_ids'][id]) == int:
368-
self.__config['telegram']['chat_ids'][id] = [
369-
self.__config['telegram']['chat_ids'][id], [[], []]]
370-
logging.warning(
371-
'Telegram chat ids were saved without shortcuts. Empty list added')
360+
if 'chat_ids' in self.__config.keys():
361+
if type(self.__config['telegram']['chat_ids']) == list:
362+
newdict = {}
363+
for id in self.__config['telegram']['chat_ids']:
364+
newdict[id] = self.__config['telegram']['eventlevel']
365+
self.__config['telegram']['chat_ids'] = newdict
366+
logging.warning('Telegram chat ids were saved as list, changed to dict.')
367+
elif type(self.__config['telegram']['chat_ids']) == dict:
368+
for id in self.__config['telegram']['chat_ids'].keys():
369+
if type(self.__config['telegram']['chat_ids'][id]) == int:
370+
self.__config['telegram']['chat_ids'][id] = [
371+
self.__config['telegram']['chat_ids'][id], [[], []]]
372+
logging.warning(
373+
'Telegram chat ids were saved without shortcuts. Empty list added')
372374

373375
if type(self.__config['tcp']['knownHosts']) == list:
374376
newdict = {}

RTOC/RTLogger/RT_data.py

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import json
1515
import psutil
1616
import copy
17+
import gzip
1718

1819
try:
1920
import xlsxwriter
@@ -955,10 +956,14 @@ def pushToDatabase(self):
955956
newData[sigID][4] = localData[sigID][4]
956957
newData[sigID][2] = list(localData[sigID][2])[int(idx):]
957958
newData[sigID][3] = list(localData[sigID][3])[int(idx):]
959+
if self.logger.config['backup']['resample'] != 0:
960+
newData[sigID][2], newData[sigID][3] = resample(newData[sigID][2], newData[sigID][3], self.logger.config['backup']['resample'])
958961
# new = True
959962
break
960963
else:
961964
newSignals[sigID] = localData[sigID]
965+
if self.logger.config['backup']['resample'] != 0:
966+
newSignals[sigID][2], newSignals[sigID][3] = resample(newSignals[sigID][2], newSignals[sigID][3], self.logger.config['backup']['resample'])
962967
# if not new:
963968
# popIDs.append(sigID)
964969

@@ -1099,6 +1104,7 @@ def _commit(self, query):
10991104
logging.info("Error while execution+commit in PostgreSQL table")
11001105
logging.error(error)
11011106
logging.error(query)
1107+
logging.error(traceback.format_exc())
11021108
ans = False
11031109

11041110
def _getSQLSignalUnit(self, sigID):
@@ -1148,9 +1154,13 @@ def _SQLdeviceExists(self, devicename):
11481154
sig = False
11491155
return sig
11501156

1151-
def _SQLsignalExists(self, signalname):
1157+
def _SQLsignalExists(self, signalname, devicename):
1158+
if self._SQLdeviceExists(devicename):
1159+
devID = self._SQLgetDeviceID(devicename)
1160+
else:
1161+
return False
11521162
existtest = "SELECT EXISTS (select ID from "+SIGNAL_TABLE_NAME + \
1153-
" where NAME = '"+str(signalname)+"');"
1163+
" where NAME = '"+str(signalname)+"' and DEVICE_ID = "+str(devID)+");"
11541164
sig = self._execute_n_fetchall(existtest)
11551165
if sig is not None and sig != []:
11561166
sig = bool(sig[0][0])
@@ -1351,9 +1361,9 @@ def _SQLplotNewData(self, x, y, dataunit, devicename, signalname, createCallback
13511361
logging.error('mergeY is NOT IMPLEMENTED YET for postgresql')
13521362
else:
13531363
sql = 'UPDATE '+SIGNAL_TABLE_NAME+' SET X = ARRAY' + \
1354-
str(x)+'::NUMERIC[] WHERE ID ='+str(sigID)+';'
1364+
str(list(x))+'::NUMERIC[] WHERE ID ='+str(sigID)+';'
13551365
sql += '\nUPDATE '+SIGNAL_TABLE_NAME + \
1356-
' SET Y = ARRAY'+str(y)+'::NUMERIC[] WHERE ID ='+str(sigID)+';'
1366+
' SET Y = ARRAY'+str(list(y))+'::NUMERIC[] WHERE ID ='+str(sigID)+';'
13571367
sql += '\nUPDATE '+SIGNAL_TABLE_NAME+' SET UNIT = \'' + \
13581368
str(dataunit)+'\' WHERE ID ='+str(sigID)+';'
13591369
self._execute_n_commit(sql)
@@ -1362,8 +1372,13 @@ def _SQLplotNewData(self, x, y, dataunit, devicename, signalname, createCallback
13621372
def _SQLExportCSV(self, filenamepart):
13631373
filenames = []
13641374
for table in [DEVICE_TABLE_NAME, SIGNAL_TABLE_NAME, EVENT_TABLE_NAME]:
1365-
filename = filenamepart+'_'+table+".csv"
1366-
sql = "COPY "+table+" TO '"+filename+"' DELIMITER ',' CSV HEADER;"
1375+
filename = filenamepart+'_'+table+".gz"
1376+
#sql = "COPY "+table+" TO '"+filename+"' DELIMITER ',' CSV HEADER;"
1377+
#ans = self._execute_n_fetchall(sql)
1378+
#print(ans)
1379+
with gzip.open(filename, 'wb') as gzip_file:
1380+
#cursor.copy_to(gzip_file, 'my_table')
1381+
self._cursor.copy_to(gzip_file, table, sep="|")
13671382
filenames.append(filename)
13681383
return filenames
13691384

@@ -1862,7 +1877,10 @@ def getSignalInfo(self, sigID, database=True):
18621877
xmax = max([xmaxLocal, xmax])
18631878
sigLen = max([sigLenLocal, sigLen])
18641879

1865-
return float(xmin), float(xmax), int(sigLen)
1880+
if xmin is None or xmax is None or sigLen is None:
1881+
return 0,0,0
1882+
else:
1883+
return float(xmin), float(xmax), int(sigLen)
18661884

18671885
def removeSignal(self, sigID, xmin=None, xmax=None, database=False):
18681886
"""
@@ -2011,10 +2029,15 @@ def getSignal(self, sigID, xmin=None, xmax=None, database=False, maxN=None):
20112029
if signal is None:
20122030
signal = signal_local
20132031
else:
2014-
for idx, x in enumerate(signal_local[2]):
2015-
if x > signal[2][-1]:
2016-
signal[2] += list(signal_local[2])[idx:]
2017-
signal[3] += list(signal_local[3])[idx:]
2032+
# for idx, x in enumerate(signal_local[2]):
2033+
# if x > signal[2][-1]:
2034+
# signal[2] += list(signal_local[2])[idx:]
2035+
# signal[3] += list(signal_local[3])[idx:]
2036+
# break
2037+
for idx, x in enumerate(signal[2]):
2038+
if signal_local[2][0] < x:
2039+
signal[2] = signal[2][:idx]+list(signal_local[2])
2040+
signal[3] = signal[3][:idx]+list(signal_local[3])
20182041
break
20192042

20202043
if signal is not None:
@@ -2167,12 +2190,14 @@ def resampleDatabase(self, samplerate):
21672190
signals = {signal[0]: list(signal)[1:] for signal in signals}
21682191

21692192
for sigID in signals.keys():
2193+
signals[sigID][0] = [float(i) for i in signals[sigID][0]]
2194+
signals[sigID][1] = [float(i) for i in signals[sigID][1]]
21702195
s = signals[sigID]
21712196
if len(s[0])>2:
21722197
xrange = s[0][-1]-s[0][0]
2173-
n = samplerate*xrange
2198+
n = samplerate*float(xrange)
21742199
if len(s[0]) == len(s[1]):
2175-
x = np.linspace(s[0][0], s[0][-1], n)
2200+
x = np.linspace(float(s[0][0]), float(s[0][-1]), n)
21762201
y = np.interp(x, s[0], s[1])
21772202

21782203
self._SQLplot(x=x, y=y, sigID=sigID)
@@ -2202,3 +2227,13 @@ def column(matrix, i):
22022227
if i < len(row):
22032228
ans.append(row[i])
22042229
return ans
2230+
2231+
2232+
def resample(x,y, samplerate):
2233+
# xlen = len(x)
2234+
xtime = x[-1]-x[0]
2235+
n = samplerate*xtime
2236+
x2 = np.linspace(x[0], x[-1], n)
2237+
y = np.interp(x2, x, y)
2238+
2239+
return list(x2), list(y)

RTOC/RTLogger/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def main():
5656
'RTOC.RTLogger [-h, -s, -l, -w]\n -h: Hilfe\n-s (--server) [COMMAND]: TCP-Server ohne GUI\n\t- start: Starts the RTOC-daemon\n\t- stop: Stops the RTOC-daemon\n\t- restart: Restarts the RTOC-daemon\n-w Startet RTLogger mit Website\n-p (--port): Starte TCP-Server auf anderem Port (Standart: 5050)\n-c (--config [OPTION=value]): Configure RTOC, type "-c list" to see all options')
5757
sys.exit(0)
5858
elif opt == '-v':
59-
logging.info("2.0.2")
59+
logging.info("2.0.3")
6060
elif opt in ('-s', '--server'):
6161
if os.name == 'nt':
6262
logging.info(

0 commit comments

Comments
 (0)