Skip to content
Snippets Groups Projects
Commit 993c9a6a authored by Jesus Miguel Zubia's avatar Jesus Miguel Zubia
Browse files

Replace CS_499_backend.py

parent 5598dafc
No related branches found
No related tags found
No related merge requests found
## Data base generation code by Group 3 CS 499 ## import psycopg2
# Morning data,afternoon ,night data for temp
import random # import CS_499_backend
import math from CS_499_backend import Door_Window, Appliance_1, Appliance_with_Water, Temperature_data, Door_Window_History, App1_History, App2_History, App3_History, time_stamp, time_stamp2, time_stamp3, time_stamp4, monthly_cost1_FEB, monthly_cost1_MAR, monthly_cost1_JAN, monthly_power1_JAN, monthly_power1_FEB, monthly_power1_MAR, monthly_cost2_FEB, monthly_cost2_JAN, monthly_cost2_MAR, monthly_water_usg_MAR, monthly_water_usg_JAN, monthly_water_usg_FEB, monthly_power2_FEB, monthly_power2_JAN, monthly_power2_MAR, monthly_temp_watts_JAN, monthly_temp_watts_FEB, monthly_temp_watts_MAR, monthly_temp_ct_JAN, monthly_temp_ct_FEB, monthly_temp_ct_MAR
import requests
import json # create a new database
import numpy as np conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432")
cur = conn.cursor()
#cur.execute("CREATE DATABASE Team3 ")
class Door_Window: conn.close()
def __init__(self,day,Door_status,Door_time,Window_status,Window_time): # create a new table for Door_Window_History
self.day=day conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432")
self.Door_status=Door_status cur = conn.cursor()
self.Door_time=Door_time cur.execute("""
self.Window_status=Window_status DROP TABLE IF EXISTS Door_Window_History;
self.Window_time=Window_time CREATE TABLE Door_Window_History (
id SERIAL PRIMARY KEY,
day VARCHAR(255),
WORKWEEK=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"] door_status INTEGER,
NUM_WEEKS=11 door_time FLOAT,
Door_Window_History=dict() window_status INTEGER,
window_time FLOAT
time_stamp=0 );
for i in range(0,NUM_WEEKS): """)
for j in range(0,7):
#door_opens = 0 conn.commit()
# window_opens=0
if j < 5: #insert the data into the Door_Window_History table
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: 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) for time_stamp, data in Door_Window_History.items():
cur.execute("""
class Appliance_1: INSERT INTO Door_Window_History (
day, door_status, door_time, window_status, window_time)
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): VALUES (%s, %s, %s, %s, %s);
self.day=day """, (
self.micro_pwr=micro_pwr data.day, data.Door_status, data.Door_time,
self.stove_pwr=stove_pwr data.Window_status, data.Window_time
self.oven_pwr=oven_pwr ))
self.Lrtv_pwr=Lrtv_pwr conn.commit()
self.Brtv_pwr=Brtv_pwr
self.fridge_pwr=fridge_pwr # create a new table for App1_History
self.micro_ct=micro_ct conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432")
self.stove_ct=stove_ct cur = conn.cursor()
self.oven_ct=oven_ct cur.execute("""
self.Lrtv_ct=Lrtv_ct DROP TABLE IF EXISTS Appliance_1_History;
self.Brtv_ct=Brtv_ct CREATE TABLE Appliance_1_History (
self.fridge_ct=fridge_ct id SERIAL PRIMARY KEY,
self.lights_pwr=lights_pwr day VARCHAR(255),
self.lights_ct=lights_ct micro_pwr FLOAT,
stove_pwr FLOAT,
App1_History=dict() oven_pwr FLOAT,
time_stamp2=1 Lrtv_pwr FLOAT,
Fridge=0 Brtv_pwr FLOAT,
for i in range(0,NUM_WEEKS): fridge_pwr FLOAT,
for j in range(0,7): micro_ct FLOAT,
Fridge += 1440 stove_ct FLOAT,
if j<5: oven_ct FLOAT,
Microwave=random.randint(18,25) Lrtv_ct FLOAT,
Stove=random.randint(13,18) Brtv_ct FLOAT,
Oven=random.randint(40,50) fridge_ct FLOAT,
Living_roomTV=random.randint(230,330) lights_pwr FLOAT,
BedroomTV=random.randint(100,190) lights_ct FLOAT
lights=random.randint(35,65) );
else: """)
Microwave=random.randint(26,40)
Stove=random.randint(25,41) for time_stamp2, data in App1_History.items():
Oven=random.randint(54,67) cur.execute("""
Living_roomTV=random.randint(432,490) INSERT INTO Appliance_1_History (
BedroomTV=random.randint(225,277) day, micro_pwr, stove_pwr, oven_pwr, Lrtv_pwr, Brtv_pwr, fridge_pwr,
lights=random.randint(55,95) micro_ct, stove_ct, oven_ct, Lrtv_ct, Brtv_ct, fridge_ct, lights_pwr, lights_ct)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);
#Watts Ussage """, (
Watts_micro=(Microwave/60)*1100 data.day, data.micro_pwr, data.stove_pwr, data.oven_pwr, data.Lrtv_pwr, data.Brtv_pwr,
Watts_stove=(Stove/60)*3500 data.fridge_pwr, data.micro_ct, data.stove_ct, data.oven_ct, data.Lrtv_ct, data.Brtv_ct,
Watts_oven=(Oven/60)*4000/60 data.fridge_ct, data.lights_pwr, data.lights_ct
Watts_Lrtv=(Living_roomTV/60)*636 ))
Watts_Brtv=(BedroomTV/60)*100 conn.commit()
Watts_Fridge=(Fridge/60)*150
Watts_Lights=(lights*random.randint(4,8))
#Cost Calculations
Cost_micro=((Watts_micro/1000)*0.12)/100 # create a new table for appliance_with_water
Cost_stove=((Watts_stove/1000)*0.12)/100 conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432")
Cost_oven=((Watts_oven/1000)*0.12)/100 cur = conn.cursor()
Cost_Lrtv=((Watts_Lrtv/1000)*0.12)/100 cur.execute("""
Cost_Brtv=((Watts_Brtv/1000)*0.12)/100 DROP TABLE IF EXISTS appliance_with_water;
Cost_Fridge=((Watts_Fridge/1000)*0.12)/100 CREATE TABLE appliance_with_water (
Cost_lights=((Watts_Lights/1000)*0.12 )/100 id SERIAL PRIMARY KEY,
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) day TEXT,
time_stamp2 += 1 water_heat_pwr FLOAT,
dishwasher_pwr FLOAT,
monthly_cost1_JAN=0 clothes_wash_pwr FLOAT,
monthly_power1_JAN=0 clothes_dry_pwr FLOAT,
monthly_cost1_FEB=0 bath_fans_pwr FLOAT,
monthly_power1_FEB=0 water_heat_ug FLOAT,
monthly_cost1_MAR=0 bath_water_ug FLOAT,
monthly_power1_MAR=0 shower_water_ug FLOAT,
dishwasher_ug FLOAT,
print("###################################################### TOTAL APP1 HISTORY FOR 77 DAYS ###################################################### \n") clothes_wash_ug FLOAT,
for i in App1_History: water_heat_ct FLOAT,
if i<=31: dishwasher_ct FLOAT,
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 clothes_wash_ct FLOAT,
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 clothes_dry_ct FLOAT,
if i>32 and i<=60: bath_fans_ct FLOAT,
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 water_ct FLOAT,
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 bath INT,
if i>61: shower INT
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) conn.commit()
print( "_ - _ - _ - _ Power used for each Month _ - _ - _ - _ \n")
print( "Jan APP1 watts used : ",monthly_power1_JAN ) # insert data into the App2_History table
print( "FEB APP1 watts used : ",monthly_power1_FEB ) for time_stamp3, data in App2_History.items():
print( "MAR APP1 watts used : ",monthly_power1_MAR ) cur = conn.cursor()
print( "_ - _ - _ - _ Cost used for each Month _ - _ - _ - _ \n") cur.execute("""
print( "Jan APP1 cost used : ",monthly_cost1_JAN ) INSERT INTO appliance_with_water (
print( "FEB APP1 cost used : ",monthly_cost1_FEB ) day, water_heat_pwr, dishwasher_pwr, clothes_wash_pwr,
print( "MAR APP1 cost used : ",monthly_cost1_MAR ) clothes_dry_pwr, bath_fans_pwr, water_heat_ug, bath_water_ug,
#print( "################################################################################################################################################################# \n") 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
)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);
class Appliance_with_Water: """, (
data.day, data.Water_Heat_pwr, data.DishWasher_pwr, data.Clothes_Wash_pwr,
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): data.Clothes_dry_pwr, data.bath_fans_pwr, data.Water_Heat_ug, data.Bath_water_ug,
self.day=day data.Shower_water_ug, data.DishWasher_ug, data.Clothes_Wash_ug, data.Water_Heat_ct,
self.Water_Heat_pwr=Water_Heat_pwr data.DishWasher_ct, data.Clothes_Wash_ct, data.Clothes_dry_ct, data.bath_fans_ct,
self.DishWasher_pwr=DishWasher_pwr data.Water_ct, data.bath, data.shower
self.Clothes_Wash_pwr=Clothes_Wash_pwr ))
self.Clothes_dry_pwr=Clothes_dry_pwr conn.commit()
self.Water_Heat_ug=Water_Heat_ug
self.DishWasher_ug=DishWasher_ug # create a new table for Temperature_data
self.Clothes_Wash_ug=Clothes_Wash_ug conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432")
self.Water_Heat_ct=Water_Heat_ct cur = conn.cursor()
self.DishWasher_ct=DishWasher_ct cur.execute("""
self.Clothes_Wash_ct=Clothes_Wash_ct DROP TABLE IF EXISTS Temperature_data;
self.Clothes_dry_ct=Clothes_dry_ct CREATE TABLE Temperature_data (
self.bath_fans_pwr=bath_fans_pwr id SERIAL PRIMARY KEY,
self.bath_fans_ct=bath_fans_ct temp_power FLOAT,
self.Bath_water_ug=Bath_water_ug temp_cost FLOAT
self.Shower_water_ug=Shower_water_ug );
self.Water_ct=Water_ct """)
self.bath=bath conn.commit()
self.shower=shower
# insert data into the App3_History Table
App2_History=dict() for time_stamp4, data in App3_History.items():
time_stamp3=0 cur = conn.cursor()
for i in range(0,NUM_WEEKS): cur.execute("""
Dish_washer_run=random.randint(3,5) INSERT INTO temperature_data (
Clths_wash_dry_run=random.randint(3,5) temp_power, temp_cost
for j in range(0,7): )
if j<5: VALUES (%s, %s);
Bath=random.randint(2,3) """, (
Shower=random.randint(2,3) data.temp_power, data.temp_cost
else: ))
Bath=random.randint(3,4) conn.commit()
Shower=random.randint(3,4)
#Calaculate Total Water #################### This is for
Bath_water=30*Bath
Shower_water=25*Shower # # create a new table for app1_cost_power
Clths_water=20*Clths_wash_dry_run # conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432")
Dish_washer_water=6*Dish_washer_run # cur = conn.cursor()
# cur.execute("""
# still have to apply floor to it ## hot water # DROP TABLE IF EXISTS app1_cost_power;
Bath_hot=math.ceil(Bath_water*0.65) # CREATE TABLE app1_cost_power (
Shower_hot=math.ceil(Shower_water*0.65) # month TEXT,
Clths_wash_hot=math.ceil(Clths_water*0.85) # watts FLOAT,
# hot water heater ## use ceil round up # cost FLOAT
Hot_water=(Bath_hot+Shower_hot+Clths_wash_hot) # )
Hot_water_time=Hot_water*4 # """)
# conn.commit()
# Watts used
Hot_water_pwr=(Hot_water_time/60)*4500 # # Insert the monthly power and cost values into the table
Dish_washer_pwr=((Dish_washer_run*45)/60)*1800 # cur.execute("""
Clothes_wash_pwr=((Clths_wash_dry_run*30)/60)*500 # INSERT INTO app1_cost_power (month, watts, cost)
Clothes_dry_pwr=((Clths_wash_dry_run*30)/60)*3000 # VALUES ('January', %s, %s),
Bath_Fans_pwr=((Bath*45)/60)*30 # ('February', %s, %s),
# ('March', %s, %s)
# Cost # """, (monthly_power1_JAN, monthly_cost1_JAN,
Hot_water_ct=((Hot_water_pwr/1000)*0.12)/100 # monthly_power1_FEB, monthly_cost1_FEB,
Dish_washer_ct=((Dish_washer_pwr/1000)*0.12)/100 # monthly_power1_MAR, monthly_cost1_MAR))
Clothes_wash_ct=((Clothes_wash_pwr/1000)*0.12)/100
Clothes_dry_ct=((Clothes_dry_pwr/1000)*0.12)/100 # # Commit the changes
Bath_Fans_ct=((Bath_Fans_pwr/1000)*0.12)/100 # conn.commit()
# Water Used / Cost # # create a new table for app2_cost_power
Water_Total=Bath_water+Shower_water+Clths_water+Dish_washer_water # conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432")
Water_Feet=Water_Total/7.48 # cur = conn.cursor()
Water_cost=Water_Feet*(2.52/100) # cur.execute("""
#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 # DROP TABLE IF EXISTS app2_cost_power;
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) # CREATE TABLE app2_cost_power (
time_stamp3+=1 # month TEXT,
# watts FLOAT,
monthly_cost2_JAN=0 # water FLOAT,
monthly_power2_JAN=0 # cost FLOAT
monthly_water_usg_JAN=0 # )
monthly_cost2_FEB=0 # """)
monthly_power2_FEB=0 # conn.commit()
monthly_water_usg_FEB=0
monthly_cost2_MAR=0 # # Insert the monthly power and cost values into the table
monthly_power2_MAR=0 # cur.execute("""
monthly_water_usg_MAR=0 # INSERT INTO app2_cost_power (month, watts, water, cost)
print("###################################################### TOTAL APP2 HISTORY FOR 77 DAYS ###################################################### \n") # VALUES ('January', %s, %s, %s),
for i in App2_History: # ('February', %s, %s, %s),
if i>=31: # ('March', %s, %s, %s)
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, monthly_water_usg_JAN, monthly_cost2_JAN,
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_power2_FEB, monthly_water_usg_FEB, monthly_cost2_FEB,
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 # monthly_power2_MAR, monthly_water_usg_MAR, monthly_cost2_MAR))
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 # # Commit the changes
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 # conn.commit()
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: # # create a new table for temp_cost_watts
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 # conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432")
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 # cur = conn.cursor()
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 # cur.execute("""
#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) # DROP TABLE IF EXISTS temp_cost_watts;
print( "_ - _ - _ - _ Power used for each Month _ - _ - _ - _ \n") # CREATE TABLE temp_cost_watts (
print( "Jan APP1 watts used : ",monthly_power2_JAN ) # month TEXT,
print( "FEB APP1 watts used : ",monthly_power2_FEB ) # watts FLOAT,
print( "MAR APP1 watts used : ",monthly_power2_MAR ) # cost FLOAT
print( "_ - _ - _ - _ Cost used for each Month _ - _ - _ - _ \n") # )
print( "Jan APP1 cost used : ",monthly_cost2_JAN ) # """)
print( "FEB APP1 cost used : ",monthly_cost2_FEB ) # conn.commit()
print( "MAR APP1 cost used : ",monthly_cost2_MAR )
print( "_ - _ - _ - _ Gallons used for each Month _ - _ - _ - _ \n") # # Insert the monthly power and cost values into the table
print( "Jan APP1 water used : ",monthly_water_usg_JAN ) # cur.execute("""
print( "FEB APP1 water used : ",monthly_water_usg_FEB ) # INSERT INTO temp_cost_watts (month, watts, cost)
print( "MAR APP1 water used : ",monthly_water_usg_MAR ) # VALUES ('January', %s, %s),
#print( "################################################################################################################################################################# \n") # ('February', %s, %s),
# ('March', %s, %s)
# """, (monthly_temp_watts_JAN, monthly_temp_ct_JAN,
# weather api to get temp from history # monthly_temp_watts_FEB, monthly_temp_ct_FEB,
# Used this to help me understand and gather API.data: https://pypi.org/project/requests/ and https://realpython.com/api-integration-in-python/ # monthly_temp_watts_MAR, monthly_temp_ct_MAR))
class Temperature_data:
def __init__(self,temp_power,temp_cost): # # Commit the changes
self.temp_power=temp_power # conn.commit()
self.temp_cost=temp_cost
# create a new table for total_cost_watts
conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432")
cur = conn.cursor()
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") cur.execute("""
data = response_API.text DROP TABLE IF EXISTS total_cost_watts;
parse_temp=json.loads(data) CREATE TABLE total_cost_watts (
hourly_pull = parse_temp['hourly'] month TEXT,
dict_pull=hourly_pull["temperature_2m"] watts FLOAT,
cost FLOAT
)
""")
App3_History=dict() conn.commit()
time_stamp4=0
daily_arr=np.array_split(dict_pull,77) # Insert the monthly power and cost values into the table
cur.execute("""
INSERT INTO total_cost_watts (month, watts, cost)
VALUES ('January', %s, %s),
for i in range(0,len(daily_arr)): ('February', %s, %s),
daily_arr[i] ('March', %s, %s)
d_t=Door_Window_History[i].Door_time """, (monthly_temp_watts_JAN+monthly_power2_JAN+monthly_power1_JAN, monthly_temp_ct_JAN+monthly_cost2_JAN+monthly_cost1_JAN,
w_t=Door_Window_History[i].Window_time monthly_temp_watts_FEB+monthly_power2_FEB+monthly_power1_FEB, monthly_temp_ct_FEB+monthly_cost2_FEB+monthly_cost1_FEB,
diff_inc = 0 monthly_temp_watts_MAR+monthly_power2_MAR+monthly_power1_MAR, monthly_temp_ct_MAR+monthly_cost2_MAR+monthly_cost1_MAR))
diff_dec = 0
for j in range(0,len(daily_arr[i])-1): # Commit the changes
num_nxt=daily_arr[i][j+1] conn.commit()
num=daily_arr[i][j]
if num > num_nxt : # Commit changes
diff_inc= num - num_nxt #conn.commit()
if num < num_nxt : cur.close()
diff_dec= num_nxt - num conn.close()
# print(diff_inc) \ No newline at end of file
# 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
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment