Exemplo n.º 1
0
    def event_handler(self, event):
        try:
            logger.debug("event type: %s", event.type)
            if event.type == "Left Object Detected":
                channel = getattr(event.origin_object, "associated_channel",
                                  None)
            else:
                channel = event.origin
            logger.debug("channel: %s", channel)
            channel = channel.split("_")[0]

            if not self.check_channel(channel):
                logger.debug("channel %s not in channels list, return",
                             channel)
                return

            channel_obj = self.obj_storage.channels.get(channel)
            if not channel_obj:
                logger.debug("channel object not found: %s, return", channel)
                return
            channel_full = channel_obj.full_guid
            server_guid = channel_obj.server

            ts = event.ts - utc_offset(server_guid) * 60 * 1e6
            dt = BaseUtils.ts_to_dt(ts)

            logger.debug(
                "Trassir timestamp: %s, Trassir dt is : %s, corrected dt: %s",
                event.ts,
                BaseUtils.ts_to_dt(event.ts),
                dt,
            )

            alarm_messages = None
            if getattr(event, "data", None):
                alarm_messages = json.loads(getattr(
                    event, "data")).get("alarm_messages")
                logger.debug("alarm message in data")

            if not alarm_messages:
                alarm_messages = make_alarm_message(channel_obj.name, dt,
                                                    event.type)
            if event.type == "Plate detected":
                ts = event.ts

            if self.callback:
                self.callback(channel_full, ts, alarm_messages)

        except Exception as err:
            logger.exception("simple_events_handler: error occurred: %s", err)
Exemplo n.º 2
0
    def event_handler(self, event):
        channel_full = "{channel}_{server}".format(channel=event.channel_guid,
                                                   server=event.server_guid)
        channel = event.channel_guid

        channel_obj = self.obj_storage.channels.get(event.channel_guid)
        if not channel_obj:
            logger.debug("channel object not found: %s, return",
                         event.channel_guid)
            return

        exceed = self._search_exceeding(self._objects_sum(event.zones))
        events = []
        for zone_id, exceed_by_type in exceed.iteritems():
            for _type, count in exceed_by_type.iteritems():
                event_data = {channel_full: {zone_id: {_type: count}}}
                if not self.same_event_filter.is_same(event_data):
                    event_type = EVENTS_TRANSLATION.get(
                        EVENTS_TYPES.get(_type), "Unknown")
                    alarm_messages = make_alarm_message(
                        channel_obj.name, BaseUtils.ts_to_dt(event.event_ts),
                        event_type, zone_id)
                    events.append((channel_full, event.event_ts,
                                   alarm_messages, zone_id))

        if self.callback:
            for event in events:
                channel_full, event_ts, alarm_messages, zone_name = event
                self.callback(channel_full,
                              event_ts,
                              alarm_messages,
                              zone_name=zone_name)
Exemplo n.º 3
0
    def open_archive(self, channel, tmstmp):
        logger.debug("Start show archive, channel is: %s, tmstmp: %s", channel,
                     tmstmp)
        ts_start = BaseUtils.ts_to_dt(tmstmp) - timedelta(seconds=5)
        ts_end = BaseUtils.ts_to_dt(tmstmp)

        start_str = ts_start.strftime("%Y%m%d_%H%M%S")
        end_str = ts_end.strftime("%Y%m%d_%H%M%S")
        logger.debug("open_arhive - chan: %s, mon: %s, start: %s, end: %s",
                     channel, self.monitor_to_show_archive_from_popup,
                     start_str, end_str)
        try:
            self._gui.show_archive(  # pylint:disable=E1101
                channel, self.monitor_to_show_archive_from_popup, start_str,
                end_str)
        except EnvironmentError as err:
            logger.debug("Can't show archive. Error occur: %s", err)
Exemplo n.º 4
0
def make_alarm_message(channel_name, tmstmp, event_type):

    event_name = "{}".format(event_type)
    event_time = BaseUtils.ts_to_dt(tmstmp)
    dt = event_time.strftime("%d-%m-%Y %H:%M:%S")

    alarm_messages = {
        name: _frmt.format(
            event_time=dt,
            text_1=loc.gate.pacs_gate_event,
            event_name=event_name,
            text2=loc.gate.channel,
            channel_name=channel_name,
        )
        for name, _frmt in all_formats.iteritems()
    }
    return alarm_messages
Exemplo n.º 5
0
    def event_handler(self, event):

        channel_full = "{channel}_{server}".format(channel=event.channel_guid,
                                                   server=event.server_guid)
        channel = event.channel_guid

        channel_obj = self.obj_storage.channels.get(event.channel_guid)
        if not channel_obj:
            logger.debug("channel object not found: %s, return",
                         event.channel_guid)
            return

        events = []

        for zone in event.zones:
            if zone.zone_type != 1:
                continue
            border_name = getattr(zone, "zone_name",
                                  getattr(zone, "name", None))

            if self.ab_borders:
                a_to_b = zone.tracking_state.a_to_b_unique_count_by_classes
                _types_a_b = self.ab_handler(a_to_b, channel, border_name)
                if _types_a_b:
                    for _type in _types_a_b:
                        event_data = {channel_full: {border_name: {_type: 0}}}
                        if not self.same_event_filter.is_same(event_data):
                            event_type = "{direction}: {object_type}".format(
                                direction=EVENTS_TRANSLATION.get(
                                    "Border Crossed A -> B"),
                                object_type=OBJECT_TYPES_TRANSLATION.get(
                                    _type),
                            )
                            alarm_messages = make_alarm_message(
                                channel_obj.name,
                                BaseUtils.ts_to_dt(event.event_ts),
                                event_type,
                                border_name,
                            )
                            events.append(
                                (channel_full, event.event_ts, alarm_messages))

            if self.ba_borders:
                b_to_a = zone.tracking_state.b_to_a_unique_count_by_classes
                _types_b_a = self.ba_handler(b_to_a, channel, border_name)
                if _types_b_a:
                    for _type in _types_b_a:
                        event_data = {channel_full: {border_name: {_type: 0}}}
                        if not self.same_event_filter.is_same(event_data):
                            event_type = "{direction}: {object_type}".format(
                                direction=EVENTS_TRANSLATION.get(
                                    "Border Crossed B -> A"),
                                object_type=OBJECT_TYPES_TRANSLATION.get(
                                    _type),
                            )
                            alarm_messages = make_alarm_message(
                                channel_obj.name,
                                BaseUtils.ts_to_dt(event.event_ts),
                                event_type,
                                border_name,
                            )
                            events.append(
                                (channel_full, event.event_ts, alarm_messages))

        if self.callback and events:
            for event in events:
                self.callback(*event)