Skip to content

Commit

Permalink
improved syntax, removed MockAssignmentFilter (used for testing)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Yiu authored and Tim Yiu committed Jul 31, 2023
1 parent efe2536 commit b202baf
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/amplitude_experiment/assignment/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def __init__(self, user: User, results: Dict[str, FlagResult]):
def canonicalize(self) -> str:
user = self.user.user_id.strip() if self.user.user_id else 'undefined'
device = self.user.device_id.strip() if self.user.device_id else 'undefined'
sb = user + ' ' + device + ' '
canonical = user + ' ' + device + ' '
for key in sorted(self.results):
value = self.results[key].value.strip() if self.results[key] else 'undefined'
sb += key.strip() + ' ' + value + ' '
return sb
canonical += key.strip() + ' ' + value + ' '
return canonical
3 changes: 2 additions & 1 deletion src/amplitude_experiment/assignment/assignment_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


class AssignmentConfig(amplitude.Config):
def __init__(self, filter_capacity: int = 65536, **kw):
def __init__(self, api_key: str, filter_capacity: int = 65536, **kw):
self.api_key = api_key
self.filter_capacity = filter_capacity
super(AssignmentConfig, self).__init__(**kw)
4 changes: 2 additions & 2 deletions src/amplitude_experiment/assignment/assignment_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


class AssignmentFilter:
def __init__(self, size: int):
self.cache = Cache(size, DAY_MILLIS)
def __init__(self, size: int, ttl_millis: int = DAY_MILLIS):
self.cache = Cache(size, ttl_millis)

def should_track(self, assignment: Assignment) -> bool:
now = time.time()
Expand Down
4 changes: 2 additions & 2 deletions src/amplitude_experiment/flagresult.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class FlagResult:
def __init__(self, value: str, is_default_variant: bool, payload: str = None, expkey: str = None,
def __init__(self, value: str, is_default_variant: bool, payload: str = None, exp_key: str = None,
deployed: bool = None, type: str = None):
self.value = value
self.payload = payload
self.is_default_variant = is_default_variant
self.expkey = expkey
self.exp_key = exp_key
self.deployed = deployed
self.type = type
1 change: 0 additions & 1 deletion src/amplitude_experiment/local/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def __init__(self, api_key: str, config: LocalEvaluationConfig = None):
self.config = config or LocalEvaluationConfig()
self.assignment_service = None
if config and config.assignment_config:
print('set assignment service')
instance = Amplitude(config.assignment_config.api_key, config.assignment_config)
self.assignment_service = AssignmentService(instance, AssignmentFilter(
config.assignment_config.filter_capacity))
Expand Down
3 changes: 1 addition & 2 deletions tests/local/assignment/assignment_filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import unittest
from src.amplitude_experiment import User, FlagResult
from src.amplitude_experiment.assignment import Assignment, AssignmentFilter
from tests.local.util.mock_assignment_filter import MockAssignmentFilter


class AssignmentFilterTestCase(unittest.TestCase):
Expand Down Expand Up @@ -107,7 +106,7 @@ def test_lru_replacement(self):
self.assertTrue(assignment_filter.should_track(assignment1))

def test_lru_expiration(self):
assignment_filter = MockAssignmentFilter(100, 1000)
assignment_filter = AssignmentFilter(100, 1000)
user1 = User(user_id='user1', device_id='device')
user2 = User(user_id='user2', device_id='device')
results = {}
Expand Down
17 changes: 0 additions & 17 deletions tests/local/util/mock_assignment_filter.py

This file was deleted.

0 comments on commit b202baf

Please sign in to comment.