@@ -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 += '\n UPDATE ' + 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 += '\n UPDATE ' + 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 """
0 commit comments