-
Notifications
You must be signed in to change notification settings - Fork 28
feat(ForcedDecisions): add forced-decisions APIs to OptimizelyUserContext #287
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
Changes from 14 commits
0d57a23
f5c9354
83ac8e2
062773b
6a69d5e
8d24927
a7953de
31241ed
9a9826e
a0893b1
eb77199
121993b
14914c7
bb221a5
c3647ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,7 @@ class DatafileProjectConfig < ProjectConfig | |
| attr_reader :variation_key_map | ||
| attr_reader :variation_id_map_by_experiment_id | ||
| attr_reader :variation_key_map_by_experiment_id | ||
| attr_reader :flag_variation_map | ||
|
|
||
| def initialize(datafile, logger, error_handler) | ||
| # ProjectConfig init method to fetch and set project config data | ||
|
|
@@ -123,6 +124,8 @@ def initialize(datafile, logger, error_handler) | |
| @variation_key_map_by_experiment_id = {} | ||
| @variation_id_to_variable_usage_map = {} | ||
| @variation_id_to_experiment_map = {} | ||
| @flag_variation_map = {} | ||
|
|
||
| @experiment_id_map.each_value do |exp| | ||
| # Excludes experiments from rollouts | ||
| variations = exp.fetch('variations') | ||
|
|
@@ -138,6 +141,17 @@ def initialize(datafile, logger, error_handler) | |
| exps = rollout.fetch('experiments') | ||
| @rollout_experiment_id_map = @rollout_experiment_id_map.merge(generate_key_map(exps, 'id')) | ||
| end | ||
|
|
||
| @feature_flags.each do |flag| | ||
| variations = [] | ||
| get_rules_for_flag(flag).each do |rule| | ||
| rule['variations'].each do |rule_variation| | ||
| variations.push(rule_variation) if variations.select { |variation| variation['id'] == rule_variation['id'] } | ||
|
||
| end | ||
| end | ||
| @flag_variation_map[flag['key']] = variations | ||
| end | ||
|
|
||
| @all_experiments = @experiment_id_map.merge(@rollout_experiment_id_map) | ||
| @all_experiments.each do |id, exp| | ||
| variations = exp.fetch('variations') | ||
|
|
@@ -165,6 +179,24 @@ def initialize(datafile, logger, error_handler) | |
| end | ||
| end | ||
|
|
||
| def get_rules_for_flag(feature_flag) | ||
| # Retrieves rules for a given feature flag | ||
| # | ||
| # feature_flag - String key representing the feature_flag | ||
| # | ||
| # Returns rules in feature flag | ||
| rules = feature_flag['experimentIds'].map { |exp_id| @experiment_id_map[exp_id] } | ||
| rollout = feature_flag['rolloutId'].empty? ? nil : @rollout_id_map[feature_flag['rolloutId']] | ||
|
|
||
| if rollout | ||
| rollout_experiments = rollout.fetch('experiments') | ||
| rollout_experiments.each do |exp| | ||
| rules.push(exp) | ||
| end | ||
| end | ||
| rules | ||
| end | ||
|
|
||
| def self.create(datafile, logger, error_handler, skip_json_validation) | ||
| # Looks up and sets datafile and config based on response body. | ||
| # | ||
|
|
@@ -279,6 +311,13 @@ def get_audience_from_id(audience_id) | |
| nil | ||
| end | ||
|
|
||
| def get_variation_from_flag(flag_key, variation_key) | ||
| variations = @flag_variation_map[flag_key] | ||
| return variations.select { |variation| variation['key'] == variation_key }.first if variations | ||
|
|
||
| nil | ||
| end | ||
|
|
||
| def get_variation_from_id(experiment_key, variation_id) | ||
| # Get variation given experiment key and variation ID | ||
| # | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why there is a comma?
decision,