def get_location_aggregate(self, location: str, dataset_name: str) -> pd.DataFrame:
     aggregate_obj = Aggregate.get_aggregate(dataset_name=dataset_name, location=location)
     location_aggregate = None
     for i in range(min(2, len(aggregate_obj))):
         leg_aggregate = aggregate_obj[i].get_samples(quantity_name=self.features)
         location_aggregate = leg_aggregate if location_aggregate is None else location_aggregate + leg_aggregate
     return location_aggregate
    def test_aggregate(self):
        kwargs = {'dataset_name': 'ukdale'}

        aggregates = Aggregate.get_aggregate(**kwargs)

        houses = {a.location for a in aggregates}
        self.assertSetEqual(
            {'house_1', 'house_2', 'house_3', 'house_4', 'house_5'}, houses,
            "Didn't get correct aggregates when only dataset_name is specified"
        )

        kwargs['location'] = 'house_1'
        aggregates = Aggregate.get_aggregate(**kwargs)
        houses = {a.location for a in aggregates}
        self.assertSetEqual(
            {'house_1'}, houses,
            "Didn't correctly get aggregate when location is specified")

        kwargs['location'] = 'house_10'
        aggregates = Aggregate.get_aggregate(**kwargs)
        self.assertEqual(0, len(aggregates),
                         "Should have retrieved empty list")
Beispiel #3
0
 def _get_aggregate_windows_without_activations(self, data_set_name, location, activations):
     """
     function to set aggregate_timeframes for caching information to retrieve examples without activations
     :param data_set_name: data_set_name of aggregate
     :param location: location where aggregate measurements were taken
     :param activations: target appliance activations for slicing aggregate window without activations
     :return: np array containing tuples of timeframes, dataset and location
     """
     aggregate = Aggregate.get_aggregate(location=location, dataset_name=data_set_name)[0]
     aggregate_data = aggregate.get_samples(quantity_name=self.features)
     gaps_between_activations = TimeFrameGroup()
     prev_end = aggregate_data.index[0]
     for activation in activations:
         gap = TimeFrame(prev_end, activation.index[0])
         gaps_between_activations.append(gap)
         prev_end = activation.index[-1]
     gap = TimeFrame(prev_end, aggregate_data.index[-1])
     gaps_between_activations.append(gap)
     good_sections = aggregate.get_good_sections(aggregate_data)
     print(len(good_sections))
     print(len(gaps_between_activations))
     print("Computing intersections")
     intersection = gaps_between_activations.greedy_find_intersection(good_sections) \
         .remove_shorter_than(self.window_size)
     print("Iterating intersections")
     aggregate_timeframes = None
     for timeframe in intersection:
         splits = timeframe.split(self.window_size)
         split_arr = np.array(
             list(
                 map(lambda split: (split, data_set_name, location),
                     splits)
             )
         )
         if aggregate_timeframes is not None:
             aggregate_timeframes = np.concatenate(
                 (aggregate_timeframes, split_arr)
             )
         else:
             aggregate_timeframes = split_arr
     return aggregate_timeframes
Beispiel #4
0
 def rpc_get_aggregate_metrics(self, project, typ="general/aggregate"):
     d, m = typ.split("/")
     res = Aggregate.get_aggregate(project.ph_id, slashify(project.ph_id, "aggregate", d))
     return res[m]