Skip to content

Commit da9e3b2

Browse files
author
Sebastian
committed
telegram fix
1 parent 62d7798 commit da9e3b2

File tree

6 files changed

+271
-259
lines changed

6 files changed

+271
-259
lines changed

RTOC/LoggerPlugin.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def telegram_send_document(self, path, priority=0, permission='write'):
577577
class _perpetualTimer():
578578

579579
def __init__(self, hFunction, samplerate=1, lock=None):
580-
self.thread_counter = 0
580+
# self.thread_counter = 0
581581
self._samplerate = samplerate
582582
self._lock = lock
583583
self._cancel = True
@@ -589,10 +589,10 @@ def __init__(self, hFunction, samplerate=1, lock=None):
589589
def _handle_function(self):
590590
start = time.time()
591591
self._lastStart = time.perf_counter()
592-
self.thread_counter -= 1
593-
if self.thread_counter != 0:
594-
logging.warning('there should not be a running thread, but unfortunately it is.')
595-
print(self.thread_counter)
592+
# self.thread_counter -= 1
593+
# if self.thread_counter != 0:
594+
# logging.warning('there should not be a running thread, but unfortunately it is.')
595+
# print(self.thread_counter)
596596

597597
if not self._cancel:
598598
with self._lock:
@@ -606,7 +606,7 @@ def _handle_function(self):
606606
if not self._cancel and not self._lock.locked():
607607
# with self._lock:
608608
self._thread = Timer(timedelta, self._handle_function)
609-
self.thread_counter += 1
609+
# self.thread_counter += 1
610610
self._thread.start()
611611

612612
def setSamplerate(self, rate):
@@ -626,21 +626,22 @@ def start(self, delayed=0):
626626
self.cancel()
627627
self._cancel = False
628628
with self._lock:
629-
if self.thread_counter <= 0:
629+
#if self.thread_counter <= 0:
630+
if self._thread is None:
630631
self._thread = Timer(delayed, self._handle_function)
631-
self.thread_counter += 1
632+
#self.thread_counter += 1
632633
self._thread.start()
633-
if self.thread_counter<0:
634-
logging.warning('Something is not right...')
634+
# if self.thread_counter<0:
635+
# logging.warning('Something is not right...')
635636
else:
636637
logging.warning('You cannot start a second perpetual timer.')
637-
print(self.thread_counter)
638+
# print(self.thread_counter)
638639

639640

640641
def cancel(self):
641642
self._cancel = True
642643
if self._thread is not None:
643644
with self._lock:
644645
self._thread.cancel()
645-
self.thread_counter -= 1
646+
# self.thread_counter -= 1
646647
self._thread = None

RTOC/RTLogger/RT_data.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,9 +1796,9 @@ def getGlobalXmin(self, database=True, fast=False):
17961796
for idx, a in enumerate(ans):
17971797
if a < 10000:
17981798
ans[idx] = time.time()
1799+
ans = min(ans)
17991800
else:
1800-
ans = 0
1801-
ans = min(ans)
1801+
ans = time.time()
18021802
else:
18031803
ans = time.time()
18041804
#else:
@@ -1832,11 +1832,11 @@ def getGlobalXmax(self, database=True, fast=False):
18321832
ans[idx] = float(i[0])
18331833
else:
18341834
ans[idx] = 0
1835+
ans = max(ans)
18351836
else:
1836-
ans = 0
1837-
ans = max(ans)
1837+
ans = time.time()
18381838
else:
1839-
ans = 0
1839+
ans = time.time()
18401840

18411841
# x_local = column(self._signals.values(), 2)
18421842
# ans = max(max(x_local), ans)
@@ -1872,7 +1872,7 @@ def getSignalInfo(self, sigID, database=True):
18721872
if xmin != [] and xmin is not None:
18731873
xmin = xmin[0][0]
18741874
else:
1875-
xmin = 0
1875+
xmin = time.time()
18761876

18771877
xmax = self._execute_n_fetchall(
18781878
"select X[array_upper(X,1)] from "+SIGNAL_TABLE_NAME+" where ID = "+str(sigID))

