From 781ade88b13c6a484412eaa37d3f95bc3fda1c88 Mon Sep 17 00:00:00 2001 From: Jesus Miguel Zubia <miquel44@uab.edu> Date: Mon, 10 Apr 2023 18:01:48 -0500 Subject: [PATCH] Updated CS_499_database.py to story the total cost and watts for all appliances each month --- CS_499_database.py | 112 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/CS_499_database.py b/CS_499_database.py index caec14b..e322a46 100644 --- a/CS_499_database.py +++ b/CS_499_database.py @@ -1,7 +1,7 @@ import psycopg2 # 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 conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432") @@ -45,7 +45,7 @@ cur = conn.cursor() cur.execute(""" DROP TABLE IF EXISTS Appliance_1_History; CREATE TABLE Appliance_1_History ( - id SERIAL PRIMARY KEY, + id SERIAL PRIMARY KEY, day VARCHAR(255), micro_pwr FLOAT, stove_pwr FLOAT, @@ -156,6 +156,114 @@ for time_stamp4, data in App3_History.items(): )) 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 #conn.commit() cur.close() -- GitLab