def run(self, cur_time, points):
        """
        Check application pre-quisites and assemble analysis data set.
        Receives mapped data from the DrivenBaseClass.  Filters non-relevent
        data and assembles analysis data set for diagnostics.
        """
        # topics = self.inp.get_topics()
        # diagnostic_topic = topics[self.fan_status_name][0]
        # cur_time = self.inp.localize_sensor_time(diagnostic_topic, current_time)
        to_zone = dateutil.tz.gettz(self.cur_tz)
        cur_time = cur_time.astimezone(to_zone)

        device_dict = {}
        dx_result = Results()

        for key, value in points.items():
            point_device = [_name.lower() for _name in key.split("&")]
            if point_device[0] not in device_dict:
                device_dict[point_device[0]] = [(point_device[1], value)]
            else:
                device_dict[point_device[0]].append((point_device[1], value))

        fan_status_data = []
        stc_pr_data = []
        fan_sp_data = []

        for key, value in device_dict.items():
            data_name = key
            if value is None:
                continue
            if data_name == self.fan_status_name:
                fan_status_data = data_builder(value, data_name)
            elif data_name == self.duct_stcpr_name:
                stc_pr_data = data_builder(value, data_name)
            elif data_name == self.fan_sp_name:
                fan_sp_data = data_builder(value, data_name)

        missing_data = []
        if not fan_status_data and not fan_sp_data:
            missing_data.append(self.fan_status_name)
        if not stc_pr_data:
            missing_data.append(self.duct_stcpr_name)

        if missing_data:
            dx_result.log("Missing data from publish: {}".format(missing_data))
            return dx_result

        current_fan_status, fan_sp = self.check_fan_status(
            fan_status_data, fan_sp_data, cur_time)

        dx_result = self.sched_aircx.sched_aircx(cur_time, stc_pr_data,
                                                 current_fan_status, dx_result)

        return dx_result
    def run(self, cur_time, points):
        """
        Check application pre-quisites and assemble analysis data set.
        Receives mapped data from the DrivenBaseClass.  Filters non-relevent
        data and assembles analysis data set for diagnostics.
        """
        # topics = self.inp.get_topics()
        # diagnostic_topic = topics[self.fan_status_name][0]
        # cur_time = self.inp.localize_sensor_time(diagnostic_topic, current_time)
        to_zone = dateutil.tz.gettz(self.cur_tz)
        cur_time = cur_time.astimezone(to_zone)

        device_dict = {}
        dx_result = Results()

        for key, value in points.items():
            point_device = [_name.lower() for _name in key.split("&")]
            if point_device[0] not in device_dict:
                device_dict[point_device[0]] = [(point_device[1], value)]
            else:
                device_dict[point_device[0]].append((point_device[1], value))

        fan_status_data = []
        stc_pr_data = []
        fan_sp_data = []

        for key, value in device_dict.items():
            data_name = key
            if value is None:
                continue
            if data_name == self.fan_status_name:
                fan_status_data = data_builder(value, data_name)
            elif data_name == self.duct_stcpr_name:
                stc_pr_data = data_builder(value, data_name)
            elif data_name == self.fan_sp_name:
                fan_sp_data = data_builder(value, data_name)

        missing_data = []
        if not fan_status_data and not fan_sp_data:
            missing_data.append(self.fan_status_name)
        if not stc_pr_data:
            missing_data.append(self.duct_stcpr_name)


        if missing_data:
            dx_result.log("Missing data from publish: {}".format(missing_data))
            return dx_result

        current_fan_status, fan_sp = self.check_fan_status(fan_status_data, fan_sp_data, cur_time)

        dx_result = self.sched_aircx.sched_aircx(cur_time, stc_pr_data, current_fan_status, dx_result)

        return dx_result
Beispiel #3
0
    def run(self, current_time, points):
        """
        Main method called by DrivenApplicationBaseClass.
        :param current_time:
        :param points:
        :return:
        """
        device_dict = {}
        diagnostic_result = Results()
        topics = self.inp.get_topics()
        diagnostic_topic = topics[self.zone_temp_name][0]
        to_zone = dateutil.tz.gettz(self.cur_tz)
        current_time = current_time.astimezone(to_zone)

        for key, value in points.items():
            device_dict[key.lower()] = value

        fan_stat_data = []
        zone_temp_data = []
        for key, value in device_dict.items():
            if key.startswith(self.fan_status_name) and value is not None:
                fan_stat_data.append(value)
            if key.startswith(self.zone_temp_name) and value is not None:
                zone_temp_data.append(value)

        if len(zone_temp_data) == 0:
            return diagnostic_result

        zn_temperature = (sum(zone_temp_data) / len(zone_temp_data))
        fan_status = sum(fan_stat_data) / len(
            fan_stat_data) if fan_stat_data else None

        diagnostic_result = self.setpoint_detector.on_new_data(
            current_time, fan_status, zn_temperature, diagnostic_result)
        return diagnostic_result
Beispiel #4
0
    def run(self, current_time, points):
        """
            Main run method that is called by the DrivenBaseClass.
            points ex: [{'zonetemp_1':72.0,'zonetemp_2':69.2}]
        """
        result = Results()
        topics = self.inp.get_topics()
        topic = topics[self.zone_temp_name][0]
        current_time = self.inp.localize_sensor_time(topic, current_time)

        out_data = {'datetime': str(current_time)}
        for zone_topic in self.zone_topics:
            if zone_topic in topics.keys():
                for i, topic in enumerate(topics[zone_topic], start=1):
                    topic_parts = topic.split('/')
                    zone = topic_parts[-2]  #the second last item
                    out_data[zone_topic + self.sep +
                             zone] = points[zone_topic + '_' + str(i)]

        result.insert_table_row(self.table_name, out_data)
        return result
Beispiel #5
0
    def run(self, current_time, points):
        """
            Main run method that is called by the DrivenBaseClass.
            points ex: [{'zonetemp_1':72.0,'zonetemp_2':69.2}]
        """
        result = Results()
        topics = self.inp.get_topics()
        topic = topics[self.zone_temp_name][0]
        current_time = self.inp.localize_sensor_time(topic, current_time)

        out_data = {
            'datetime': str(current_time)
        }
        for zone_topic in self.zone_topics:
            if zone_topic in topics.keys():
                for i, topic in enumerate(topics[zone_topic], start=1):
                    topic_parts = topic.split('/')
                    zone = topic_parts[-2] #the second last item
                    out_data[zone_topic + self.sep + zone] = points[zone_topic + '_' + str(i)]

        result.insert_table_row(self.table_name, out_data)
        return result
Beispiel #6
0
    def run(self, time, inputs):
        results = Results()

        if self.first:
            results.log('First Post!!!!11111ELEVENTY', logging.INFO)
            self.first = False

        inputs['time'] = time

        results.insert_table_row('output', inputs)

        self.counter += 1
        results.command('/awesome/counter', self.counter)

        return results
Beispiel #7
0
    def run(self, time, inputs):
        results = Results()

        if self.first:
            results.log("First Post!!!!11111ELEVENTY", logging.INFO)
            self.first = False

        inputs["time"] = time

        results.insert_table_row("output", inputs)

        self.counter += 1
        results.command("/awesome/counter", self.counter)

        return results
    def run(self, current_time, points):
        device_dict = {}
        diagnostic_result = Results()
        topics = self.inp.get_topics()
        diagnostic_topic = topics[self.zone_temp_name][0]
        to_zone = dateutil.tz.gettz(self.cur_tz)
        current_time = current_time.astimezone(to_zone)

        for key, value in points.items():
            device_dict[key.lower()] = value

        zone_temp_data = []
        for key, value in device_dict.items():
            if key.startswith(self.zone_temp_name) and value is not None:
                zone_temp_data.append(value)

        if len(zone_temp_data) == 0:
            return diagnostic_result

        zonetemp = (sum(zone_temp_data) / len(zone_temp_data))
        diagnostic_result = self.schedule_detector.on_new_data(current_time, zonetemp, diagnostic_result)

        return diagnostic_result
Beispiel #9
0
 def shutdown(self):
     results = Results()
     results.log("ARG!! I DIED!!", logging.INFO)
     return results
    def run(self, current_time, points):
        """
        Check application pre-quisites and assemble analysis data set.
        Receives mapped data from the DrivenBaseClass.  Filters non-relevent
        data and assembles analysis data set for diagnostics.
        """
        # topics = self.inp.get_topics()
        # diagnostic_topic = topics[self.fan_status_name][0])
        # cur_time = self.inp.localize_sensor_time(diagnostic_topic, current_time)
        to_zone = dateutil.tz.gettz(self.cur_tz)
        cur_time = current_time.astimezone(to_zone)
        device_dict = {}
        diagnostic_result = Results()
        fan_status_data = []
        supply_fan_off = False

        for key, value in points.items():
            point_device = [_name.lower() for _name in key.split('&&&')]
            print(point_device)
            if point_device[0] not in device_dict:
                device_dict[point_device[0]] = [(point_device[1], value)]
            else:
                device_dict[point_device[0]].append((point_device[1], value))

        if self.fan_status_name in device_dict:
            fan_status = device_dict[self.fan_status_name]
            fan_status = [point[1] for point in fan_status]
            fan_status = [status for status in fan_status if status is not None]
            if fan_status:
                fan_status_data.append(min(fan_status))
                if not int(fan_status_data[0]):
                    supply_fan_off = True
                    self.warm_up_flag = True

        if self.fan_speedcmd_name in device_dict:
            fan_speed = device_dict[self.fan_speedcmd_name]
            fan_speed = mean([point[1] for point in fan_speed])
            if self.fan_status_name is None:
                if not int(fan_speed):
                    supply_fan_off = True
                    self.warm_up_flag = True
                fan_status_data.append(bool(int(fan_speed)))


        zn_dmpr_data = []
        satemp_data = []
        rht_data = []
        sat_stpt_data = []

        def data_builder(value_tuple, point_name):
            value_list = []
            for item in value_tuple:
                value_list.append(item[1])
            return value_list

        for key, value in device_dict.items():
            data_name = key
            if value is None:
                continue
            elif data_name == self.sat_stpt_name:
                sat_stpt_data = data_builder(value, data_name)
            elif data_name == self.sa_temp_name:
                satemp_data = data_builder(value, data_name)
            elif data_name == self.zone_reheat_name:
                rht_data = data_builder(value, data_name)
            elif data_name == self.zone_damper_name:
                zn_dmpr_data = data_builder(value, data_name)

        missing_data = []
        if not satemp_data:
            missing_data.append(self.sa_temp_name)
        if not rht_data:
            missing_data.append(self.zone_reheat_name)
        if not sat_stpt_data:
            diagnostic_result.log('Supply-air temperature set point data is '
                                  'missing. This will limit the effectiveness of '
                                  'the supply-air temperature diagnostics.')
        if not zn_dmpr_data:
            missing_data.append(self.zone_damper_name)
        if not fan_status:
            missing_data.append(self.fan_status_name)
        if missing_data:
            diagnostic_result.log('Missing required data: {}'.format(missing_data))
            return diagnostic_result

        if supply_fan_off:
            diagnostic_result.log('Supply fan is off. Data will not be used for '
                                  'retuning diagnostics.')
            return diagnostic_result
        if self.warm_up_flag:
            self.warm_up_flag = False
            self.warm_up_start = cur_time
            return diagnostic_result
        time_check = td(minutes=self.warm_up_time)
        if self.warm_up_start is not None and (cur_time - self.warm_up_start) < time_check:
            diagnostic_result.log('Unit may be in warm-up. Data will not be analyzed.')
            return diagnostic_result
        dx_status, diagnostic_result = self.sat_dx.sat_rcx(cur_time, satemp_data, sat_stpt_data,
                                                           rht_data, zn_dmpr_data, diagnostic_result)
        return diagnostic_result
