Skip to content
Snippets Groups Projects
CS_499_backend.py 16 KiB
Newer Older
## Data base generation code by Group 3 CS 499 ##
# Morning data,afternoon ,night data for temp
import random
import math
import requests
import json
import numpy as np


class Door_Window:

    def __init__(self,day,Door_status,Door_time,Window_status,Window_time):
        self.day=day
        self.Door_status=Door_status
        self.Door_time=Door_time
        self.Window_status=Window_status
        self.Window_time=Window_time
    

WORKWEEK=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
NUM_WEEKS=11
time_stamp=0
for i in range(0,NUM_WEEKS):
    for j in range(0,7):
        #door_opens = 0
       # window_opens=0
        if j < 5:
            door_opens = random.randint(14,22)
            window_open= random.randint(1,5)
        else:
            door_opens = random.randint(26,36)
            window_open= random.randint(7,12)
        door_minutes = door_opens*30/60
        window_minutes = window_open *45/60
        Door_Window_History[time_stamp] = Door_Window(WORKWEEK[j], door_opens, door_minutes, window_open, window_minutes)
        time_stamp += 1

for i in Door_Window_History:
    print(i,Door_Window_History[i].day,Door_Window_History[i].Door_status,Door_Window_History[i].Door_time,Door_Window_History[i].Window_status,Door_Window_History[i].Window_time)

class Appliance_1:

    def __init__(self,day,micro_pwr,stove_pwr,oven_pwr,Lrtv_pwr,Brtv_pwr,fridge_pwr,lights_pwr,micro_ct,stove_ct,oven_ct,Lrtv_ct,Brtv_ct,fridge_ct,lights_ct):
        self.day=day
        self.micro_pwr=micro_pwr
        self.stove_pwr=stove_pwr
        self.oven_pwr=oven_pwr
        self.Lrtv_pwr=Lrtv_pwr
        self.Brtv_pwr=Brtv_pwr
        self.fridge_pwr=fridge_pwr
        self.micro_ct=micro_ct
        self.stove_ct=stove_ct
        self.oven_ct=oven_ct
        self.Lrtv_ct=Lrtv_ct
        self.Brtv_ct=Brtv_ct
        self.fridge_ct=fridge_ct
        self.lights_pwr=lights_pwr
        self.lights_ct=lights_ct
        
App1_History=dict()
time_stamp2=1
Fridge=0
for i in range(0,NUM_WEEKS):
    for j in range(0,7):
        Fridge += 1440
        if j<5:
            Microwave=random.randint(18,25)
            Stove=random.randint(13,18)
            Oven=random.randint(40,50)
            Living_roomTV=random.randint(230,330)
            BedroomTV=random.randint(100,190)
            lights=random.randint(35,65)
        else:
            Microwave=random.randint(26,40)
            Stove=random.randint(25,41)
            Oven=random.randint(54,67)
            Living_roomTV=random.randint(432,490)
            BedroomTV=random.randint(225,277)
            lights=random.randint(55,95)
        
        #Watts Ussage
        Watts_micro=(Microwave/60)*1100
        Watts_stove=(Stove/60)*3500
        Watts_oven=(Oven/60)*4000/60
        Watts_Lrtv=(Living_roomTV/60)*636
        Watts_Brtv=(BedroomTV/60)*100
        Watts_Fridge=(Fridge/60)*150
        Watts_Lights=(lights*random.randint(4,8))
        Cost_micro=((Watts_micro/1000)*0.12)/100
        Cost_stove=((Watts_stove/1000)*0.12)/100
        Cost_oven=((Watts_oven/1000)*0.12)/100
        Cost_Lrtv=((Watts_Lrtv/1000)*0.12)/100
        Cost_Brtv=((Watts_Brtv/1000)*0.12)/100
        Cost_Fridge=((Watts_Fridge/1000)*0.12)/100   
        Cost_lights=((Watts_Lights/1000)*0.12 )/100  
        App1_History[time_stamp2] = Appliance_1(WORKWEEK[j],Watts_micro,Watts_stove,Watts_oven,Watts_Lrtv,Watts_Brtv,Watts_Fridge,Watts_Lights,Cost_micro,Cost_stove,Cost_oven,Cost_Lrtv,Cost_Brtv,Cost_Fridge,Cost_lights)
        time_stamp2 += 1

