Exemplo n.º 1
0
        def build_event_info(self, event_xml):
            e_id = event.get_event_id(event_xml)
            e_mod_num = event.get_mod_number(event_xml)
            e_status = event.get_status(event_xml)

            # TODO get target & resource info
            event_start_dttm = event.get_active_period_start(event_xml)
            event_start_dttm = schedule.dttm_to_str(event_start_dttm)
            signals = event.get_signals(event_xml)

            # get start/end time
            start_at = event_xml.findtext(
                'ei:eiActivePeriod/xcal:properties/xcal:dtstart/xcal:date-time',
                namespaces=event.NS_A)
            start_at = schedule.str_to_datetime(start_at)
            duration = event_xml.findtext(
                'ei:eiActivePeriod/xcal:properties/xcal:duration/xcal:duration',
                namespaces=event.NS_A)
            start_at, end_at = schedule.durations_to_dates(start_at, [duration])
            
            event_info = {
                    "id"      	: e_id,
                    "mod_num" 	: e_mod_num,
                    "status"  	: e_status,
                    "start_at"	: start_at.strftime("%Y-%m-%d %H:%M:%S"),
                    "end_at"	: end_at.strftime("%Y-%m-%d %H:%M:%S"),
                    }
            if signals: event_info["signals"] = signals
            
            return event_info
Exemplo n.º 2
0
        def build_event_info(self, event_xml):
            e_id = event.get_event_id(event_xml)
            e_mod_num = event.get_mod_number(event_xml)
            e_status = event.get_status(event_xml)

            # TODO get target & resource info
            event_start_dttm = event.get_active_period_start(event_xml)
            event_start_dttm = schedule.dttm_to_str(event_start_dttm)
            signals = event.get_signals(event_xml)

            # get start/end time
            start_at = event_xml.findtext(
                'ei:eiActivePeriod/xcal:properties/xcal:dtstart/xcal:date-time',
                namespaces=event.NS_A)
            start_at = schedule.str_to_datetime(start_at)
            duration = event_xml.findtext(
                'ei:eiActivePeriod/xcal:properties/xcal:duration/xcal:duration',
                namespaces=event.NS_A)
            start_at, end_at = schedule.durations_to_dates(
                start_at, [duration])

            event_info = {
                "id": e_id,
                "mod_num": e_mod_num,
                "status": e_status,
                "start_at": start_at.strftime("%Y-%m-%d %H:%M:%S"),
                "end_at": end_at.strftime("%Y-%m-%d %H:%M:%S"),
            }
            if signals: event_info["signals"] = signals

            return event_info
Exemplo n.º 3
0
    def _calculate_current_event_status(self, events):
        '''
        returns a 3-tuple of (current_signal_level, current_event_id, remove_events=[])
        '''

        highest_signal_val = 0
        current_event_id = None
        remove_events = []  # to collect expired events

        for e in events:
            try:
                e_id = event.get_event_id(e, self.event_handler.ns_map)
                e_mod_num = event.get_mod_number(e, self.event_handler.ns_map)
                e_status = event.get_status(e, self.event_handler.ns_map)

                if not self.event_handler.check_target_info(e):
                    logging.debug("Ignoring event %s - no target match", e_id)
                    continue

                event_start_dttm = event.get_active_period_start(e, self.event_handler.ns_map)
                signals = event.get_signals(e, self.event_handler.ns_map)

                if signals is None:
                    logging.debug("Ignoring event %s - no valid signals", e_id)
                    continue

                logging.debug("All signals: %r", signals)
                intervals = [s[0] for s in signals]
                current_interval = schedule.choose_interval( event_start_dttm, intervals )

                if current_interval is None:
                    logging.debug("Event %s(%d) has ended", e_id, e_mod_num)
                    remove_events.append(e_id)
                    continue

                if current_interval < 0:
                    logging.debug("Event %s(%d) has not started yet.", e_id, e_mod_num)
                    continue

                logging.debug('---------- chose interval %d', current_interval)
                _, interval_uid, signal_level = signals[current_interval]
#                signal_level = event.get_current_signal_value(e, self.event_handler.ns_map)

                logging.debug('Control loop: Evt ID: %s(%s); Interval: %s; Current Signal: %s',
                        e_id, e_mod_num, interval_uid, signal_level )
                
                signal_level = float(signal_level) if signal_level is not None else 0

                if signal_level > highest_signal_val:
                    highest_signal_val = signal_level
                    current_event_id = e_id

            except Exception as e:
                logging.exception("Error parsing event: %s", e)

        return highest_signal_val, current_event_id, remove_events
Exemplo n.º 4
0
    def _calculate_current_event_status(self, events):
        '''
        returns a 3-tuple of (current_signal_level, current_event_id, remove_events=[])
        '''

        highest_signal_val = 0
        current_event_id = None
        remove_events = []  # to collect expired events

        for e in events:
            try:
                e_id = event.get_event_id(e, self.event_handler.ns_map)
                e_mod_num = event.get_mod_number(e, self.event_handler.ns_map)
                e_status = event.get_status(e, self.event_handler.ns_map)

                if not self.event_handler.check_target_info(e):
                    logging.debug("Ignoring event %s - no target match", e_id)
                    continue

                event_start_dttm = event.get_active_period_start(
                    e, self.event_handler.ns_map)
                signals = event.get_signals(e, self.event_handler.ns_map)

                if signals is None:
                    logging.debug("Ignoring event %s - no valid signals", e_id)
                    continue

                logging.debug("All signals: %r", signals)
                intervals = [s[0] for s in signals]
                current_interval = schedule.choose_interval(
                    event_start_dttm, intervals)

                if current_interval is None:
                    logging.debug("Event %s(%d) has ended", e_id, e_mod_num)
                    remove_events.append(e_id)
                    continue

                if current_interval < 0:
                    logging.debug("Event %s(%d) has not started yet.", e_id,
                                  e_mod_num)
                    continue

                logging.debug('---------- chose interval %d', current_interval)
                _, interval_uid, signal_level = signals[current_interval]
                #                signal_level = event.get_current_signal_value(e, self.event_handler.ns_map)

                logging.debug(
                    'Control loop: Evt ID: %s(%s); Interval: %s; Current Signal: %s',
                    e_id, e_mod_num, interval_uid, signal_level)

                signal_level = float(
                    signal_level) if signal_level is not None else 0

                if signal_level > highest_signal_val:
                    highest_signal_val = signal_level
                    current_event_id = e_id

            except Exception as e:
                logging.exception("Error parsing event: %s", e)

        return highest_signal_val, current_event_id, remove_events