diff --git a/__pycache__/.DS_Store b/__pycache__/.DS_Store deleted file mode 100644 index ebc5a4b675bbcc66f8906eb255b434dbdc7be046..0000000000000000000000000000000000000000 Binary files a/__pycache__/.DS_Store and /dev/null differ diff --git a/__pycache__/CS_499_backend.cpython-311.pyc b/__pycache__/CS_499_backend.cpython-311.pyc deleted file mode 100644 index 6e24384d334f3233bef3084999ebbd2c80db25cf..0000000000000000000000000000000000000000 Binary files a/__pycache__/CS_499_backend.cpython-311.pyc and /dev/null differ diff --git a/__pycache__/app.cpython-311.pyc b/__pycache__/app.cpython-311.pyc deleted file mode 100644 index a1206b53895b002e4e92bbb27c613f3b18b36a4e..0000000000000000000000000000000000000000 Binary files a/__pycache__/app.cpython-311.pyc and /dev/null differ diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..dad2b2bbbf25d64bf5b15e6b086ab87c6e106afc --- /dev/null +++ b/backend/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +.flaskenv \ No newline at end of file diff --git a/backend/__init__.py b/backend/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/backend/api/__init__.py b/backend/api/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..0a071a20be3295cc3e29ea4569ee9ece4538600b --- /dev/null +++ b/backend/api/__init__.py @@ -0,0 +1,25 @@ +from flask import Flask + +# from database.db_connection import get_db_connection + + +def create_app(): + app = Flask(__name__) + + from api.routes.tempData import tempData_bp + from api.routes.powerData import powerData_bp + from api.routes.waterData import waterData_bp + from api.routes.costData import costData_bp + + app.register_blueprint(tempData_bp, url_prefix='/api') + app.register_blueprint(powerData_bp, url_prefix='/api') + app.register_blueprint(waterData_bp, url_prefix='/api') + app.register_blueprint(costData_bp, url_prefix='/api') + + # The following only needs to be run once to create the database. DO NOT UNCOMMENT!!! + + # with app.app_context(): + # from database.CS_499_create_db import create_and_seed_db + # create_and_seed_db() + + return app \ No newline at end of file diff --git a/backend/api/requirements.txt b/backend/api/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..fb0dec5b667552bb10defa307c3deb82cf282eb0 --- /dev/null +++ b/backend/api/requirements.txt @@ -0,0 +1 @@ +Flask==2.0.3 \ No newline at end of file diff --git a/backend/api/routes/costData.py b/backend/api/routes/costData.py new file mode 100644 index 0000000000000000000000000000000000000000..35065aef6bbf0edd186df1c06b99eccd7054a95a --- /dev/null +++ b/backend/api/routes/costData.py @@ -0,0 +1,18 @@ +from flask import request, Blueprint, jsonify +from database.db_connection import get_db_connection + +costData_bp = Blueprint('costData', __name__) + +@costData_bp.route('/costData', methods = ['GET']) +def get_costData(): + all_costData = get_data() + return jsonify(all_costData) + + +def get_data(): + conn = get_db_connection() + cur = conn.cursor() + cur.execute('SELECT * FROM total_cost_watts;') + all_costData = cur.fetchall() + cur.close() + return all_costData \ No newline at end of file diff --git a/backend/api/routes/powerData.py b/backend/api/routes/powerData.py new file mode 100644 index 0000000000000000000000000000000000000000..cb68aa17de85db5a09e9c52cb0166c39495c6762 --- /dev/null +++ b/backend/api/routes/powerData.py @@ -0,0 +1,17 @@ +from flask import request, Blueprint, jsonify +from database.db_connection import get_db_connection + +powerData_bp = Blueprint('powerData', __name__) + +@powerData_bp.route('/powerData', methods = ['GET']) +def get_powerData(): + all_powerData = get_data() + return jsonify(all_powerData) + +def get_data(): + conn = get_db_connection() + cur = conn.cursor() + cur.execute('SELECT * FROM power_testcases;') + all_powerData = cur.fetchall() + cur.close() + return all_powerData \ No newline at end of file diff --git a/backend/api/routes/tempData.py b/backend/api/routes/tempData.py new file mode 100644 index 0000000000000000000000000000000000000000..fe9b68ffc3c06a12d4e2232dbb960c04c6dc3844 --- /dev/null +++ b/backend/api/routes/tempData.py @@ -0,0 +1,17 @@ +from flask import request, Blueprint, jsonify +from database.db_connection import get_db_connection + +tempData_bp = Blueprint('tempData', __name__) + +@tempData_bp.route('/tempData', methods = ['GET']) +def get_temperatureData(): + all_tempData = get_data() + return jsonify(all_tempData) + +def get_data(): + conn = get_db_connection() + cur = conn.cursor() + cur.execute('SELECT * FROM temperature_data;') + all_tempData = cur.fetchall() + cur.close() + return all_tempData \ No newline at end of file diff --git a/backend/api/routes/waterData.py b/backend/api/routes/waterData.py new file mode 100644 index 0000000000000000000000000000000000000000..a7ca8b0177207c4335028a479589e0bbd6581401 --- /dev/null +++ b/backend/api/routes/waterData.py @@ -0,0 +1,17 @@ +from flask import request, Blueprint, jsonify +from database.db_connection import get_db_connection + +waterData_bp = Blueprint('waterData', __name__) + +@waterData_bp.route('/waterData', methods = ['GET']) +def get_waterData(): + all_waterData = get_data() + return jsonify(all_waterData) + +def get_data(): + conn = get_db_connection() + cur = conn.cursor() + cur.execute('SELECT * FROM appliance_with_water') + all_waterData = cur.fetchall() + cur.close() + return all_waterData \ No newline at end of file diff --git a/backend/app.py b/backend/app.py new file mode 100644 index 0000000000000000000000000000000000000000..85711ff225b07c1fc4263b033795df823a37c3a0 --- /dev/null +++ b/backend/app.py @@ -0,0 +1,9 @@ +from api import create_app +app = create_app() + +@app.route('/', methods=['GET']) +def hello(): + return {'message': 'Hello, world!'} + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/CS_499_backend.py b/backend/database/CS_499_backend.py similarity index 81% rename from CS_499_backend.py rename to backend/database/CS_499_backend.py index e23b21ed8f9a987f255ba750b8bedbfbb67ded72..bc27be800b450dccbb92f423b1f33e60dfe5c020 100644 --- a/CS_499_backend.py +++ b/backend/database/CS_499_backend.py @@ -37,8 +37,8 @@ for i in range(0,NUM_WEEKS): Door_Window_History[time_stamp] = Door_Window(WORKWEEK[j], door_opens, door_minutes, window_open, window_minutes) time_stamp += 1 -for i in Door_Window_History: - print(i, Door_Window_History[i].day, Door_Window_History[i].Door_status, Door_Window_History[i].Door_time, Door_Window_History[i].Window_status, Door_Window_History[i].Window_time) +# for i in Door_Window_History: +# print(i, Door_Window_History[i].day, Door_Window_History[i].Door_status, Door_Window_History[i].Door_time, Door_Window_History[i].Window_status, Door_Window_History[i].Window_time) class Appliance_1: @@ -106,7 +106,7 @@ monthly_power1_FEB=0 monthly_cost1_MAR=0 monthly_power1_MAR=0 -print("###################################################### TOTAL APP1 HISTORY FOR 77 DAYS ###################################################### \n") +# print("###################################################### TOTAL APP1 HISTORY FOR 77 DAYS ###################################################### \n") for i in App1_History: if i<=31: monthly_power1_JAN += App1_History[i].micro_pwr + App1_History[i].stove_pwr + App1_History[i].oven_pwr + App1_History[i].Lrtv_pwr + App1_History[i].Brtv_pwr + App1_History[i].fridge_pwr +App1_History[i].lights_pwr @@ -118,14 +118,14 @@ for i in App1_History: monthly_power1_MAR += App1_History[i].micro_pwr + App1_History[i].stove_pwr + App1_History[i].oven_pwr + App1_History[i].Lrtv_pwr + App1_History[i].Brtv_pwr + App1_History[i].fridge_pwr +App1_History[i].lights_pwr monthly_cost1_MAR += App1_History[i].micro_ct + App1_History[i].stove_ct + App1_History[i].oven_ct + App1_History[i].Lrtv_ct + App1_History[i].Brtv_ct + App1_History[i].fridge_ct + App1_History[i].lights_ct #print(i,App1_History[i].day,App1_History[i].micro_pwr,App1_History[i].stove_pwr,App1_History[i].oven_pwr,App1_History[i].Lrtv_pwr,App1_History[i].Brtv_pwr,App1_History[i].micro_ct,App1_History[i].stove_ct,App1_History[i].oven_ct,App1_History[i].Lrtv_ct,App1_History[i].Brtv_ct) -print( "_ - _ - _ - _ Power used for each Month _ - _ - _ - _ \n") -print( "Jan APP1 watts used : ",monthly_power1_JAN ) -print( "FEB APP1 watts used : ",monthly_power1_FEB ) -print( "MAR APP1 watts used : ",monthly_power1_MAR ) -print( "_ - _ - _ - _ Cost used for each Month _ - _ - _ - _ \n") -print( "Jan APP1 cost used : ",monthly_cost1_JAN ) -print( "FEB APP1 cost used : ",monthly_cost1_FEB ) -print( "MAR APP1 cost used : ",monthly_cost1_MAR ) +# print( "_ - _ - _ - _ Power used for each Month _ - _ - _ - _ \n") +# print( "Jan APP1 watts used : ",monthly_power1_JAN ) +# print( "FEB APP1 watts used : ",monthly_power1_FEB ) +# print( "MAR APP1 watts used : ",monthly_power1_MAR ) +# print( "_ - _ - _ - _ Cost used for each Month _ - _ - _ - _ \n") +# print( "Jan APP1 cost used : ",monthly_cost1_JAN ) +# print( "FEB APP1 cost used : ",monthly_cost1_FEB ) +# print( "MAR APP1 cost used : ",monthly_cost1_MAR ) #print("################################################################################################################################################################# \n") @@ -212,7 +212,7 @@ monthly_water_usg_FEB=0 monthly_cost2_MAR=0 monthly_power2_MAR=0 monthly_water_usg_MAR=0 -print("###################################################### TOTAL APP2 HISTORY FOR 77 DAYS ###################################################### \n") +# print("###################################################### TOTAL APP2 HISTORY FOR 77 DAYS ###################################################### \n") for i in App2_History: if i>=31: monthly_cost2_JAN+= App2_History[i].Water_Heat_ct + App2_History[i].DishWasher_ct + App2_History[i].Clothes_Wash_ct + App2_History[i].Clothes_dry_ct +App2_History[i].Water_ct + App2_History[i].bath_fans_ct @@ -227,18 +227,18 @@ for i in App2_History: monthly_power2_MAR+= App2_History[i].Water_Heat_pwr+ App2_History[i].DishWasher_pwr + App2_History[i].Clothes_Wash_pwr + App2_History[i].Clothes_dry_pwr + App2_History[i].bath_fans_pwr monthly_water_usg_MAR+= App2_History[i].Bath_water_ug + App2_History[i].Shower_water_ug + App2_History[i].DishWasher_ug+ App2_History[i].Clothes_Wash_ug #print(i,App2_History[i].day,App2_History[i].Water_Heat_pwr,App2_History[i].DishWasher_pwr,App2_History[i].Clothes_Wash_pwr,App2_History[i].Clothes_dry_pwr,App2_History[i].bath_fans_pwr,App2_History[i].Water_Heat_ug,App2_History[i].Bath_water_ug,App2_History[i].Shower_water_ug,App2_History[i].DishWasher_ug,App2_History[i].Clothes_Wash_ug,App2_History[i].Water_Heat_ct,App2_History[i].DishWasher_ct,App2_History[i].Clothes_Wash_ct,App2_History[i].Clothes_dry_ct,App2_History[i].bath_fans_ct,App2_History[i].Water_ct,App2_History[i].bath,App2_History[i].shower) -print( "_ - _ - _ - _ Power used for each Month _ - _ - _ - _ \n") -print( "Jan APP2 watts used : ",monthly_power2_JAN ) -print( "FEB APP2 watts used : ",monthly_power2_FEB ) -print( "MAR APP2 watts used : ",monthly_power2_MAR ) -print( "_ - _ - _ - _ Cost used for each Month _ - _ - _ - _ \n") -print( "Jan APP2 cost used : ",monthly_cost2_JAN ) -print( "FEB APP2 cost used : ",monthly_cost2_FEB ) -print( "MAR APP2 cost used : ",monthly_cost2_MAR ) -print( "_ - _ - _ - _ Gallons used for each Month _ - _ - _ - _ \n") -print( "Jan APP2 water used : ",monthly_water_usg_JAN ) -print( "FEB APP2 water used : ",monthly_water_usg_FEB ) -print( "MAR APP2 water used : ",monthly_water_usg_MAR ) +# print( "_ - _ - _ - _ Power used for each Month _ - _ - _ - _ \n") +# print( "Jan APP2 watts used : ",monthly_power2_JAN ) +# print( "FEB APP2 watts used : ",monthly_power2_FEB ) +# print( "MAR APP2 watts used : ",monthly_power2_MAR ) +# print( "_ - _ - _ - _ Cost used for each Month _ - _ - _ - _ \n") +# print( "Jan APP2 cost used : ",monthly_cost2_JAN ) +# print( "FEB APP2 cost used : ",monthly_cost2_FEB ) +# print( "MAR APP2 cost used : ",monthly_cost2_MAR ) +# print( "_ - _ - _ - _ Gallons used for each Month _ - _ - _ - _ \n") +# print( "Jan APP2 water used : ",monthly_water_usg_JAN ) +# print( "FEB APP2 water used : ",monthly_water_usg_FEB ) +# print( "MAR APP2 water used : ",monthly_water_usg_MAR ) #print( "################################################################################################################################################################# \n") @@ -299,7 +299,7 @@ monthly_temp_ct_FEB=0 monthly_temp_watts_FEB=0 monthly_temp_ct_MAR=0 monthly_temp_watts_MAR=0 -print("###################################################### TOTAL TEMP HISTORY FOR 77 DAYS ###################################################### \n") +# print("###################################################### TOTAL TEMP HISTORY FOR 77 DAYS ###################################################### \n") for i in App3_History: if i<=31: monthly_temp_watts_JAN+=App3_History[i].temp_power @@ -310,21 +310,21 @@ for i in App3_History: if i>59: monthly_temp_ct_MAR+=App3_History[i].temp_cost monthly_temp_watts_MAR+=App3_History[i].temp_power -print( "_ - _ - _ - _ Power used for each Month _ - _ - _ - _ \n") -print( "Jan APP3 watts used : ",monthly_temp_watts_JAN ) -print( "FEB APP3 watts used : ",monthly_temp_watts_FEB ) -print( "MAR APP3 watts used : ",monthly_temp_watts_MAR ) -print( "_ - _ - _ - _ Cost used for each Month _ - _ - _ - _ \n") -print( "Jan APP3 cost used : ",monthly_temp_ct_JAN ) -print( "FEB APP3 cost used : ",monthly_temp_ct_FEB ) -print( "MAR APP3 cost used : ",monthly_temp_ct_MAR ) -print( "################################################################################################################################################################# \n") -print("January Total cost",monthly_temp_ct_JAN+monthly_cost2_JAN+monthly_cost1_JAN) -print("Febuary Total cost",monthly_temp_ct_FEB+monthly_cost2_FEB+monthly_cost1_FEB) -print("March Total cost",monthly_temp_ct_MAR+monthly_cost2_FEB+monthly_cost1_MAR) -print("January Total Watts",monthly_temp_watts_JAN+monthly_power2_JAN+monthly_power1_JAN) -print("Febuary Total Watts",monthly_temp_watts_FEB+monthly_power2_FEB+monthly_power1_FEB) -print("March Total Watts",monthly_temp_watts_MAR+monthly_power2_MAR+monthly_power1_MAR) +# print( "_ - _ - _ - _ Power used for each Month _ - _ - _ - _ \n") +# print( "Jan APP3 watts used : ",monthly_temp_watts_JAN ) +# print( "FEB APP3 watts used : ",monthly_temp_watts_FEB ) +# print( "MAR APP3 watts used : ",monthly_temp_watts_MAR ) +# print( "_ - _ - _ - _ Cost used for each Month _ - _ - _ - _ \n") +# print( "Jan APP3 cost used : ",monthly_temp_ct_JAN ) +# print( "FEB APP3 cost used : ",monthly_temp_ct_FEB ) +# print( "MAR APP3 cost used : ",monthly_temp_ct_MAR ) +# print( "################################################################################################################################################################# \n") +# print("January Total cost",monthly_temp_ct_JAN+monthly_cost2_JAN+monthly_cost1_JAN) +# print("Febuary Total cost",monthly_temp_ct_FEB+monthly_cost2_FEB+monthly_cost1_FEB) +# print("March Total cost",monthly_temp_ct_MAR+monthly_cost2_FEB+monthly_cost1_MAR) +# print("January Total Watts",monthly_temp_watts_JAN+monthly_power2_JAN+monthly_power1_JAN) +# print("Febuary Total Watts",monthly_temp_watts_FEB+monthly_power2_FEB+monthly_power1_FEB) +# print("March Total Watts",monthly_temp_watts_MAR+monthly_power2_MAR+monthly_power1_MAR) diff --git a/backend/database/CS_499_create_db.py b/backend/database/CS_499_create_db.py new file mode 100644 index 0000000000000000000000000000000000000000..66b74ecb6b5bc55ad519219384064ffb91ba9a8f --- /dev/null +++ b/backend/database/CS_499_create_db.py @@ -0,0 +1,234 @@ + +# 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, 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 +from .db_connection import get_db_connection + +def create_and_seed_db(): + conn = get_db_connection() + cur = conn.cursor() + + print("\033[33mCreating and seeding database...\033[33m") + + + # create a new table for Door_Window_History + print("\033[33mCreating table for Door_Window_History...\033[33m") + + cur.execute(""" + DROP TABLE IF EXISTS Door_Window_History; + CREATE TABLE Door_Window_History ( + id SERIAL PRIMARY KEY, + day VARCHAR(255), + door_status INTEGER, + door_time FLOAT, + window_status INTEGER, + window_time FLOAT + ); + """) + + conn.commit() + print("\033[32mDoor_Window_History table created successfully in PostgreSQL\033[32m") + + + #insert the data into the Door_Window_History table + for i in Door_Window_History: + print(" \033[34mInserting data into Door_Window_History table... \033[34m") + for time_stamp, data in Door_Window_History.items(): + cur.execute(""" + INSERT INTO Door_Window_History ( + day, door_status, door_time, window_status, window_time) + VALUES (%s, %s, %s, %s, %s); + """, ( + data.day, data.Door_status, data.Door_time, + data.Window_status, data.Window_time + )) + conn.commit() + + # create a new table for App1_History + print("\033[33mCreating table for App1_History...\033[33m") + cur.execute(""" + DROP TABLE IF EXISTS Appliance_1_History; + CREATE TABLE Appliance_1_History ( + id SERIAL PRIMARY KEY, + day VARCHAR(255), + micro_pwr FLOAT, + stove_pwr FLOAT, + oven_pwr FLOAT, + Lrtv_pwr FLOAT, + Brtv_pwr FLOAT, + fridge_pwr FLOAT, + micro_ct FLOAT, + stove_ct FLOAT, + oven_ct FLOAT, + Lrtv_ct FLOAT, + Brtv_ct FLOAT, + fridge_ct FLOAT, + lights_pwr FLOAT, + lights_ct FLOAT + ); + """) + print("\033[32mApp1_History table created successfully in PostgreSQL\033[32m ") + + + for time_stamp2, data in App1_History.items(): + print(" \033[34mInserting data into Appliance_1_History table... \033[34m") + cur.execute(""" + INSERT INTO Appliance_1_History ( + day, micro_pwr, stove_pwr, oven_pwr, Lrtv_pwr, Brtv_pwr, fridge_pwr, + micro_ct, stove_ct, oven_ct, Lrtv_ct, Brtv_ct, fridge_ct, lights_pwr, lights_ct) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s); + """, ( + data.day, data.micro_pwr, data.stove_pwr, data.oven_pwr, data.Lrtv_pwr, data.Brtv_pwr, + data.fridge_pwr, data.micro_ct, data.stove_ct, data.oven_ct, data.Lrtv_ct, data.Brtv_ct, + data.fridge_ct, data.lights_pwr, data.lights_ct + )) + conn.commit() + + + + # create a new table for appliance_with_water + print("\033[33mCreating table for appliance_with_water...\033[33m") + cur.execute(""" + DROP TABLE IF EXISTS appliance_with_water; + CREATE TABLE appliance_with_water ( + id SERIAL PRIMARY KEY, + day TEXT, + water_heat_pwr FLOAT, + dishwasher_pwr FLOAT, + clothes_wash_pwr FLOAT, + clothes_dry_pwr FLOAT, + bath_fans_pwr FLOAT, + water_heat_ug FLOAT, + bath_water_ug FLOAT, + shower_water_ug FLOAT, + dishwasher_ug FLOAT, + clothes_wash_ug FLOAT, + water_heat_ct FLOAT, + dishwasher_ct FLOAT, + clothes_wash_ct FLOAT, + clothes_dry_ct FLOAT, + bath_fans_ct FLOAT, + water_ct FLOAT, + bath INT, + shower INT + ); + """) + conn.commit() + print("\033[32mappliance_with_water table created successfully in PostgreSQL\033[32m ") + + + # insert data into the App2_History table + for time_stamp3, data in App2_History.items(): + print(" \033[34mInserting data into appliance_with_water table... \033[34m") + cur.execute(""" + INSERT INTO appliance_with_water ( + day, water_heat_pwr, dishwasher_pwr, clothes_wash_pwr, + clothes_dry_pwr, bath_fans_pwr, water_heat_ug, bath_water_ug, + shower_water_ug, dishwasher_ug, clothes_wash_ug, water_heat_ct, + dishwasher_ct, clothes_wash_ct, clothes_dry_ct, bath_fans_ct, + water_ct, bath, shower + ) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s); + """, ( + data.day, data.Water_Heat_pwr, data.DishWasher_pwr, data.Clothes_Wash_pwr, + data.Clothes_dry_pwr, data.bath_fans_pwr, data.Water_Heat_ug, data.Bath_water_ug, + data.Shower_water_ug, data.DishWasher_ug, data.Clothes_Wash_ug, data.Water_Heat_ct, + data.DishWasher_ct, data.Clothes_Wash_ct, data.Clothes_dry_ct, data.bath_fans_ct, + data.Water_ct, data.bath, data.shower + )) + conn.commit() + + # create a new table for Temperature_data + print("\033[33mCreating table for Temperature_data...\033[33m") + cur.execute(""" + DROP TABLE IF EXISTS Temperature_data; + CREATE TABLE Temperature_data ( + id SERIAL PRIMARY KEY, + temp_power FLOAT, + temp_cost FLOAT + ); + """) + conn.commit() + print("\033[32mTemperature_data table created successfully in PostgreSQL\033[32m") + + + # insert data into the App3_History Table + for time_stamp4, data in App3_History.items(): + print(" \033[34mInserting data into Temperature_data table... \033[34m") + cur = conn.cursor() + cur.execute(""" + INSERT INTO temperature_data ( + temp_power, temp_cost + ) + VALUES (%s, %s); + """, ( + data.temp_power, data.temp_cost + )) + conn.commit() + + + + ###################################################################################################################################### + ###################################################################################################################################### + ############################################ TEMPERATURE DATA TABLE WATTS & COST BY MONTH ############################################ + + # 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 ('Temperature Data (January):', %s, %s), + ('Temperature Data (February):', %s, %s), + ('Temperature Data (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 + print("\033[33mCreating table for total_cost_watts...\033[33m") + cur.execute(""" + DROP TABLE IF EXISTS total_cost_watts; + CREATE TABLE total_cost_watts ( + month TEXT, + watts FLOAT, + cost FLOAT + ) + """) + conn.commit() + print("\033[32mtotal_cost_watts table created successfully in PostgreSQL\033[32m") + + + # 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() + + # Close communication with the database + cur.close() + conn.close() + print("\033[32mDatabase generated successfully\033[32m") diff --git a/backend/database/__init__.py b/backend/database/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/backend/database/db_connection.py b/backend/database/db_connection.py new file mode 100644 index 0000000000000000000000000000000000000000..d496ba9661c659161880663a5b2fa795d3d80842 --- /dev/null +++ b/backend/database/db_connection.py @@ -0,0 +1,15 @@ +import psycopg2 + +def get_db_connection(): + print('Connecting to the PostgreSQL database...') + conn = psycopg2.connect( + database="Team3DB", + user="Team3", + password="team3", + host="138.26.48.83", + port="5432" + ) + print('Database connection successful') + return conn + + diff --git a/backend/database/requirements.txt b/backend/database/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..5f671b781639b0c98b7974110d1f97d2d44b8535 --- /dev/null +++ b/backend/database/requirements.txt @@ -0,0 +1,4 @@ +requests==2.26.0 +psycopg2-binary==2.9.1 +# If numpy won't install make sure your python version is < 3.10 +numpy==1.21.2 \ No newline at end of file diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..2cdb95e9f2e50e0e8146d918976132a2f2b7defe --- /dev/null +++ b/backend/requirements.txt @@ -0,0 +1,8 @@ +# These are the required packages to run this project +# As we use more packages this list will be updated +Flask==2.0.3 +psycopg2-binary==2.9.1 +#Flask_SQLAlchemy==2.5.1 + + + \ No newline at end of file diff --git a/costData.py b/costData.py deleted file mode 100644 index 277dac04270e50a36b9ebb8f025a8f37bf426504..0000000000000000000000000000000000000000 --- a/costData.py +++ /dev/null @@ -1,12 +0,0 @@ -from flask import request, Blueprint, jsonify -import psycopg2 - -costData_bp = Blueprint('costData', __name__) - -@costData_bp.route('/costData', methods = ['GET']) -def get_costData(): - conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432") - cur = conn.cursor() - all_costData = cur.execute ('SELECT * FROM total_cost_watts;').fetchall() - - return jsonify(all_costData) \ No newline at end of file diff --git a/frontend/public/weatherIcons/01d.svg b/frontend/public/weatherIcons/01d.svg new file mode 100644 index 0000000000000000000000000000000000000000..5bd98463dac0c7c04a7c35711adc1b4ca870e14d --- /dev/null +++ b/frontend/public/weatherIcons/01d.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><g><path fill="none" stroke="#f59e0b" stroke-linecap="round" stroke-miterlimit="10" stroke-width="3" d="M42.5 32A10.5 10.5 0 1132 21.5 10.5 10.5 0 0142.5 32zM32 15.71V9.5m0 45v-6.21m11.52-27.81l4.39-4.39M16.09 47.91l4.39-4.39m0-23l-4.39-4.39m31.82 31.78l-4.39-4.39M15.71 32H9.5m45 0h-6.21"/><animateTransform attributeName="transform" dur="45s" from="0 32 32" repeatCount="indefinite" to="360 32 32" type="rotate"/></g></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/01n.svg b/frontend/public/weatherIcons/01n.svg new file mode 100644 index 0000000000000000000000000000000000000000..529e18ae0fdbb92ccf7631949118d6af24c49691 --- /dev/null +++ b/frontend/public/weatherIcons/01n.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><g><path fill="none" stroke="#72b9d5" stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M46.66 36.2a16.66 16.66 0 01-16.78-16.55 16.29 16.29 0 01.55-4.15A16.56 16.56 0 1048.5 36.1c-.61.06-1.22.1-1.84.1z"/><animateTransform attributeName="transform" dur="10s" repeatCount="indefinite" type="rotate" values="-5 32 32;15 32 32;-5 32 32"/></g></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/02d.svg b/frontend/public/weatherIcons/02d.svg new file mode 100644 index 0000000000000000000000000000000000000000..dd40d02a9df6f58faaac4767563a8fdc087ebf7a --- /dev/null +++ b/frontend/public/weatherIcons/02d.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><defs><clipPath id="a"><path fill="none" d="M12 35l-5.28-4.21-2-6 1-7 4-5 5-3h6l5 1 3 3L33 20l-6 4h-6l-3 3v4l-4 2-2 2z"/></clipPath></defs><g clip-path="url(#a)"><g><path fill="none" stroke="#f59e0b" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M23.5 24a4.5 4.5 0 11-4.5-4.5 4.49 4.49 0 014.5 4.5zM19 15.67V12.5m0 23v-3.17m5.89-14.22l2.24-2.24M10.87 32.13l2.24-2.24m0-11.78l-2.24-2.24m16.26 16.26l-2.24-2.24M7.5 24h3.17m19.83 0h-3.17"/><animateTransform attributeName="transform" dur="45s" from="0 19 24" repeatCount="indefinite" to="360 19 24" type="rotate"/></g></g><path fill="none" stroke="#e5e7eb" stroke-linejoin="round" stroke-width="3" d="M46.5 31.5h-.32a10.49 10.49 0 00-19.11-8 7 7 0 00-10.57 6 7.21 7.21 0 00.1 1.14A7.5 7.5 0 0018 45.5a4.19 4.19 0 00.5 0v0h28a7 7 0 000-14z"/></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/02n.svg b/frontend/public/weatherIcons/02n.svg new file mode 100644 index 0000000000000000000000000000000000000000..bdbe5f741338071ce2f1215357c393f066f7f400 --- /dev/null +++ b/frontend/public/weatherIcons/02n.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><defs><clipPath id="a"><path fill="none" d="M12 35l-5.28-4.21-2-6 1-7 4-5 5-3h6l5 1 3 3L33 20l-6 4h-6l-3 3v4l-4 2-2 2z"/></clipPath></defs><g clip-path="url(#a)"><g><path fill="none" stroke="#72b9d5" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M29.33 26.68a10.61 10.61 0 01-10.68-10.54A10.5 10.5 0 0119 13.5a10.54 10.54 0 1011.5 13.11 11.48 11.48 0 01-1.17.07z"/><animateTransform attributeName="transform" dur="10s" repeatCount="indefinite" type="rotate" values="-10 19.22 24.293;10 19.22 24.293;-10 19.22 24.293"/></g></g><path fill="none" stroke="#e5e7eb" stroke-linejoin="round" stroke-width="3" d="M46.5 31.5h-.32a10.49 10.49 0 00-19.11-8 7 7 0 00-10.57 6 7.21 7.21 0 00.1 1.14A7.5 7.5 0 0018 45.5a4.19 4.19 0 00.5 0v0h28a7 7 0 000-14z"/></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/03d.svg b/frontend/public/weatherIcons/03d.svg new file mode 100644 index 0000000000000000000000000000000000000000..41c1848a54cac87143c49030150ffe9157d7b8d2 --- /dev/null +++ b/frontend/public/weatherIcons/03d.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><g><path fill="none" stroke="#e5e7eb" stroke-linejoin="round" stroke-width="3" d="M46.5 31.5h-.32a10.49 10.49 0 00-19.11-8 7 7 0 00-10.57 6 7.21 7.21 0 00.1 1.14A7.5 7.5 0 0018 45.5a4.19 4.19 0 00.5 0v0h28a7 7 0 000-14z"/><animateTransform attributeName="transform" dur="7s" repeatCount="indefinite" type="translate" values="-3 0; 3 0; -3 0"/></g></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/03n.svg b/frontend/public/weatherIcons/03n.svg new file mode 100644 index 0000000000000000000000000000000000000000..41c1848a54cac87143c49030150ffe9157d7b8d2 --- /dev/null +++ b/frontend/public/weatherIcons/03n.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><g><path fill="none" stroke="#e5e7eb" stroke-linejoin="round" stroke-width="3" d="M46.5 31.5h-.32a10.49 10.49 0 00-19.11-8 7 7 0 00-10.57 6 7.21 7.21 0 00.1 1.14A7.5 7.5 0 0018 45.5a4.19 4.19 0 00.5 0v0h28a7 7 0 000-14z"/><animateTransform attributeName="transform" dur="7s" repeatCount="indefinite" type="translate" values="-3 0; 3 0; -3 0"/></g></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/04d.svg b/frontend/public/weatherIcons/04d.svg new file mode 100644 index 0000000000000000000000000000000000000000..41c1848a54cac87143c49030150ffe9157d7b8d2 --- /dev/null +++ b/frontend/public/weatherIcons/04d.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><g><path fill="none" stroke="#e5e7eb" stroke-linejoin="round" stroke-width="3" d="M46.5 31.5h-.32a10.49 10.49 0 00-19.11-8 7 7 0 00-10.57 6 7.21 7.21 0 00.1 1.14A7.5 7.5 0 0018 45.5a4.19 4.19 0 00.5 0v0h28a7 7 0 000-14z"/><animateTransform attributeName="transform" dur="7s" repeatCount="indefinite" type="translate" values="-3 0; 3 0; -3 0"/></g></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/04n.svg b/frontend/public/weatherIcons/04n.svg new file mode 100644 index 0000000000000000000000000000000000000000..41c1848a54cac87143c49030150ffe9157d7b8d2 --- /dev/null +++ b/frontend/public/weatherIcons/04n.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><g><path fill="none" stroke="#e5e7eb" stroke-linejoin="round" stroke-width="3" d="M46.5 31.5h-.32a10.49 10.49 0 00-19.11-8 7 7 0 00-10.57 6 7.21 7.21 0 00.1 1.14A7.5 7.5 0 0018 45.5a4.19 4.19 0 00.5 0v0h28a7 7 0 000-14z"/><animateTransform attributeName="transform" dur="7s" repeatCount="indefinite" type="translate" values="-3 0; 3 0; -3 0"/></g></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/09d.svg b/frontend/public/weatherIcons/09d.svg new file mode 100644 index 0000000000000000000000000000000000000000..f674ec91ba096096b14e95e25a6002f3b3a3849e --- /dev/null +++ b/frontend/public/weatherIcons/09d.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><path fill="none" stroke="#e5e7eb" stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M43.67 45.5h2.83a7 7 0 000-14h-.32a10.49 10.49 0 00-19.11-8 7 7 0 00-10.57 6 7.21 7.21 0 00.1 1.14A7.5 7.5 0 0018 45.5a4.19 4.19 0 00.5 0v0"/><g><path fill="none" stroke="#2885c7" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M24.39 43.03l-.78 4.94"/><animateTransform attributeName="transform" dur="0.7s" repeatCount="indefinite" type="translate" values="1 -5; -2 10"/><animate attributeName="opacity" dur="0.7s" repeatCount="indefinite" values="0;1;1;0"/></g><g><path fill="none" stroke="#2885c7" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M31.39 43.03l-.78 4.94"/><animateTransform attributeName="transform" begin="-0.4s" dur="0.7s" repeatCount="indefinite" type="translate" values="1 -5; -2 10"/><animate attributeName="opacity" begin="-0.4s" dur="0.7s" repeatCount="indefinite" values="0;1;1;0"/></g><g><path fill="none" stroke="#2885c7" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M38.39 43.03l-.78 4.94"/><animateTransform attributeName="transform" begin="-0.2s" dur="0.7s" repeatCount="indefinite" type="translate" values="1 -5; -2 10"/><animate attributeName="opacity" begin="-0.2s" dur="0.7s" repeatCount="indefinite" values="0;1;1;0"/></g></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/09n.svg b/frontend/public/weatherIcons/09n.svg new file mode 100644 index 0000000000000000000000000000000000000000..f674ec91ba096096b14e95e25a6002f3b3a3849e --- /dev/null +++ b/frontend/public/weatherIcons/09n.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><path fill="none" stroke="#e5e7eb" stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M43.67 45.5h2.83a7 7 0 000-14h-.32a10.49 10.49 0 00-19.11-8 7 7 0 00-10.57 6 7.21 7.21 0 00.1 1.14A7.5 7.5 0 0018 45.5a4.19 4.19 0 00.5 0v0"/><g><path fill="none" stroke="#2885c7" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M24.39 43.03l-.78 4.94"/><animateTransform attributeName="transform" dur="0.7s" repeatCount="indefinite" type="translate" values="1 -5; -2 10"/><animate attributeName="opacity" dur="0.7s" repeatCount="indefinite" values="0;1;1;0"/></g><g><path fill="none" stroke="#2885c7" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M31.39 43.03l-.78 4.94"/><animateTransform attributeName="transform" begin="-0.4s" dur="0.7s" repeatCount="indefinite" type="translate" values="1 -5; -2 10"/><animate attributeName="opacity" begin="-0.4s" dur="0.7s" repeatCount="indefinite" values="0;1;1;0"/></g><g><path fill="none" stroke="#2885c7" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M38.39 43.03l-.78 4.94"/><animateTransform attributeName="transform" begin="-0.2s" dur="0.7s" repeatCount="indefinite" type="translate" values="1 -5; -2 10"/><animate attributeName="opacity" begin="-0.2s" dur="0.7s" repeatCount="indefinite" values="0;1;1;0"/></g></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/10d.svg b/frontend/public/weatherIcons/10d.svg new file mode 100644 index 0000000000000000000000000000000000000000..7d3dfa83c21c6882e8bf57a9efccec3aeb460f52 --- /dev/null +++ b/frontend/public/weatherIcons/10d.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><defs><clipPath id="a"><path fill="none" d="M12 35l-5.28-4.21-2-6 1-7 4-5 5-3h6l5 1 3 3L33 20l-6 4h-6l-3 3v4l-4 2-2 2z"/></clipPath></defs><g clip-path="url(#a)"><g><path fill="none" stroke="#f59e0b" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M23.5 24a4.5 4.5 0 11-4.5-4.5 4.49 4.49 0 014.5 4.5zM19 15.67V12.5m0 23v-3.17m5.89-14.22l2.24-2.24M10.87 32.13l2.24-2.24m0-11.78l-2.24-2.24m16.26 16.26l-2.24-2.24M7.5 24h3.17m19.83 0h-3.17"/><animateTransform attributeName="transform" dur="45s" from="0 19 24" repeatCount="indefinite" to="360 19 24" type="rotate"/></g></g><path fill="none" stroke="#e5e7eb" stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M43.67 45.5h2.83a7 7 0 000-14h-.32a10.49 10.49 0 00-19.11-8 7 7 0 00-10.57 6 7.21 7.21 0 00.1 1.14A7.5 7.5 0 0018 45.5a4.19 4.19 0 00.5 0v0"/><g><path fill="none" stroke="#2885c7" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M24.39 43.03l-.78 4.94"/><animateTransform attributeName="transform" dur="0.7s" repeatCount="indefinite" type="translate" values="1 -5; -2 10"/><animate attributeName="opacity" dur="0.7s" repeatCount="indefinite" values="0;1;1;0"/></g><g><path fill="none" stroke="#2885c7" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M31.39 43.03l-.78 4.94"/><animateTransform attributeName="transform" begin="-0.4s" dur="0.7s" repeatCount="indefinite" type="translate" values="1 -5; -2 10"/><animate attributeName="opacity" begin="-0.4s" dur="0.7s" repeatCount="indefinite" values="0;1;1;0"/></g><g><path fill="none" stroke="#2885c7" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M38.39 43.03l-.78 4.94"/><animateTransform attributeName="transform" begin="-0.2s" dur="0.7s" repeatCount="indefinite" type="translate" values="1 -5; -2 10"/><animate attributeName="opacity" begin="-0.2s" dur="0.7s" repeatCount="indefinite" values="0;1;1;0"/></g></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/10n.svg b/frontend/public/weatherIcons/10n.svg new file mode 100644 index 0000000000000000000000000000000000000000..2e31ac3c1216d2594337cce6c8e8052d02c3783b --- /dev/null +++ b/frontend/public/weatherIcons/10n.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><defs><clipPath id="a"><path fill="none" d="M12 35l-5.28-4.21-2-6 1-7 4-5 5-3h6l5 1 3 3L33 20l-6 4h-6l-3 3v4l-4 2-2 2z"/></clipPath></defs><g clip-path="url(#a)"><g><path fill="none" stroke="#72b9d5" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M29.33 26.68a10.61 10.61 0 01-10.68-10.54A10.5 10.5 0 0119 13.5a10.54 10.54 0 1011.5 13.11 11.48 11.48 0 01-1.17.07z"/><animateTransform attributeName="transform" dur="10s" repeatCount="indefinite" type="rotate" values="-10 19.22 24.293;10 19.22 24.293;-10 19.22 24.293"/></g></g><path fill="none" stroke="#e5e7eb" stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M43.67 45.5h2.83a7 7 0 000-14h-.32a10.49 10.49 0 00-19.11-8 7 7 0 00-10.57 6 7.21 7.21 0 00.1 1.14A7.5 7.5 0 0018 45.5a4.19 4.19 0 00.5 0v0"/><g><path fill="none" stroke="#2885c7" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M24.39 43.03l-.78 4.94"/><animateTransform attributeName="transform" dur="0.7s" repeatCount="indefinite" type="translate" values="1 -5; -2 10"/><animate attributeName="opacity" dur="0.7s" repeatCount="indefinite" values="0;1;1;0"/></g><g><path fill="none" stroke="#2885c7" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M31.39 43.03l-.78 4.94"/><animateTransform attributeName="transform" begin="-0.4s" dur="0.7s" repeatCount="indefinite" type="translate" values="1 -5; -2 10"/><animate attributeName="opacity" begin="-0.4s" dur="0.7s" repeatCount="indefinite" values="0;1;1;0"/></g><g><path fill="none" stroke="#2885c7" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M38.39 43.03l-.78 4.94"/><animateTransform attributeName="transform" begin="-0.2s" dur="0.7s" repeatCount="indefinite" type="translate" values="1 -5; -2 10"/><animate attributeName="opacity" begin="-0.2s" dur="0.7s" repeatCount="indefinite" values="0;1;1;0"/></g></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/11d.svg b/frontend/public/weatherIcons/11d.svg new file mode 100644 index 0000000000000000000000000000000000000000..ce9b1f924cad8c7c0bfd8f6e34d1e56619a8bb8d --- /dev/null +++ b/frontend/public/weatherIcons/11d.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><path fill="none" stroke="#e5e7eb" stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M43.67 45.5h2.83a7 7 0 000-14h-.32a10.49 10.49 0 00-19.11-8 7 7 0 00-10.57 6 7.21 7.21 0 00.1 1.14A7.5 7.5 0 0018 45.5a4.19 4.19 0 00.5 0v0"/><g><path fill="#f59e0b" d="M30 36l-4 12h4l-2 10 10-14h-6l4-8h-6z"/><animate attributeName="opacity" dur="2s" repeatCount="indefinite" values="1;1;1;1;1;1;0.1;1;0.1;1;1;0.1;1;0.1;1"/></g></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/11n.svg b/frontend/public/weatherIcons/11n.svg new file mode 100644 index 0000000000000000000000000000000000000000..ce9b1f924cad8c7c0bfd8f6e34d1e56619a8bb8d --- /dev/null +++ b/frontend/public/weatherIcons/11n.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><path fill="none" stroke="#e5e7eb" stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M43.67 45.5h2.83a7 7 0 000-14h-.32a10.49 10.49 0 00-19.11-8 7 7 0 00-10.57 6 7.21 7.21 0 00.1 1.14A7.5 7.5 0 0018 45.5a4.19 4.19 0 00.5 0v0"/><g><path fill="#f59e0b" d="M30 36l-4 12h4l-2 10 10-14h-6l4-8h-6z"/><animate attributeName="opacity" dur="2s" repeatCount="indefinite" values="1;1;1;1;1;1;0.1;1;0.1;1;1;0.1;1;0.1;1"/></g></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/13d.svg b/frontend/public/weatherIcons/13d.svg new file mode 100644 index 0000000000000000000000000000000000000000..7a352c426cc58dfc5fe8247b3431f85443b11048 --- /dev/null +++ b/frontend/public/weatherIcons/13d.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><defs><clipPath id="a"><path fill="none" d="M12 35l-5.28-4.21-2-6 1-7 4-5 5-3h6l5 1 3 3L33 20l-6 4h-6l-3 3v4l-4 2-2 2z"/></clipPath></defs><g clip-path="url(#a)"><g><path fill="none" stroke="#f59e0b" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M23.5 24a4.5 4.5 0 11-4.5-4.5 4.49 4.49 0 014.5 4.5zM19 15.67V12.5m0 23v-3.17m5.89-14.22l2.24-2.24M10.87 32.13l2.24-2.24m0-11.78l-2.24-2.24m16.26 16.26l-2.24-2.24M7.5 24h3.17m19.83 0h-3.17"/><animateTransform attributeName="transform" dur="45s" from="0 19 24" repeatCount="indefinite" to="360 19 24" type="rotate"/></g></g><path fill="none" stroke="#e5e7eb" stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M43.67 45.5h2.83a7 7 0 000-14h-.32a10.49 10.49 0 00-19.11-8 7 7 0 00-10.57 6 7.21 7.21 0 00.1 1.14A7.5 7.5 0 0018 45.5a4.19 4.19 0 00.5 0v0"/><g><circle cx="31" cy="45" r="1.25" fill="none" stroke="#72b8d4" stroke-miterlimit="10"/><path fill="none" stroke="#72b8d4" stroke-linecap="round" stroke-miterlimit="10" d="M33.17 46.25l-1.09-.63m-2.16-1.24l-1.09-.63M31 42.5v1.25m0 3.75v-1.25m-1.08-.63l-1.09.63m4.34-2.5l-1.09.63"/><animateTransform additive="sum" attributeName="transform" dur="4s" repeatCount="indefinite" type="translate" values="-1 -6; 1 12"/><animateTransform additive="sum" attributeName="transform" dur="9s" repeatCount="indefinite" type="rotate" values="0 31 45; 360 31 45"/><animate attributeName="opacity" dur="4s" repeatCount="indefinite" values="0;1;1;1;0"/></g><g><circle cx="24" cy="45" r="1.25" fill="none" stroke="#72b8d4" stroke-miterlimit="10"/><path fill="none" stroke="#72b8d4" stroke-linecap="round" stroke-miterlimit="10" d="M26.17 46.25l-1.09-.63m-2.16-1.24l-1.09-.63M24 42.5v1.25m0 3.75v-1.25m-1.08-.63l-1.09.63m4.34-2.5l-1.09.63"/><animateTransform additive="sum" attributeName="transform" begin="-2s" dur="4s" repeatCount="indefinite" type="translate" values="1 -6; -1 12"/><animateTransform additive="sum" attributeName="transform" dur="9s" repeatCount="indefinite" type="rotate" values="0 24 45; 360 24 45"/><animate attributeName="opacity" begin="-2s" dur="4s" repeatCount="indefinite" values="0;1;1;1;0"/></g><g><circle cx="38" cy="45" r="1.25" fill="none" stroke="#72b8d4" stroke-miterlimit="10"/><path fill="none" stroke="#72b8d4" stroke-linecap="round" stroke-miterlimit="10" d="M40.17 46.25l-1.09-.63m-2.16-1.24l-1.09-.63M38 42.5v1.25m0 3.75v-1.25m-1.08-.63l-1.09.63m4.34-2.5l-1.09.63"/><animateTransform additive="sum" attributeName="transform" begin="-1s" dur="4s" repeatCount="indefinite" type="translate" values="1 -6; -1 12"/><animateTransform additive="sum" attributeName="transform" dur="9s" repeatCount="indefinite" type="rotate" values="0 38 45; 360 38 45"/><animate attributeName="opacity" begin="-1s" dur="4s" repeatCount="indefinite" values="0;1;1;1;0"/></g></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/13n.svg b/frontend/public/weatherIcons/13n.svg new file mode 100644 index 0000000000000000000000000000000000000000..7a352c426cc58dfc5fe8247b3431f85443b11048 --- /dev/null +++ b/frontend/public/weatherIcons/13n.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><defs><clipPath id="a"><path fill="none" d="M12 35l-5.28-4.21-2-6 1-7 4-5 5-3h6l5 1 3 3L33 20l-6 4h-6l-3 3v4l-4 2-2 2z"/></clipPath></defs><g clip-path="url(#a)"><g><path fill="none" stroke="#f59e0b" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M23.5 24a4.5 4.5 0 11-4.5-4.5 4.49 4.49 0 014.5 4.5zM19 15.67V12.5m0 23v-3.17m5.89-14.22l2.24-2.24M10.87 32.13l2.24-2.24m0-11.78l-2.24-2.24m16.26 16.26l-2.24-2.24M7.5 24h3.17m19.83 0h-3.17"/><animateTransform attributeName="transform" dur="45s" from="0 19 24" repeatCount="indefinite" to="360 19 24" type="rotate"/></g></g><path fill="none" stroke="#e5e7eb" stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M43.67 45.5h2.83a7 7 0 000-14h-.32a10.49 10.49 0 00-19.11-8 7 7 0 00-10.57 6 7.21 7.21 0 00.1 1.14A7.5 7.5 0 0018 45.5a4.19 4.19 0 00.5 0v0"/><g><circle cx="31" cy="45" r="1.25" fill="none" stroke="#72b8d4" stroke-miterlimit="10"/><path fill="none" stroke="#72b8d4" stroke-linecap="round" stroke-miterlimit="10" d="M33.17 46.25l-1.09-.63m-2.16-1.24l-1.09-.63M31 42.5v1.25m0 3.75v-1.25m-1.08-.63l-1.09.63m4.34-2.5l-1.09.63"/><animateTransform additive="sum" attributeName="transform" dur="4s" repeatCount="indefinite" type="translate" values="-1 -6; 1 12"/><animateTransform additive="sum" attributeName="transform" dur="9s" repeatCount="indefinite" type="rotate" values="0 31 45; 360 31 45"/><animate attributeName="opacity" dur="4s" repeatCount="indefinite" values="0;1;1;1;0"/></g><g><circle cx="24" cy="45" r="1.25" fill="none" stroke="#72b8d4" stroke-miterlimit="10"/><path fill="none" stroke="#72b8d4" stroke-linecap="round" stroke-miterlimit="10" d="M26.17 46.25l-1.09-.63m-2.16-1.24l-1.09-.63M24 42.5v1.25m0 3.75v-1.25m-1.08-.63l-1.09.63m4.34-2.5l-1.09.63"/><animateTransform additive="sum" attributeName="transform" begin="-2s" dur="4s" repeatCount="indefinite" type="translate" values="1 -6; -1 12"/><animateTransform additive="sum" attributeName="transform" dur="9s" repeatCount="indefinite" type="rotate" values="0 24 45; 360 24 45"/><animate attributeName="opacity" begin="-2s" dur="4s" repeatCount="indefinite" values="0;1;1;1;0"/></g><g><circle cx="38" cy="45" r="1.25" fill="none" stroke="#72b8d4" stroke-miterlimit="10"/><path fill="none" stroke="#72b8d4" stroke-linecap="round" stroke-miterlimit="10" d="M40.17 46.25l-1.09-.63m-2.16-1.24l-1.09-.63M38 42.5v1.25m0 3.75v-1.25m-1.08-.63l-1.09.63m4.34-2.5l-1.09.63"/><animateTransform additive="sum" attributeName="transform" begin="-1s" dur="4s" repeatCount="indefinite" type="translate" values="1 -6; -1 12"/><animateTransform additive="sum" attributeName="transform" dur="9s" repeatCount="indefinite" type="rotate" values="0 38 45; 360 38 45"/><animate attributeName="opacity" begin="-1s" dur="4s" repeatCount="indefinite" values="0;1;1;1;0"/></g></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/50d.svg b/frontend/public/weatherIcons/50d.svg new file mode 100644 index 0000000000000000000000000000000000000000..47377b984d5b06c5fcbeb7c365d70e8759a5eccb --- /dev/null +++ b/frontend/public/weatherIcons/50d.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><g><path fill="none" stroke="#e5e7eb" stroke-linecap="round" stroke-miterlimit="10" stroke-width="3" d="M17 32h30"/><animateTransform attributeName="transform" begin="0s" dur="5s" repeatCount="indefinite" type="translate" values="-4 0; 4 0; -4 0"/></g><g><path fill="none" stroke="#e5e7eb" stroke-linecap="round" stroke-miterlimit="10" stroke-width="3" d="M17 39h30"/><animateTransform attributeName="transform" begin="-2s" dur="5s" repeatCount="indefinite" type="translate" values="-3 0; 3 0; -3 0"/></g><g><path fill="none" stroke="#e5e7eb" stroke-linecap="round" stroke-miterlimit="10" stroke-width="3" d="M17 25h30"/><animateTransform attributeName="transform" begin="-4s" dur="5s" repeatCount="indefinite" type="translate" values="-4 0; 4 0; -4 0"/></g></svg> \ No newline at end of file diff --git a/frontend/public/weatherIcons/50n.svg b/frontend/public/weatherIcons/50n.svg new file mode 100644 index 0000000000000000000000000000000000000000..47377b984d5b06c5fcbeb7c365d70e8759a5eccb --- /dev/null +++ b/frontend/public/weatherIcons/50n.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><g><path fill="none" stroke="#e5e7eb" stroke-linecap="round" stroke-miterlimit="10" stroke-width="3" d="M17 32h30"/><animateTransform attributeName="transform" begin="0s" dur="5s" repeatCount="indefinite" type="translate" values="-4 0; 4 0; -4 0"/></g><g><path fill="none" stroke="#e5e7eb" stroke-linecap="round" stroke-miterlimit="10" stroke-width="3" d="M17 39h30"/><animateTransform attributeName="transform" begin="-2s" dur="5s" repeatCount="indefinite" type="translate" values="-3 0; 3 0; -3 0"/></g><g><path fill="none" stroke="#e5e7eb" stroke-linecap="round" stroke-miterlimit="10" stroke-width="3" d="M17 25h30"/><animateTransform attributeName="transform" begin="-4s" dur="5s" repeatCount="indefinite" type="translate" values="-4 0; 4 0; -4 0"/></g></svg> \ No newline at end of file diff --git a/frontend/src/App.js b/frontend/src/App.js index 5cb00d771045447b94e0748b9cc883c50f147882..c5a45066be51b516bef60c460fde9cf5acf4ced9 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -11,6 +11,7 @@ import DarkModeToggleButton from './darkModeToggleButton'; import ChartComponent from './chartComponent'; import CostsCollection from './costsCollection'; import TempsCollection from './tempsCollection'; +import ForecastCollection from './forecastCollection'; function App() { @@ -57,13 +58,13 @@ function App() { <ReactTooltip id="tooltip" place="top" effect="solid" /> <CarouselProvider isIntrinsicHeight={true} - totalSlides={2} + totalSlides={3} style={{display: 'flex', borderRadius: '10px'}}> <ButtonBack id="button1" style={{width: '10%', background: 'none', border: 'none'}}> <TfiArrowCircleLeft style={{width: '5em', height: '5em', color: 'rgba(0, 0, 0, 0.35)'}}/> </ButtonBack> - <Slider style={{width: '80%'}}> + <Slider style={{width: '80%',}}> <Slide index={0}> <TempsCollection /> <div data-tooltip-id="tooltip" @@ -78,6 +79,9 @@ function App() { <ChartComponent /> <CostsCollection /> </Slide> + <Slide index={2}> + <ForecastCollection /> + </Slide> </Slider> <ButtonNext id="button2" style={{width: '10%', background: 'none', border: 'none'}}> <TfiArrowCircleRight style={{width: '5em', height: '5em', color: 'rgba(0, 0, 0, 0.35)'}} /> diff --git a/frontend/src/DesiredTemp.js b/frontend/src/DesiredTemp.js index 0228da8414acd61c2d0bca593ca6f63891ce1ccb..e653b349a99c975ec6843fc4aab846bd933dba5e 100644 --- a/frontend/src/DesiredTemp.js +++ b/frontend/src/DesiredTemp.js @@ -18,7 +18,7 @@ const DesiredTemp = (props) => { <div id="tempsCollection"> <DecreaseTempButton handleDecreaseTempClick={handleDecreaseTempClick}/> <div id="currentTemp" className='temps'> - <p className='title'>Current</p> + <p className='title'>Desired</p> <p className='title'>Temperature</p> <p className='temperatures'>{desiredTemp} °F</p> </div> diff --git a/frontend/src/costsCollection.js b/frontend/src/costsCollection.js index 5a1309c41ad8bbabd05e1520fcab6f57b8280ac1..460505a528f270b8abf895ea837cb854f4e28799 100644 --- a/frontend/src/costsCollection.js +++ b/frontend/src/costsCollection.js @@ -22,12 +22,12 @@ const CostsCollection = (props) => { <p className='title'>Cost</p> <p className='amounts'>81.00</p> </div> - <div id="outsideTemp" className='costs'> + {/* <div id="outsideTemp" className='costs'> <p className='title'>Total</p> <p className='title'>Monthly</p> <p className='title'>Cost</p> <p className='amounts'>81.00</p> - </div> + </div> */} </div> ); }; diff --git a/frontend/src/forecastCollection.js b/frontend/src/forecastCollection.js new file mode 100644 index 0000000000000000000000000000000000000000..f47fa29c2c56b5ec70cb10ce88907cdc85256676 --- /dev/null +++ b/frontend/src/forecastCollection.js @@ -0,0 +1,59 @@ +import * as React from "react"; +import { useState, useEffect} from 'react'; + +const ForecastCollection = (props) => { + const [forecast, setForecast] = useState(null); + + const fetchData = async () => { + try { + const response = await fetch('https://api.openweathermap.org/data/2.5/forecast/daily?q=Birmingham,US&cnt=5&units=imperial&&appid=3563bf5e2d2996538b6ec9d50c045948'); + + if (!response.ok) { + throw new Error('Network response was not ok'); + } + + const temp = await response.json(); + setForecast(temp); + console.log(temp) + } catch (error) { + console.error('There was a problem with the fetch operation:', error); + } + }; + + useEffect(() => { + fetchData(); + }, []); + + // https://api.openweathermap.org/data/2.5/forecast?lat=33.5186&lon=86.8104&appid=3563bf5e2d2996538b6ec9d50c045948 + // https://api.openweathermap.org/data/2.5/forecast?lat=33.5186&lon=86.8104&appid=96c71299fdf8ace053d64d762f029353 + + // Assume data is the object containing the weather forecast data + + // from ./public/weatherIcons/01d.svg + + + if (forecast && forecast.city) { + return ( + <div className="forecast-days"> + {forecast.list.map(day => ( + <div className="forecasted-day"> + <p>{new Date(day.dt * 1000).toLocaleDateString()}</p> + <p>Temperature: {day.temp.day.toFixed(0)}°F</p> + <img src={`${process.env.PUBLIC_URL}/weatherIcons/${day.weather[0].icon}.svg`} alt="weather icon" /> + </div> + ))} + </div> + ); + } else { + return <div>Loading...</div>; + } + +}; + +export default ForecastCollection; + + + + + + diff --git a/frontend/src/index.css b/frontend/src/index.css index 83e22523351f5f6e6dd213b0d6b9fca1cc23e1f2..214b20d72100e534d142ae58b2be076574a3c016 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -39,7 +39,7 @@ body { margin: 0; width: 100%; /* min-height: 100vh; */ - display: grid; + /* display: grid; */ align-items: center; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', @@ -1989,4 +1989,24 @@ animation-iteration-count: 1; 100% { stroke: #000 } +} + +/* .slideInner___2mfX9{ + position: unset; +} */ + +.forecast-days{ + display: flex; + flex-direction: row; + flex-wrap: nowrap; + justify-content: space-evenly; + position: unset; +} + +.forecasted-day{ + display: flex; + flex-direction: column; + align-content: center; + align-items: center; + position: relative; } \ No newline at end of file diff --git a/frontend/src/tempsCollection.js b/frontend/src/tempsCollection.js index 349df2cceebdaacaa13057e7d4e2671fd4bacbbe..afacc4dc194a649dcf38fa18fc40f827206f5542 100644 --- a/frontend/src/tempsCollection.js +++ b/frontend/src/tempsCollection.js @@ -1,19 +1,42 @@ import * as React from "react"; -import { useState } from 'react'; +import { useState, useEffect} from 'react'; const TempsCollection = (props) => { + const [outdoorTemp, setOutdoorTemp] = useState(null); + + const fetchData = async () => { + try { + const response = await fetch('http://api.weatherapi.com/v1/current.json?key=6cfca6888bde479cb6b63543231504&q=35235&aqi=no'); + + if (!response.ok) { + throw new Error('Network response was not ok'); + } + + const temp = await response.json(); + setOutdoorTemp(temp.current.temp_f); + } catch (error) { + console.error('There was a problem with the fetch operation:', error); + } + }; + + useEffect(() => { + fetchData(); + }, []); + + + return ( <div id="tempsCollection"> <div id="desiredTemp" className='temps'> <p className='title'>Outside</p> <p className='title'>Temperature</p> - <p className='temperatures'>81 °F</p> + <p className='temperatures'>{outdoorTemp} °F</p> </div> <div id="comfortTemp" className='temps'> - <p className='title'>Desired</p> + <p className='title'>Current</p> <p className='title'>Temperature</p> - <p className='temperatures'>81 °F</p> + <p className='temperatures'>70 °F</p> </div> <div id="outsideTemp" className='temps'> <p className='title'>Comfort</p> diff --git a/other/CS499_database2.py b/other/CS499_database2.py new file mode 100644 index 0000000000000000000000000000000000000000..b8e716fd7d187dda15b5e9f7fa00ead3adf1639a --- /dev/null +++ b/other/CS499_database2.py @@ -0,0 +1,340 @@ +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, 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, TC_ct_MAR_lrtv, TC_ct_MAR_brtv, TC_pwr_MAR_brtv, TC_pwr_MAR_lrtv, TC_shower_cost2_MAR, TC_shower_power2_MAR, TC_shower_water_usg_MAR + +# create a new database +conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432") +cur = conn.cursor() +#cur.execute("CREATE DATABASE Team3 ") +conn.close() + +# create a new table for Door_Window_History +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 Door_Window_History; + CREATE TABLE Door_Window_History ( + id SERIAL PRIMARY KEY, + day VARCHAR(255), + door_status INTEGER, + door_time FLOAT, + window_status INTEGER, + window_time FLOAT + ); + """) + +conn.commit() + +#insert the data into the Door_Window_History table +for i in Door_Window_History: + for time_stamp, data in Door_Window_History.items(): + cur.execute(""" + INSERT INTO Door_Window_History ( + day, door_status, door_time, window_status, window_time) + VALUES (%s, %s, %s, %s, %s); + """, ( + data.day, data.Door_status, data.Door_time, + data.Window_status, data.Window_time + )) +conn.commit() + +# create a new table for App1_History +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 Appliance_1_History; + CREATE TABLE Appliance_1_History ( + id SERIAL PRIMARY KEY, + day VARCHAR(255), + micro_pwr FLOAT, + stove_pwr FLOAT, + oven_pwr FLOAT, + Lrtv_pwr FLOAT, + Brtv_pwr FLOAT, + fridge_pwr FLOAT, + micro_ct FLOAT, + stove_ct FLOAT, + oven_ct FLOAT, + Lrtv_ct FLOAT, + Brtv_ct FLOAT, + fridge_ct FLOAT, + lights_pwr FLOAT, + lights_ct FLOAT + ); + """) + +for time_stamp2, data in App1_History.items(): + cur.execute(""" + INSERT INTO Appliance_1_History ( + day, micro_pwr, stove_pwr, oven_pwr, Lrtv_pwr, Brtv_pwr, fridge_pwr, + micro_ct, stove_ct, oven_ct, Lrtv_ct, Brtv_ct, fridge_ct, lights_pwr, lights_ct) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s); + """, ( + data.day, data.micro_pwr, data.stove_pwr, data.oven_pwr, data.Lrtv_pwr, data.Brtv_pwr, + data.fridge_pwr, data.micro_ct, data.stove_ct, data.oven_ct, data.Lrtv_ct, data.Brtv_ct, + data.fridge_ct, data.lights_pwr, data.lights_ct + )) +conn.commit() + + + +# create a new table for appliance_with_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 appliance_with_water; + CREATE TABLE appliance_with_water ( + id SERIAL PRIMARY KEY, + day TEXT, + water_heat_pwr FLOAT, + dishwasher_pwr FLOAT, + clothes_wash_pwr FLOAT, + clothes_dry_pwr FLOAT, + bath_fans_pwr FLOAT, + water_heat_ug FLOAT, + bath_water_ug FLOAT, + shower_water_ug FLOAT, + dishwasher_ug FLOAT, + clothes_wash_ug FLOAT, + water_heat_ct FLOAT, + dishwasher_ct FLOAT, + clothes_wash_ct FLOAT, + clothes_dry_ct FLOAT, + bath_fans_ct FLOAT, + water_ct FLOAT, + bath INT, + shower INT + ); +""") +conn.commit() + +# insert data into the App2_History table +for time_stamp3, data in App2_History.items(): + cur = conn.cursor() + cur.execute(""" + INSERT INTO appliance_with_water ( + day, water_heat_pwr, dishwasher_pwr, clothes_wash_pwr, + clothes_dry_pwr, bath_fans_pwr, water_heat_ug, bath_water_ug, + shower_water_ug, dishwasher_ug, clothes_wash_ug, water_heat_ct, + dishwasher_ct, clothes_wash_ct, clothes_dry_ct, bath_fans_ct, + water_ct, bath, shower + ) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s); + """, ( + data.day, data.Water_Heat_pwr, data.DishWasher_pwr, data.Clothes_Wash_pwr, + data.Clothes_dry_pwr, data.bath_fans_pwr, data.Water_Heat_ug, data.Bath_water_ug, + data.Shower_water_ug, data.DishWasher_ug, data.Clothes_Wash_ug, data.Water_Heat_ct, + data.DishWasher_ct, data.Clothes_Wash_ct, data.Clothes_dry_ct, data.bath_fans_ct, + data.Water_ct, data.bath, data.shower + )) + conn.commit() + +# create a new table for Temperature_data +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 Temperature_data; + CREATE TABLE Temperature_data ( + id SERIAL PRIMARY KEY, + temp_power FLOAT, + temp_cost FLOAT + ); +""") +conn.commit() + +# insert data into the App3_History Table +for time_stamp4, data in App3_History.items(): + cur = conn.cursor() + cur.execute(""" + INSERT INTO temperature_data ( + temp_power, temp_cost + ) + VALUES (%s, %s); + """, ( + data.temp_power, data.temp_cost + )) + 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() + + +###################################################################################################################################### +###################################################################################################################################### +############################################ TEMPERATURE DATA TABLE WATTS & COST BY MONTH ############################################ + +# 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 ('Temperature Data (January):', %s, %s), + ('Temperature Data (February):', %s, %s), + ('Temperature Data (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() + +# create a new table for power_testcases +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 power_testcases; + CREATE TABLE power_testcases ( + id SERIAL PRIMARY KEY, + test_case TEXT, + test_case_pwr FLOAT, + test_case_cost FLOAT + ) +""") +conn.commit() + +# Insert the two test case for living room TV & bedroom tv power and cost values into the table +cur.execute(""" + INSERT INTO power_testcases (test_case, test_case_pwr, test_case_cost) + VALUES ('Test case 1 (Living Room TV):', %s, %s), + ('Test case 2 (Bedroom TV):', %s, %s) +""", (TC_pwr_MAR_lrtv, TC_ct_MAR_lrtv, + TC_pwr_MAR_brtv, TC_ct_MAR_brtv)) + +# Commit the changes +conn.commit() + + + +##################################################################################################################### +##################################################################################################################### +############################################ WATER TEST CASE SHOWER CODE ############################################ + +# create a new table for water_testcase +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 water_testcase; + CREATE TABLE water_testcase ( + id SERIAL PRIMARY KEY, + test_case TEXT, + test_case_pwr FLOAT, + test_case_cost FLOAT, + test_case_usg FLOAT + ) +""") +conn.commit() + +# Insert a test case for shower and display power, cost, and water used into the table +cur.execute(""" + INSERT INTO water_testcase (test_case, test_case_pwr, test_case_cost, test_case_usg) + VALUES ('Test case (Shower):', %s, %s, %s) +""", (TC_shower_power2_MAR, TC_shower_cost2_MAR, TC_shower_water_usg_MAR)) + +# Commit the changes +conn.commit() + +##################################################################################################################### +##################################################################################################################### +##################################################################################################################### + + +# Commit changes +#conn.commit() +cur.close() +conn.close() diff --git a/CS_499_Webframe.fig b/other/CS_499_Webframe.fig similarity index 100% rename from CS_499_Webframe.fig rename to other/CS_499_Webframe.fig diff --git a/CS_499_database.py b/other/CS_499_database.py similarity index 100% rename from CS_499_database.py rename to other/CS_499_database.py diff --git a/Pseudo_Code_CS_499__2_.docx b/other/Pseudo_Code_CS_499__2_.docx similarity index 100% rename from Pseudo_Code_CS_499__2_.docx rename to other/Pseudo_Code_CS_499__2_.docx diff --git a/app.py b/other/app.py similarity index 83% rename from app.py rename to other/app.py index 6564906e622b404f2d84e0f8146ee4a1ccdcec3b..947930df1dfe9919a50db53b0c2971f4734f3ef3 100644 --- a/app.py +++ b/other/app.py @@ -1,5 +1,5 @@ from flask import Flask -from main import create_app +from backend.api import create_app app = create_app() diff --git a/erd499_finalized__1_.drawio.pdf b/other/erd499_finalized__1_.drawio.pdf similarity index 100% rename from erd499_finalized__1_.drawio.pdf rename to other/erd499_finalized__1_.drawio.pdf diff --git a/main.py b/other/main.py similarity index 100% rename from main.py rename to other/main.py diff --git a/powerData.py b/powerData.py deleted file mode 100644 index 2f044e2ebfafa59f9f6683a424407a5fab1e509e..0000000000000000000000000000000000000000 --- a/powerData.py +++ /dev/null @@ -1,12 +0,0 @@ -from flask import request, Blueprint, jsonify -import psycopg2 - -powerData_bp = Blueprint('powerData', __name__) - -@powerData_bp.route('/powerData', methods = ['GET']) -def get_powerData(): - conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432") - cur = conn.cursor() - all_powerData = cur.execute('SELECT * FROM') - - return jsonify(all_powerData) diff --git a/tempData.py b/tempData.py deleted file mode 100644 index de5bf49f1779807cffb72e0f2c4f2eb79ebe52f2..0000000000000000000000000000000000000000 --- a/tempData.py +++ /dev/null @@ -1,12 +0,0 @@ -from flask import request, Blueprint, jsonify -import psycopg2 - -tempData_bp = Blueprint('tempData', __name__) - -@tempData_bp.route('/tempData', methods = ['GET']) -def get_temperatureData(): - conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432") - cur = conn.cursor() - all_tempData = cur.execute('SELECT * FROM ') - - return jsonify(all_tempData) diff --git a/waterData.py b/waterData.py deleted file mode 100644 index d0c960ef769f0a9356857cf533c1caca19fcf9c9..0000000000000000000000000000000000000000 --- a/waterData.py +++ /dev/null @@ -1,12 +0,0 @@ -from flask import request, Blueprint, jsonify -import psycopg2 - -waterData_bp = Blueprint('waterData', __name__) - -@waterData_bp.route('/waterData', methods = ['GET']) -def get_waterData(): - conn = psycopg2.connect(database="Team3DB", user="Team3", password="team3", host="138.26.48.83", port="5432") - cur = conn.cursor() - all_waterData = cur.execute('SELECT * FROM') - - return jsonify(all_waterData) \ No newline at end of file