예제 #1
0
    def test_bin_by_semester(self):
        dates = [
            parser.parse('2015-10-31 23:59:59'),
            parser.parse('2015-11-01 0:00:00'),
            parser.parse('2015-12-31 23:59:59'),
            parser.parse('2016-01-01 0:00:00'),
            parser.parse('2016-03-23 13:00:00'),
            parser.parse('2016-04-30 23:59:59'),
            parser.parse('2016-05-01 0:00:00'),
            parser.parse('2016-08-23 04:05:06'),
            parser.parse('2016-10-31 23:59:59'),
            parser.parse('2016-11-01 0:00:00'),
            parser.parse('2023-05-01 0:00:00')
        ]
        df = pd.DataFrame(
            dict(dates=dates,
                 a=[i for i in range(0, len(dates))],
                 b=[2 * i for i in range(0, len(dates))]))

        # default aggregation function
        binned = bin_by_semester(df,
                                 date_column='dates',
                                 semester_column='semesters')
        self.assertEqual(5, len(binned['semesters']))
        self.assertEqual('2015-1', binned['semesters'].iloc[0])
        self.assertEqual('2015-2', binned['semesters'].iloc[1])
        self.assertEqual('2016-1', binned['semesters'].iloc[2])
        self.assertEqual('2016-2', binned['semesters'].iloc[3])
        self.assertEqual('2023-1', binned['semesters'].iloc[4])
        self.assertEqual([0, 15, 21, 9, 10], binned['a'].values.tolist())
        self.assertEqual([0, 30, 42, 18, 20], binned['b'].values.tolist())

        # np.sum as aggregation function
        binned = bin_by_semester(df,
                                 agg_func=np.sum,
                                 date_column='dates',
                                 semester_column='semesters')
        self.assertEqual(5, len(binned['semesters']))
        self.assertEqual('2015-1', binned['semesters'].iloc[0])
        self.assertEqual('2015-2', binned['semesters'].iloc[1])
        self.assertEqual('2016-1', binned['semesters'].iloc[2])
        self.assertEqual('2016-2', binned['semesters'].iloc[3])
        self.assertEqual('2023-1', binned['semesters'].iloc[4])
        self.assertEqual([0, 15, 21, 9, 10], binned['a'].values.tolist())
        self.assertEqual([0, 30, 42, 18, 20], binned['b'].values.tolist())

        # np.mean aggregation function
        binned = bin_by_semester(df,
                                 agg_func=np.mean,
                                 date_column='dates',
                                 semester_column='semesters')
        self.assertEqual(5, len(binned['semesters']))
        self.assertEqual('2015-1', binned['semesters'].iloc[0])
        self.assertEqual('2015-2', binned['semesters'].iloc[1])
        self.assertEqual('2016-1', binned['semesters'].iloc[2])
        self.assertEqual('2016-2', binned['semesters'].iloc[3])
        self.assertEqual('2023-1', binned['semesters'].iloc[4])
        self.assertEqual([0, 3, 7, 9, 10], binned['a'].values.tolist())
        self.assertEqual([0, 6, 14, 18, 20], binned['b'].values.tolist())
