def variables(self, y, m, h, d):
     power_meters = self.hosts()
     energy_list = list()
     for resources in power_meters:
         query = self.get_query(resources, y, m, h, d)
         energy_samples = self.get_energy_meters(query)
         energy_samples = list(reversed(energy_samples))
         meter_list_len = len(energy_samples)
         div = meter_list_len/5
         if div == 0:
             div = 1
         start = 0
         end = div
         for num in range(0, (meter_list_len/div)):
             energy = sum(map(lambda p: float(p.counter_volume),
                              energy_samples[start:end]))
             energy /= div
             timestamp = energy_samples[start].timestamp
             energy_list.append(dict(energy=energy, timestamp=timestamp, resource=resources))
             start += div
             end += div
     samples = sorted(energy_list, key=lambda engy: engy['timestamp'])
     for i in samples:
         datew = str(y) + '-' + self.month_list[m-1]
         timestamp = i['timestamp']
         total_energy = i['energy']
         resource1 = i['resource']
         joule = PowerSamplesAdm.create(value=total_energy, resource=resource1, date=datew, timestamp=timestamp)
         joule.save()
    def energy_samples(self):
        """

        :rtype : dict
        :type self: AdminManager
        """
        data_list = list()
        data = ''
        for meter in self.power_meters:
            date_query = '{0}-{1}'.format(str(self.year), str(self.month_list[self.month-1]))
            data = PowerSamplesAdm.select().where((PowerSamplesAdm.date == date_query) &
                                                  (PowerSamplesAdm.resource == meter))
            if data:
                data_list.append(map(lambda m: m.value, data))

        values = map(lambda m: sum(m), zip(*data_list))
        timestamp = (map(lambda m: m.timestamp, data))
        return dict(timestamp=timestamp, value=values)
    def energy_samples(self):
        """

        :rtype : dict
        :type self: AdminManager
        """
        data_list = list()
        data = ''
        for meter in self.power_meters:
            date_query = '{0}-{1}'.format(str(self.year),
                                          str(self.month_list[self.month - 1]))
            data = PowerSamplesAdm.select().where(
                (PowerSamplesAdm.date == date_query)
                & (PowerSamplesAdm.resource == meter))
            if data:
                data_list.append(map(lambda m: m.value, data))

        values = map(lambda m: sum(m), zip(*data_list))
        timestamp = (map(lambda m: m.timestamp, data))
        return dict(timestamp=timestamp, value=values)