Beispiel #11
0
    def run(self,current_time,points):
        '''
        Check application pre-quisites and assemble data set for analysis.
        '''
        device_dict = {}
        diagnostic_result = Results()

        for key, value in points.items():
            device_dict[key.lower()] = value

        Application.pre_msg_time.append(current_time)
        message_check =  datetime.timedelta(minutes=(self.data_window))
 
        if (Application.pre_msg_time[-1]-Application.pre_msg_time[0]) >= message_check:
            msg_lst = [self.pre_msg0, self.pre_msg1, self.pre_msg2, self.pre_msg3, self.pre_msg4, 
                       self.pre_msg5,self.pre_msg6, self.pre_msg7, self.pre_msg8, self.pre_msg9, self.pre_msg10,
                       self.pre_msg11, self.pre_msg12]
            for item in msg_lst:
                if Application.pre_requiste_messages.count(item) > (0.25)*len(Application.pre_msg_time):
                    diagnostic_result.log(item, logging.INFO)
            Application.pre_requiste_messages = []
            Application.pre_msg_time = []

        fan_stat_check = False
        for key, value in device_dict.items():
            if key.startswith(self.fan_status_name): 
                fan_stat_check = True
                if int(value) == 0:
                    self.pre_requiste_messages.append(self.pre_msg1)
                    return diagnostic_result
        if not fan_stat_check:
            Application.pre_requiste_messages.append(self.pre_msg2)
            return diagnostic_result

        damper_data, oatemp_data, matemp_data = [], [], []
        ratemp_data, cooling_data = [], [] 

        for key, value in device_dict.items():
            if key.startswith(self.damper_signal_name) and value != None: 
                damper_data.append(value)

            elif key.startswith(self.oa_temp_name) and value != None:
                oatemp_data.append(value)
                
            elif key.startswith(self.ma_temp_name) and value != None: 
                matemp_data.append(value)

            elif key.startswith(self.ra_temp_name) and value != None:
                ratemp_data.append(value)
            
            elif key.startswith(self.cool_call_name) and value != None:
                cooling_data.append(value)
        
        if not oatemp_data:
            Application.pre_requiste_messages.append(self.pre_msg3)
 
        if not ratemp_data:
            Application.pre_requiste_messages.append(self.pre_msg4)
           
        if not matemp_data:
            Application.pre_requiste_messages.append(self.pre_msg5)
 
        if not damper_data:
            Application.pre_requiste_messages.append(self.pre_msg6)
           
        if not cooling_data:
            Application.pre_requiste_messages.append(self.pre_msg7)

        if not (oatemp_data and ratemp_data and matemp_data and
            damper_data and cooling_data):
            return diagnostic_result
        
        oatemp = (sum(oatemp_data)/len(oatemp_data))
        ratemp = (sum(ratemp_data)/len(ratemp_data))
        matemp = (sum(matemp_data)/len(matemp_data))
        damper_signal = (sum(damper_data)/len(damper_data))

        limit_check = False
        if oatemp < self.oat_low_threshold or oatemp > self.oat_high_threshold:
            Application.pre_requiste_messages.append(self.pre_msg8)
            limit_check = True
        if ratemp < self.rat_low_threshold or ratemp > self.rat_high_threshold:
            Application.pre_requiste_messages.append(self.pre_msg9)
            limit_check = True
        if matemp < self.mat_low_threshold or matemp > self.mat_high_threshold:
            Application.pre_requiste_messages.append(self.pre_msg10)
            limit_check = True

        if limit_check:
            return diagnostic_result

        if abs(oatemp - ratemp) < self.oa_ra_tempdiff_threshold:
            diagnostic_result.log('Conditions are not favorable for diagnostics ' 
                                  'data corresponding to {timestamp} will not be used.'.format(timestamp=str(current_time)), logging.INFO)
            return diagnostic_result

        device_type_error = False
        if self.device_type == 'ahu':
            cooling_valve = sum(cooling_data)/len(cooling_data)
            if cooling_valve > self.cooling_enabled_threshold: 
                cooling_call = True
            else:
                cooling_call = False
        elif self.device_type == 'rtu':
            cooling_call = int(max(cooling_data))
        else:
            device_type_error = True
            diagnostic_result.log('device_type must be specified as "AHU" or "RTU" check Configuration input.', logging.INFO)
            
        if device_type_error:
            return diagnostic_result
        
        if self.economizer_type[0] == 'ddb':
            economizer_conditon = (oatemp < (ratemp - self.temp_deadband))
        else:
            economizer_conditon = (oatemp < (self.economizer_type[1] - self.temp_deadband))

        diagnostic_result = self.econ1.econ_alg1(diagnostic_result,cooling_call, oatemp, ratemp, 
                                                                    matemp, damper_signal,current_time)

        try:
            if temperature_sensor_dx.temp_sensor_problem == None:
                Application.pre_requiste_messages.append(self.pre_msg12)
                return diagnostic_result
            elif temperature_sensor_dx.temp_sensor_problem != None and self.pre_msg12 in Application.pre_requiste_messages:
                Application.pre_requiste_messages = [x for x in Application.pre_requiste_messages if x != self.pre_msg12]
            if temperature_sensor_dx.temp_sensor_problem == True:
                Application.pre_requiste_messages.append(self.pre_msg11)
                return diagnostic_result
        except:
            pass

        diagnostic_result = self.econ2.econ_alg2(diagnostic_result,cooling_call, oatemp, ratemp, 
                                                                    matemp, damper_signal,economizer_conditon,current_time)
        diagnostic_result = self.econ3.econ_alg3(diagnostic_result,cooling_call, oatemp, ratemp, 
                                                                    matemp, damper_signal,economizer_conditon,current_time)
        diagnostic_result = self.econ4.econ_alg4(diagnostic_result,cooling_call, oatemp, ratemp, 
                                                                    matemp, damper_signal,economizer_conditon,current_time)
        diagnostic_result = self.econ5.econ_alg5(diagnostic_result,cooling_call, oatemp, ratemp, 
                                                                    matemp, damper_signal,economizer_conditon,current_time)
        return diagnostic_result
    def run(self, current_time, points):
        """
        Check application pre-quisites and assemble analysis data set.
        Receives mapped data from the DrivenBaseClass.  Filters non-relevent
        data and assembles analysis data set for diagnostics.
        """
        # topics = self.inp.get_topics()
        # diagnostic_topic = topics[self.fan_status_name][0]
        # cur_time = self.inp.localize_sensor_time(diagnostic_topic, current_time)
        to_zone = dateutil.tz.gettz(self.cur_tz)
        cur_time = current_time.astimezone(to_zone)
        device_dict = {}
        dx_result = Results()

        for key, value in points.items():
            point_device = [_name.lower() for _name in key.split("&&&")]
            if point_device[0] not in device_dict:
                device_dict[point_device[0]] = [(point_device[1], value)]
            else:
                device_dict[point_device[0]].append((point_device[1], value))

        fan_status_data = []
        fan_sp_data = []
        stc_pr_data = []
        stcpr_stpt_data = []
        zn_dmpr_data = []

        for key, value in device_dict.items():
            data_name = key
            if value is None:
                continue
            if data_name == self.fan_status_name:
                fan_status_data = data_builder(value, data_name)
            elif data_name == self.fan_sp_name:
                fan_sp_data = data_builder(value, data_name)
            elif data_name == self.duct_stcpr_stpt_name:
                stcpr_stpt_data = data_builder(value, data_name)
            elif data_name == self.duct_stcpr_name:
                stc_pr_data = data_builder(value, data_name)
            elif data_name == self.zn_damper_name:
                zn_dmpr_data = data_builder(value, data_name)

        missing_data = []
        if not stc_pr_data:
            missing_data.append(self.duct_stcpr_name)
        if not stcpr_stpt_data:
            dx_result.log('Duct static pressure set point data is '
                          'missing. This will limit the effectiveness of '
                          'the duct static pressure diagnostics.')
        missing_data = []
        if not fan_status_data and not fan_sp_data:
            missing_data.append(self.fan_status_name)
        if not stc_pr_data:
            missing_data.append(self.duct_stcpr_name)
        if not stcpr_stpt_data:
            dx_result.log("Duct static pressure set point data is missing.")
        if not zn_dmpr_data:
            missing_data.append(self.zn_damper_name)

        if missing_data:
            dx_result.log("Missing data from publish: {}".format(missing_data))
            return dx_result

        current_fan_status, fan_sp = self.check_fan_status(
            fan_status_data, fan_sp_data, cur_time)
        dx_result = self.check_elapsed_time(dx_result, cur_time,
                                            self.unit_status, FAN_OFF)

        if not current_fan_status:
            dx_result.log("Supply fan is off: {}".format(cur_time))
            self.warm_up_flag = True
            return dx_result

        dx_result.log("Supply fan is on: {}".format(cur_time))

        low_sf_cond = True if fan_sp is not None and fan_sp > self.high_sf_thr else False
        high_sf_cond = True if fan_sp is not None and fan_sp < self.low_sf_thr else False

        if self.warm_up_flag:
            self.warm_up_flag = False
            self.warm_up_start = cur_time
            return dx_result

        if self.warm_up_start is not None and (
                cur_time - self.warm_up_start) < self.warm_up_time:
            dx_result.log("Unit is in warm-up. Data will not be analyzed.")
            return dx_result

        dx_result = self.stcpr_aircx.stcpr_aircx(cur_time, stcpr_stpt_data,
                                                 stc_pr_data, zn_dmpr_data,
                                                 low_sf_cond, high_sf_cond,
                                                 dx_result)
        dx_result = self.stcpr_reset_aircx.stcpr_reset_aircx(
            cur_time, stcpr_stpt_data, dx_result)

        return dx_result
    def run(self, cur_time, points):

        to_zone = dateutil.tz.gettz(self.cur_tz)
        cur_time = cur_time.astimezone(to_zone)
        device_dict = {}
        dx_result = Results()

        for key, value in points.items():
            point_device = [_name.lower() for _name in key.split("&&&")]
            if point_device[0] not in device_dict:
                device_dict[point_device[0]] = [(point_device[1], value)]
            else:
                device_dict[point_device[0]].append((point_device[1], value))

        fan_status_data = []
        fan_sp_data = []
        zn_dmpr_data = []
        sat_data = []
        zn_rht_data = []
        sat_stpt_data = []

        def data_builder(value_tuple, point_name):
            value_list = []
            for item in value_tuple:
                value_list.append(item[1])
            return value_list

        for key, value in device_dict.items():
            data_name = key
            if value is None:
                continue
            if data_name == self.fan_status_name:
                fan_status_data = data_builder(value, data_name)
            elif data_name == self.fan_sp_name:
                fan_sp_data = data_builder(value, data_name)
            elif data_name == self.sat_stpt_name:
                sat_stpt_data = data_builder(value, data_name)
            elif data_name == self.sat_name:
                sat_data = data_builder(value, data_name)
            elif data_name == self.zn_reheat_name:
                zn_rht_data = data_builder(value, data_name)
            elif data_name == self.zn_damper_name:
                zn_dmpr_data = data_builder(value, data_name)

        missing_data = []
        if not sat_data:
            missing_data.append(self.sat_name)
        if not zn_rht_data:
            missing_data.append(self.zn_reheat_name)
        if not sat_stpt_data:
            dx_result.log('Supply-air temperature set point data is '
                          'missing. This will limit the effectiveness of '
                          'the supply-air temperature diagnostics.')
        if not fan_status_data and not fan_sp_data:
            missing_data.append(self.fan_status_name)
        if not zn_dmpr_data:
            missing_data.append(self.zn_damper_name)

        if missing_data:
            dx_result.log('Missing required data: {}'.format(missing_data))
            return dx_result

        current_fan_status, fan_sp = self.check_fan_status(
            fan_status_data, fan_sp_data, cur_time)
        dx_result = self.check_elapsed_time(dx_result, cur_time,
                                            self.unit_status, FAN_OFF)

        if not current_fan_status:
            dx_result.log("Supply fan is off: {}".format(cur_time))
            self.warm_up_flag = True
            return dx_result

        dx_result.log("Supply fan is on: {}".format(cur_time))

        if self.warm_up_flag:
            self.warm_up_flag = False
            self.warm_up_start = cur_time
            return dx_result

        if self.warm_up_start is not None and (
                cur_time - self.warm_up_start) < self.warm_up_time:
            dx_result.log("Unit is in warm-up. Data will not be analyzed.")
            return dx_result

        dx_result = self.satr_reset_aircx.sat_reset_aircx(
            cur_time, sat_stpt_data, dx_result)
        dx_result = self.sat_aircx.sat_aircx(cur_time, sat_data, sat_stpt_data,
                                             zn_rht_data, zn_dmpr_data,
                                             dx_result)
        return dx_result
