-
Notifications
You must be signed in to change notification settings - Fork 6
feat: evaluation v2 #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
583d215
feat: evaluation v2
bgiori c7daaa9
fix: assigment service and tests
bgiori 1a4b2e0
fix: test imports
bgiori 840b691
skip benchmark tests
bgiori 8f1e0f1
fix: user to context; add tests
bgiori fdefa7f
update method comment
bgiori 7f9008d
rename file
bgiori 3bf1204
add mains
bgiori c7af8b1
fix import
bgiori 03e3601
better comment for evaluate
bgiori 2d8df4f
fix: support non-string values
bgiori 857767c
fix: build
bgiori 1f4af5f
fix: tests
bgiori File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.