experimentation get_value for multiple variable for a feature (#566)
This commit is contained in:
@@ -8,6 +8,7 @@ LOG = structlog.get_logger()
|
|||||||
class BaseExperimentationProvider(ABC):
|
class BaseExperimentationProvider(ABC):
|
||||||
# feature_name -> distinct_id -> result
|
# feature_name -> distinct_id -> result
|
||||||
result_map: dict[str, dict[str, bool]] = {}
|
result_map: dict[str, dict[str, bool]] = {}
|
||||||
|
variant_map: dict[str, dict[str, str | None]] = {}
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def is_feature_enabled(self, feature_name: str, distinct_id: str, properties: dict | None = None) -> bool:
|
def is_feature_enabled(self, feature_name: str, distinct_id: str, properties: dict | None = None) -> bool:
|
||||||
@@ -24,7 +25,25 @@ class BaseExperimentationProvider(ABC):
|
|||||||
|
|
||||||
return self.result_map[feature_name][distinct_id]
|
return self.result_map[feature_name][distinct_id]
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_value(self, feature_name: str, distinct_id: str, properties: dict | None = None) -> str | None:
|
||||||
|
"""Get the value of a feature."""
|
||||||
|
|
||||||
|
def get_value_cached(self, feature_name: str, distinct_id: str, properties: dict | None = None) -> str | None:
|
||||||
|
"""Get the value of a feature."""
|
||||||
|
if feature_name not in self.variant_map:
|
||||||
|
self.variant_map[feature_name] = {}
|
||||||
|
if distinct_id not in self.variant_map[feature_name]:
|
||||||
|
variant = self.get_value(feature_name, distinct_id, properties)
|
||||||
|
self.variant_map[feature_name][distinct_id] = variant
|
||||||
|
if variant:
|
||||||
|
LOG.info("Feature is found", flag=feature_name, distinct_id=distinct_id)
|
||||||
|
return self.variant_map[feature_name][distinct_id]
|
||||||
|
|
||||||
|
|
||||||
class NoOpExperimentationProvider(BaseExperimentationProvider):
|
class NoOpExperimentationProvider(BaseExperimentationProvider):
|
||||||
def is_feature_enabled(self, feature_name: str, distinct_id: str, properties: dict | None = None) -> bool:
|
def is_feature_enabled(self, feature_name: str, distinct_id: str, properties: dict | None = None) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def get_value(self, feature_name: str, distinct_id: str, properties: dict | None = None) -> str | None:
|
||||||
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user