Beispiel #14
0
    def run(self, current_time, points):
        """
            Main run method that is called by the DrivenBaseClass.
        """
        device_dict = {}
        result = Results()
        topics = self.inp.get_topics()
        topic = topics[self.oa_temp_name][0]
        current_time = self.inp.localize_sensor_time(topic, current_time)
        base_topic = self.inp.get_topics()
        meta_topics = self.inp.get_topics_meta()
        unit_dict = {
            self.oa_temp_name:
            meta_topics[self.oa_temp_name][base_topic[self.oa_temp_name][0]]
            ['unit']
        }

        if len(base_topic[self.ma_temp_name]) > 0:
            unit_dict[self.ma_temp_name] = meta_topics[self.ma_temp_name][
                base_topic[self.ma_temp_name][0]]['unit']
        if len(base_topic[self.ra_temp_name]) > 0:
            unit_dict[self.ra_temp_name] = meta_topics[self.ra_temp_name][
                base_topic[self.ra_temp_name][0]]['unit']
        if len(base_topic[self.da_temp_name]) > 0:
            unit_dict[self.da_temp_name] = meta_topics[self.da_temp_name][
                base_topic[self.da_temp_name][0]]['unit']
        if len(base_topic[self.da_temp_setpoint_name]) > 0:
            unit_dict[self.da_temp_setpoint_name] = \
                meta_topics[self.da_temp_setpoint_name][base_topic[self.da_temp_setpoint_name][0]]['unit']

        for key, value in points.items():
            device_dict[key.lower()] = value

        damper_data = []
        oatemp_data = []
        matemp_data = []
        ratemp_data = []
        datemp_data = []
        datemp_stpt_data = []
        ccv_data = []
        fan_speedcmd_data = []
        fan_status_data = []
        hcv_data = []
        return_fan_speedcmd_data = []
        occ_data = []
        discharge_sp_data = []
        staticpressure_sp_data = []

        for key, value in device_dict.items():
            if (key.startswith(self.outdoor_damper_name)  #Damper
                    and value is not None):
                damper_data.append(value)
            elif (key.startswith(self.oa_temp_name)  #OAT
                  and value is not None):
                oatemp_data.append(value)
            elif (key.startswith(self.ma_temp_name)  #MAT
                  and value is not None):
                matemp_data.append(value)
            elif (key.startswith(self.ra_temp_name)  #RAT
                  and value is not None):
                ratemp_data.append(value)
            elif (key.startswith(self.da_temp_name)  #DAT
                  and value is not None):
                datemp_data.append(value)
            elif (key.startswith(self.da_temp_setpoint_name)  #DAT SetPoint
                  and value is not None):
                datemp_stpt_data.append(value)
            elif (key.startswith(self.cc_valve_name)  #CoolCoilValvePos
                  and value is not None):
                ccv_data.append(value)
            elif (key.startswith(self.hc_valve_name)  #HeatCoilValvePos
                  and value is not None):
                hcv_data.append(value)
            elif (key.startswith(self.fan_speedcmd_name)  #Fan speed
                  and value is not None):
                fan_speedcmd_data.append(value)
            elif (key.startswith(self.fan_status_name)  #Fan status
                  and value is not None):
                fan_status_data.append(value)
            elif (key.startswith(
                    self.returnfan_speedcmd_name)  #returnfan_speedcmd_name
                  and value is not None):
                return_fan_speedcmd_data.append(value)
            elif (key.startswith(self.occ_name)  #Occupancy
                  and value is not None):
                occ_data.append(value)
            elif (key.startswith(self.discharge_sp_name)  #discharge_sp_data
                  and value is not None):
                discharge_sp_data.append(value)
            elif (key.startswith(
                    self.sp_setpoint_name)  #staticpressure_sp_data
                  and value is not None):
                staticpressure_sp_data.append(value)

        if not oatemp_data:
            return result

        if 'celcius' or 'kelvin' in unit_dict.values:
            if unit_dict[self.oa_temp_name] == 'celcius':
                oatemp_data = cu.convertCelciusToFahrenheit(oatemp_data)
            elif unit_dict[self.oa_temp_name] == 'kelvin':
                oatemp_data = cu.convertKelvinToCelcius(
                    cu.convertCelciusToFahrenheit(oatemp_data))
            #if self.ma_temp_name in unit_dict:
            if unit_dict[self.ma_temp_name] == 'celcius':
                matemp_data = cu.convertCelciusToFahrenheit(matemp_data)
            elif unit_dict[self.ma_temp_name] == 'kelvin':
                matemp_data = cu.convertKelvinToCelcius(
                    cu.convertCelciusToFahrenheit(matemp_data))
            if self.ra_temp_name in unit_dict:
                if unit_dict[self.ra_temp_name] == 'celcius':
                    ratemp_data = cu.convertCelciusToFahrenheit(ratemp_data)
                elif unit_dict[self.ra_temp_name] == 'kelvin':
                    ratemp_data = cu.convertKelvinToCelcius(
                        cu.convertCelciusToFahrenheit(ratemp_data))
            if self.da_temp_name in unit_dict:
                if unit_dict[self.da_temp_name] == 'celcius':
                    datemp_data = cu.convertCelciusToFahrenheit(datemp_data)
                elif unit_dict[self.da_temp_name] == 'kelvin':
                    datemp_data = cu.convertKelvinToCelcius(
                        cu.convertCelciusToFahrenheit(datemp_data))
            if self.da_temp_setpoint_name in unit_dict:
                if unit_dict[self.da_temp_setpoint_name] == 'celcius':
                    datemp_stpt_data = cu.convertCelciusToFahrenheit(
                        datemp_stpt_data)
                elif unit_dict[self.da_temp_setpoint_name] == 'kelvin':
                    datemp_stpt_data = cu.convertKelvinToCelcius(
                        cu.convertCelciusToFahrenheit(datemp_stpt_data))

        oatemp = (sum(oatemp_data) / len(oatemp_data))
        matemp = (sum(matemp_data) / len(matemp_data))
        matemp_data = None
        ratemp = datemp = datemp_stpt = None
        fanstatus = fanspeed = outdoor_damper = ccv = hcv = None
        oaf = None

        return_fan_speedcmd = None
        occupancy = None
        discharge_sp = staticpressure_sp = None

        if matemp_data:
            matemp = (sum(matemp_data) / len(matemp_data))
        if ratemp_data:
            ratemp = (sum(ratemp_data) / len(ratemp_data))
        if datemp_data:
            datemp = (sum(datemp_data) / len(datemp_data))
        if datemp_stpt_data:
            datemp_stpt = (sum(datemp_stpt_data) / len(datemp_stpt_data))
        if fan_status_data:
            fanstatus = (sum(fan_status_data) / len(fan_status_data))
        if fan_speedcmd_data:
            fanspeed = (sum(fan_speedcmd_data) / len(fan_speedcmd_data))
        if damper_data:
            outdoor_damper = (sum(damper_data) / len(damper_data))
        if ccv_data:
            ccv = (sum(ccv_data) / len(ccv_data))
        if hcv_data:
            hcv = (sum(hcv_data) / len(hcv_data))
        if matemp_data and ratemp_data:
            denominator = oatemp - ratemp
            if denominator == 0:
                oaf = 0
            else:
                oaf = (matemp - ratemp) / denominator
            if oaf > 1:
                oaf = 1
            elif oaf < 0:
                oaf = 0
            oaf *= 100

        if return_fan_speedcmd_data:
            return_fan_speedcmd = (sum(return_fan_speedcmd_data) /
                                   len(return_fan_speedcmd_data))
        if occ_data:
            occupancy = (sum(occ_data) / len(occ_data)) * 100
        if discharge_sp_data:
            discharge_sp = (sum(discharge_sp_data) / len(discharge_sp_data))
        if staticpressure_sp_data:
            staticpressure_sp = (sum(staticpressure_sp_data) /
                                 len(staticpressure_sp_data))

        out_data = {
            'datetime':
            str(current_time),
            'OutdoorAirTemperature':
            oatemp,
            'MixedAirTemperature':
            None if not matemp else matemp,
            'ReturnAirTemperature':
            None if ratemp is None else ratemp,
            'DischargeAirTemperature':
            None if datemp is None else datemp,
            'DischargeAirTemperatureSetPoint':
            None if datemp_stpt is None else datemp_stpt,
            'SupplyFanStatus':
            None if fanstatus is None else fanstatus,
            'SupplyFanSpeed':
            None if fanspeed is None else fanspeed,
            'OutdoorDamper':
            None if outdoor_damper is None else outdoor_damper,
            'CCV':
            None if ccv is None else ccv,
            'HCV':
            None if hcv is None else hcv,
            'OutdoorAirFraction':
            None if oaf is None else oaf,
            'ReturnFanSpeed':
            None if return_fan_speedcmd is None else return_fan_speedcmd,
            'OccupancyMode':
            None if occupancy is None else occupancy,
            'DuctStaticPressure':
            None if discharge_sp is None else discharge_sp,
            'DuctStaticPressureSetPoint':
            None if staticpressure_sp is None else staticpressure_sp,
        }
        result.insert_table_row('AhuEcam', out_data)
        return result
    def run(self, current_time, points):
        """
        Check algorithm pre-quisites and assemble data set for analysis.
        :param current_time:
        :param points:
        :return:
        """
        topics = self.inp.get_topics()
        # diagnostic_topic = topics[self.loop_dp_name][0]
        # current_time = self.inp.localize_sensor_time(diagnostic_topic,
        #                                             current_time)
        to_zone = dateutil.tz.gettz(self.cur_tz)
        current_time = current_time.astimezone(to_zone)
        device_dict = {}
        diagnostic_result = Results()
        for key, value in points.items():
            device_dict[key.lower()] = value

        flow_check, dp_data = self.data_check(device_dict, self.loop_dp_name, self.loop_dp_stpt_name)
        for value in dp_data:
            if value < self.min_dp_threshold:
                self.warm_up_flag = True
                Application.pre_requiste_messages.append(self.pre_msg1)
                diagnostic_result = self.pre_message(diagnostic_result,
                                                     current_time)
                return diagnostic_result
            elif value > self.max_dp_threshold:
                Application.pre_requiste_messages.append(self.pre_msg2)
                diagnostic_result = self.pre_message(diagnostic_result,
                                                     current_time)
                return diagnostic_result

        if not flow_check or not dp_data:
            pump_id = fnmatch.filter(device_dict,''.join(['*', self.pump_status_name, '*']))
            if not pump_id:
                Application.pre_requiste_messages.append(self.pre_msg3)
                diagnostic_result = self.pre_message(diagnostic_result, current_time)
                return diagnostic_result

            pump_stat = list(device_dict[val] for val in pump_id if val in device_dict and int(device_dict[val]) > 0)
            if not pump_stat:
                self.warm_up_flag = True
                Application.pre_requiste_messages.append(self.pre_msg4)
                diagnostic_result = self.pre_message(diagnostic_result, current_time)
                return diagnostic_result

        boiler_id = fnmatch.filter(device_dict, ''.join(['*', self.boiler_status_name, '*']))
        boiler_stat = list(device_dict[val] for val in boiler_id if val in device_dict and int(device_dict[val]) > 0)

        if not boiler_stat:
            self.warm_up_flag = True
            Application.pre_requiste_messages.append(self.pre_msg5)
            diagnostic_result = self.pre_message(diagnostic_result, current_time)
            return diagnostic_result

        if self.warm_up_flag:
            self.warm_up_flag = False
            self.warm_up_start = current_time

        time_check = datetime.timedelta(minutes=self.warm_up_time)
        if self.warm_up_start is not None and (current_time - self.warm_up_start) < time_check:
            diagnostic_result = self.pre_message(diagnostic_result, current_time)
            return diagnostic_result

        loop_dp_values = []
        loop_dp_stpt_values = []
        hw_pump_vfd_values = []
        hw_stsp_values = []
        hws_temp_values = []
        hwr_temp_values = []
        oa_temp_values = []

        for key, value in device_dict.items():
            if key.startswith(self.loop_dp_stpt_name) and value is not None:
                loop_dp_stpt_values.append(value)
            elif key.startswith(self.loop_dp_name) and value is not None:
                loop_dp_values.append(value)
            elif key.startswith(self.hw_pump_vfd_name) and value is not None:
                hw_pump_vfd_values.append(value)
            elif key.startswith(self.hw_stsp_name) and value is not None:
                hw_stsp_values.append(value)
            elif key.startswith(self.hws_temp_name) and value is not None:
                hws_temp_values.append(value)
            elif key.startswith(self.hwr_temp_name) and value is not None:
                hwr_temp_values.append(value)
            elif key.startswith(self.oa_temp_name) and value is not None:
                oa_temp_values.append(value)

        if not loop_dp_values:
            Application.pre_requiste_messages.append(self.pre_msg6)
        if not hw_pump_vfd_values:
            Application.pre_requiste_messages.append(self.pre_msg7)
        if not hws_temp_values:
            Application.pre_requiste_messages.append(self.pre_msg8)
        if not hwr_temp_values:
            Application.pre_requiste_messages.append(self.pre_msg9)
        if not (loop_dp_values and hws_temp_values and hwr_temp_values and
                hw_pump_vfd_values):
            diagnostic_result = self.pre_message(diagnostic_result, current_time)
            return diagnostic_result

        diagnostic_result = self.hw_dx1.hw_dp_rcx(diagnostic_result, current_time,
                                                  loop_dp_stpt_values, loop_dp_values,
                                                  hw_pump_vfd_values, oa_temp_values)

        diagnostic_result = self.hw_dx2.temp_rcx(diagnostic_result, current_time,
                                                 hws_temp_values, hwr_temp_values,
                                                 hw_pump_vfd_values, hw_stsp_values)

        diagnostic_result = self.hw_dx3.reset_rcx(current_time, hw_stsp_values,
                                                  loop_dp_stpt_values, diagnostic_result)
        Application.pre_requiste_messages = []
        Application.pre_msg_time = []
        return diagnostic_result
    def run(self, current_time, points):
        """
        Check application pre-quisites and assemble analysis data set.
        Receives mapped data from the DrivenBaseClass.  Filters non-relevent
        data and assembles analysis data set for diagnostics.
        """
        # topics = self.inp.get_topics()
        # diagnostic_topic = topics[self.fan_status_name][0]
        # cur_time = self.inp.localize_sensor_time(diagnostic_topic, current_time)
        to_zone = dateutil.tz.gettz(self.cur_tz)
        cur_time = current_time.astimezone(to_zone)
        device_dict = {}
        dx_result = Results()

        for key, value in points.items():
            point_device = [_name.lower() for _name in key.split("&&&")]
            if point_device[0] not in device_dict:
                device_dict[point_device[0]] = [(point_device[1], value)]
            else:
                device_dict[point_device[0]].append((point_device[1], value))

        fan_status_data = []
        fan_sp_data = []
        stc_pr_data = []
        stcpr_stpt_data = []
        zn_dmpr_data = []

        for key, value in device_dict.items():
            data_name = key
            if value is None:
                continue
            if data_name == self.fan_status_name:
                fan_status_data = data_builder(value, data_name)
            elif data_name == self.fan_sp_name:
                fan_sp_data = data_builder(value, data_name)
            elif data_name == self.duct_stcpr_stpt_name:
                stcpr_stpt_data = data_builder(value, data_name)
            elif data_name == self.duct_stcpr_name:
                stc_pr_data = data_builder(value, data_name)
            elif data_name == self.zn_damper_name:
                zn_dmpr_data = data_builder(value, data_name)

        missing_data = []
        if not stc_pr_data:
            missing_data.append(self.duct_stcpr_name)
        if not stcpr_stpt_data:
            dx_result.log('Duct static pressure set point data is '
                          'missing. This will limit the effectiveness of '
                          'the duct static pressure diagnostics.')
        missing_data = []
        if not fan_status_data and not fan_sp_data:
            missing_data.append(self.fan_status_name)
        if not stc_pr_data:
            missing_data.append(self.duct_stcpr_name)
        if not stcpr_stpt_data:
            dx_result.log("Duct static pressure set point data is missing.")
        if not zn_dmpr_data:
            missing_data.append(self.zn_damper_name)

        if missing_data:
            dx_result.log("Missing data from publish: {}".format(missing_data))
            return dx_result

        current_fan_status, fan_sp = self.check_fan_status(fan_status_data, fan_sp_data, cur_time)
        dx_result = self.check_elapsed_time(dx_result, cur_time, self.unit_status, FAN_OFF)

        if not current_fan_status:
            dx_result.log("Supply fan is off: {}".format(cur_time))
            self.warm_up_flag = True
            return dx_result

        dx_result.log("Supply fan is on: {}".format(cur_time))

        low_sf_cond = True if fan_sp is not None and fan_sp > self.high_sf_thr else False
        high_sf_cond = True if fan_sp is not None and fan_sp < self.low_sf_thr else False

        if self.warm_up_flag:
            self.warm_up_flag = False
            self.warm_up_start = cur_time
            return dx_result

        if self.warm_up_start is not None and (cur_time - self.warm_up_start) < self.warm_up_time:
            dx_result.log("Unit is in warm-up. Data will not be analyzed.")
            return dx_result

        dx_result = self.stcpr_aircx.stcpr_aircx(cur_time, stcpr_stpt_data, stc_pr_data,
                                                 zn_dmpr_data, low_sf_cond, high_sf_cond,
                                                 dx_result)
        dx_result = self.stcpr_reset_aircx.stcpr_reset_aircx(cur_time, stcpr_stpt_data, dx_result)

        return dx_result
