diff --git a/backend/database/CS_499_create_db.py b/backend/database/CS_499_create_db.py index 66b74ecb6b5bc55ad519219384064ffb91ba9a8f..93dc3064979e027beb8d4096c1976d5d06503b45 100644 --- a/backend/database/CS_499_create_db.py +++ b/backend/database/CS_499_create_db.py @@ -228,6 +228,42 @@ def create_and_seed_db(): # Commit the changes conn.commit() + ################################################################################################################################### + ################################################################################################################################### + ############################################ Implement total water used in total table ############################################ + + # create a new table for total_cost_watts_water + # 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_water; + CREATE TABLE total_cost_watts_water ( + month TEXT, + watts FLOAT, + cost FLOAT, + gallons_usage FLOAT + + ) + """) + conn.commit() + + # Insert the monthly power, gallons, usage and cost values into the table + cur.execute(""" + INSERT INTO total_cost_watts_water (month, watts, cost, gallons_usage) + VALUES ('January', %s, %s, %s), + ('February', %s, %s, %s), + ('March', %s, %s, %s) + """, (monthly_temp_watts_JAN+monthly_power2_JAN+monthly_power1_JAN, monthly_temp_ct_JAN+monthly_cost2_JAN+monthly_cost1_JAN, monthly_water_usg_JAN, + monthly_temp_watts_FEB+monthly_power2_FEB+monthly_power1_FEB, monthly_temp_ct_FEB+monthly_cost2_FEB+monthly_cost1_FEB, monthly_water_usg_FEB, + monthly_temp_watts_MAR+monthly_power2_MAR+monthly_power1_MAR, monthly_temp_ct_MAR+monthly_cost2_MAR+monthly_cost1_MAR, monthly_water_usg_MAR)) + + # Commit the changes + conn.commit() + + ###################################################################################################################################### + ###################################################################################################################################### + ###################################################################################################################################### + # Close communication with the database cur.close() conn.close()