autos working!

This commit is contained in:
2024-11-20 18:00:33 -05:00
parent 7c9b7f8998
commit 8569430468
8 changed files with 273 additions and 276 deletions

View File

@@ -1,40 +1,13 @@
from decimal import Decimal
from datetime import datetime
from database import session
from app.models.auto import Auto_Delivery
def update_automatic(get_delivery, gallons_delivered ):
now = datetime.utcnow()
get_auto_delivery = (session
.query(Auto_Delivery)
.filter(Auto_Delivery.customer_id == get_delivery.customer_id)
.first())
gallons_put_in_home = Decimal(gallons_delivered)
customer_home_factor = get_auto_delivery.house_factor
new_home_factor = calc_home_factor(gallons_put_in_home = gallons_put_in_home,
current_house_factor=customer_home_factor)
get_auto_delivery.house_factor = new_home_factor
get_auto_delivery.tank_height = 'Full'
get_auto_delivery.last_fill = now
get_auto_delivery.estimated_gallons_left = 240
get_auto_delivery.estimated_gallons_left_prev_day = 240
get_auto_delivery.auto_status = 0
session.add(get_auto_delivery)
def calc_home_factor(gallons_put_in_home, current_house_factor):
if 200.01 >= gallons_put_in_home >= 500:
if 200.01 <= gallons_put_in_home <= 500:
customer_home_factor = Decimal(current_house_factor) + Decimal(1)
elif 170.01 <= gallons_put_in_home <= 200:
customer_home_factor = Decimal(current_house_factor) + Decimal(1.5)