Beispiel #17
0
    def run(self, current_time, points):
        '''
        Check algorithm pre-quisites and assemble data set for analysis.
        '''
        device_dict = {}
        result = Results()
        topics = self.inp.get_topics()
        topic = topics[self.hws_temp_name][0]
        current_time = self.inp.localize_sensor_time(topic, current_time)
        base_topic = self.inp.get_topics()
        meta_topics = self.inp.get_topics_meta()

        unit_dict = {}
        if len(base_topic[self.oa_temp_name]) > 0:
            unit_dict[self.oa_temp_name] = meta_topics[self.oa_temp_name][base_topic[self.oa_temp_name][0]]['unit']
        if len(base_topic[self.hws_temp_name]) > 0:
            unit_dict[self.hws_temp_name] = meta_topics[self.hws_temp_name][base_topic[self.hws_temp_name][0]]['unit']
        if len(base_topic[self.hwr_temp_name]) > 0:
            unit_dict[self.hwr_temp_name] = meta_topics[self.hwr_temp_name][base_topic[self.hwr_temp_name][0]]['unit']
        if len(base_topic[self.hw_stsp_name]) > 0:
            unit_dict[self.hw_stsp_name] = meta_topics[self.hw_stsp_name][base_topic[self.hw_stsp_name][0]]['unit']

        for key, value in points.items():
            device_dict[key.lower()] = value

        oatemp_data = []
        loop_dp_values = []
        loop_dp_stpt_values = []
        hw_pump_status_values = []
        boiler_status_values = []
        hw_pump_vfd_values = []
        hw_stsp_values = []
        hws_temp_values = []
        hwr_temp_values = []

        for key, value in device_dict.items():
            if key.startswith(self.loop_dp_stpt_name) and value is not None:
                loop_dp_stpt_values.append(value)
            elif key.startswith(self.loop_dp_name) and value is not None:
                loop_dp_values.append(value)
            elif key.startswith(self.hw_pump_status_name) and value is not None:
                hw_pump_status_values.append(value)
            elif key.startswith(self.boiler_status_name) and value is not None:
                boiler_status_values.append(value)
            elif key.startswith(self.hw_pump_vfd_name) and value is not None:
                hw_pump_vfd_values.append(value)
            elif key.startswith(self.hw_stsp_name) and value is not None:
                hw_stsp_values.append(value)
            elif key.startswith(self.hws_temp_name) and value is not None:
                hws_temp_values.append(value)
            elif key.startswith(self.hwr_temp_name) and value is not None:
                hwr_temp_values.append(value)
            elif (key.startswith(self.oa_temp_name) #OAT
                  and value is not None):
                oatemp_data.append(value)

        if 'celcius' or 'kelvin' in unit_dict.values:
            if self.oa_temp_name in unit_dict:
                if unit_dict[self.oa_temp_name] == 'celcius':
                    oatemp_data = cu.convertCelciusToFahrenheit(oatemp_data)
                elif unit_dict[self.oa_temp_name] == 'kelvin':
                    oatemp_data = cu.convertKelvinToCelcius(
                        cu.convertCelciusToFahrenheit(oatemp_data))
            if self.hw_stsp_name in unit_dict:
                if unit_dict[self.hw_stsp_name] == 'celcius':
                    hw_stsp_values = cu.convertCelciusToFahrenheit(hw_stsp_values)
                elif unit_dict[self.hw_stsp_name] == 'kelvin':
                    hw_stsp_values = cu.convertKelvinToCelcius(
                        cu.convertCelciusToFahrenheit(hw_stsp_values))
            if self.hw_stsp_name in unit_dict:
                if unit_dict[self.hws_temp_name] == 'celcius':
                    hws_temp_values = cu.convertCelciusToFahrenheit(hws_temp_values)
                elif unit_dict[self.hws_temp_name] == 'kelvin':
                    hws_temp_values = cu.convertKelvinToCelcius(
                        cu.convertCelciusToFahrenheit(hws_temp_values))
            if self.hwr_temp_name in unit_dict:
                if unit_dict[self.hwr_temp_name] == 'celcius':
                    hwr_temp_values = cu.convertCelciusToFahrenheit(hwr_temp_values)
                elif unit_dict[self.hwr_temp_name] == 'kelvin':
                    hwr_temp_values = cu.convertKelvinToCelcius(
                        cu.convertCelciusToFahrenheit(hwr_temp_values))


        oatemp = hw_stsp_temp = hws_temp = hwr_temp = None
        loop_dp = loop_dp_stpt = None
        hw_pump_status = boiler_status = None
        hw_pump_vfd = None

        if oatemp_data:
            oatemp = (sum(oatemp_data) / len(oatemp_data))
        if hw_stsp_values:
            hw_stsp_temp = (sum(hw_stsp_values) / len(hw_stsp_values))
        if hws_temp_values:
            hws_temp = (sum(hws_temp_values) / len(hws_temp_values))
        if hwr_temp_values:
            hwr_temp = (sum(hwr_temp_values) / len(hwr_temp_values))

        if loop_dp_stpt_values:
            loop_dp_stpt = (sum(loop_dp_stpt_values) / len(loop_dp_stpt_values))
        if loop_dp_values:
            loop_dp = (sum(loop_dp_values) / len(loop_dp_values))

        if hw_pump_status_values:
            hw_pump_status = (sum(hw_pump_status_values) / len(hw_pump_status_values))
        if boiler_status_values:
            boiler_status = (sum(boiler_status_values) / len(boiler_status_values))

        if hw_pump_vfd_values:
            hw_pump_vfd = (sum(hw_pump_vfd_values) / len(hw_pump_vfd_values))


        out_data = {
            'datetime': str(current_time),
        }

        if not oatemp is None:
            out_data['OutdoorAirTemperature'] = oatemp
        if not hws_temp is None:
            out_data['HotWaterSupplyTemperature'] = hws_temp
        if not hwr_temp is None:
            out_data['HotWaterReturnTemperature'] = hwr_temp
        if not hw_stsp_temp is None:
            out_data['HotWaterTemperatureSetPoint'] = hw_stsp_temp

        if not loop_dp is None:
            out_data['LoopDifferentialPressure'] = loop_dp
        if not loop_dp_stpt is None:
            out_data['LoopDifferentialPressureSetPoint'] = loop_dp_stpt

        if not hw_pump_status is None:
            out_data['PumpStatus'] = hw_pump_status
        if not boiler_status is None:
            out_data['BoilerStatus'] = boiler_status

        if not hw_pump_vfd is None:
            out_data['HotWaterPumpVfd'] = hw_pump_vfd

        result.insert_table_row(self.table_name, out_data)

        return result
    def run(self,current_time, points):
        '''
        Check algorithm pre-quisites and assemble data set for analysis.
        '''
        device_dict = {}
        diagnostic_result = Results()

        for key, value in points.items():
            device_dict[key.lower()] = value

        self.pre_msg_time.append(current_time)
        message_check =  datetime.timedelta(minutes=(self.data_window))

        if (self.pre_msg_time[-1]-self.pre_msg_time[0]) >= message_check:
            msg_lst = [self.pre_msg1, self.pre_msg2, self.pre_msg3, self.pre_msg4, self.pre_msg5, 
                       self.pre_msg6, self.pre_msg7, self.pre_msg8, self.pre_msg9, self.pre_msg10,
                       self.pre_msg11, Application.pre_msg12, Application.pre_msg13]
            for item in msg_lst:
                if self.pre_requiste_messages.count(item) > (0.25)*len(self.pre_msg_time):
                    diagnostic_result.log(item, logging.INFO)
            self.pre_requiste_messages = []
            self.pre_msg_time = []
        
        
        flow_check, dp_data = self.data_check(device_dict,self.loop_dp_name,self.loop_dp_stpt_name)

        for value in dp_data:
            if value < self.min_dp_threshold:
                Application.pre_requiste_messages.append(self.pre_msg1)
                return diagnostic_result
            elif value > self.max_dp_threshold:
                Application.pre_requiste_messages.append(self.pre_msg2)
                return diagnostic_result

        if not flow_check or not dp_data:
            pump_id = fnmatch.filter(device_dict,''.join(['*', self.pump_status_name, '*']))

            if not pump_id:
                Application.pre_requiste_messages.append(self.pre_msg3)
                return diagnostic_result

            pump_stat = (list(device_dict[val] for val in pump_id if val in 
                              device_dict and int(device_dict[val]) > 0))

            if not pump_stat:
                Application.pre_requiste_messages.append(self.pre_msg4)
                return diagnostic_result

        boiler_id = fnmatch.filter(device_dict,''.join(['*', self.boiler_status_name,'*']))
        boiler_stat= (list(device_dict[val] for val in boiler_id if val in device_dict 
                           and int(device_dict[val]) > 0))  
        if not boiler_stat:
            Application.pre_requiste_messages.append(self.pre_msg5)
            return diagnostic_result
    
        loop_dp_values = []
        rht_vlv_values = []
        oa_temp_values = []
        loop_dp_stpt_values = []
        hw_pump_vfd_values = []
        hw_stsp_values = []
        hws_temp_values = []
        hwr_temp_values = []

        for key, value in device_dict.items():
            if key.startswith(self.loop_dp_stpt_name) and value != None:
                loop_dp_stpt_values.append(value)
            elif key.startswith(self.loop_dp_name) and value != None: 
                loop_dp_values.append(value)
            elif key.startswith(self.zone_reheat_name) and value != None: 
                rht_vlv_values.append(value)
            elif key.startswith(self.oa_temp_name) and value != None:
                oa_temp_values.append(value)
            elif key.startswith(self.hw_pump_vfd_name) and value != None:
                hw_pump_vfd_values.append(value)
            elif key.startswith(self.hw_stsp_name) and value != None: 
                hw_stsp_values.append(value)
            elif key.startswith(self.hws_temp_name) and value != None:
                hws_temp_values.append(value)
            elif key.startswith(self.hwr_temp_name) and value != None: 
                hwr_temp_values.append(value)

        if not oa_temp_values:
            Application.pre_requiste_messages.append(self.pre_msg6)
        if not rht_vlv_values:
            Application.pre_requiste_messages.append(self.pre_msg7)
        if not loop_dp_values:
            Application.pre_requiste_messages.append(self.pre_msg8)
        if not hw_pump_vfd_values:
            Application.pre_requiste_messages.append(self.pre_msg9)
        if not hws_temp_values:
            Application.pre_requiste_messages.append(self.pre_msg10)
        if not hwr_temp_values:
            Application.pre_requiste_messages.append(self.pre_msg11)

        if (not (oa_temp_values and rht_vlv_values and loop_dp_values) and
            not (hws_temp_values and hwr_temp_values)):
            return diagnostic_result
        
        diagnostic_result = self.hw_dx1.hw_dp_dx(diagnostic_result, current_time, oa_temp_values, loop_dp_stpt_values,
                                                   loop_dp_values,rht_vlv_values, hw_pump_vfd_values)
        diagnostic_result = self.hw_dx2.hw_temp_dx(diagnostic_result, current_time, hws_temp_values, hwr_temp_values,
                                                   hw_pump_vfd_values, rht_vlv_values, oa_temp_values)
        return diagnostic_result
