Example #1
0
def get_usage_per_month(datastreams, start, end, property):
	months = []
	if start.date() > date.today():
		return months
	start_temp = start.date()
	start_values = []
	for datastream in datastreams:
		start_values.append(get_datapoint(datastream=datastream,timestamp=start_temp))
	
	while True:
		end_temp = min(date.today(),end.date(),nextMonth(start_temp))
		end_values = []
		for datastream in datastreams:
			end_values.append(get_datapoint(datastream=datastream,timestamp=end_temp))

		usages = []
		for i in xrange(len(end_values)):
			usages.append(Usage(datastream=datastreams[i],value=(end_values[i] - start_values[i])))

		print start_temp
		print end_temp	
		print property.get_historical_prices(timestamp=start_temp).electricity
		months.append(Month(start_date=start_temp,end_date=end_temp,usages=usages,prices=property.get_historical_prices(timestamp=start_temp)))

		if end_temp == date.today() or end_temp == end.date():
			break
		else:
			start_temp = end_temp
			start_values = end_values
	return months
Example #2
0
def get_last_year(datastreams,property):
	total = 0
	for datastream in datastreams:
		end_value = get_datapoint(datastream=datastream,timestamp=datetime.utcnow())
		start_value = get_datapoint(datastream=datastream,timestamp=datetime.utcnow()-timedelta(weeks=52))
		usage = end_value - start_value
		total = total + usage
	return total