예제 #2
0
    def test_bin_by_semester(self):
        dates = [parser.parse('2015-10-31 23:59:59'),
                 parser.parse('2015-11-01 0:00:00'),
                 parser.parse('2015-12-31 23:59:59'),
                 parser.parse('2016-01-01 0:00:00'),
                 parser.parse('2016-03-23 13:00:00'),
                 parser.parse('2016-04-30 23:59:59'),
                 parser.parse('2016-05-01 0:00:00'),
                 parser.parse('2016-08-23 04:05:06'),
                 parser.parse('2016-10-31 23:59:59'),
                 parser.parse('2016-11-01 0:00:00'),
                 parser.parse('2023-05-01 0:00:00')]
        df = pd.DataFrame(dict(dates=dates,
                               a=[i for i in range(0, len(dates))],
                               b=[2 * i for i in range(0, len(dates))]))

        # default aggregation function
        binned = bin_by_semester(df, date_column='dates', semester_column='semesters')
        self.assertEqual(5, len(binned['semesters']))
        self.assertEqual('2015-1', binned['semesters'].iloc[0])
        self.assertEqual('2015-2', binned['semesters'].iloc[1])
        self.assertEqual('2016-1', binned['semesters'].iloc[2])
        self.assertEqual('2016-2', binned['semesters'].iloc[3])
        self.assertEqual('2023-1', binned['semesters'].iloc[4])
        self.assertEqual([0, 15, 21, 9, 10], binned['a'].values.tolist())
        self.assertEqual([0, 30, 42, 18, 20], binned['b'].values.tolist())

        # np.sum as aggregation function
        binned = bin_by_semester(df, agg_func=np.sum, date_column='dates', semester_column='semesters')
        self.assertEqual(5, len(binned['semesters']))
        self.assertEqual('2015-1', binned['semesters'].iloc[0])
        self.assertEqual('2015-2', binned['semesters'].iloc[1])
        self.assertEqual('2016-1', binned['semesters'].iloc[2])
        self.assertEqual('2016-2', binned['semesters'].iloc[3])
        self.assertEqual('2023-1', binned['semesters'].iloc[4])
        self.assertEqual([0, 15, 21, 9, 10], binned['a'].values.tolist())
        self.assertEqual([0, 30, 42, 18, 20], binned['b'].values.tolist())

        # np.mean aggregation function
        binned = bin_by_semester(df, agg_func=np.mean,  date_column='dates', semester_column='semesters')
        self.assertEqual(5, len(binned['semesters']))
        self.assertEqual('2015-1', binned['semesters'].iloc[0])
        self.assertEqual('2015-2', binned['semesters'].iloc[1])
        self.assertEqual('2016-1', binned['semesters'].iloc[2])
        self.assertEqual('2016-2', binned['semesters'].iloc[3])
        self.assertEqual('2023-1', binned['semesters'].iloc[4])
        self.assertEqual([0, 3, 7, 9, 10], binned['a'].values.tolist())
        self.assertEqual([0, 6, 14, 18, 20], binned['b'].values.tolist())
    def semester_to_date_plot(self):
        """Dial plot displaying the shutter open efficiency for the semester in which `self.date` lies.

        All dates in the semester up to but excluding `self.date` are included when calculating the shutter open
        efficiency.

        Returns:
        --------
        app.plot.plot.DialPlot
            Plot of the shutter open efficiency for the semester to date.
        """

        sem = semester(self.date)
        binned_df = bin_by_semester(df=self.df,
                                    cutoff_date=self.date,
                                    date_column='Date',
                                    semester_column='Semester')
        current_semester = binned_df[binned_df.Semester == sem]
        if len(current_semester):
            shutter_open_efficiency = self._shutter_open_efficiency(
                current_semester.ShutterOpenTime[0],
                current_semester.ScienceTime[0])
        else:
            shutter_open_efficiency = 0

        dial_color_func = neutral_color_func

        return DialPlot(
            values=[shutter_open_efficiency],
            label_values=range(0, 101, 10),
            dial_color_func=dial_color_func,
            display_values=['{:.1f}%'.format(shutter_open_efficiency)],
            **self.kwargs)
    def semester_to_date_plot(self):
        """Dial plot displaying the operation efficiency for the semester in which `self.date` lies.

        All dates in the semester up to but excluding `self.date` are included when calculating the operation
        efficiency.

        Returns:
        --------
        app.plot.plot.DialPlot
            Plot of the operation efficiency for the semester to date.
        """

        sem = semester(self.date)
        binned_df = bin_by_semester(df=self.df, cutoff_date=self.date, date_column='Date', semester_column='Semester')
        current_semester = binned_df[binned_df.Semester == sem]
        if len(current_semester):
            operation_efficiency = self._observation_efficiency(current_semester.ObsTime[0],
                                                                current_semester.ScienceTime[0])
        else:
            operation_efficiency = 0

        dial_color_func = good_mediocre_bad_color_func(good_limit=90, bad_limit=80)

        required_operation_efficiency = required_for_semester_average(date=self.date,
                                                                      average=operation_efficiency,
                                                                      target_average=90)

        return DialPlot(values=[operation_efficiency, required_operation_efficiency],
                        label_values=range(0, 101, 10),
                        dial_color_func=dial_color_func,
                        display_values=['{:.1f}%'.format(operation_efficiency)],
                        **self.kwargs)
    def semester_to_date_plot(self):
        """Dial plot displaying the weather downtime for the semester in which `self.date` lies.

        All dates in the semester up to but excluding `self.date` are included when calculating the shutter open
        efficiency.

        The weather downtime is displayed as a percentage relative to the night length. A second hand shows the average
        percentage which must be achieved in the remaining time of the semester in order to achieve the target
        percentage.

        In addition its absolute value is displayed in hours.

        Returns:
        --------
        app.plot.plot.DialPlot
            Plot of the shutter open efficiency for the semester to date.
        """

        sem = semester(self.date)
        binned_df = bin_by_semester(df=self.df,
                                    cutoff_date=self.date,
                                    date_column='Date',
                                    semester_column='Semester')
        current_semester = binned_df[binned_df.Semester == sem]
        target_percentage = 55
        if len(current_semester):
            weather_downtime_percentage = 100 * current_semester.TimeLostToWeather[
                0] / current_semester.NightLength[0]
            required_percentage = required_for_semester_average(
                self.date, weather_downtime_percentage, target_percentage)
            weather_downtime = current_semester.TimeLostToWeather[0] / 3600
        else:
            weather_downtime_percentage = 0
            required_percentage = target_percentage
            weather_downtime = 0

        dial_color_func = good_mediocre_bad_color_func(good_limit=49,
                                                       bad_limit=40)

        return DialPlot(
            values=[weather_downtime_percentage, required_percentage],
            label_values=[v for v in range(0, 41, 10)] + [45] +
            [v for v in range(50, 101, 10)],
            dial_color_func=dial_color_func,
            display_values=[
                '{:.1f}%'.format(weather_downtime_percentage),
                '{:.1f}h'.format(weather_downtime)
            ],
            **self.kwargs)
    def semester_to_date_plot(self):
        """Dial plot displaying the telescope downtime for the semester in which `self.date` lies.

        All dates in the semester up to but excluding `self.date` are included when calculating the shutter open
        efficiency.

        The telescope downtime is displayed as a percentage relative to the night length. A second hand shows the
        average percentage which must be achieved in the remaining time of the semester in order to achieve the target
        percentage.

        In addition its absolute value is displayed in hours.

        Returns:
        --------
        app.plot.plot.DialPlot
            Plot of the shutter open efficiency for the semester to date.
        """

        sem = semester(self.date)
        binned_df = bin_by_semester(df=self.df, cutoff_date=self.date, date_column='Date', semester_column='Semester')
        current_semester = binned_df[binned_df.Semester == sem]
        target_percentage = 3
        if len(current_semester):
            telescope_downtime_percentage =\
                100 * current_semester.TimeLostToProblems[0] / current_semester.NightLength[0]
            required_percentage = required_for_semester_average(self.date,
                                                                telescope_downtime_percentage,
                                                                target_percentage)
            telescope_downtime = current_semester.TimeLostToProblems[0] / 3600
        else:
            telescope_downtime_percentage = 0
            required_percentage = target_percentage
            telescope_downtime = 0

        dial_color_func = good_mediocre_bad_color_func(good_limit=3, bad_limit=6)

        return DialPlot(values=[telescope_downtime_percentage, required_percentage],
                        label_values=range(0, 16, 1),
                        dial_color_func=dial_color_func,
                        display_values=['{:.1f}%'.format(telescope_downtime_percentage),
                                        '{:.1f}h'.format(telescope_downtime)],
                        **self.kwargs)
    def semester_to_date_plot(self):
        """Dial plot displaying the operation efficiency for the semester in which `self.date` lies.

        All dates in the semester up to but excluding `self.date` are included when calculating the operation
        efficiency.

        Returns:
        --------
        app.plot.plot.DialPlot
            Plot of the operation efficiency for the semester to date.
        """

        sem = semester(self.date)
        binned_df = bin_by_semester(df=self.df,
                                    cutoff_date=self.date,
                                    date_column='Date',
                                    semester_column='Semester')
        current_semester = binned_df[binned_df.Semester == sem]
        if len(current_semester):
            operation_efficiency = self._observation_efficiency(
                current_semester.ObsTime[0], current_semester.ScienceTime[0])
        else:
            operation_efficiency = 0

        dial_color_func = good_mediocre_bad_color_func(good_limit=90,
                                                       bad_limit=80)

        required_operation_efficiency = required_for_semester_average(
            date=self.date, average=operation_efficiency, target_average=90)

        return DialPlot(
            values=[operation_efficiency, required_operation_efficiency],
            label_values=range(0, 101, 10),
            dial_color_func=dial_color_func,
            display_values=['{:.1f}%'.format(operation_efficiency)],
            **self.kwargs)