monthly_cost1_JAN=0
monthly_power1_JAN=0
monthly_cost1_FEB=0
monthly_power1_FEB=0
monthly_cost1_MAR=0
monthly_power1_MAR=0
print("######################################################  TOTAL APP1 HISTORY FOR 77  DAYS  ###################################################### \n")
    if i<=31:
        monthly_power1_JAN += App1_History[i].micro_pwr + App1_History[i].stove_pwr + App1_History[i].oven_pwr + App1_History[i].Lrtv_pwr + App1_History[i].Brtv_pwr + App1_History[i].fridge_pwr +App1_History[i].lights_pwr
        monthly_cost1_JAN += App1_History[i].micro_ct + App1_History[i].stove_ct + App1_History[i].oven_ct + App1_History[i].Lrtv_ct + App1_History[i].Brtv_ct + App1_History[i].fridge_ct + App1_History[i].lights_ct
    if i>32 and i<=60:
        monthly_power1_FEB += App1_History[i].micro_pwr + App1_History[i].stove_pwr + App1_History[i].oven_pwr + App1_History[i].Lrtv_pwr + App1_History[i].Brtv_pwr + App1_History[i].fridge_pwr +App1_History[i].lights_pwr
        monthly_cost1_FEB += App1_History[i].micro_ct + App1_History[i].stove_ct + App1_History[i].oven_ct + App1_History[i].Lrtv_ct + App1_History[i].Brtv_ct + App1_History[i].fridge_ct + App1_History[i].lights_ct
    if i>61:
        monthly_power1_MAR += App1_History[i].micro_pwr + App1_History[i].stove_pwr + App1_History[i].oven_pwr + App1_History[i].Lrtv_pwr + App1_History[i].Brtv_pwr + App1_History[i].fridge_pwr +App1_History[i].lights_pwr
        monthly_cost1_MAR += App1_History[i].micro_ct + App1_History[i].stove_ct + App1_History[i].oven_ct + App1_History[i].Lrtv_ct + App1_History[i].Brtv_ct + App1_History[i].fridge_ct + App1_History[i].lights_ct
    #print(i,App1_History[i].day,App1_History[i].micro_pwr,App1_History[i].stove_pwr,App1_History[i].oven_pwr,App1_History[i].Lrtv_pwr,App1_History[i].Brtv_pwr,App1_History[i].micro_ct,App1_History[i].stove_ct,App1_History[i].oven_ct,App1_History[i].Lrtv_ct,App1_History[i].Brtv_ct)
print( "_ - _ - _ - _  Power used for each Month  _ - _ - _ - _ \n")
print( "Jan APP1 watts used : ",monthly_power1_JAN )
print( "FEB APP1 watts used : ",monthly_power1_FEB )
print( "MAR APP1 watts used : ",monthly_power1_MAR )
print( "_ - _ - _ - _  Cost used for each Month  _ - _ - _ - _ \n")
print( "Jan APP1 cost used : ",monthly_cost1_JAN )
print( "FEB APP1 cost used : ",monthly_cost1_FEB )
print( "MAR APP1 cost used : ",monthly_cost1_MAR )
#print( "################################################################################################################################################################# \n")




class Appliance_with_Water:

    def __init__(self,day,Water_Heat_pwr,DishWasher_pwr,Clothes_Wash_pwr,Clothes_dry_pwr,bath_fans_pwr,Water_Heat_ug,Bath_water_ug,Shower_water_ug,DishWasher_ug,Clothes_Wash_ug,Water_Heat_ct,DishWasher_ct,Clothes_Wash_ct,Clothes_dry_ct,bath_fans_ct,Water_ct,bath,shower):
        self.day=day
        self.Water_Heat_pwr=Water_Heat_pwr
        self.DishWasher_pwr=DishWasher_pwr
        self.Clothes_Wash_pwr=Clothes_Wash_pwr
        self.Clothes_dry_pwr=Clothes_dry_pwr
        self.Water_Heat_ug=Water_Heat_ug
        self.DishWasher_ug=DishWasher_ug
        self.Clothes_Wash_ug=Clothes_Wash_ug
        self.Water_Heat_ct=Water_Heat_ct
        self.DishWasher_ct=DishWasher_ct
        self.Clothes_Wash_ct=Clothes_Wash_ct
        self.Clothes_dry_ct=Clothes_dry_ct
        self.bath_fans_pwr=bath_fans_pwr
        self.bath_fans_ct=bath_fans_ct
        self.Bath_water_ug=Bath_water_ug
        self.Shower_water_ug=Shower_water_ug
        self.Water_ct=Water_ct
        self.bath=bath
        self.shower=shower

