def test_excessive_day_light_ones(self):
        """Test: Lights are on for the whole time period."""
        a = dt.datetime(2014, 1, 1, 0, 0, 0, 0)
        b = dt.datetime(2014, 1, 4, 0, 0, 0, 0)
        base = set_up_datetimes(a, b, 21600)

        light_stat = np.ones(len(base),bool)

        append_data_to_datetime(base, light_stat)

        result = excessive_daylight(base, [[7,17],[1,2,3,4,5],[]], 100, 100)
        self.assertTrue('Problem' in result.keys())
    def test_excessive_day_light_expect_success_unoccupied_time(self):
        """Test: Lights not on during half of the whole occupied period."""
        a = dt.datetime(2014, 1, 1, 0, 0, 0, 0)
        b = dt.datetime(2014, 1, 2, 0, 0, 0, 0)
        base = set_up_datetimes(a, b, 3600)

        light_stat = np.zeros(len(base), bool)
        light_stat[15:23] = True
        append_data_to_datetime(base, light_stat)
        result = excessive_daylight(base, [[7,17],[1,2,3,4,5],[]], 100, 100)

        self.assertTrue(result == {})
    def test_excessive_day_light_expect_fail(self):
        """Test: Lights are on throughout the whole occupied period.""" 
        a = dt.datetime(2014, 1, 1, 0, 0, 0, 0)
        b = dt.datetime(2014, 1, 3, 0, 0, 0, 0)
        base = set_up_datetimes(a, b, 3600)

        light_stat = np.zeros(len(base), bool)
        light_stat[7:17] = True
        light_stat[31:41] = True
        append_data_to_datetime(base, light_stat)

        result = excessive_daylight(base, [[7,17],[1,2,3,4,5],[]], 100, 100)
        self.assertTrue('Problem' in result.keys())
    def execute(self):
        # Called after User hits GO
        """
        Accepts lighting status and operational hours to determine if there
        is excessive lighting during daytime.
        """
        self.out.log(
            "Starting application: Sensor Suitcase excessive lighting.",
            logging.INFO)

        # FIXME: Modify logging message.
        self.out.log('@building_area' + str(self.building_area), logging.INFO)
        self.out.log('@electricity_cost' + str(self.electricity_cost),
                     logging.INFO)
        self.out.log('@operating_sched' + str(self.operating_sched),
                     logging.INFO)

        # Get lighting status from database
        lighting_query = self.inp.get_query_sets('lightingstatus',
                                                 exclude={'value': None})
        datetime_lightmode = []
        for x in lighting_query[0]:
            datetime_lightmode.append((x[0], x[1]))

        daylight_flag = edl.excessive_daylight(datetime_lightmode,
                                               self.operating_sched,
                                               self.building_area,
                                               self.electricity_cost)
        if daylight_flag != {}:
            self.out.insert_row(
                'SensorSuitcaseLight', {
                    'analysis': 'Excessive Daylighting',
                    'problem': daylight_flag['Problem'],
                    'diagnostic': daylight_flag['Diagnostic'],
                    'recommendation': daylight_flag['Recommendation'],
                    'savings': '${:.2f}'.format(daylight_flag['Savings'])
                })

        nighttime_flag = enl.excessive_nighttime(datetime_lightmode,
                                                 self.operating_sched,
                                                 self.building_area,
                                                 self.electricity_cost)
        if nighttime_flag != {}:
            self.out.insert_row(
                'SensorSuitcaseLight', {
                    'analysis': 'Excessive Daylighting',
                    'problem': nighttime_flag['Problem'],
                    'diagnostic': nighttime_flag['Diagnostic'],
                    'recommendation': nighttime_flag['Recommendation'],
                    'savings': '${:.2f}'.format(nighttime_flag['Savings'])
                })
    def test_excessive_day_light_expect_success_on_off(self):
        """Test: Lights turn on and off twice during the occupied period."""
        a = dt.datetime(2014, 1, 1, 0, 0, 0, 0)
        b = dt.datetime(2014, 1, 2, 0, 0, 0, 0)
        base = set_up_datetimes(a, b, 3600)

        light_stat = np.zeros(len(base), bool)
        light_stat[7:11] = True
        light_stat[13:14] = True
        light_stat[16] = True
        append_data_to_datetime(base, light_stat)

        result = excessive_daylight(base, [[7,17],[1,2,3,4,5],[]], 100, 100)
        self.assertTrue(result == {})
    def execute(self):
        # Called after User hits GO
        """
        Accepts lighting status and operational hours to determine if there
        is excessive lighting during daytime.
        """
        self.out.log("Starting application: Sensor Suitcase excessive lighting.", logging.INFO)

        # FIXME: Modify logging message.
        self.out.log('@building_area'+str(self.building_area), logging.INFO)
        self.out.log('@electricity_cost'+str(self.electricity_cost), logging.INFO)
        self.out.log('@operating_sched'+str(self.operating_sched), logging.INFO)

        # Get lighting status from database
        lighting_query = self.inp.get_query_sets('lightingstatus',
                                                 exclude={'value':None} )
        datetime_lightmode = []
        for x in lighting_query[0]:
            datetime_lightmode.append((x[0],x[1]))

        daylight_flag = edl.excessive_daylight(datetime_lightmode,
                                               self.operating_sched,
                                               self.building_area,
                                               self.electricity_cost)
        if daylight_flag != {}:
            self.out.insert_row('SensorSuitcaseLight', {
                                'analysis': 'Excessive Daylighting',
                                'problem': daylight_flag['Problem'],
                                'diagnostic': daylight_flag['Diagnostic'],
                                'recommendation': daylight_flag['Recommendation'],
                                'savings': '${:.2f}'.format(daylight_flag['Savings'])
                                })

        nighttime_flag = enl.excessive_nighttime(datetime_lightmode,
                                                 self.operating_sched,
                                                 self.building_area,
                                                 self.electricity_cost)
        if nighttime_flag != {}:
            self.out.insert_row('SensorSuitcaseLight', {
                                'analysis': 'Excessive Daylighting',
                                'problem': nighttime_flag['Problem'],
                                'diagnostic': nighttime_flag['Diagnostic'],
                                'recommendation': nighttime_flag['Recommendation'],
                                'savings': '${:.2f}'.format(nighttime_flag['Savings'])
                                })