Skip to content

Commit

Permalink
Merge pull request #40 from TogetherCrew/fix/39-memberactivities-date…
Browse files Browse the repository at this point in the history
…-comparison

chore: update version to 1.4.15 and add timezone support in date hand…
  • Loading branch information
amindadgar authored Jan 20, 2025
2 parents af8bc93 + 4ccd1ff commit f670234
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="tc-analyzer-lib",
version="1.4.14",
version="1.4.15",
author="Mohammad Amin Dadgar, TogetherCrew",
maintainer="Mohammad Amin Dadgar",
maintainer_email="[email protected]",
Expand Down
9 changes: 3 additions & 6 deletions tc_analyzer_lib/algorithms/member_activity_history.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# checking the past history of member activities

from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

from tc_analyzer_lib.algorithms.utils.member_activity_history_utils import (
MemberActivityPastUtils,
Expand Down Expand Up @@ -106,11 +106,8 @@ def check_past_history(
# db_analysis_start_date = None
db_analysis_end_date = None

# # the input date_range in format of datetime
# # converting the dates into datetime format
# date_format = "%y/%m/%d"
# date_range_start = datetime.datetime.strptime(date_range[0], date_format)
# date_range_end = datetime.datetime.strptime(date_range[1], date_format)
if db_analysis_end_date:
db_analysis_end_date = db_analysis_end_date.replace(tzinfo=timezone.utc)

new_date_range: list[datetime]
# if for the requested date_range, its results were available in db
Expand Down
11 changes: 8 additions & 3 deletions tc_analyzer_lib/metrics/analyzer_memberactivities.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

from tc_analyzer_lib.algorithms.compute_member_activity import compute_member_activity
from tc_analyzer_lib.metrics.memberactivity_utils import MemberActivityUtils
Expand Down Expand Up @@ -73,7 +73,9 @@ def analysis_member_activity(
return (None, None)

# get date range to be analyzed
today = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
today = datetime.now().replace(
hour=0, minute=0, second=0, microsecond=0, tzinfo=timezone.utc
)

logging.info(f"{guild_msg} memberactivities Analysis started!")

Expand All @@ -87,7 +89,7 @@ def analysis_member_activity(
load_past_data = load_past_data and not from_start

first_date = self.analyzer_period.replace(
hour=0, minute=0, second=0, microsecond=0
hour=0, minute=0, second=0, microsecond=0, tzinfo=timezone.utc
)
if first_date is None:
logging.error(
Expand Down Expand Up @@ -136,6 +138,9 @@ def analysis_member_activity(
if not from_start:
# first date of storing the data
first_storing_date = member_activity_c.get_last_date()
if first_storing_date:
first_storing_date = first_storing_date.replace(tzinfo=timezone.utc)

activities = self.utils.refine_memberactivities_data(
activities, first_storing_date
)
Expand Down
3 changes: 2 additions & 1 deletion tc_analyzer_lib/models/MemberActivityModel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import logging
from datetime import datetime

import pymongo
from tc_analyzer_lib.models.BaseModel import BaseModel
Expand All @@ -12,7 +13,7 @@ def __init__(self, database=None):
raise Exception("Database should not be None")
super().__init__(collection_name="memberactivities", database=database)

def get_last_date(self):
def get_last_date(self) -> datetime | None:
"""
Gets the date of the last document
"""
Expand Down
6 changes: 3 additions & 3 deletions tc_analyzer_lib/tc_analyzer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from datetime import datetime
from datetime import datetime, timezone

from tc_analyzer_lib.metrics.analyzer_memberactivities import MemberActivities
from tc_analyzer_lib.metrics.heatmaps import Heatmaps
Expand Down Expand Up @@ -105,7 +105,7 @@ async def run_once(self):
action_config=self.action,
window_config=self.window,
analyzer_config=self.analyzer_config,
analyzer_period=self.period,
analyzer_period=self.period.replace(tzinfo=timezone.utc),
)
(
member_activities_data,
Expand Down Expand Up @@ -190,7 +190,7 @@ async def recompute(self):
action_config=self.action,
window_config=self.window,
analyzer_config=self.analyzer_config,
analyzer_period=self.period,
analyzer_period=self.period.replace(tzinfo=timezone.utc),
)
(
member_activities_data,
Expand Down

0 comments on commit f670234

Please sign in to comment.