RTOC/RTLogger/telegramBot.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,6 @@ def signalsHandlerAns(self, bot, chat_id, strung):
896896
self.signals_range[chat_id] = []
897897
self.menuHandler(bot, chat_id)
898898
else:
899-
a = strung.split('.')
900899
units = self.logger.database.getUniqueUnits()
901900
multiSelectorList = []
902901
for unit in units:
@@ -911,7 +910,7 @@ def signalsHandlerAns(self, bot, chat_id, strung):
911910
# pass
912911
plot_signals.append(sig)
913912
else:
914-
names = sig.split('.')
913+
names = self.str2signal(sig)
915914
sigID = self.logger.database.getSignalID(names[0], names[1])
916915
if sigID != -1:
917916
plot_signals.append(sig)
@@ -966,7 +965,7 @@ def signalsHandlerAns(self, bot, chat_id, strung):
966965
xmin, xmax = self.signals_range[chat_id]
967966
for sigName in self.signals_selected[chat_id]:
968967
if sigName != 'Events':
969-
sigID = self.logger.database.getSignalID(*sigName.split('.'))
968+
sigID = self.logger.database.getSignalID(*self.str2signal(sigName))
970969
if sigID != -1:
971970
self.logger.database.removeSignal(sigID, xmin, xmax, True)
972971
self.signals_selected[chat_id] = []
@@ -976,7 +975,7 @@ def signalsHandlerAns(self, bot, chat_id, strung):
976975
xmin, xmax = self.signals_range[chat_id]
977976
for sigName in self.signals_selected[chat_id]:
978977
if sigName != 'Events':
979-
sigID = self.logger.database.getSignalID(*sigName.split('.'))
978+
sigID = self.logger.database.getSignalID(*self.str2signal(sigName))
980979
if sigID != -1:
981980
self.logger.database.removeEvents(sigID, xmin, xmax, True)
982981
self.send_message(chat_id=chat_id,
@@ -1004,7 +1003,7 @@ def signalsHandlerAns(self, bot, chat_id, strung):
10041003
self.send_message(chat_id=chat_id,
10051004
text=translate('RTOC', 'I\'m collecting the data now...'))
10061005
sigIDs = [self.logger.database.getSignalID(
1007-
*i.split('.')) for i in self.signals_selected[chat_id]]
1006+
*self.str2signal(i)) for i in self.signals_selected[chat_id]]
10081007
xmin, xmax = self.signals_range[chat_id]
10091008
dir = self.logger.config['global']['documentfolder']
10101009
self.logger.database.signalsToCSV(
@@ -1056,11 +1055,20 @@ def signalsDeviceSubHandlerAns(self, bot, chat_id, strung):
10561055
device = self.telegram_clients[str(chat_id)]['menu'].split(':')[0]
10571056
self.signalsDeviceSubHandler(bot, chat_id, device)
10581057

1058+
def str2signal(self, strung):
1059+
a = strung.split('.')
1060+
if len(a)>2:
1061+
# b=['.'.join(a[:-1]),a[-1]]
1062+
b=[a[0],'.'.join(a[1:])]
1063+
return b
1064+
elif len(a) == 2:
1065+
return a
1066+
10591067
def selectSignal(self, bot, chat_id, strung):
10601068
a = strung.split('.')
10611069
if len(a)>2:
10621070
self.send_message(chat_id, translate('RTOC', 'Please rename this signal. Signals should not contain "." and ":".'))
1063-
b=['.'.join(a[:-2]),a[-1]]
1071+
b=['.'.join(a[:-1]),a[-1]]
10641072
self.selectSignal2(bot, chat_id, strung, b)
10651073
b=[a[0],'.'.join(a[1:])]
10661074
self.selectSignal2(bot, chat_id, strung, b)
@@ -1069,10 +1077,11 @@ def selectSignal(self, bot, chat_id, strung):
10691077

10701078

10711079
def selectSignal2(self, bot, chat_id, strung, a):
1072-
a = strung.split('.')
10731080
if len(a) == 2:
10741081
if strung not in self.signals_selected[chat_id]:
10751082
sigID = self.logger.database.getSignalID(a[0], a[1])
1083+
if sigID == -1:
1084+
return
10761085
xmin, xmax, sigLen = self.logger.database.getSignalInfo(sigID)
10771086
if xmin != None:
10781087
self.signals_selected[chat_id].append(strung)
@@ -1754,7 +1763,8 @@ def sendSignalPlot(self, bot, chat_id, signalnames, xmin_plot, xmax_plot):
17541763
maxLen = 0
17551764

17561765
for idx, signalname in enumerate(signalnames):
1757-
a = signalname.split('.')
1766+
# a = signalname.split('.')
1767+
a = self.str2signal(signalname)
17581768
signal = self.logger.database.getSignal_byName(
17591769
a[0], a[1], xmin=xmin_plot, xmax=xmax_plot, database=True, maxN=1000)
17601770
# bot.send_chat_action(chat_id=chat_id,

RTOC/locales/de_de.qm

147 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)