App2_History=dict()
time_stamp3=0
for i in range(0,NUM_WEEKS):
    Dish_washer_run=random.randint(3,5)
    Clths_wash_dry_run=random.randint(3,5)
    for j in range(0,7):
        if j<5:
            Bath=random.randint(2,3)
            Shower=random.randint(2,3)
        else:
            Bath=random.randint(3,4)
            Shower=random.randint(3,4)

        #Calaculate Total Water 
        Bath_water=30*Bath
        Shower_water=25*Shower
        Clths_water=20*Clths_wash_dry_run
        Dish_washer_water=6*Dish_washer_run

        # still have to apply floor to it ## hot water
        Bath_hot=math.ceil(Bath_water*0.65)
        Shower_hot=math.ceil(Shower_water*0.65)
        Clths_wash_hot=math.ceil(Clths_water*0.85)
        # hot water heater ## use ceil round up
        Hot_water=(Bath_hot+Shower_hot+Clths_wash_hot)
        Hot_water_time=Hot_water*4

        # Watts used
        Hot_water_pwr=(Hot_water_time/60)*4500
        Dish_washer_pwr=((Dish_washer_run*45)/60)*1800
        Clothes_wash_pwr=((Clths_wash_dry_run*30)/60)*500
        Clothes_dry_pwr=((Clths_wash_dry_run*30)/60)*3000
        Bath_Fans_pwr=((Bath*45)/60)*30

        # Cost
        Hot_water_ct=((Hot_water_pwr/1000)*0.12)/100
        Dish_washer_ct=((Dish_washer_pwr/1000)*0.12)/100
        Clothes_wash_ct=((Clothes_wash_pwr/1000)*0.12)/100
        Clothes_dry_ct=((Clothes_dry_pwr/1000)*0.12)/100
        Bath_Fans_ct=((Bath_Fans_pwr/1000)*0.12)/100

        # Water Used / Cost
        Water_Total=Bath_water+Shower_water+Clths_water+Dish_washer_water
        Water_Feet=Water_Total/7.48
        Water_cost=Water_Feet*(2.52/100)
        #Water_Heat_pwr,DishWasher_pwr,Clothes_Wash_pwr,Clothes_dry_pwr,bath_fan_pwr,Water_Heat_ug,DishWasher_ug,Clothes_Wash_ug,Water_Heat_ct,DishWasher_ct,Clothes_Wash_ct,Clothes_dry_ct,bath_fan_ct,bath,shower
        App2_History[time_stamp3] = Appliance_with_Water(WORKWEEK[j],Hot_water_pwr,Dish_washer_pwr,Clothes_wash_pwr,Clothes_dry_pwr,Bath_Fans_pwr,Hot_water,Bath_water,Shower_water,Dish_washer_water,Clths_water,Hot_water_ct,Dish_washer_ct,Clothes_wash_ct,Clothes_dry_ct,Bath_Fans_ct,Water_cost,Bath,Shower)
        time_stamp3+=1

