Skip to content

Commit 9892a98

Browse files
author
Sebastian
committed
release 2.0.2
1 parent fd2a1c6 commit 9892a98

File tree

18 files changed

+325
-211
lines changed

18 files changed

+325
-211
lines changed

RTOC.egg-info/PKG-INFO

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: RTOC
3-
Version: 2.0.1
3+
Version: 2.0.2
44
Summary: RealTime OpenControl
55
Home-page: https://github.com/Haschtl/RealTimeOpenControl
66
Author: Sebastian Keller
@@ -159,7 +159,7 @@ Classifier: Topic :: Scientific/Engineering :: Visualization
159159
Classifier: Topic :: Software Development :: User Interfaces
160160
Requires-Python: >=3
161161
Description-Content-Type: text/markdown
162-
Provides-Extra: ALL
163-
Provides-Extra: Telegram
164-
Provides-Extra: Webserver
165162
Provides-Extra: GUI
163+
Provides-Extra: Webserver
164+
Provides-Extra: Telegram
165+
Provides-Extra: ALL

RTOC/LoggerPlugin.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def getDir(self, dir=None):
8080

8181
return packagedir
8282

83-
def stream(self, y, snames, dname=None, unit=None, x=None, slist=None, sdict=None):
83+
def stream(self, y=[], snames=[], dname=None, unit=None, x=None, slist=None, sdict=None):
8484
"""
8585
Use this function to send new measurements to RTOC. You can send multiple signals at once.
8686
@@ -543,39 +543,55 @@ def __updateT(self, func):
543543

544544

545545
class _perpetualTimer():
546+
thread_counter = 0
547+
546548
def __init__(self, hFunction, samplerate=1, lock=None):
547549
self._samplerate = samplerate
548550
self._lock = lock
549551
self._hFunction = hFunction
550552
self._thread = None
551553

552554
def _handle_function(self):
553-
start = time.time()
555+
self.thread_counter -= 1
556+
if self.thread_counter != 0:
557+
logging.warning('there should not be a running thread, but unfortunately it is.')
558+
print(self.thread_counter)
559+
554560
with self._lock:
561+
start = time.time()
555562
self._hFunction()
556-
diff = time.time() - start
557-
timedelta = 1/self._samplerate - diff
558-
if timedelta < 0:
559-
timedelta = 0
563+
diff = time.time() - start
564+
timedelta = 1/self._samplerate - diff
565+
if timedelta < 0:
566+
timedelta = 0
560567
self._thread = Timer(timedelta, self._handle_function)
568+
self.thread_counter += 1
561569
self._thread.start()
562570

563571
def setSamplerate(self, rate):
564572
if rate != self._samplerate:
565573
self._samplerate = rate
566-
if self._thread is not None:
567-
self.cancel()
568-
self._thread = Timer(1/self._samplerate, self._handle_function)
569-
self._thread.start()
574+
self.cancel()
575+
if self.thread_counter == 0:
576+
self._thread = Timer(1/self._samplerate, self._handle_function)
577+
self.thread_counter += 1
578+
self._thread.start()
579+
else:
580+
logging.warning('Thread should have stopped before changing samplerate, but it didnt.')
570581

571582
def getSamplerate(self):
572583
return self._samplerate
573584

574585
def start(self):
586+
logging.info('Starting perpetual timer')
587+
self.cancel()
575588
self._thread = Timer(0, self._handle_function)
589+
self.thread_counter += 1
576590
self._thread.start()
577591

578592
def cancel(self):
579593
if self._thread is not None:
580-
self._thread.cancel()
581-
self._thread = None
594+
with self._lock:
595+
self._thread.cancel()
596+
self.thread_counter -= 1
597+
self._thread = None

RTOC/RTLogger/DeviceFunctions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,5 @@ def analysePlugin(self, object, name):
322322
origParName = "self.pluginObjects['"+name+"']."+str(element)
323323

324324
self.pluginParameters[name+"." +element] = origParName
325+
326+
# print(self.pluginFunctions)

RTOC/RTLogger/NetworkFunctions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def toggleTcpServer(self, value=None):
8888
self.__tcpserver.start()
8989
logging.info("TCPServer gestartet")
9090
return True
91-
except OSError:
92-
logging.error("Port already in use. Cannot start TCP-Server")
91+
except OSError as error:
92+
logging.error("Port already in use. Cannot start TCP-Server:\n{}".format(error))
9393
self.tcpRunning = False
9494
# self.config['tcp']['active'] = False
9595
return False
@@ -345,7 +345,7 @@ def getPluginDict(self):
345345
for fun in self.pluginFunctions.keys():
346346
hiddenFuncs = ["loadGUI", "updateT", "stream", "plot", "event", "createTCPClient", "sendTCP", "close", "cancel", "start", "setSamplerate","setDeviceName",'setPerpetualTimer','setInterval','getDir']
347347

348-
if fun not in [name+'.'+i for i in hiddenFuncs]:
348+
if fun.startswith(name+".") and fun not in [name+'.'+i for i in hiddenFuncs]:
349349
dict[name]['functions'].append(fun.replace(name+".", ''))
350350
for fun in self.pluginParameters.keys():
351351
hiddenParams = ["run", "smallGUI", 'widget', 'samplerate','lockPerpetialTimer']

RTOC/RTLogger/RTLogger.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@
8282
"telegram": {
8383
"active": False,
8484
"token": "",
85-
"eventlevel": 0,
85+
"default_eventlevel": 0,
86+
"default_permission": 'blocked', # or 'read' or 'write' or 'admin'
8687
"chat_ids": {},
8788
"inlineMenu": False,
8889
"onlyAdmin": False

RTOC/RTLogger/RTRemote.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import time
2-
from threading import Thread
2+
# from threading import Thread
33
import traceback
44
import json
55
import socket
@@ -145,8 +145,8 @@ def updateEvents(self, newEventList):
145145
if evID not in self.eventlist.keys():
146146
# self.eventlist[evID] = newEventList[evID]
147147
ev = newEventList[evID]
148-
self.event(x=ev[4], text=ev[3], sname=str(ev[0]),
149-
dname=self.name+":"+str(ev[1]), priority=ev[6])
148+
self.event(x=ev[4], text=ev[3], sname=str(ev[1]),
149+
dname=self.name+":"+str(ev[0]), priority=ev[6])
150150

151151
self.eventlist = newEventList
152152

RTOC/RTLogger/RT_data.py

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -772,12 +772,15 @@ def events(self, beauty=False):
772772
Returns:
773773
dict: {EVENT_ID: [DEVICE_ID,SIGNAL_ID,EVENT_ID,TEXT,TIME,VALUE,PRIORITY, ID],...}
774774
"""
775-
ev = {}
776-
for evID in self._events.keys():
777-
name = self.getEventName(evID)
778-
old = self._events[evID]
779-
ev[evID]=[name[0],name[1],*old[2:]]
780-
return ev
775+
if beauty:
776+
ev = {}
777+
for evID in self._events.keys():
778+
name = self.getEventName(evID)
779+
old = self._events[evID]
780+
ev[evID]=[name[0],name[1],*old[2:]]
781+
return ev
782+
else:
783+
return dict(self._events)
781784

