def test_setback_basic(self):
        a = datetime.datetime(2014, 1, 1, 0, 0, 0, 0)
        b = datetime.datetime(2014, 1, 3, 12, 0, 0, 0)
        # delta = 6 hours
        base = set_up_datetimes(a, b, 21600)

        DAT = copy.deepcopy(base)
        DAT_temp = [10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        append_data_to_datetime(DAT, DAT_temp)

        IAT = copy.deepcopy(base)
        IAT_temp = [60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60]
        append_data_to_datetime(IAT, IAT_temp)

        # just the first data point will count as during operational hours
        op_hours = [[0, 1], [3], []]

        test_ele_cost = 10000
        test_area = 5000
        result = setback_non_op(IAT, DAT, op_hours, test_ele_cost, test_area)

        expected = {
            "Problem": "Nighttime thermostat setbacks are not enabled.",
            "Diagnostic": "More than 30 percent of the data indicates that the "
            + "building is being conditioned or ventilated normally "
            + "during unoccupied hours.",
            "Recommendation": "Program your thermostats to decrease the "
            + "heating setpoint, or increase the cooling setpoint during "
            + "unoccuppied times.  Additionally, you may have a "
            + "contractor configure the RTU to reduce ventilation.",
            "Savings": round(((80 - 60) * 0.03 * 1 * 0.07 * test_ele_cost * (10 / 11)), 2),
        }

        self.assertEqual(result, expected)
    def test_setback_basic(self):
        a = datetime.datetime(2014, 1, 1, 0, 0, 0, 0)
        b = datetime.datetime(2014, 1, 3, 12, 0, 0, 0)
        #delta = 6 hours
        base = set_up_datetimes(a, b, 21600)

        DAT = copy.deepcopy(base)
        DAT_temp = [10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        append_data_to_datetime(DAT, DAT_temp)

        IAT = copy.deepcopy(base)
        IAT_temp = [60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60]
        append_data_to_datetime(IAT, IAT_temp)

        # just the first data point will count as during operational hours
        op_hours = [[0, 1], [3], []]

        test_ele_cost = 10000
        test_area = 5000
        result = setback_non_op(IAT, DAT, op_hours, test_ele_cost, test_area)

        expected = {
            'Problem': "Nighttime thermostat setbacks are not enabled.",
            'Diagnostic': "More than 30 percent of the data indicates that the " + \
                    "building is being conditioned or ventilated normally " + \
                    "during unoccupied hours.",
            'Recommendation': "Program your thermostats to decrease the " + \
                    "heating setpoint, or increase the cooling setpoint during " + \
                    "unoccuppied times.  Additionally, you may have a " + \
                    "contractor configure the RTU to reduce ventilation.",
            'Savings': round(((80-60) * 0.03 * 1 * 0.07 * test_ele_cost * (10/11)), 2)}

        self.assertEqual(result, expected)
    def test_setback_success(self):
        # ten data points
        a = datetime.datetime(2014, 1, 1, 0, 0, 0, 0)
        b = datetime.datetime(2014, 1, 3, 6, 0, 0, 0)
        # delta = 6 hours
        base = set_up_datetimes(a, b, 21600)

        # copy data to put in the right format
        DAT = copy.deepcopy(base)
        DAT_temp = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        append_data_to_datetime(DAT, DAT_temp)

        IAT = copy.deepcopy(base)
        IAT_temp = [10, 10, 10, 10, 10, 10, 10, 10, 80, 80]
        append_data_to_datetime(IAT, IAT_temp)

        # the first point is the only operational point
        op_hours = [[0, 1], [3], []]

        result = setback_non_op(IAT, DAT, op_hours, 10000, 5000)

        self.assertEqual(result, {})
    def test_setback_success(self):
        # ten data points
        a = datetime.datetime(2014, 1, 1, 0, 0, 0, 0)
        b = datetime.datetime(2014, 1, 3, 6, 0, 0, 0)
        #delta = 6 hours
        base = set_up_datetimes(a, b, 21600)

        # copy data to put in the right format
        DAT = copy.deepcopy(base)
        DAT_temp = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        append_data_to_datetime(DAT, DAT_temp)

        IAT = copy.deepcopy(base)
        IAT_temp = [10, 10, 10, 10, 10, 10, 10, 10, 80, 80]
        append_data_to_datetime(IAT, IAT_temp)

        # the first point is the only operational point
        op_hours = [[0, 1], [3], []]

        result = setback_non_op(IAT, DAT, op_hours, 10000, 5000)

        self.assertEqual(result, {})
Example #5
0
    def execute(self):
        # Called after User hits GO
        """
        Calculates weather sensitivity using Spearman rank.
        Also, outputs data points for energy signature scatter plot.
        """
        self.out.log("Starting Day Time Temperature Analysis", logging.INFO)

        self.out.log('@operating_sched'+str(self.operating_sched), logging.INFO)
        self.out.log('@building_area'+str(self.building_area), logging.INFO)
        self.out.log('@electricity_cost'+str(self.electricity_cost), logging.INFO)
        
        # Query the database
        zat_query = self.inp.get_query_sets('zat', exclude={'value':None},
                                                   wrap_for_merge=True,
                                                   group_by='minute')
                                                   
        dat_query = self.inp.get_query_sets('dat', exclude={'value':None},
                                                   wrap_for_merge=True,
                                                   group_by='minute')
                                                   
        oat_query = self.inp.get_query_sets('oat', exclude={'value':None},
                                                   wrap_for_merge=True,
                                                   group_by='minute')
                                                   
        status_query = self.inp.get_query_sets('hvacstatus', exclude={'value':None},
                                                   wrap_for_merge=True,
                                                   group_by='minute')
        # Merge temperatures and the HVACStatus
        merged_temperatures_status = self.inp.merge(zat_query, oat_query, dat_query,status_query)
        
        # Get conversion factor
        base_topic = self.inp.get_topics()
        meta_topics = self.inp.get_topics_meta()
        zat_unit = meta_topics['zat'][base_topic['zat'][0]]['unit']
        dat_unit = meta_topics['dat'][base_topic['dat'][0]]['unit']
        oat_unit = meta_topics['oat'][base_topic['oat'][0]]['unit']
        
        #From the merged values make the arrays for the models
        datetime_ZAT = []
        datetime_DAT = []
        datetime_OAT = []
        datetime_HVACStatus = []
        for line in merged_temperatures_status:
            # Convert datetime str to datetime obj
            datetimeObj = dt.datetime.strptime(line['time'],'%Y-%m-%d %H:%M')
            
            # Convert ZAT
            if zat_unit == 'celcius':
                convertedZAT = cu.convertCelciusToFahrenheit(line['zat'][0])
            elif zat_unit == 'kelvin':
                convertedZAT = cu.convertKelvinToCelcius(
                                cu.convertCelciusToFahrenheit(line['zat'][0]))
            else: 
                convertedZAT = line['zat'][0]
            #    
            datetime_ZAT.append((datetimeObj, convertedZAT)) 
        
            # Convert DAT
            if dat_unit == 'celcius':
                convertedDAT = cu.convertCelciusToFahrenheit(line['dat'][0])
            elif dat_unit == 'kelvin':
                convertedDAT = cu.convertKelvinToCelcius(
                                cu.convertCelciusToFahrenheit(line['dat'][0]))
            else: 
                convertedDAT = line['dat'][0]        
            #
            datetime_DAT.append((datetimeObj, convertedDAT)) 
                
            # Convert OAT
            if oat_unit == 'celcius':
                convertedOAT = cu.convertCelciusToFahrenheit(line['oat'][0])
            elif oat_unit == 'kelvin':
                convertedOAT = cu.convertKelvinToCelcius(
                                cu.convertCelciusToFahrenheit(line['oat'][0]))
            else: 
                convertedOAT = line['oat'][0]
            #
            datetime_OAT.append((datetimeObj, convertedOAT)) 
            #
            datetime_HVACStatus.append((datetimeObj, line['hvacstatus'][0])) 
        # Apply the comfort_and_setpoint model.
        comfort_flag, setback_flag = cs.comfort_and_setpoint(datetime_ZAT, 
                                                   datetime_DAT, 
                                                   self.operating_sched, 
                                                   self.building_area, 
                                                   self.electricity_cost, 
                                                   datetime_HVACStatus)
        if comfort_flag != {}:
            self.out.insert_row('SensorSuitcaseHVAC', { 
                                'analysis': 'Comfort Optimization',
                                'problem': comfort_flag['Problem'],
                                'diagnostic': comfort_flag['Diagnostic'],
                                'recommendation': comfort_flag['Recommendation'],
                                'savings': '${:.2f}'.format(comfort_flag['Savings'])
                                })
                                
        if setback_flag != {}:
            self.out.insert_row('SensorSuitcaseHVAC', { 
                                'analysis': 'Comfort Optimization',
                                'problem': setback_flag['Problem'],
                                'diagnostic': setback_flag['Diagnostic'],
                                'recommendation': setback_flag['Recommendation'],
                                'savings': '${:.2f}'.format(setback_flag['Savings'])
                                })
                                
        # Apply the economizer model.
        economizer_flag = ecn.economizer(datetime_DAT, 
                                         datetime_OAT, 
                                         datetime_HVACStatus, 
                                         self.electricity_cost, 
                                         self.building_area)    
        if economizer_flag != {}:
            self.out.insert_row('SensorSuitcaseHVAC', { 
                                'analysis': 'Economizer Diagnostics',
                                'problem': economizer_flag['Problem'],
                                'diagnostic': economizer_flag['Diagnostic'],
                                'recommendation': economizer_flag['Recommendation'],
                                'savings': '${:.2f}'.format(economizer_flag['Savings'])
                                })
        
        # Apply the setback_non_op model.
        setback_nonop_flag = sb.setback_non_op(datetime_ZAT, 
                                         datetime_DAT, 
                                         self.operating_sched, 
                                         self.electricity_cost, 
                                         self.building_area, 
                                         datetime_HVACStatus)
        if setback_nonop_flag != {}:
            self.out.insert_row('SensorSuitcaseHVAC', { 
                                'analysis': 'Setback During Unoccupied Hours',
                                'problem': setback_nonop_flag['Problem'],
                                'diagnostic': setback_nonop_flag['Diagnostic'],
                                'recommendation': setback_nonop_flag['Recommendation'],
                                'savings': '${:.2f}'.format(setback_nonop_flag['Savings'])
                                })
        
        # Apply the short_cycling model.
        shortcycling_flag = shc.short_cycling(datetime_HVACStatus, 
                                              self.electricity_cost)
        if shortcycling_flag != {}:
            self.out.insert_row('SensorSuitcaseHVAC', { 
                                'analysis': 'Shortcycling',
                                'problem': shortcycling_flag['Problem'],
                                'diagnostic': shortcycling_flag['Diagnostic'],
                                'recommendation': shortcycling_flag['Recommendation'],
                                'savings': '${:.2f}'.format(shortcycling_flag['Savings'])
                                })
Example #6
0
    def execute(self):
        # Called after User hits GO
        """
        Calculates weather sensitivity using Spearman rank.
        Also, outputs data points for energy signature scatter plot.
        """
        self.out.log("Starting application: Sensor Suitcase HVAC.",
                     logging.INFO)

        self.out.log('@operating_sched' + str(self.operating_sched),
                     logging.INFO)
        self.out.log('@building_area' + str(self.building_area), logging.INFO)
        self.out.log('@electricity_cost' + str(self.electricity_cost),
                     logging.INFO)

        # Query the database
        zat_query = self.inp.get_query_sets('zat',
                                            exclude={'value': None},
                                            wrap_for_merge=True,
                                            group_by='minute')

        dat_query = self.inp.get_query_sets('dat',
                                            exclude={'value': None},
                                            wrap_for_merge=True,
                                            group_by='minute')

        oat_query = self.inp.get_query_sets('oat',
                                            exclude={'value': None},
                                            wrap_for_merge=True,
                                            group_by='minute')

        status_query = self.inp.get_query_sets('hvacstatus',
                                               exclude={'value': None},
                                               wrap_for_merge=True,
                                               group_by='minute')
        # Merge temperatures and the HVACStatus
        merged_temperatures_status = self.inp.merge(zat_query, oat_query,
                                                    dat_query, status_query)

        self.out.log("Getting unit conversions.", logging.INFO)
        base_topic = self.inp.get_topics()
        meta_topics = self.inp.get_topics_meta()

        zat_unit = meta_topics['zat'][base_topic['zat'][0]]['unit']
        self.out.log(
            "Convert zone air temperatures from [{}] to [F].".format(zat_unit),
            logging.INFO)

        dat_unit = meta_topics['dat'][base_topic['dat'][0]]['unit']
        self.out.log(
            "Convert discharge air temperatures from [{}] to [F].".format(
                dat_unit), logging.INFO)

        oat_unit = meta_topics['oat'][base_topic['oat'][0]]['unit']
        self.out.log(
            "Convert outside air temperatures from [{}] to [F].".format(
                oat_unit), logging.INFO)

        #From the merged values make the arrays for the models
        datetime_ZAT = []
        datetime_DAT = []
        datetime_OAT = []
        datetime_HVACStatus = []
        for line in merged_temperatures_status:
            # Convert datetime str to datetime obj
            #             datetimeObj = dt.datetime.strptime(line['time'],'%Y-%m-%d %H:%M')
            datetimeObj = line['time']

            # Convert ZAT
            if zat_unit == 'celcius':
                convertedZAT = cu.convertCelciusToFahrenheit(line['zat'][0])
            elif zat_unit == 'kelvin':
                convertedZAT = cu.convertKelvinToCelcius(
                    cu.convertCelciusToFahrenheit(line['zat'][0]))
            else:
                convertedZAT = line['zat'][0]
            #
            datetime_ZAT.append((datetimeObj, convertedZAT))

            # Convert DAT
            if dat_unit == 'celcius':
                convertedDAT = cu.convertCelciusToFahrenheit(line['dat'][0])
            elif dat_unit == 'kelvin':
                convertedDAT = cu.convertKelvinToCelcius(
                    cu.convertCelciusToFahrenheit(line['dat'][0]))
            else:
                convertedDAT = line['dat'][0]
            #
            datetime_DAT.append((datetimeObj, convertedDAT))

            # Convert OAT
            if oat_unit == 'celcius':
                convertedOAT = cu.convertCelciusToFahrenheit(line['oat'][0])
            elif oat_unit == 'kelvin':
                convertedOAT = cu.convertKelvinToCelcius(
                    cu.convertCelciusToFahrenheit(line['oat'][0]))
            else:
                convertedOAT = line['oat'][0]
            #
            datetime_OAT.append((datetimeObj, convertedOAT))
            #
            datetime_HVACStatus.append((datetimeObj, line['hvacstatus'][0]))
        # Apply the comfort_and_setpoint model.
        comfort_flag, setback_flag = cs.comfort_and_setpoint(
            datetime_ZAT, datetime_DAT, self.operating_sched,
            self.building_area, self.electricity_cost, datetime_HVACStatus)
        if comfort_flag != {}:
            self.out.insert_row(
                'SensorSuitcaseHVAC', {
                    'analysis': 'Comfort Optimization',
                    'problem': comfort_flag['Problem'],
                    'diagnostic': comfort_flag['Diagnostic'],
                    'recommendation': comfort_flag['Recommendation'],
                    'savings': '${:.2f}'.format(comfort_flag['Savings'])
                })

        if setback_flag != {}:
            self.out.insert_row(
                'SensorSuitcaseHVAC', {
                    'analysis': 'Comfort Optimization',
                    'problem': setback_flag['Problem'],
                    'diagnostic': setback_flag['Diagnostic'],
                    'recommendation': setback_flag['Recommendation'],
                    'savings': '${:.2f}'.format(setback_flag['Savings'])
                })

        # Apply the economizer model.
        economizer_flag = ecn.economizer(datetime_DAT, datetime_OAT,
                                         datetime_HVACStatus,
                                         self.electricity_cost,
                                         self.building_area)
        if economizer_flag != {}:
            self.out.insert_row(
                'SensorSuitcaseHVAC', {
                    'analysis': 'Economizer Diagnostics',
                    'problem': economizer_flag['Problem'],
                    'diagnostic': economizer_flag['Diagnostic'],
                    'recommendation': economizer_flag['Recommendation'],
                    'savings': '${:.2f}'.format(economizer_flag['Savings'])
                })

        # Apply the setback_non_op model.
        setback_nonop_flag = sb.setback_non_op(datetime_ZAT, datetime_DAT,
                                               self.operating_sched,
                                               self.electricity_cost,
                                               self.building_area,
                                               datetime_HVACStatus)
        if setback_nonop_flag != {}:
            self.out.insert_row(
                'SensorSuitcaseHVAC', {
                    'analysis': 'Setback During Unoccupied Hours',
                    'problem': setback_nonop_flag['Problem'],
                    'diagnostic': setback_nonop_flag['Diagnostic'],
                    'recommendation': setback_nonop_flag['Recommendation'],
                    'savings': '${:.2f}'.format(setback_nonop_flag['Savings'])
                })

        # Apply the short_cycling model.
        shortcycling_flag = shc.short_cycling(datetime_HVACStatus,
                                              self.electricity_cost,
                                              self.building_area)
        if shortcycling_flag != {}:
            self.out.insert_row(
                'SensorSuitcaseHVAC', {
                    'analysis': 'Shortcycling',
                    'problem': shortcycling_flag['Problem'],
                    'diagnostic': shortcycling_flag['Diagnostic'],
                    'recommendation': shortcycling_flag['Recommendation'],
                    'savings': '${:.2f}'.format(shortcycling_flag['Savings'])
                })