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

Updated CS_499_database.py to story the total cost and watts for all appliances each month

parent 5d8ee49f
No related branches found
No related tags found
No related merge requests found
import psycopg2 import psycopg2
# import CS_499_backend # import CS_499_backend
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 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
# create a new database # create a new database
conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432") conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432")
...@@ -45,7 +45,7 @@ cur = conn.cursor() ...@@ -45,7 +45,7 @@ cur = conn.cursor()
cur.execute(""" cur.execute("""
DROP TABLE IF EXISTS Appliance_1_History; DROP TABLE IF EXISTS Appliance_1_History;
CREATE TABLE Appliance_1_History ( CREATE TABLE Appliance_1_History (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
day VARCHAR(255), day VARCHAR(255),
micro_pwr FLOAT, micro_pwr FLOAT,
stove_pwr FLOAT, stove_pwr FLOAT,
...@@ -156,6 +156,114 @@ for time_stamp4, data in App3_History.items(): ...@@ -156,6 +156,114 @@ for time_stamp4, data in App3_History.items():
)) ))
conn.commit() conn.commit()
#################### This is for
# # create a new table for app1_cost_power
# conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432")
# cur = conn.cursor()
# cur.execute("""
# DROP TABLE IF EXISTS app1_cost_power;
# CREATE TABLE app1_cost_power (
# month TEXT,
# watts FLOAT,
# cost FLOAT
# )
# """)
# conn.commit()
# # Insert the monthly power and cost values into the table
# cur.execute("""
# INSERT INTO app1_cost_power (month, watts, cost)
# VALUES ('January', %s, %s),
# ('February', %s, %s),
# ('March', %s, %s)
# """, (monthly_power1_JAN, monthly_cost1_JAN,
# monthly_power1_FEB, monthly_cost1_FEB,
# monthly_power1_MAR, monthly_cost1_MAR))
# # Commit the changes
# conn.commit()
# # create a new table for app2_cost_power
# conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432")
# cur = conn.cursor()
# cur.execute("""
# DROP TABLE IF EXISTS app2_cost_power;
# CREATE TABLE app2_cost_power (
# month TEXT,
# watts FLOAT,
# water FLOAT,
# cost FLOAT
# )
# """)
# conn.commit()
# # Insert the monthly power and cost values into the table
# cur.execute("""
# INSERT INTO app2_cost_power (month, watts, water, cost)
# VALUES ('January', %s, %s, %s),
# ('February', %s, %s, %s),
# ('March', %s, %s, %s)
# """, (monthly_power2_JAN, monthly_water_usg_JAN, monthly_cost2_JAN,
# monthly_power2_FEB, monthly_water_usg_FEB, monthly_cost2_FEB,
# monthly_power2_MAR, monthly_water_usg_MAR, monthly_cost2_MAR))
# # Commit the changes
# conn.commit()
# # create a new table for temp_cost_watts
# conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432")
# cur = conn.cursor()
# cur.execute("""
# DROP TABLE IF EXISTS temp_cost_watts;
# CREATE TABLE temp_cost_watts (
# month TEXT,
# watts FLOAT,
# cost FLOAT
# )
# """)
# conn.commit()
# # Insert the monthly power and cost values into the table
# cur.execute("""
# INSERT INTO temp_cost_watts (month, watts, cost)
# VALUES ('January', %s, %s),
# ('February', %s, %s),
# ('March', %s, %s)
# """, (monthly_temp_watts_JAN, monthly_temp_ct_JAN,
# monthly_temp_watts_FEB, monthly_temp_ct_FEB,
# monthly_temp_watts_MAR, monthly_temp_ct_MAR))
# # Commit the changes
# conn.commit()
# 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()
cur.execute("""
DROP TABLE IF EXISTS total_cost_watts;
CREATE TABLE total_cost_watts (
month TEXT,
watts FLOAT,
cost FLOAT
)
""")
conn.commit()
# Insert the monthly power and cost values into the table
cur.execute("""
INSERT INTO total_cost_watts (month, watts, cost)
VALUES ('January', %s, %s),
('February', %s, %s),
('March', %s, %s)
""", (monthly_temp_watts_JAN+monthly_power2_JAN+monthly_power1_JAN, monthly_temp_ct_JAN+monthly_cost2_JAN+monthly_cost1_JAN,
monthly_temp_watts_FEB+monthly_power2_FEB+monthly_power1_FEB, monthly_temp_ct_FEB+monthly_cost2_FEB+monthly_cost1_FEB,
monthly_temp_watts_MAR+monthly_power2_MAR+monthly_power1_MAR, monthly_temp_ct_MAR+monthly_cost2_MAR+monthly_cost1_MAR))
# Commit the changes
conn.commit()
# Commit changes # Commit changes
#conn.commit() #conn.commit()
cur.close() cur.close()
......
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