Esempio n. 1
0
    def getq(self):
        '''
		Reads data from the queue and updates the stream.

		:rtype: bool
		:return: Returns ``True`` if stream is updated, otherwise ``False``.
		'''
        d = self.queue.get(True, timeout=None)
        self.queue.task_done()
        if 'TERM' in str(d):
            self.alive = False
            printM('Exiting.', self.sender)
            sys.exit()
        elif str(d.decode('UTF-8')).split(' ')[0] in [
                'ALARM', 'RESET', 'IMGPATH'
        ]:
            pass
        else:
            if rs.getCHN(d) in self.chans:
                self.stream = rs.update_stream(stream=self.stream,
                                               d=d,
                                               fill_value=None)
                return True
            else:
                return False
Esempio n. 2
0
    def _getd(self):
        '''
		Reads data from the queue and updates the stream.
		'''
        d = self._getq()

        if rs.getCHN(d) in self.cha:
            self.stream = rs.update_stream(stream=self.stream,
                                           d=d,
                                           fill_value='latest')
        else:
            self._messagetests(d)
Esempio n. 3
0
    def getq(self):
        '''
		Get data from the queue and test for whether it has certain strings.
		ALARM and TERM both trigger specific behavior.
		ALARM messages cause the event counter to increment, and if
		:py:data:`screencap==True` then aplot image will be saved when the
		event is :py:data:`self.save_pct` of the way across the plot.
		'''
        d = self.queue.get()
        self.queue.task_done()
        if 'TERM' in str(d):
            plt.close()
            if 'SELF' in str(d):
                printM('Plot has been closed, plot thread will exit.',
                       self.sender)
            self.alive = False
            rs.producer = False

        elif 'ALARM' in str(d):
            self.events += 1  # add event to count
            self.save_timer -= 1  # don't push the save time forward if there are a large number of alarm events
            event = [
                self.save_timer + int(self.save_pct * self.pkts_in_period),
                helpers.fsec(helpers.get_msg_time(d))
            ]  # event = [save after count, datetime]
            self.last_event_str = '%s UTC' % (
                event[1].strftime('%Y-%m-%d %H:%M:%S.%f')[:22])
            printM('Event time: %s' % (self.last_event_str),
                   sender=self.sender)  # show event time in the logs
            if self.screencap:
                printM(
                    'Saving png in about %i seconds' %
                    (self.save_pct * (self.seconds)), self.sender)
                self.save.append(event)  # append
            self.fig.suptitle(
                '%s.%s live output - detected events: %s'  # title
                % (self.net, self.stn, self.events),
                fontsize=14,
                color=self.fgcolor,
                x=0.52)
            self.fig.canvas.set_window_title(
                '(%s) %s.%s - Raspberry Shake Monitor' %
                (self.events, self.net, self.stn))

        if rs.getCHN(d) in self.chans:
            self.raw = rs.update_stream(stream=self.raw,
                                        d=d,
                                        fill_value='latest')
            return True
        else:
            return False
Esempio n. 4
0
 def _getq(self):
     d = self.queue.get(True, timeout=None)
     self.queue.task_done()
     if self.cha in str(d):
         self.raw = RS.update_stream(stream=self.raw,
                                     d=d,
                                     fill_value='latest')
         return True
     elif 'TERM' in str(d):
         self.alive = False
         printM('Exiting.', self.sender)
         sys.exit()
     else:
         return False
Esempio n. 5
0
    def _datatests(self, d):
        '''
		Run tests on a data packet to see if it can be processed into a stream object.
		If so, mark the data and processing tests passed.

		:param bytes d: a data packet from the queue

		'''

        if rs.getCHN(d) in self.cha:
            t.TEST['c_data'][1] = True
            self.stream = rs.update_stream(stream=self.stream,
                                           d=d,
                                           fill_value='latest')
            t.TEST['c_processing'][1] = True
Esempio n. 6
0
    def getq(self):
        d = self.queue.get()
        self.queue.task_done()
        if 'TERM' in str(d):
            plt.close()
            if 'SELF' in str(d):
                print()
                printM('Plot has been closed, plot thread will exit.',
                       self.sender)
            self.alive = False
            RS.producer = False

        elif 'ALARM' in str(d):
            self.events += 1  # add event to count
            self.save_timer -= 1  # don't push the save time forward if there are a large number of alarm events
            event = [
                self.save_timer + int(self.save_pct * self.pkts_in_period),
                RS.UTCDateTime.strptime(d.decode('utf-8'),
                                        'ALARM %Y-%m-%dT%H:%M:%S.%fZ')
            ]  # event = [save after count, datetime]
            self.last_event_str = event[1].strftime('%Y-%m-%d %H:%M:%S UTC')
            printM('Event time: %s' % (self.last_event_str),
                   self.sender)  # show event time in the logs
            if self.screencap:
                print()
                printM(
                    'Saving png in about %i seconds' %
                    (self.save_pct * (self.seconds)), self.sender)
                self.save.append(event)  # append
            self.fig.suptitle(
                '%s.%s live output - detected events: %s'  # title
                % (self.net, self.stn, self.events),
                fontsize=14,
                color=self.fgcolor,
                x=0.52)
            self.fig.canvas.set_window_title(
                '(%s) %s.%s - Raspberry Shake Monitor' %
                (self.events, self.net, self.stn))

        if RS.getCHN(d) in self.chans:
            self.raw = RS.update_stream(stream=self.raw,
                                        d=d,
                                        fill_value='latest')
            return True
        else:
            return False
Esempio n. 7
0
 def getq(self):
     d = self.queue.get(True, timeout=None)
     self.queue.task_done()
     if 'TERM' in str(d):
         self.alive = False
         printM('Exiting.', self.sender)
         sys.exit()
     elif 'ALARM' in str(d):
         pass
     else:
         if RS.getCHN(d) in self.chans:
             self.stream = RS.update_stream(stream=self.stream,
                                            d=d,
                                            fill_value=None)
             return True
         else:
             return False
Esempio n. 8
0
	def _getq(self):
		'''
		Reads data from the queue and updates the stream.

		:rtype: bool
		:return: Returns ``True`` if stream is updated, otherwise ``False``.
		'''
		d = self.queue.get(True, timeout=None)
		self.queue.task_done()
		if self.cha in str(d):
			self.raw = rs.update_stream(stream=self.raw, d=d, fill_value='latest')
			return True
		elif 'TERM' in str(d):
			self.alive = False
			printM('Exiting.', self.sender)
			sys.exit()
		else:
			return False