This commit is contained in:
alexjanousekGSA
2025-01-29 12:59:20 -05:00
parent c7e7ab9a60
commit 8e883ab0ba
2 changed files with 21 additions and 7 deletions

View File

@@ -1,6 +1,5 @@
import uuid
from datetime import timedelta
import pytz
from flask import current_app
from sqlalchemy import Float, cast, delete, select
@@ -746,10 +745,14 @@ def get_specific_days_stats(data, start_date, days=None, end_date=None):
raise ValueError("Either days or end_date must be set.")
for item in data:
print(f"DEBUG12345 - Timestamp Check: {item.timestamp.isoformat()} {item.status.value})")
print(
f"DEBUG12345 - Timestamp Check: {item.timestamp.isoformat()} {item.status.value})"
)
grouped_data = {date: [] for date in gen_range} | {
timestamp.date(): [row for row in data if row.timestamp.date() == timestamp.date()]
timestamp.date(): [
row for row in data if row.timestamp.date() == timestamp.date()
]
for timestamp in {item.timestamp for item in data}
}

View File

@@ -231,6 +231,7 @@ def convert_local_to_utc(local_dt, user_timezone="America/New_York"):
localized_dt = local_tz.localize(local_dt)
return localized_dt.astimezone(pytz.utc)
def get_service_statistics_for_specific_days(service_id, start, days=7):
print(f"DEBUG - Received start: {start}, days: {days}")
@@ -238,16 +239,26 @@ def get_service_statistics_for_specific_days(service_id, start, days=7):
local_end_date = datetime.strptime(start, "%Y-%m-%d")
local_start_date = local_end_date - timedelta(days=days - 1)
utc_start_date = convert_local_to_utc(local_start_date.replace(hour=0, minute=0, second=0), user_timezone)
utc_end_date = convert_local_to_utc(local_end_date.replace(hour=23, minute=59, second=59), user_timezone)
utc_start_date = convert_local_to_utc(
local_start_date.replace(hour=0, minute=0, second=0), user_timezone
)
utc_end_date = convert_local_to_utc(
local_end_date.replace(hour=23, minute=59, second=59), user_timezone
)
now_local = datetime.utcnow().replace(tzinfo=pytz.utc).astimezone(pytz.timezone(user_timezone))
now_local = (
datetime.utcnow()
.replace(tzinfo=pytz.utc)
.astimezone(pytz.timezone(user_timezone))
)
if now_local.hour >= 19:
utc_end_date += timedelta(days=1)
print(f"DEBUG - Querying db from {utc_start_date} UTC to {utc_end_date} UTC")
results = dao_fetch_stats_for_service_from_days(service_id, utc_start_date, utc_end_date)
results = dao_fetch_stats_for_service_from_days(
service_id, utc_start_date, utc_end_date
)
stats = get_specific_days_stats(results, utc_start_date, days=days)