Skip to content

Commit

Permalink
use timezone.now() instead of datetime.now()
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Feb 5, 2024
1 parent f546602 commit 2be2378
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions recipes/VideoBotsStats.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.utils import timezone

from daras_ai_v2.base import BasePage, MenuTabs
import gooey_ui as st
from furl import furl
Expand Down Expand Up @@ -287,9 +289,9 @@ def render(self):
def render_date_view_inputs(self, bi):
if st.checkbox("Show All"):
start_date = bi.created_at
end_date = datetime.now()
end_date = timezone.now()
else:
start_of_year_date = datetime.now().replace(month=1, day=1)
start_of_year_date = timezone.now().replace(month=1, day=1)
st.session_state.setdefault(
"start_date",
self.request.query_params.get(
Expand All @@ -302,11 +304,11 @@ def render_date_view_inputs(self, bi):
st.session_state.setdefault(
"end_date",
self.request.query_params.get(
"end_date", datetime.now().strftime("%Y-%m-%d")
"end_date", timezone.now().strftime("%Y-%m-%d")
),
)
end_date: datetime = (
st.date_input("End date", key="end_date") or datetime.now()
st.date_input("End date", key="end_date") or timezone.now()
)
st.session_state.setdefault(
"view", self.request.query_params.get("view", "Weekly")
Expand Down Expand Up @@ -359,7 +361,7 @@ def calculate_overall_stats(self, bid, bi, run_title, run_url):
num_active_users_last_7_days = (
user_messages.filter(
conversation__in=users,
created_at__gte=datetime.now() - timedelta(days=7),
created_at__gte=timezone.now() - timedelta(days=7),
)
.distinct(
*ID_COLUMNS,
Expand All @@ -369,7 +371,7 @@ def calculate_overall_stats(self, bid, bi, run_title, run_url):
num_active_users_last_30_days = (
user_messages.filter(
conversation__in=users,
created_at__gte=datetime.now() - timedelta(days=30),
created_at__gte=timezone.now() - timedelta(days=30),
)
.distinct(
*ID_COLUMNS,
Expand Down Expand Up @@ -544,7 +546,9 @@ def calculate_stats_binned_by_time(
) * 100
df["Msgs_per_convo"] = df["Messages_Sent"] / df["Convos"]
df["Msgs_per_user"] = df["Messages_Sent"] / df["Senders"]
df["Average_response_time"] = df["Average_response_time"] * factor
df["Average_response_time"] = (
df["Average_response_time"].dt.total_seconds() * factor
)
df.fillna(0, inplace=True)
df = df.round(0).astype("int32", errors="ignore")
return df
Expand Down

0 comments on commit 2be2378

Please sign in to comment.