From 82494de1138aed45ef8fc91719b4a1e9f454175d Mon Sep 17 00:00:00 2001 From: d-robinson Date: Fri, 15 Nov 2024 11:25:01 +0100 Subject: [PATCH 1/2] Add support for publishing historical achievements --- sdk/context.py | 4 ++-- test/test_context.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/sdk/context.py b/sdk/context.py index 79599ab..5555a82 100644 --- a/sdk/context.py +++ b/sdk/context.py @@ -452,11 +452,11 @@ def publish_async(self): self.check_not_closed() return self.flush() - def track(self, goal_name: str, properties: dict): + def track(self, goal_name: str, properties: dict, achieved_at: int = None): self.check_not_closed() achievement = GoalAchievement() - achievement.achievedAt = self.clock.millis() + achievement.achievedAt = achieved_at or self.clock.millis() achievement.name = goal_name if properties is None: achievement.properties = None diff --git a/test/test_context.py b/test/test_context.py index 84017a3..3016c13 100644 --- a/test/test_context.py +++ b/test/test_context.py @@ -1135,3 +1135,20 @@ def test_assignment_with_historical_exposed_at_timestamp(self): exposure = context.exposures[0] self.assertEqual(1713218400000, exposure.exposedAt) context.close() + + def test_achievement_with_historical_achieved_at_timestamp(self): + self.set_up() + config = ContextConfig() + config.units = self.units + context = self.create_test_context(config, self.data_future_ready) + self.assertEqual(True, context.is_ready()) + self.assertEqual(False, context.is_failed()) + + context.track( + "goal_test_historical_timestamp", + properties = {}, + achieved_at = 1713218400000 + ) + achievement = context.achievements[0] + self.assertEqual(1713218400000, achievement.achievedAt) + context.close() From 5b39ae93c529250e65c868b0c305fcc8c568f6fb Mon Sep 17 00:00:00 2001 From: d-robinson Date: Fri, 15 Nov 2024 11:25:30 +0100 Subject: [PATCH 2/2] Update version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 67123bb..113c55a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "ABSmartly" -version = "0.2.3" +version = "0.2.4" description = "ABSmartly Python SDK lib" readme = "README.md" authors = [{ name = "ABSmartly", email = "info@ABSmartly.com" }]