monthly_cost2_JAN=0
monthly_power2_JAN=0
monthly_water_usg_JAN=0
monthly_cost2_FEB=0
monthly_power2_FEB=0
monthly_water_usg_FEB=0
monthly_cost2_MAR=0
monthly_power2_MAR=0
monthly_water_usg_MAR=0
print("######################################################  TOTAL APP2 HISTORY FOR 77 DAYS  ###################################################### \n")
    if i>=31:
        monthly_cost2_JAN+= App2_History[i].Water_Heat_ct + App2_History[i].DishWasher_ct + App2_History[i].Clothes_Wash_ct + App2_History[i].Clothes_dry_ct +App2_History[i].Water_ct + App2_History[i].bath_fans_ct
        monthly_power2_JAN+= App2_History[i].Water_Heat_pwr+ App2_History[i].DishWasher_pwr + App2_History[i].Clothes_Wash_pwr + App2_History[i].Clothes_dry_pwr + App2_History[i].bath_fans_pwr
        monthly_water_usg_JAN+= App2_History[i].Bath_water_ug + App2_History[i].Shower_water_ug + App2_History[i].DishWasher_ug+ App2_History[i].Clothes_Wash_ug
    if i>32 and i<=60:
        monthly_cost2_FEB+= App2_History[i].Water_Heat_ct + App2_History[i].DishWasher_ct + App2_History[i].Clothes_Wash_ct + App2_History[i].Clothes_dry_ct +App2_History[i].Water_ct + App2_History[i].bath_fans_ct
        monthly_power2_FEB+= App2_History[i].Water_Heat_pwr+ App2_History[i].DishWasher_pwr + App2_History[i].Clothes_Wash_pwr + App2_History[i].Clothes_dry_pwr + App2_History[i].bath_fans_pwr
        monthly_water_usg_FEB+= App2_History[i].Bath_water_ug + App2_History[i].Shower_water_ug + App2_History[i].DishWasher_ug+ App2_History[i].Clothes_Wash_ug
    if i>61:
        monthly_cost2_MAR+= App2_History[i].Water_Heat_ct + App2_History[i].DishWasher_ct + App2_History[i].Clothes_Wash_ct + App2_History[i].Clothes_dry_ct +App2_History[i].Water_ct + App2_History[i].bath_fans_ct
        monthly_power2_MAR+= App2_History[i].Water_Heat_pwr+ App2_History[i].DishWasher_pwr + App2_History[i].Clothes_Wash_pwr + App2_History[i].Clothes_dry_pwr + App2_History[i].bath_fans_pwr
        monthly_water_usg_MAR+= App2_History[i].Bath_water_ug + App2_History[i].Shower_water_ug + App2_History[i].DishWasher_ug+ App2_History[i].Clothes_Wash_ug
    #print(i,App2_History[i].day,App2_History[i].Water_Heat_pwr,App2_History[i].DishWasher_pwr,App2_History[i].Clothes_Wash_pwr,App2_History[i].Clothes_dry_pwr,App2_History[i].bath_fans_pwr,App2_History[i].Water_Heat_ug,App2_History[i].Bath_water_ug,App2_History[i].Shower_water_ug,App2_History[i].DishWasher_ug,App2_History[i].Clothes_Wash_ug,App2_History[i].Water_Heat_ct,App2_History[i].DishWasher_ct,App2_History[i].Clothes_Wash_ct,App2_History[i].Clothes_dry_ct,App2_History[i].bath_fans_ct,App2_History[i].Water_ct,App2_History[i].bath,App2_History[i].shower)
print( "_ - _ - _ - _  Power used for each Month  _ - _ - _ - _ \n")
print( "Jan APP1 watts used : ",monthly_power2_JAN )
print( "FEB APP1 watts used : ",monthly_power2_FEB )
print( "MAR APP1 watts used : ",monthly_power2_MAR )
print( "_ - _ - _ - _  Cost used for each Month  _ - _ - _ - _ \n")
print( "Jan APP1 cost used : ",monthly_cost2_JAN )
print( "FEB APP1 cost used : ",monthly_cost2_FEB )
print( "MAR APP1 cost used : ",monthly_cost2_MAR )
print( "_ - _ - _ - _  Gallons used for each Month  _ - _ - _ - _ \n")
print( "Jan APP1 water used : ",monthly_water_usg_JAN )
print( "FEB APP1 water used : ",monthly_water_usg_FEB )
print( "MAR APP1 water used : ",monthly_water_usg_MAR )
#print( "################################################################################################################################################################# \n")
# Used this to help me understand and gather API.data: https://pypi.org/project/requests/ and https://realpython.com/api-integration-in-python/
Anthony Gobble's avatar
Anthony Gobble committed
class Temperature_data:
    def __init__(self,temp_power,temp_cost):
        self.temp_power=temp_power
        self.temp_cost=temp_cost



