This commit is contained in:
2024-07-16 10:30:09 -04:00
parent 853529b871
commit 007dca7bfb
2 changed files with 64 additions and 38 deletions

View File

@@ -1,10 +1,32 @@
from sqlalchemy import Column, Integer,\ from sqlalchemy import (Column, Integer,
DECIMAL, Text,\ DECIMAL, Text,
VARCHAR, TIMESTAMP, Date, INTEGER VARCHAR, TIMESTAMP, Date, INTEGER)
from datetime import datetime, timezone from datetime import datetime, timezone
from database import Base from database import Base
# class Auto_Customer(Base):
# __tablename__ = 'auto_customer'
# id = Column(Integer,
# primary_key=True,
# autoincrement=True,
# unique=False)
# customer_id = Column(INTEGER())
# customer_full_name = Column(VARCHAR(250))
# last_fill = Column(TIMESTAMP(), default=datetime.utcnow())
# last_updated = Column(TIMESTAMP(), default=datetime.utcnow())
# estimated_gallons_left = Column(INTEGER)
# estimated_gallons_left_prev_day = Column(INTEGER)
# tank_height = Column(VARCHAR(25))
# tank_size = Column(VARCHAR(25))
# house_factor = Column(DECIMAL(5, 2))
class Auto_Temp(Base): class Auto_Temp(Base):
__tablename__ = 'auto_temp' __tablename__ = 'auto_temp'
@@ -14,10 +36,10 @@ class Auto_Temp(Base):
unique=False) unique=False)
todays_date = Column(TIMESTAMP(), default=datetime.utcnow()) todays_date = Column(TIMESTAMP(), default=datetime.utcnow())
temp = Column(DECIMAL(50, 2)) temp = Column(DECIMAL(5, 2))
temp_max = Column(DECIMAL(50, 2)) temp_max = Column(DECIMAL(5, 2))
temp_min = Column(DECIMAL(50, 2)) temp_min = Column(DECIMAL(5, 2))
temp_avg = Column(DECIMAL(50, 2)) temp_avg = Column(DECIMAL(5, 2))
degree_day = Column(INTEGER()) degree_day = Column(INTEGER())

View File

@@ -14,11 +14,8 @@ router = APIRouter(
def Average(lst):
return sum(lst) / len(lst)
@router.route("/update", methods=["GET"]) @router.route("/update", methods=["GET"])
def update_auto(): def update_auto_customers():
today_temp = session\ today_temp = session\
@@ -33,8 +30,34 @@ def update_auto():
.limit(25) .limit(25)
for f in auto_customers: for f in auto_customers:
pass
# figure out how much temperature effects oil
if today_temp >= 60:
use_day = 1
elif 40 >= today_temp >= 59:
use_day = 3
elif 30 >= today_temp >= 39:
use_day = 5
elif 0 >= today_temp >= 29:
use_day = 7
elif -20 >= today_temp >= -1:
use_day = 10
else:
use_day = 0
# times temp factory by house factor
gallon_use_today = f.house_factor * use_day
# get estimated gallons left
get_gallons_left = f.estimated_gallons_left_prev_day - gallon_use_today
# get previous day gallons left
f.estimated_gallons_left_prev_day = f.estimated_gallons_left + gallon_use_today
f.estimated_gallons_left = get_gallons_left
session.add(f)
session.commit()
return ({"ok": True}), 200 return ({"ok": True}), 200
@@ -52,13 +75,13 @@ def update_temp():
observation = mgr.weather_at_place('Worcester, US') observation = mgr.weather_at_place('Worcester, US')
w = observation.weather w = observation.weather
temp_dict_kelvin = w.temperature() # a dict in Kelvin units (default when no temperature units provided) temp_dict_fahrenheit = w.temperature() # a dict in Kelvin units (default when no temperature units provided)
temp_dict_kelvin['temp_min'] temp_dict_fahrenheit['temp_min']
temp_dict_kelvin['temp_max'] temp_dict_fahrenheit['temp_max']
temp_dict_fahrenheit = w.temperature('fahrenheit') temp_dict_fahrenheit = w.temperature('fahrenheit')
low_temp = temp_dict_kelvin['temp_min'] low_temp = temp_dict_fahrenheit['temp_min']
high_temp = temp_dict_kelvin['temp_max'] high_temp = temp_dict_fahrenheit['temp_max']
temps.append(temp_dict_fahrenheit['temp_max']) temps.append(temp_dict_fahrenheit['temp_max'])
temps.append(temp_dict_fahrenheit['temp_min']) temps.append(temp_dict_fahrenheit['temp_min'])
@@ -66,7 +89,6 @@ def update_temp():
rounded_temp = round(get_avg) rounded_temp = round(get_avg)
dday = (65 - ((low_temp + high_temp) /2)) dday = (65 - ((low_temp + high_temp) /2))
add_new_temp = Auto_Temp( add_new_temp = Auto_Temp(
temp = temp_dict_fahrenheit['temp'], temp = temp_dict_fahrenheit['temp'],
@@ -83,25 +105,7 @@ def update_temp():
return ({"ok": True}), 200 return ({"ok": True}), 200
@router.get("/today") def Average(lst):
def auto_today(): return sum(lst) / len(lst)
today_auto = session.query().filter().first()
return ({"ok": True}), 200
@router.get("/week")
def auto_this_week():
print("here")
return ({"ok": True}), 200
@router.get("/all")
def all_auto():
return ({"ok": True}), 200
@router.get("/completed")
def completed_auto():
return ({"ok": True}), 200