Beispiel #19
0
    def run(self, current_time, points):
        """
            Main run method that is called by the DrivenBaseClass.
        """
        device_dict = {}
        result = Results()
        topics = self.inp.get_topics()
        topic = topics[self.oa_temp_name][0]
        current_time = self.inp.localize_sensor_time(topic, current_time)
        base_topic = self.inp.get_topics()
        meta_topics = self.inp.get_topics_meta()
        unit_dict = {
            self.oa_temp_name: meta_topics[self.oa_temp_name][base_topic[self.oa_temp_name][0]]['unit']
        }

        if len(base_topic[self.ma_temp_name]) > 0:
            unit_dict[self.ma_temp_name] = meta_topics[self.ma_temp_name][base_topic[self.ma_temp_name][0]]['unit']
        if len(base_topic[self.ra_temp_name]) > 0:
            unit_dict[self.ra_temp_name] = meta_topics[self.ra_temp_name][base_topic[self.ra_temp_name][0]]['unit']
        if len(base_topic[self.da_temp_name]) > 0:
            unit_dict[self.da_temp_name] = meta_topics[self.da_temp_name][base_topic[self.da_temp_name][0]]['unit']
        if len(base_topic[self.da_temp_setpoint_name]) > 0:
            unit_dict[self.da_temp_setpoint_name] = \
                meta_topics[self.da_temp_setpoint_name][base_topic[self.da_temp_setpoint_name][0]]['unit']

        for key, value in points.items():
            device_dict[key.lower()] = value

        damper_data = []
        oatemp_data = []
        matemp_data = []
        ratemp_data = []
        datemp_data = []
        datemp_stpt_data = []
        ccv_data = []
        fan_speedcmd_data = []
        fan_status_data = []
        hcv_data = []
        return_fan_speedcmd_data = []
        occ_data = []
        discharge_sp_data = []
        staticpressure_sp_data = []

        for key, value in device_dict.items():
            if (key.startswith(self.outdoor_damper_name) #Damper
                    and value is not None):
                damper_data.append(value)
            elif (key.startswith(self.oa_temp_name) #OAT
                  and value is not None):
                oatemp_data.append(value)
            elif (key.startswith(self.ma_temp_name) #MAT
                  and value is not None):
                matemp_data.append(value)
            elif (key.startswith(self.ra_temp_name) #RAT
                  and value is not None):
                ratemp_data.append(value)
            elif (key.startswith(self.da_temp_name) #DAT
                  and value is not None):
                datemp_data.append(value)
            elif (key.startswith(self.da_temp_setpoint_name) #DAT SetPoint
                  and value is not None):
                datemp_stpt_data.append(value)
            elif (key.startswith(self.cc_valve_name) #CoolCoilValvePos
                  and value is not None):
                ccv_data.append(value)
            elif (key.startswith(self.hc_valve_name) #HeatCoilValvePos
                  and value is not None):
                hcv_data.append(value)
            elif (key.startswith(self.fan_speedcmd_name) #Fan speed
                  and value is not None):
                fan_speedcmd_data.append(value)
            elif (key.startswith(self.fan_status_name) #Fan status
                  and value is not None):
                fan_status_data.append(value)
            elif (key.startswith(self.returnfan_speedcmd_name) #returnfan_speedcmd_name
                  and value is not None):
                return_fan_speedcmd_data.append(value)
            elif (key.startswith(self.occ_name) #Occupancy
                  and value is not None):
                occ_data.append(value)
            elif (key.startswith(self.discharge_sp_name) #discharge_sp_data
                  and value is not None):
                discharge_sp_data.append(value)
            elif (key.startswith(self.sp_setpoint_name) #staticpressure_sp_data
                  and value is not None):
                staticpressure_sp_data.append(value)

        if not oatemp_data:
            return result

        if 'celcius' or 'kelvin' in unit_dict.values:
            if unit_dict[self.oa_temp_name] == 'celcius':
                oatemp_data = cu.convertCelciusToFahrenheit(oatemp_data)
            elif unit_dict[self.oa_temp_name] == 'kelvin':
                oatemp_data = cu.convertKelvinToCelcius(
                    cu.convertCelciusToFahrenheit(oatemp_data))
            #if self.ma_temp_name in unit_dict:
            if unit_dict[self.ma_temp_name] == 'celcius':
                matemp_data = cu.convertCelciusToFahrenheit(matemp_data)
            elif unit_dict[self.ma_temp_name] == 'kelvin':
                matemp_data = cu.convertKelvinToCelcius(
                    cu.convertCelciusToFahrenheit(matemp_data))
            if self.ra_temp_name in unit_dict:
                if unit_dict[self.ra_temp_name] == 'celcius':
                    ratemp_data = cu.convertCelciusToFahrenheit(ratemp_data)
                elif unit_dict[self.ra_temp_name] == 'kelvin':
                    ratemp_data = cu.convertKelvinToCelcius(
                        cu.convertCelciusToFahrenheit(ratemp_data))
            if self.da_temp_name in unit_dict:
                if unit_dict[self.da_temp_name] == 'celcius':
                    datemp_data = cu.convertCelciusToFahrenheit(datemp_data)
                elif unit_dict[self.da_temp_name] == 'kelvin':
                    datemp_data = cu.convertKelvinToCelcius(
                        cu.convertCelciusToFahrenheit(datemp_data))
            if self.da_temp_setpoint_name in unit_dict:
                if unit_dict[self.da_temp_setpoint_name] == 'celcius':
                    datemp_stpt_data = cu.convertCelciusToFahrenheit(datemp_stpt_data)
                elif unit_dict[self.da_temp_setpoint_name] == 'kelvin':
                    datemp_stpt_data = cu.convertKelvinToCelcius(
                        cu.convertCelciusToFahrenheit(datemp_stpt_data))


        oatemp = (sum(oatemp_data) / len(oatemp_data))
        matemp = (sum(matemp_data) / len(matemp_data))
        matemp_data = None
        ratemp = datemp = datemp_stpt = None
        fanstatus = fanspeed = outdoor_damper = ccv = hcv = None
        oaf = None

        return_fan_speedcmd = None
        occupancy = None
        discharge_sp = staticpressure_sp = None

        if matemp_data:
            matemp = (sum(matemp_data) / len(matemp_data))
        if ratemp_data:
            ratemp = (sum(ratemp_data) / len(ratemp_data))
        if datemp_data:
            datemp = (sum(datemp_data) / len(datemp_data))
        if datemp_stpt_data:
            datemp_stpt = (sum(datemp_stpt_data) / len(datemp_stpt_data))
        if fan_status_data:
            fanstatus = (sum(fan_status_data) / len(fan_status_data))
        if fan_speedcmd_data:
            fanspeed = (sum(fan_speedcmd_data) / len(fan_speedcmd_data))
        if damper_data:
            outdoor_damper = (sum(damper_data) / len(damper_data))
        if ccv_data:
            ccv = (sum(ccv_data) / len(ccv_data))
        if hcv_data:
            hcv = (sum(hcv_data) / len(hcv_data))
        if matemp_data and ratemp_data:
            denominator = oatemp - ratemp
            if denominator == 0:
                oaf = 0
            else:
                oaf = (matemp - ratemp) / denominator
            if oaf > 1:
                oaf = 1
            elif oaf < 0:
                oaf = 0
            oaf *= 100

        if return_fan_speedcmd_data:
            return_fan_speedcmd = (sum(return_fan_speedcmd_data) / len(return_fan_speedcmd_data))
        if occ_data:
            occupancy = (sum(occ_data) / len(occ_data))*100
        if discharge_sp_data:
            discharge_sp = (sum(discharge_sp_data) / len(discharge_sp_data))
        if staticpressure_sp_data:
            staticpressure_sp = (sum(staticpressure_sp_data) / len(staticpressure_sp_data))

        out_data = {
            'datetime': str(current_time),
            'OutdoorAirTemperature': oatemp,
            'MixedAirTemperature': None if not matemp else matemp,
            'ReturnAirTemperature': None if ratemp is None else ratemp,
            'DischargeAirTemperature': None if datemp is None else datemp,
            'DischargeAirTemperatureSetPoint': None if datemp_stpt is None else datemp_stpt,
            'SupplyFanStatus': None if fanstatus is None else fanstatus,
            'SupplyFanSpeed': None if fanspeed is None else fanspeed,
            'OutdoorDamper': None if outdoor_damper is None else outdoor_damper,
            'CCV': None if ccv is None else ccv,
            'HCV': None if hcv is None else hcv,
            'OutdoorAirFraction': None if oaf is None else oaf,
            'ReturnFanSpeed': None if return_fan_speedcmd is None else return_fan_speedcmd,
            'OccupancyMode': None if occupancy is None else occupancy,
            'DuctStaticPressure': None if discharge_sp is None else discharge_sp,
            'DuctStaticPressureSetPoint': None if staticpressure_sp is None else staticpressure_sp,
        }
        result.insert_table_row('AhuEcam', out_data)
        return result
