diff --git a/CS_499_backend.py b/CS_499_backend.py
index 5fd6da3f5bd29364c9c685fd444da487ccd9a2d6..e322a46fad0dc63410400575d37e14610918eb2c 100644
--- a/CS_499_backend.py
+++ b/CS_499_backend.py
@@ -1,341 +1,270 @@
-## Data base generation code by Group 3 CS 499 ##
-# Morning data,afternoon ,night data for temp
-import random
-import math
-import requests
-import json
-import numpy as np
-
-
-class Door_Window:
-
-    def __init__(self,day,Door_status,Door_time,Window_status,Window_time):
-        self.day=day
-        self.Door_status=Door_status
-        self.Door_time=Door_time
-        self.Window_status=Window_status
-        self.Window_time=Window_time
-    
-
-WORKWEEK=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
-NUM_WEEKS=11
-Door_Window_History=dict()
-
-time_stamp=0
-for i in range(0,NUM_WEEKS):
-    for j in range(0,7):
-        #door_opens = 0
-       # window_opens=0
-        if j < 5:
-            door_opens = random.randint(14,22)
-            window_open= random.randint(1,5)
-        else:
-            door_opens = random.randint(26,36)
-            window_open= random.randint(7,12)
-        door_minutes = door_opens*30/60
-        window_minutes = window_open *45/60
-        Door_Window_History[time_stamp] = Door_Window(WORKWEEK[j], door_opens, door_minutes, window_open, window_minutes)
-        time_stamp += 1
-
+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
+
+# 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:
-    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:
-
-    def __init__(self,day,micro_pwr,stove_pwr,oven_pwr,Lrtv_pwr,Brtv_pwr,fridge_pwr,lights_pwr,micro_ct,stove_ct,oven_ct,Lrtv_ct,Brtv_ct,fridge_ct,lights_ct):
-        self.day=day
-        self.micro_pwr=micro_pwr
-        self.stove_pwr=stove_pwr
-        self.oven_pwr=oven_pwr
-        self.Lrtv_pwr=Lrtv_pwr
-        self.Brtv_pwr=Brtv_pwr
-        self.fridge_pwr=fridge_pwr
-        self.micro_ct=micro_ct
-        self.stove_ct=stove_ct
-        self.oven_ct=oven_ct
-        self.Lrtv_ct=Lrtv_ct
-        self.Brtv_ct=Brtv_ct
-        self.fridge_ct=fridge_ct
-        self.lights_pwr=lights_pwr
-        self.lights_ct=lights_ct
-        
-App1_History=dict()
-time_stamp2=1
-Fridge=0
-for i in range(0,NUM_WEEKS):
-    for j in range(0,7):
-        Fridge += 1440
-        if j<5:
-            Microwave=random.randint(18,25)
-            Stove=random.randint(13,18)
-            Oven=random.randint(40,50)
-            Living_roomTV=random.randint(230,330)
-            BedroomTV=random.randint(100,190)
-            lights=random.randint(35,65)
-        else:
-            Microwave=random.randint(26,40)
-            Stove=random.randint(25,41)
-            Oven=random.randint(54,67)
-            Living_roomTV=random.randint(432,490)
-            BedroomTV=random.randint(225,277)
-            lights=random.randint(55,95)
-        
-        #Watts Ussage
-        Watts_micro=(Microwave/60)*1100
-        Watts_stove=(Stove/60)*3500
-        Watts_oven=(Oven/60)*4000/60
-        Watts_Lrtv=(Living_roomTV/60)*636
-        Watts_Brtv=(BedroomTV/60)*100
-        Watts_Fridge=(Fridge/60)*150
-        Watts_Lights=(lights*random.randint(4,8))
-        #Cost Calculations
-        Cost_micro=((Watts_micro/1000)*0.12)/100
-        Cost_stove=((Watts_stove/1000)*0.12)/100
-        Cost_oven=((Watts_oven/1000)*0.12)/100
-        Cost_Lrtv=((Watts_Lrtv/1000)*0.12)/100
-        Cost_Brtv=((Watts_Brtv/1000)*0.12)/100
-        Cost_Fridge=((Watts_Fridge/1000)*0.12)/100   
-        Cost_lights=((Watts_Lights/1000)*0.12 )/100  
-        App1_History[time_stamp2] = Appliance_1(WORKWEEK[j],Watts_micro,Watts_stove,Watts_oven,Watts_Lrtv,Watts_Brtv,Watts_Fridge,Watts_Lights,Cost_micro,Cost_stove,Cost_oven,Cost_Lrtv,Cost_Brtv,Cost_Fridge,Cost_lights)
-        time_stamp2 += 1
-
-monthly_cost1_JAN=0
-monthly_power1_JAN=0
-monthly_cost1_FEB=0
-monthly_power1_FEB=0
-monthly_cost1_MAR=0
-monthly_power1_MAR=0
-
-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
-        monthly_cost1_JAN += 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
-    if i>32 and i<=60:
-        monthly_power1_FEB += 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_FEB += 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
-    if i>61:
-        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( "################################################################################################################################################################# \n")
-
-
-
-
-class Appliance_with_Water:
-
-    def __init__(self,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):
-        self.day=day
-        self.Water_Heat_pwr=Water_Heat_pwr
-        self.DishWasher_pwr=DishWasher_pwr
-        self.Clothes_Wash_pwr=Clothes_Wash_pwr
-        self.Clothes_dry_pwr=Clothes_dry_pwr
-        self.Water_Heat_ug=Water_Heat_ug
-        self.DishWasher_ug=DishWasher_ug
-        self.Clothes_Wash_ug=Clothes_Wash_ug
-        self.Water_Heat_ct=Water_Heat_ct
-        self.DishWasher_ct=DishWasher_ct
-        self.Clothes_Wash_ct=Clothes_Wash_ct
-        self.Clothes_dry_ct=Clothes_dry_ct
-        self.bath_fans_pwr=bath_fans_pwr
-        self.bath_fans_ct=bath_fans_ct
-        self.Bath_water_ug=Bath_water_ug
-        self.Shower_water_ug=Shower_water_ug
-        self.Water_ct=Water_ct
-        self.bath=bath
-        self.shower=shower
-
-App2_History=dict()
-time_stamp3=0
-for i in range(0,NUM_WEEKS):
-    Dish_washer_run=random.randint(3,5)
-    Clths_wash_dry_run=random.randint(3,5)
-    for j in range(0,7):
-        if j<5:
-            Bath=random.randint(2,3)
-            Shower=random.randint(2,3)
-        else:
-            Bath=random.randint(3,4)
-            Shower=random.randint(3,4)
-
-        #Calaculate Total Water 
-        Bath_water=30*Bath
-        Shower_water=25*Shower
-        Clths_water=20*Clths_wash_dry_run
-        Dish_washer_water=6*Dish_washer_run
-
-        # still have to apply floor to it ## hot water
-        Bath_hot=math.ceil(Bath_water*0.65)
-        Shower_hot=math.ceil(Shower_water*0.65)
-        Clths_wash_hot=math.ceil(Clths_water*0.85)
-        # hot water heater ## use ceil round up
-        Hot_water=(Bath_hot+Shower_hot+Clths_wash_hot)
-        Hot_water_time=Hot_water*4
-
-        # Watts used
-        Hot_water_pwr=(Hot_water_time/60)*4500
-        Dish_washer_pwr=((Dish_washer_run*45)/60)*1800
-        Clothes_wash_pwr=((Clths_wash_dry_run*30)/60)*500
-        Clothes_dry_pwr=((Clths_wash_dry_run*30)/60)*3000
-        Bath_Fans_pwr=((Bath*45)/60)*30
-
-        # Cost
-        Hot_water_ct=((Hot_water_pwr/1000)*0.12)/100
-        Dish_washer_ct=((Dish_washer_pwr/1000)*0.12)/100
-        Clothes_wash_ct=((Clothes_wash_pwr/1000)*0.12)/100
-        Clothes_dry_ct=((Clothes_dry_pwr/1000)*0.12)/100
-        Bath_Fans_ct=((Bath_Fans_pwr/1000)*0.12)/100
-
-        # Water Used / Cost
-        Water_Total=Bath_water+Shower_water+Clths_water+Dish_washer_water
-        Water_Feet=Water_Total/7.48
-        Water_cost=Water_Feet*(2.52/100)
-        #Water_Heat_pwr,DishWasher_pwr,Clothes_Wash_pwr,Clothes_dry_pwr,bath_fan_pwr,Water_Heat_ug,DishWasher_ug,Clothes_Wash_ug,Water_Heat_ct,DishWasher_ct,Clothes_Wash_ct,Clothes_dry_ct,bath_fan_ct,bath,shower
-        App2_History[time_stamp3] = Appliance_with_Water(WORKWEEK[j],Hot_water_pwr,Dish_washer_pwr,Clothes_wash_pwr,Clothes_dry_pwr,Bath_Fans_pwr,Hot_water,Bath_water,Shower_water,Dish_washer_water,Clths_water,Hot_water_ct,Dish_washer_ct,Clothes_wash_ct,Clothes_dry_ct,Bath_Fans_ct,Water_cost,Bath,Shower)
-        time_stamp3+=1
-
-monthly_cost2_JAN=0
-monthly_power2_JAN=0
-monthly_water_usg_JAN=0
-monthly_cost2_FEB=0
-monthly_power2_FEB=0
-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")
-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
-        monthly_power2_JAN+= 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_JAN+= App2_History[i].Bath_water_ug + App2_History[i].Shower_water_ug + App2_History[i].DishWasher_ug+ App2_History[i].Clothes_Wash_ug
-    if i>32 and i<=60:
-        monthly_cost2_FEB+= 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
-        monthly_power2_FEB+= 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_FEB+= App2_History[i].Bath_water_ug + App2_History[i].Shower_water_ug + App2_History[i].DishWasher_ug+ App2_History[i].Clothes_Wash_ug
-    if i>61:
-        monthly_cost2_MAR+= 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
-        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 APP1 watts used : ",monthly_power2_JAN )
-print( "FEB APP1 watts used : ",monthly_power2_FEB )
-print( "MAR APP1 watts used : ",monthly_power2_MAR )
-print( "_ - _ - _ - _  Cost used for each Month  _ - _ - _ - _ \n")
-print( "Jan APP1 cost used : ",monthly_cost2_JAN )
-print( "FEB APP1 cost used : ",monthly_cost2_FEB )
-print( "MAR APP1 cost used : ",monthly_cost2_MAR )
-print( "_ - _ - _ - _  Gallons used for each Month  _ - _ - _ - _ \n")
-print( "Jan APP1 water used : ",monthly_water_usg_JAN )
-print( "FEB APP1 water used : ",monthly_water_usg_FEB )
-print( "MAR APP1 water used : ",monthly_water_usg_MAR )
-#print( "################################################################################################################################################################# \n")
-
-
-# weather api to get temp from history
-# Used this to help me understand and gather API.data: https://pypi.org/project/requests/ and https://realpython.com/api-integration-in-python/
-class Temperature_data:
-    def __init__(self,temp_power,temp_cost):
-        self.temp_power=temp_power
-        self.temp_cost=temp_cost
-
-
-
-response_API = requests.get("https://archive-api.open-meteo.com/v1/archive?latitude=33.52&longitude=-86.80&start_date=2023-01-01&end_date=2023-03-12&hourly=temperature_2m&timezone=America%2FChicago&temperature_unit=fahrenheit")
-data = response_API.text
-parse_temp=json.loads(data)
-hourly_pull = parse_temp['hourly']
-dict_pull=hourly_pull["temperature_2m"]
-
-
-
-App3_History=dict()
-time_stamp4=0
-daily_arr=np.array_split(dict_pull,77)
-
-
-
-for i in range(0,len(daily_arr)):
-    daily_arr[i]
-    d_t=Door_Window_History[i].Door_time
-    w_t=Door_Window_History[i].Window_time
-    diff_inc = 0
-    diff_dec = 0        
-    for j in range(0,len(daily_arr[i])-1):
-        num_nxt=daily_arr[i][j+1]
-        num=daily_arr[i][j]
-        if num > num_nxt :
-            diff_inc= num - num_nxt
-        if num < num_nxt :
-            diff_dec= num_nxt - num
-    # print(diff_inc)
-    # print(diff_dec)
-    sum=(diff_inc+diff_dec)*random.randint(2,17)
-    #Total number of minutes ac runs
-    min_op=sum*60+(d_t+w_t)
-    watts_per_day=(min_op)*3500
-    ct_per_day=((watts_per_day/1000)*0.12)/100
-    App3_History[time_stamp4]=Temperature_data(watts_per_day,ct_per_day)
-    time_stamp4+=1
-    #print(ct_per_day)
-    #print(watts_per_day)
-    # print("what i is",i)
-    # print("timestamp",i)
-
-
-
-monthly_temp_ct_JAN=0
-monthly_temp_watts_JAN=0
-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")
-for i in App3_History:
-    if i<=31:
-        monthly_temp_watts_JAN+=App3_History[i].temp_power
-        monthly_temp_ct_JAN+=App3_History[i].temp_cost
-    if i>31 and i<=59:
-        monthly_temp_watts_FEB+=App3_History[i].temp_power
-        monthly_temp_ct_FEB+=App3_History[i].temp_cost
-    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 APP1 watts used : ",monthly_temp_watts_JAN )
-print( "FEB APP1 watts used : ",monthly_temp_watts_FEB )
-print( "MAR APP1 watts used : ",monthly_temp_watts_MAR )
-print( "_ - _ - _ - _  Cost used for each Month  _ - _ - _ - _ \n")
-print( "Jan APP1 cost used : ",monthly_temp_ct_JAN )
-print( "FEB APP1 cost used : ",monthly_temp_ct_FEB )
-print( "MAR APP1 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)
-
-
-
-
-
-
-
-
-
-
-
-        
-
+    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()
+
+# # 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()
+conn.close()
\ No newline at end of file