-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
937 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
from .libevaluation_interop import libevaluation_interop_symbols | ||
from ctypes import cast, c_char_p | ||
|
||
def evaluate(rules: str, user: str) -> str: | ||
|
||
def evaluate(rules: str, context: str) -> str: | ||
""" | ||
Local evaluation wrapper. | ||
Parameters: | ||
rules (str): rules JSON string | ||
user (str): user JSON string | ||
context (str): context JSON string | ||
Returns: | ||
Evaluation results with variants in JSON | ||
""" | ||
result = libevaluation_interop_symbols().contents.kotlin.root.evaluate(rules, user) | ||
result = libevaluation_interop_symbols().contents.kotlin.root.evaluate(rules, context) | ||
py_result = cast(result, c_char_p).value | ||
libevaluation_interop_symbols().contents.DisposeString(result) | ||
return str(py_result, 'utf-8') |
Binary file modified
BIN
-291 KB
(91%)
src/amplitude_experiment/local/evaluation/lib/linuxArm64/libevaluation_interop.so
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-361 KB
(89%)
src/amplitude_experiment/local/evaluation/lib/linuxX64/libevaluation_interop.so
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-295 KB
(89%)
src/amplitude_experiment/local/evaluation/lib/macosArm64/libevaluation_interop.dylib
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-436 KB
(84%)
src/amplitude_experiment/local/evaluation/lib/macosX64/libevaluation_interop.dylib
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from typing import Dict, Set, Any, List, Optional | ||
|
||
|
||
class CycleException(Exception): | ||
""" | ||
Raised when topological sorting encounters a cycle between flag dependencies. | ||
""" | ||
|
||
def __init__(self, path: Set[str]): | ||
self.path = path | ||
|
||
def __str__(self): | ||
return f"Detected a cycle between flags {self.path}" | ||
|
||
|
||
def topological_sort( | ||
flags: Dict[str, Dict[str, Any]], | ||
keys: List[str] = None, | ||
ordered: bool = False | ||
) -> List[Dict[str, Any]]: | ||
available = flags.copy() | ||
result = [] | ||
starting_keys = keys if keys is not None and len(keys) > 0 else list(flags.keys()) | ||
# Used for testing to ensure consistency. | ||
if ordered and (keys is None or len(keys) == 0): | ||
starting_keys.sort() | ||
for flag_key in starting_keys: | ||
traversal = __parent_traversal(flag_key, available, set()) | ||
if traversal is not None: | ||
result.extend(traversal) | ||
return result | ||
|
||
|
||
def __parent_traversal( | ||
flag_key: str, | ||
available: Dict[str, Dict[str, Any]], | ||
path: Set[str] | ||
) -> Optional[List[Dict[str, Any]]]: | ||
flag = available.get(flag_key) | ||
if flag is None: | ||
return None | ||
dependencies = flag.get('dependencies') | ||
if dependencies is None or len(dependencies) == 0: | ||
available.pop(flag_key) | ||
return [flag] | ||
path.add(flag_key) | ||
result = [] | ||
for parent_key in dependencies: | ||
if parent_key in path: | ||
raise CycleException(path) | ||
traversal = __parent_traversal(parent_key, available, path) | ||
if traversal is not None: | ||
result.extend(traversal) | ||
result.append(flag) | ||
path.remove(flag_key) | ||
available.pop(flag_key) | ||
return result |
Oops, something went wrong.