def showData(self, data: Data): """ To show data if this module start standalone """ if data.source_name == self.ME_NAME + '/Skeleton': person = data.data #Points of skeleton aux = data.strToJSon(data.aux) h = int(Misc.hasKey(aux, 'H', self.ME_CONFIG['FRAME_HEIGHT'])) w = int(Misc.hasKey(aux, 'W', self.ME_CONFIG['FRAME_WIDTH'])) rgbImage = np.zeros((h, w, 3), np.uint8) for idj, join in enumerate(person): if join[0] != None: cv2.circle(rgbImage, (join[0], join[1]), 5, self.colors[idj], thickness=-1) elif data.source_name == self.ME_NAME + '/Person': rgbImage = np.zeros((data.data.shape[0], data.data.shape[1], 3), dtype=np.uint8) rgbImage[:, :, 0] = np.where(data.data[:, :] == 1, 255, 0) rgbImage[:, :, 1] = np.where(data.data[:, :] == 1, 255, 0) rgbImage[:, :, 2] = np.where(data.data[:, :] == 1, 255, 0) else: rgbImage = data.data # For capture the image in RGB color space # Display the resulting frame cv2.imshow(data.source_name + '-' + data.source_item, cv2.cvtColor(rgbImage, cv2.COLOR_BGR2RGB)) if cv2.waitKey(1) & 0xFF == ord('q'): self.stop() cv2.destroyAllWindows()
def predict(self, data: Data): """ Exec prediction to recognize an activity """ dataReturn = [] d = data.strToJSon(data.aux) if Misc.hasKey(d, 'time', '') == '' or Misc.hasKey(d, 'event', '') == '': return dataReturn time_event = d['time'] event = d['event'] auxData = '{' + '"time":"{}", "event":"{}"'.format(time_event, event) + '}' dataSimulated = Data() dataSimulated.source_name = self.ME_NAME dataSimulated.source_type = SourceTypes.RECOGNIZER dataSimulated.source_item = event dataSimulated.data = {'class': event, 'acc': 1.0} dataSimulated.aux = auxData dataReturn.append(dataSimulated) return dataReturn
def putMessagePool(self, data: Data): """ Put new messages into pool to send then """ try: d = Dispatch() d.tokens = {} d.tickets = [] d.events = [] d.alerts = [] d.files = [] d.alerts.append(data) dataRecognizer = [] auxAnalyzer = data.strToJSon(data.aux) filterRecognizer = Data() filterRecognizer.id = '' filterRecognizer.package = Misc.hasKey(auxAnalyzer, 'source_package', '-') filterRecognizer.source_type = SourceTypes.RECOGNIZER dataRecognizer = self.COMMPOOL.receive(data=filterRecognizer, limit=-1, lastTime=0, onlyActive=False) if len(dataRecognizer) == 0: return event = Data() for ev in dataRecognizer[1:]: #event = Data().fromDict(ev) d.events.append(ev) packages = [] for ev in d.events: if not ev.package in packages: packages.append(ev.package) for pck in packages: dataController = [] filterController = Data() filterController.id = '' filterController.package = pck filterController.source_type = SourceTypes.CONTROLLER dataController = self.COMMPOOL.receive(data=filterController, limit=-1, lastTime=0, onlyActive=False) for ticket in dataController[1:]: d.tickets.append(ticket) for attallow in self.authoraizedAttachments: attsallow = attallow.split(':') if len(attsallow) == 3 and \ (attsallow[0] == '*' or SourceTypes.parse(attsallow[0]) == ticket.source_type) and \ (attsallow[1] == '*' or attsallow[1] == ticket.source_name) and \ (attsallow[2] == '*' or attsallow[2] == ticket.source_item): f = ticket.toFile(path="./" + self.ANALYZER_PATH) if f != '': d.files.append(f) # Tokens list t_s = time() - (5 * 60 * 60) data.born -= (5 * 60 * 60) d.tokens['server_time'] = t_s d.tokens['server_time_human'] = Misc.timeToString(t_s, '%H:%M') d.tokens['analyzer_source_name'] = data.source_name d.tokens['analysis_time'] = data.born d.tokens['analysis_time_human'] = Misc.timeToString( data.born, '%H:%M') d.tokens['analysis_data'] = data.data d.tokens['analysis_aux'] = data.aux d.tokens['analysis_id'] = data.id d.tokens['event_data'] = data.data if len( d.events) == 0 else d.events[0].source_item d.tokens['recognizer_source_id'] = '' if len( d.events) == 0 else ','.join([str(x.id) for x in d.events]) d.tokens['recognizer_source_id_0'] = '' if len( d.events) == 0 else d.events[0].id if len(d.events) > 0 else '' d.tokens['recognizer_source_id_1'] = '' if len( d.events) == 0 else d.events[1].id if len(d.events) > 1 else '' d.tokens['recognizer_source_id_2'] = '' if len( d.events) == 0 else d.events[2].id if len(d.events) > 2 else '' d.tokens['recognizer_source_name'] = '' if len( d.events) == 0 else ','.join( [str(x.source_name) for x in d.events]) d.tokens['recognizer_source_name_0'] = '' if len( d.events) == 0 else d.events[0].source_name if len( d.events) > 0 else '' d.tokens['recognizer_source_name_1'] = '' if len( d.events) == 0 else d.events[1].source_name if len( d.events) > 1 else '' d.tokens['recognizer_source_name_2'] = '' if len( d.events) == 0 else d.events[2].source_name if len( d.events) > 2 else '' d.tokens['recognizer_source_item'] = '' if len( d.events) == 0 else ','.join( [str(x.source_item) for x in d.events]) d.tokens['recognizer_source_item_0'] = '' if len( d.events) == 0 else d.events[0].source_item if len( d.events) > 0 else '' d.tokens['recognizer_source_item_1'] = '' if len( d.events) == 0 else d.events[1].source_item if len( d.events) > 1 else '' d.tokens['recognizer_source_item_2'] = '' if len( d.events) == 0 else d.events[2].source_item if len( d.events) > 2 else '' d.tokens['controller_source_id'] = '' if len( d.tickets) == 0 else ','.join([str(x.id) for x in d.tickets]) d.tokens['controller_source_id_0'] = '' if len( d.tickets) == 0 else d.tickets[0].id if len( d.tickets) > 0 else '' d.tokens['controller_source_id_1'] = '' if len( d.tickets) == 0 else d.tickets[1].id if len( d.tickets) > 1 else '' d.tokens['controller_source_id_2'] = '' if len( d.tickets) == 0 else d.tickets[2].id if len( d.tickets) > 2 else '' d.tokens['controller_source_name'] = '' if len( d.tickets) == 0 else ','.join( [str(x.source_name) for x in d.tickets]) d.tokens['controller_source_name_0'] = '' if len( d.tickets) == 0 else d.tickets[0].source_name if len( d.tickets) > 0 else '' d.tokens['controller_source_name_1'] = '' if len( d.tickets) == 0 else d.tickets[1].source_name if len( d.tickets) > 1 else '' d.tokens['controller_source_name_2'] = '' if len( d.tickets) == 0 else d.tickets[2].source_name if len( d.tickets) > 2 else '' d.tokens['controller_source_item'] = '' if len( d.tickets) == 0 else ','.join( [str(x.source_item) for x in d.tickets]) d.tokens['controller_source_item_0'] = '' if len( d.tickets) == 0 else d.tickets[0].source_item if len( d.tickets) > 0 else '' d.tokens['controller_source_item_1'] = '' if len( d.tickets) == 0 else d.tickets[1].source_item if len( d.tickets) > 1 else '' d.tokens['controller_source_item_2'] = '' if len( d.tickets) == 0 else d.tickets[2].source_item if len( d.tickets) > 2 else '' event_time = d.tokens['analysis_time_human'] if len(d.events) > 0: aux_event0 = d.events[0].strToJSon(d.events[0].aux) if Misc.hasKey(aux_event0, 'source_aux', '') != '': event_time = aux_event0['source_aux']['time'] event_time = datetime.strptime(event_time, '%Y-%m-%d %H:%M:%S') event_time = event_time.timestamp() event_time -= (5 * 60 * 60) event_time = Misc.timeToString(event_time, '%H:%M') d.tokens['analysis_phrase'] = 'At ' + event_time d.tokens['analysis_phrase'] += ' some ' + data.data d.tokens['analysis_phrase'] = d.tokens['analysis_phrase'] if len( d.events ) == 0 else d.tokens['analysis_phrase'] + ' with ' + str( round(d.events[0].data['acc'] * 100, 2)) + '% of accuracy was detected' d.tokens['analysis_phrase'] = d.tokens['analysis_phrase'] if len( d.events) == 0 else d.tokens[ 'analysis_phrase'] + ' by ' + d.events[0].source_name d.tokens['analysis_phrase'] += '.' for c in self.channels: chnl = self.channels[c] if chnl.ENABLED: if len( self.authoraizedChannels ) > 0 and chnl.ME_NAME not in self.authoraizedChannels: continue # Skip not authorized channels msg = d.copy() msg.to = Misc.hasKey(chnl.ME_CONFIG, 'TO', '') msg.message = Misc.hasKey(chnl.ME_CONFIG, 'MESSAGE', '') crr = Carrier(msg, chnl) crr.message.message = crr.message.replace_tokens( crr.message.message) existsCarrier = False for crrDis in self.POOL_DISPATCHES: if crrDis.equals(crr): existsCarrier = True break if not existsCarrier: self.POOL_DISPATCHES.append(crr) except: dataE = Data() dataE.source_type = SourceTypes.ANALYZER dataE.source_name = 'LoaderOfChannel' dataE.source_item = '' dataE.data = self.COMMPOOL.errorDetail( Messages.channel_error_put_msg) dataE.aux = '' self.COMMPOOL.logFromCore(dataE, LogTypes.ERROR, self.__class__.__name__)