major update
This commit is contained in:
@@ -1,12 +1,30 @@
|
||||
from flask import jsonify
|
||||
from sqlalchemy import func, or_
|
||||
from datetime import date
|
||||
from app.stats import stats
|
||||
import datetime
|
||||
from app import db
|
||||
from app.classes.delivery import Delivery_Delivery
|
||||
from app.classes.stats_company import Stats_Company, Stats_Company_schema
|
||||
from app.classes.stats_customer import Stats_Customer, Stats_Customer_schema
|
||||
|
||||
|
||||
def get_monday_date(date_object):
|
||||
"""Gets the date of the Monday for the given date."""
|
||||
|
||||
# Get the day of the week as an integer (0 = Monday, 6 = Sunday)
|
||||
day_of_week = date_object.weekday()
|
||||
|
||||
# Calculate the number of days to subtract to get to Monday
|
||||
days_to_monday = day_of_week - 0 # Monday is 0
|
||||
|
||||
# Subtract the days from the given date to get Monday's date
|
||||
monday_date = date_object - datetime.timedelta(days=days_to_monday)
|
||||
|
||||
return monday_date
|
||||
|
||||
|
||||
|
||||
|
||||
@stats.route("/calls/add", methods=["PUT"])
|
||||
def total_calls_post():
|
||||
total_calls_today = (db.session
|
||||
@@ -149,4 +167,26 @@ def get_user_last_delivery(user_id):
|
||||
date_delivered = "no deliveries on record"
|
||||
return jsonify({"ok": True,
|
||||
'date': date_delivered,
|
||||
}), 200
|
||||
}), 200
|
||||
|
||||
|
||||
@stats.route("/gallons/week", methods=["GET"])
|
||||
def total_gallons_delivered_this_week():
|
||||
# Get today's date
|
||||
total_gallons = 0
|
||||
|
||||
today = datetime.date.today()
|
||||
|
||||
# Get the date of the Monday for today
|
||||
monday = get_monday_date(today)
|
||||
get_total = (db.session
|
||||
.query(Delivery_Delivery)
|
||||
.filter(Delivery_Delivery.when_delivered >= monday)
|
||||
.filter(Delivery_Delivery.when_delivered <= today)
|
||||
.all())
|
||||
for f in get_total:
|
||||
total_gallons = total_gallons + f.gallons_delivered
|
||||
return jsonify({"ok": True,
|
||||
'total': total_gallons,
|
||||
}), 200
|
||||
|
||||
|
||||
Reference in New Issue
Block a user