782785
def signals(self):
783786
"""
@@ -1123,11 +1126,12 @@ def _addSQLSignal(self, sigID, signal):
11231126
dev = self._SQLdeviceExists(devicename)
11241127
if dev is False:
11251128
self._SQLcreateDevice(signal[0], devicename)
1126-
sigID = self._SQLcreateSignal(sigID, signalname, devicename, x, y, unit)
1129+
if not self.signalExists(signalname, devicename):
1130+
sigID = self._SQLcreateSignal(sigID, signalname, devicename, x, y, unit)
11271131
# add data
1128-
sql = 'UPDATE '+SIGNAL_TABLE_NAME+' SET X = ARRAY'+str(x)+' WHERE ID ='+str(sigID)+';'
1132+
sql = 'UPDATE '+SIGNAL_TABLE_NAME+' SET X = ARRAY'+str(x)+'::NUMERIC[] WHERE ID ='+str(sigID)+';'
11291133
sql += '\nUPDATE '+SIGNAL_TABLE_NAME + \
1130-
' SET Y = ARRAY'+str(y)+' WHERE ID ='+str(sigID)+';'
1134+
' SET Y = ARRAY'+str(y)+'::NUMERIC[] WHERE ID ='+str(sigID)+';'
11311135
sql += '\nUPDATE '+SIGNAL_TABLE_NAME+' SET UNIT = \'' + \
11321136
str(unit)+'\' WHERE ID ='+str(sigID)+';'
11331137
self._execute_n_commit(sql)
@@ -1193,10 +1197,11 @@ def _SQLcreateEvent(self, devID, sigID, evID, strung, x, value, priority, eventi
11931197
if check_devID == -1:
11941198
self._SQLcreateDevice(devID, devicename)
11951199
devID = self._SQLgetDeviceID(devicename)
1196-
check_sigID = self._SQLgetSignalID(devicename, signalname)
1197-
if check_sigID == -1:
1198-
self._SQLcreateSignal(sigID, devicename, signalname)
1199-
sigID = self._SQLgetSignalID(devicename, signalname)
1200+
# check_sigID = self._SQLgetSignalID(devicename, signalname)
1201+
# if check_sigID == -1:
1202+
if not self.signalExists(signalname, devicename):
1203+
sigID = self._SQLcreateSignal(sigID, devicename, signalname)
1204+
# sigID = self._SQLgetSignalID(devicename, signalname)
12001205
if devID != -1 and sigID != -1:
12011206
sql = '''INSERT INTO '''+EVENT_TABLE_NAME+'''(ID, TIME, TEXT, DEVICE_ID, SIGNAL_ID, PRIORITY, VALUE, EVENT_ID)
12021207
VALUES
@@ -1837,12 +1842,13 @@ def getSignalInfo(self, sigID, database=True):
18371842
#else:
18381843
signal = self.getSignal(sigID)
18391844
if signal is not None:
1840-
xminLocal = min(signal[2])
1841-
xmaxLocal = max(signal[2])
1842-
sigLenLocal = len(list(signal[2]))
1843-
xmin = min([xminLocal, xmin])
1844-
xmax = max([xmaxLocal, xmax])
1845-
sigLen = max([sigLenLocal, sigLen])
1845+
if len(signal[2])>0:
1846+
xminLocal = min(signal[2])
1847+
xmaxLocal = max(signal[2])
1848+
sigLenLocal = len(list(signal[2]))
1849+
xmin = min([xminLocal, xmin])
1850+
xmax = max([xmaxLocal, xmax])
1851+
sigLen = max([sigLenLocal, sigLen])
18461852

18471853
return float(xmin), float(xmax), int(sigLen)
18481854

@@ -1978,24 +1984,37 @@ def getSignal(self, sigID, xmin=None, xmax=None, database=False, maxN=None):
19781984
if xmin == None:
19791985
xmin = 0
19801986
if xmax == None:
1981-
xmax = time.time()*2
1987+
xmax = float(time.time())*2
19821988

1989+
signal = None
19831990
if self.logger.config['postgresql']['active'] and database:
19841991
signal = self._getSQLSignal(sigID, None, xmin=xmin, xmax=xmax, maxN=maxN) # sigLen)
19851992
if signal == None:
19861993
logging.warning('Could not find {} in database'.format(sigID))
19871994
database = False
19881995

1989-
if database:
1996+
if sigID in self._signals:
1997+
# signal = copy.deepcopy(self._signals[sigID])
1998+
signal_local = list(self._signals[sigID])
1999+
if signal is None:
2000+
signal = signal_local
2001+
else:
2002+
for idx, x in enumerate(signal_local[2]):
2003+
if x > signal[2][-1]:
2004+
signal[2] += list(signal_local[2])[idx:]
2005+
signal[3] += list(signal_local[3])[idx:]
2006+
break
2007+
2008+
if signal is not None:
19902009
for idx, x in enumerate(signal[2]):
19912010
if x > xmin:
1992-
signal[2] = signal[2][idx:]
1993-
signal[3] = signal[3][idx:]
2011+
signal[2] = list(signal[2])[idx:]
2012+
signal[3] = list(signal[3])[idx:]
19942013
break
19952014
for idx, x in enumerate(signal[2]):
19962015
if x > xmax:
1997-
signal[2] = signal[2][0:idx-1]
1998-
signal[3] = signal[3][0:idx-1]
2016+
signal[2] = list(signal[2])[0:idx-1]
2017+
signal[3] = list(signal[3])[0:idx-1]
19992018
break
20002019
if maxN != None and type(maxN) == int:
20012020
if len(signal[2]) > maxN:
@@ -2010,33 +2029,7 @@ def getSignal(self, sigID, xmin=None, xmax=None, database=False, maxN=None):
20102029
signal[3] = newY
20112030
return signal
20122031
else:
2013-
if sigID in self._signals:
2014-
# signal = copy.deepcopy(self._signals[sigID])
2015-
signal = list(self._signals[sigID])
2016-
for idx, x in enumerate(signal[2]):
2017-
if x > xmin:
2018-
signal[2] = list(signal[2])[idx:]
2019-
signal[3] = list(signal[3])[idx:]
2020-
break
2021-
for idx, x in enumerate(signal[2]):
2022-
if x > xmax:
2023-
signal[2] = list(signal[2])[0:idx-1]
2024-
signal[3] = list(signal[3])[0:idx-1]
2025-
break
2026-
if maxN != None and type(maxN) == int:
2027-
if len(signal[2]) > maxN:
2028-
overRatio = int(len(signal[2])/maxN)
2029-
newX = []
2030-
newY = []
2031-
for idx, i in enumerate(signal[2]):
2032-
if idx % overRatio == 0:
2033-
newX.append(signal[2][idx])
2034-
newY.append(signal[3][idx])
2035-
signal[2] = newX
2036-
signal[3] = newY
2037-
return signal
2038-
else:
2039-
return None
2032+
return None
20402033

20412034
def getSignal_byName(self, devicename, signalname, xmin=None, xmax=None, database=False, maxN=None):
20422035
"""

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.1")
59+
logging.info("2.0.2")
6060
elif opt in ('-s', '--server'):
6161
if os.name == 'nt':
6262
logging.info(

0 commit comments

Comments
 (0)