def energy_per_month(self, start): month_energy_list = [] for month in range(start, self.month+2): date_query = '{0}-{1}'.format(str(self.month_list[month-1]), str(self.year)) data = MonthlyJoules.select().where((MonthlyJoules.date == date_query)) energy = sum(map(lambda m: int(m.joules), data))/1000 month_energy_list.append({'name': self.month_list[month-1], 'data': [energy]}) return month_energy_list
def energy_per_month(self, start): month_energy_list = [] for month in range(start, self.month + 2): date_query = '{0}-{1}'.format(str(self.month_list[month - 1]), str(self.year)) data = MonthlyJoules.select().where( (MonthlyJoules.date == date_query)) energy = sum(map(lambda m: int(m.joules), data)) / 1000 month_energy_list.append({ 'name': self.month_list[month - 1], 'data': [energy] }) return month_energy_list
def total_energy(self): energy_list = list() energy_list_sup = list() date_query = '{0}-{1}'.format(str(self.month_list[self.month-1]), str(self.year)) data = MonthlyJoules.select().where((MonthlyJoules.date == date_query)) for energy in data: if energy.resource not in energy_list_sup: energy_list_sup.append(energy.resource) energy_list.append(dict(resource=energy.resource, value=energy.joules)) else: for e in energy_list: if energy.resource == e['resource']: e['value'] += energy.joules self.energy = energy_list
def total_energy(self): energy_list = list() energy_list_sup = list() date_query = '{0}-{1}'.format(str(self.month_list[self.month - 1]), str(self.year)) data = MonthlyJoules.select().where((MonthlyJoules.date == date_query)) for energy in data: if energy.resource not in energy_list_sup: energy_list_sup.append(energy.resource) energy_list.append( dict(resource=energy.resource, value=energy.joules)) else: for e in energy_list: if energy.resource == e['resource']: e['value'] += energy.joules self.energy = energy_list
def insert(self, y, m, h, d): power_meters = self.hosts() 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)) initial_energy = energy_samples[0].counter_volume previous_sample = initial_energy total_energy = 0 for samples in energy_samples: if samples.counter_volume > previous_sample: total_energy += samples.counter_volume - previous_sample previous_sample = samples.counter_volume datew = self.month_list[m - 1] + "-" + str(y) timestamp = datetime(y, m, d, h) total_energy *= 3600000 joule = MonthlyJoules.create(joules=total_energy, resource=resources, date=datew, timestamp=timestamp) joule.save()
def insert(self, y, m, h, d): power_meters = self.hosts() 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)) initial_energy = energy_samples[0].counter_volume previous_sample = initial_energy total_energy = 0 for samples in energy_samples: if samples.counter_volume > previous_sample: total_energy += samples.counter_volume - previous_sample previous_sample = samples.counter_volume datew = self.month_list[m - 1] + '-' + str(y) timestamp = datetime(y, m, d, h) total_energy *= 3600000 joule = MonthlyJoules.create(joules=total_energy, resource=resources, date=datew, timestamp=timestamp) joule.save()