Exemple #1
0
def full_running_totals(dictionary1, days, unit):
    #creadted for use with master_dict
    #newest and working
    #limit days after this calculation for range
    #Creates running totals for each day - not just activity day
    calculation_range_time = []
    final_list = []
    dictionary = dictionary1.copy()
    x = days
    #time functions
    now = datetime.datetime.now()
    start_of_today = datetime.datetime(now.year,
                                       now.month,
                                       now.day,
                                       hour=0,
                                       minute=0,
                                       second=0)
    end_of_today = datetime.datetime(now.year,
                                     now.month,
                                     now.day,
                                     hour=23,
                                     minute=59,
                                     second=59)

    difference = start_of_today - get_time.forever()  #fix start peroid

    calculation_range = list(range(
        0, (difference.days +
            1)))  #creates list from past date(given) to current date
    calculation_range_rev = list(reversed(calculation_range))
    calculation_range_time = [
        end_of_today - datetime.timedelta(days=x)
        for x in range(0, (difference.days + 1))
    ]

    for i, f in zip(
            calculation_range_time,
            calculation_range):  #for every calculation day ex 1,2,3,4,5 back
        dictionary_1 = dictionary.copy()  #create a new dictionary
        oldest_time = end_of_today - (datetime.timedelta(days=(x + f)))
        for key in list(dictionary_1):
            if key > i:
                del dictionary_1[key]  #delete keys newer than calculation day
        for key in list(dictionary_1):
            if key < oldest_time:  #delete keys older than oldest time
                del dictionary_1[key]
        value_list = []
        for key in dictionary_1:
            value_list.append(float(
                dictionary_1[key][unit]))  #adds variables to list
        list_sum = sum(value_list)
        final_list.append(list_sum)
    new_date_list = []
    for i in calculation_range:  #create list of days going backwards from today
        new_day = get_time.day(i)
        new_date_list.append(new_day)
    new_dict = dict(zip(new_date_list, final_list))
    return new_dict
Exemple #2
0
def all_running_totals(dictionary1, days):
    #used by Noteables2 to get dictionary of running totals and datetime for keys
    calculation_range_time = []
    final_list = []

    dictionary = dictionary1.copy()
    x = days

    #time functions
    now = datetime.datetime.now()
    start_of_today = datetime.datetime(now.year,
                                       now.month,
                                       now.day,
                                       hour=0,
                                       minute=0,
                                       second=0)
    end_of_today = datetime.datetime(now.year,
                                     now.month,
                                     now.day,
                                     hour=23,
                                     minute=59,
                                     second=59)
    difference = start_of_today - get_time.FOY()

    calculation_range = list(range(
        0, (difference.days +
            1)))  #creates list from past date(given) to current date
    calculation_range_rev = list(reversed(calculation_range))
    calculation_range_time = [
        end_of_today - datetime.timedelta(days=x)
        for x in range(0, (difference.days + 1))
    ]

    for i, f in zip(
            calculation_range_time,
            calculation_range):  #for every calculation day ex 1,2,3,4,5 back
        dictionary_1 = dictionary.copy()  #create a new dictionary
        oldest_time = end_of_today - (datetime.timedelta(days=(x + f)))
        for key in list(dictionary_1):
            if key > i:
                del dictionary_1[key]  #delete keys newer than calculation day
        for key in list(dictionary_1):
            if key < oldest_time:  #delete keys older than oldest time
                del dictionary_1[key]

        value_list = (dictionary_1.values())  #grabs x values from list
        meters = sum(value_list)
        miles = meters_to_miles(meters)
        final_list.append(float(miles))
    #new_dict = dict(zip(calculation_range_rev, final_list))
    new_date_list = []
    for i in calculation_range:  #create list of days going backwards from today
        new_day = get_time.day(i)
        new_date_list.append(new_day)
    #print(final_list)
    new_dict = dict(zip(new_date_list, final_list))
    return new_dict
from requests import get
from pprint import pprint
from datetime import datetime
from datetime import timedelta
import matplotlib.pyplot as plt
import pylab
import matplotlib.dates as mdates
import credentials
import get_time

def hass_time_format(stamp):
    return stamp.strftime("%Y-%m-%dT%T")

period_start = hass_time_format(get_time.day(.25))
period_end = hass_time_format(datetime.now())

input_var = '/api/history/period/'+period_start+'?end_time='+period_end

the_title = 'Temp Sensors'

value_1 = 'sensor.bathroom_temperature'
value_2 = 'sensor.sensor2_temperature'
value_3 = 'sensor.sensor3_temperature'

url = credentials.api_url+input_var
headers = {'x-ha-access': credentials.api_password,
           'content-type': 'application/json'}

response = get(url, headers=headers).json()

value_1_dict = {}
Exemple #4
0
from requests import get
from pprint import pprint
from datetime import datetime
from datetime import timedelta
import get_time
import credentials
import pprint
import matplotlib.pyplot as plt
import numpy as np



def hass_time_format(stamp):
    return stamp.strftime("%Y-%m-%dT%T")

period_start = hass_time_format(get_time.day(1)) #x days ago
period_end = hass_time_format(datetime.now()) #now obviously

input_var = '/api/history/period/'+period_start+'?end_time='+period_start #should be period_end
input_var = '/api/states'
url = credentials.api_url+input_var
headers = {'x-ha-access': credentials.api_password,
           'content-type': 'application/json'}

response = get(url, headers=headers).json()

value_dict = [
'sensor.report_monthly_switch_kitchen_overhead',
'sensor.report_monthly_light_cabinets',
'sensor.report_monthly_light_wall',
'sensor.report_monthly_light_sink',