Beispiel #20
0
 def shutdown(self):
     results = Results()
     results.log('ARG!! I DIED!!', logging.INFO)
     return results
Beispiel #21
0
    def run(self, current_time, points):
        '''
        Check algorithm pre-quisites and assemble data set for analysis.
        '''
        device_dict = {}
        result = Results()
        topics = self.inp.get_topics()
        topic = topics[self.hws_temp_name][0]
        current_time = self.inp.localize_sensor_time(topic, current_time)
        base_topic = self.inp.get_topics()
        meta_topics = self.inp.get_topics_meta()

        unit_dict = {}
        if len(base_topic[self.oa_temp_name]) > 0:
            unit_dict[self.oa_temp_name] = meta_topics[self.oa_temp_name][
                base_topic[self.oa_temp_name][0]]['unit']
        if len(base_topic[self.hws_temp_name]) > 0:
            unit_dict[self.hws_temp_name] = meta_topics[self.hws_temp_name][
                base_topic[self.hws_temp_name][0]]['unit']
        if len(base_topic[self.hwr_temp_name]) > 0:
            unit_dict[self.hwr_temp_name] = meta_topics[self.hwr_temp_name][
                base_topic[self.hwr_temp_name][0]]['unit']
        if len(base_topic[self.hw_stsp_name]) > 0:
            unit_dict[self.hw_stsp_name] = meta_topics[self.hw_stsp_name][
                base_topic[self.hw_stsp_name][0]]['unit']

        for key, value in points.items():
            device_dict[key.lower()] = value

        oatemp_data = []
        loop_dp_values = []
        loop_dp_stpt_values = []
        hw_pump_status_values = []
        boiler_status_values = []
        hw_pump_vfd_values = []
        hw_stsp_values = []
        hws_temp_values = []
        hwr_temp_values = []

        for key, value in device_dict.items():
            if key.startswith(self.loop_dp_stpt_name) and value is not None:
                loop_dp_stpt_values.append(value)
            elif key.startswith(self.loop_dp_name) and value is not None:
                loop_dp_values.append(value)
            elif key.startswith(
                    self.hw_pump_status_name) and value is not None:
                hw_pump_status_values.append(value)
            elif key.startswith(self.boiler_status_name) and value is not None:
                boiler_status_values.append(value)
            elif key.startswith(self.hw_pump_vfd_name) and value is not None:
                hw_pump_vfd_values.append(value)
            elif key.startswith(self.hw_stsp_name) and value is not None:
                hw_stsp_values.append(value)
            elif key.startswith(self.hws_temp_name) and value is not None:
                hws_temp_values.append(value)
            elif key.startswith(self.hwr_temp_name) and value is not None:
                hwr_temp_values.append(value)
            elif (key.startswith(self.oa_temp_name)  #OAT
                  and value is not None):
                oatemp_data.append(value)

        if 'celcius' or 'kelvin' in unit_dict.values:
            if self.oa_temp_name in unit_dict:
                if unit_dict[self.oa_temp_name] == 'celcius':
                    oatemp_data = cu.convertCelciusToFahrenheit(oatemp_data)
                elif unit_dict[self.oa_temp_name] == 'kelvin':
                    oatemp_data = cu.convertKelvinToCelcius(
                        cu.convertCelciusToFahrenheit(oatemp_data))
            if self.hw_stsp_name in unit_dict:
                if unit_dict[self.hw_stsp_name] == 'celcius':
                    hw_stsp_values = cu.convertCelciusToFahrenheit(
                        hw_stsp_values)
                elif unit_dict[self.hw_stsp_name] == 'kelvin':
                    hw_stsp_values = cu.convertKelvinToCelcius(
                        cu.convertCelciusToFahrenheit(hw_stsp_values))
            if self.hw_stsp_name in unit_dict:
                if unit_dict[self.hws_temp_name] == 'celcius':
                    hws_temp_values = cu.convertCelciusToFahrenheit(
                        hws_temp_values)
                elif unit_dict[self.hws_temp_name] == 'kelvin':
                    hws_temp_values = cu.convertKelvinToCelcius(
                        cu.convertCelciusToFahrenheit(hws_temp_values))
            if self.hwr_temp_name in unit_dict:
                if unit_dict[self.hwr_temp_name] == 'celcius':
                    hwr_temp_values = cu.convertCelciusToFahrenheit(
                        hwr_temp_values)
                elif unit_dict[self.hwr_temp_name] == 'kelvin':
                    hwr_temp_values = cu.convertKelvinToCelcius(
                        cu.convertCelciusToFahrenheit(hwr_temp_values))

        oatemp = hw_stsp_temp = hws_temp = hwr_temp = None
        loop_dp = loop_dp_stpt = None
        hw_pump_status = boiler_status = None
        hw_pump_vfd = None

        if oatemp_data:
            oatemp = (sum(oatemp_data) / len(oatemp_data))
        if hw_stsp_values:
            hw_stsp_temp = (sum(hw_stsp_values) / len(hw_stsp_values))
        if hws_temp_values:
            hws_temp = (sum(hws_temp_values) / len(hws_temp_values))
        if hwr_temp_values:
            hwr_temp = (sum(hwr_temp_values) / len(hwr_temp_values))

        if loop_dp_stpt_values:
            loop_dp_stpt = (sum(loop_dp_stpt_values) /
                            len(loop_dp_stpt_values))
        if loop_dp_values:
            loop_dp = (sum(loop_dp_values) / len(loop_dp_values))

        if hw_pump_status_values:
            hw_pump_status = (sum(hw_pump_status_values) /
                              len(hw_pump_status_values))
        if boiler_status_values:
            boiler_status = (sum(boiler_status_values) /
                             len(boiler_status_values))

        if hw_pump_vfd_values:
            hw_pump_vfd = (sum(hw_pump_vfd_values) / len(hw_pump_vfd_values))

        out_data = {
            'datetime': str(current_time),
        }

        if not oatemp is None:
            out_data['OutdoorAirTemperature'] = oatemp
        if not hws_temp is None:
            out_data['HotWaterSupplyTemperature'] = hws_temp
        if not hwr_temp is None:
            out_data['HotWaterReturnTemperature'] = hwr_temp
        if not hw_stsp_temp is None:
            out_data['HotWaterTemperatureSetPoint'] = hw_stsp_temp

        if not loop_dp is None:
            out_data['LoopDifferentialPressure'] = loop_dp
        if not loop_dp_stpt is None:
            out_data['LoopDifferentialPressureSetPoint'] = loop_dp_stpt

        if not hw_pump_status is None:
            out_data['PumpStatus'] = hw_pump_status
        if not boiler_status is None:
            out_data['BoilerStatus'] = boiler_status

        if not hw_pump_vfd is None:
            out_data['HotWaterPumpVfd'] = hw_pump_vfd

        result.insert_table_row(self.table_name, out_data)

        return result
    def run(self, current_time, points):
        # topics = self.inp.get_topics()
        # diagnostic_topic = topics[self.zonetemperature_name][0]
        # current_time = self.inp.localize_sensor_time(diagnostic_topic, current_time)
        device_dict = {}
        diagnostic_result = Results()
        to_zone = dateutil.tz.gettz(self.cur_tz)
        current_time = current_time.astimezone(to_zone)

        for key, value in points.items():
            point_device = [_name.lower() for _name in key.split('&&&')]
            if point_device[0] not in device_dict:
                device_dict[point_device[0]] = [(point_device[1], value)]
            else:
                device_dict[point_device[0]].append((point_device[1], value))

        fan_status_data = []
        zn_temperature_data = []
        compressor_status_data = []
        zn_temperature_stpt_data = []

        def data_builder(value_tuple):
            value_list = []
            for item in value_tuple:
                if item[1] is not None:
                    value_list.append(item[1])
            return value_list

        for key, value in device_dict.items():
            data_name = key
            if value is None:
                continue
            if data_name == self.fanstatus_name:
                fan_status_data = data_builder(value)
            if data_name == self.zonetemperature_stpt_name:
                zn_temperature_stpt_data = data_builder(value)
            if data_name == self.zonetemperature_name:
                zn_temperature_data = data_builder(value)
            if data_name == self.comprstatus_name:
                compressor_status_data = data_builder(value)

        if not zn_temperature_data:
            return diagnostic_result

        zn_temperature = sum(zn_temperature_data) / len(zn_temperature_data)
        fan_status = None
        compressor_status = None
        zn_temperature_stpt = None

        if fan_status_data:
            fan_status = max(fan_status_data)
        if compressor_status_data:
            compressor_status = max(compressor_status_data)
        if zn_temperature_stpt_data:
            zn_temperature_stpt = sum(zn_temperature_stpt_data) / len(
                zn_temperature_stpt_data)

        zn_temperature = zn_temperature or default_if_none
        fan_status = fan_status if fan_status is not None else default_if_none
        compressor_status = compressor_status if compressor_status is not None else default_if_none
        zn_temperature_stpt = zn_temperature_stpt if zn_temperature_stpt is not None else default_if_none

        diagnostic_result = self.cycling_detector.on_new_data(
            current_time, zn_temperature, zn_temperature_stpt, fan_status,
            compressor_status, diagnostic_result)

        return diagnostic_result