response_API = requests.get("https://archive-api.open-meteo.com/v1/archive?latitude=33.52&longitude=-86.80&start_date=2023-01-01&end_date=2023-03-12&hourly=temperature_2m&timezone=America%2FChicago&temperature_unit=fahrenheit")
data = response_API.text
parse_temp=json.loads(data)
hourly_pull = parse_temp['hourly']
dict_pull=hourly_pull["temperature_2m"]



App3_History=dict()
time_stamp4=0
daily_arr=np.array_split(dict_pull,77)



for i in range(0,len(daily_arr)):
    daily_arr[i]
    d_t=Door_Window_History[i].Door_time
    w_t=Door_Window_History[i].Window_time
    diff_inc = 0
    diff_dec = 0        
    for j in range(0,len(daily_arr[i])-1):
        num_nxt=daily_arr[i][j+1]
        num=daily_arr[i][j]
        if num > num_nxt :
            diff_inc= num - num_nxt
        if num < num_nxt :
            diff_dec= num_nxt - num
    # print(diff_inc)
    # print(diff_dec)
    sum=(diff_inc+diff_dec)*random.randint(2,17)
    #Total number of minutes ac runs
    min_op=sum*60+(d_t+w_t)
    watts_per_day=(min_op)*3500
    ct_per_day=((watts_per_day/1000)*0.12)/100
Anthony Gobble's avatar
Anthony Gobble committed
    App3_History[time_stamp4]=Temperature_data(watts_per_day,ct_per_day)
    time_stamp4+=1
    #print(ct_per_day)
    #print(watts_per_day)
    # print("what i is",i)
    # print("timestamp",i)



monthly_temp_ct_JAN=0
monthly_temp_watts_JAN=0
monthly_temp_ct_FEB=0
monthly_temp_watts_FEB=0
monthly_temp_ct_MAR=0
monthly_temp_watts_MAR=0
print("######################################################  TOTAL TEMP HISTORY FOR 77 DAYS  ###################################################### \n")
for i in App3_History:
    if i<=31:
        monthly_temp_watts_JAN+=App3_History[i].temp_power
        monthly_temp_ct_JAN+=App3_History[i].temp_cost
    if i>31 and i<=59:
        monthly_temp_watts_FEB+=App3_History[i].temp_power
        monthly_temp_ct_FEB+=App3_History[i].temp_cost
    if i>59:
        monthly_temp_ct_MAR+=App3_History[i].temp_cost
        monthly_temp_watts_MAR+=App3_History[i].temp_power
print( "_ - _ - _ - _  Power used for each Month  _ - _ - _ - _ \n")
print( "Jan APP1 watts used : ",monthly_temp_watts_JAN )
print( "FEB APP1 watts used : ",monthly_temp_watts_FEB )
print( "MAR APP1 watts used : ",monthly_temp_watts_MAR )
print( "_ - _ - _ - _  Cost used for each Month  _ - _ - _ - _ \n")
print( "Jan APP1 cost used : ",monthly_temp_ct_JAN )
print( "FEB APP1 cost used : ",monthly_temp_ct_FEB )
print( "MAR APP1 cost used : ",monthly_temp_ct_MAR )
print( "################################################################################################################################################################# \n")
print("January Total cost",monthly_temp_ct_JAN+monthly_cost2_JAN+monthly_cost1_JAN)
print("Febuary Total cost",monthly_temp_ct_FEB+monthly_cost2_FEB+monthly_cost1_FEB)
print("March Total cost",monthly_temp_ct_MAR+monthly_cost2_FEB+monthly_cost1_MAR)
print("January Total Watts",monthly_temp_watts_JAN+monthly_power2_JAN+monthly_power1_JAN)
print("Febuary Total Watts",monthly_temp_watts_FEB+monthly_power2_FEB+monthly_power1_FEB)
print("March Total Watts",monthly_temp_watts_MAR+monthly_power2_MAR+monthly_power1_MAR)