Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CS 499
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hamid Choucha
CS 499
Commits
781ade88
Commit
781ade88
authored
2 years ago
by
Jesus Miguel Zubia
Browse files
Options
Downloads
Patches
Plain Diff
Updated CS_499_database.py to story the total cost and watts for all appliances each month
parent
5d8ee49f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CS_499_database.py
+110
-2
110 additions, 2 deletions
CS_499_database.py
with
110 additions
and
2 deletions
CS_499_database.py
+
110
−
2
View file @
781ade88
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
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment