From 368283589020c73f2d728179907894cc77beeea1 Mon Sep 17 00:00:00 2001 From: francoisdillinger <elmojester@gmail.com> Date: Sun, 16 Apr 2023 23:58:46 -0500 Subject: [PATCH] Add water total to DB creation --- backend/database/CS_499_create_db.py | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/backend/database/CS_499_create_db.py b/backend/database/CS_499_create_db.py index 66b74ec..93dc306 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() -- GitLab