wingify-fme-python-sdk 1.70.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tests/data/__init__.py +13 -0
- tests/data/dummy_test_data_reader.py +63 -0
- tests/data/user_storage.py +48 -0
- tests/e2e/__init__.py +13 -0
- tests/e2e/custom_bucketing_test.py +514 -0
- tests/e2e/force_users_test.py +368 -0
- tests/e2e/get_flag_test.py +195 -0
- tests/unit/__init__.py +13 -0
- tests/unit/packages/__init__.py +13 -0
- tests/unit/packages/decision_maker/__init__.py +13 -0
- tests/unit/packages/decision_maker/decision_maker_test.py +83 -0
- tests/unit/packages/segmentation_evaluator/__init__.py +13 -0
- tests/unit/packages/segmentation_evaluator/segmentation_evaluator_test.py +284 -0
- tests/unit/packages/segmentation_evaluator/segmentation_manager_test.py +215 -0
- tests/unit/packages/segmentation_evaluator/web_testing_segment_test.py +216 -0
- tests/unit/services/__init__.py +0 -0
- tests/unit/services/hooks_manager_test.py +80 -0
- tests/unit/services/internal_events_sampling_service_test.py +160 -0
- tests/unit/settings/__init__.py +13 -0
- tests/unit/settings/settings_schema_validation_test.py +67 -0
- tests/unit/utils/__init__.py +0 -0
- tests/unit/utils/campaign_util_test.py +248 -0
- tests/unit/utils/decision_util_force_users_test.py +790 -0
- tests/unit/utils/log_message_test.py +65 -0
- tests/unit/vwo_wingify_test.py +175 -0
- tests/unit/wingify_client_validation_test.py +72 -0
- vwo/__init__.py +35 -0
- vwo/models/__init__.py +13 -0
- vwo/models/batch_event_data.py +19 -0
- vwo/models/user/__init__.py +13 -0
- vwo/models/user/context_vwo_model.py +21 -0
- vwo/models/user/get_flag.py +19 -0
- vwo/models/vwo_options_model.py +21 -0
- vwo/packages/__init__.py +13 -0
- vwo/packages/logger/__init__.py +13 -0
- vwo/packages/logger/enums/__init__.py +13 -0
- vwo/packages/logger/enums/log_level_enum.py +19 -0
- vwo/packages/storage/__init__.py +13 -0
- vwo/packages/storage/connector.py +19 -0
- vwo/vwo.py +58 -0
- vwo/vwo_builder.py +21 -0
- vwo/vwo_client.py +22 -0
- wingify/__init__.py +36 -0
- wingify/api/__init__.py +13 -0
- wingify/api/get_flag_api.py +727 -0
- wingify/api/set_attribute_api.py +60 -0
- wingify/api/track_api.py +99 -0
- wingify/constants/Constants.py +94 -0
- wingify/constants/__init__.py +13 -0
- wingify/constants/sampled_debug_error_template_keys.py +34 -0
- wingify/decorators/__init__.py +13 -0
- wingify/decorators/storage_decorator.py +92 -0
- wingify/enums/__init__.py +13 -0
- wingify/enums/api_enum.py +26 -0
- wingify/enums/campaign_type_enum.py +22 -0
- wingify/enums/debug_category_enum.py +24 -0
- wingify/enums/event_enum.py +26 -0
- wingify/enums/headers_enum.py +21 -0
- wingify/enums/hooks_enum.py +24 -0
- wingify/enums/status_enum.py +21 -0
- wingify/enums/storage_enum.py +25 -0
- wingify/enums/url_enum.py +29 -0
- wingify/models/Alias.py +60 -0
- wingify/models/AliasSetResponse.py +43 -0
- wingify/models/__init__.py +13 -0
- wingify/models/batch_event_data.py +68 -0
- wingify/models/campaign/__init__.py +13 -0
- wingify/models/campaign/campaign_model.py +140 -0
- wingify/models/campaign/feature_model.py +95 -0
- wingify/models/campaign/holdout_model.py +94 -0
- wingify/models/campaign/impact_campaign_model.py +60 -0
- wingify/models/campaign/metric_model.py +42 -0
- wingify/models/campaign/rule_model.py +42 -0
- wingify/models/campaign/variable_model.py +44 -0
- wingify/models/campaign/variation_model.py +109 -0
- wingify/models/gateway_service_model.py +48 -0
- wingify/models/schemas/__init__.py +13 -0
- wingify/models/schemas/campaign_group_schema.py +19 -0
- wingify/models/schemas/campaign_metric_schema.py +26 -0
- wingify/models/schemas/campaign_schema.py +37 -0
- wingify/models/schemas/campaign_variation_schema.py +34 -0
- wingify/models/schemas/empty_object_schema.py +15 -0
- wingify/models/schemas/feature_schema.py +38 -0
- wingify/models/schemas/group_schema.py +37 -0
- wingify/models/schemas/holdout_schema.py +29 -0
- wingify/models/schemas/rule_schema.py +24 -0
- wingify/models/schemas/settings_schema.py +47 -0
- wingify/models/schemas/variable_schema.py +24 -0
- wingify/models/settings/__init__.py +13 -0
- wingify/models/settings/internal_event_sampling_settings_model.py +53 -0
- wingify/models/settings/settings_model.py +127 -0
- wingify/models/storage/__init__.py +13 -0
- wingify/models/storage/storage_model.py +84 -0
- wingify/models/user/__init__.py +13 -0
- wingify/models/user/context_model.py +113 -0
- wingify/models/user/context_vwo_model.py +34 -0
- wingify/models/user/get_flag.py +47 -0
- wingify/models/vwo_options_model.py +21 -0
- wingify/models/wingify_options_model.py +129 -0
- wingify/packages/__init__.py +13 -0
- wingify/packages/decision_maker/__init__.py +13 -0
- wingify/packages/decision_maker/decision_maker.py +89 -0
- wingify/packages/logger/__init__.py +13 -0
- wingify/packages/logger/core/__init__.py +13 -0
- wingify/packages/logger/core/log_manager.py +123 -0
- wingify/packages/logger/core/log_transport_manager.py +57 -0
- wingify/packages/logger/enums/__init__.py +13 -0
- wingify/packages/logger/enums/log_level_enum.py +24 -0
- wingify/packages/logger/enums/log_level_number_enum.py +21 -0
- wingify/packages/logger/log_message_builder.py +70 -0
- wingify/packages/logger/logger.py +38 -0
- wingify/packages/logger/transports/__init__.py +13 -0
- wingify/packages/logger/transports/console_transport.py +43 -0
- wingify/packages/network_layer/__init__.py +13 -0
- wingify/packages/network_layer/client/__init__.py +13 -0
- wingify/packages/network_layer/client/network_client.py +167 -0
- wingify/packages/network_layer/handlers/__init__.py +13 -0
- wingify/packages/network_layer/handlers/request_handler.py +40 -0
- wingify/packages/network_layer/manager/__init__.py +13 -0
- wingify/packages/network_layer/manager/network_manager.py +79 -0
- wingify/packages/network_layer/models/__init__.py +13 -0
- wingify/packages/network_layer/models/global_request_model.py +70 -0
- wingify/packages/network_layer/models/request_model.py +133 -0
- wingify/packages/network_layer/models/response_model.py +55 -0
- wingify/packages/segmentation_evaluator/__init__.py +13 -0
- wingify/packages/segmentation_evaluator/core/__init__.py +13 -0
- wingify/packages/segmentation_evaluator/core/segmentation_manager.py +140 -0
- wingify/packages/segmentation_evaluator/enums/__init__.py +13 -0
- wingify/packages/segmentation_evaluator/enums/segment_operand_regex_enum.py +31 -0
- wingify/packages/segmentation_evaluator/enums/segment_operand_value_enum.py +29 -0
- wingify/packages/segmentation_evaluator/enums/segment_operator_value_enum.py +37 -0
- wingify/packages/segmentation_evaluator/evaluators/__init__.py +13 -0
- wingify/packages/segmentation_evaluator/evaluators/segment_evaluator.py +237 -0
- wingify/packages/segmentation_evaluator/evaluators/segment_operand_evaluator.py +518 -0
- wingify/packages/segmentation_evaluator/utils/__init__.py +13 -0
- wingify/packages/segmentation_evaluator/utils/segment_util.py +33 -0
- wingify/packages/segmentation_evaluator/utils/web_testing_segment_util.py +295 -0
- wingify/packages/storage/__init__.py +13 -0
- wingify/packages/storage/connector.py +25 -0
- wingify/packages/storage/storage.py +39 -0
- wingify/resources/__init__.py +13 -0
- wingify/resources/debug-messages.json +21 -0
- wingify/resources/error-messages.json +62 -0
- wingify/resources/info-message.json +47 -0
- wingify/resources/trace-messages.json +1 -0
- wingify/resources/warn-messages.json +1 -0
- wingify/services/__init__.py +13 -0
- wingify/services/batch_event_queue.py +140 -0
- wingify/services/campaign_decision_service.py +268 -0
- wingify/services/hooks_manager.py +65 -0
- wingify/services/internal_events_sampling_service.py +62 -0
- wingify/services/settings_manager.py +293 -0
- wingify/services/storage_service.py +58 -0
- wingify/services/url_service.py +51 -0
- wingify/utils/__init__.py +13 -0
- wingify/utils/aliasing_util.py +108 -0
- wingify/utils/brand_context.py +26 -0
- wingify/utils/brand_util.py +37 -0
- wingify/utils/campaign_util.py +592 -0
- wingify/utils/data_type_util.py +125 -0
- wingify/utils/debugger_service_util.py +58 -0
- wingify/utils/decision_util.py +589 -0
- wingify/utils/event_util.py +85 -0
- wingify/utils/function_util.py +188 -0
- wingify/utils/gateway_service_util.py +179 -0
- wingify/utils/holdout_util.py +264 -0
- wingify/utils/impression_util.py +151 -0
- wingify/utils/internal_events_sampling_util.py +106 -0
- wingify/utils/log_message_util.py +95 -0
- wingify/utils/meg_util.py +561 -0
- wingify/utils/model_utils.py +136 -0
- wingify/utils/network_util.py +706 -0
- wingify/utils/rule_evaluation_util.py +102 -0
- wingify/utils/settings_util.py +39 -0
- wingify/utils/usage_stats_util.py +116 -0
- wingify/utils/uuid_util.py +81 -0
- wingify/vwo_client.py +21 -0
- wingify/wingify.py +159 -0
- wingify/wingify_builder.py +282 -0
- wingify/wingify_client.py +520 -0
- wingify_fme_python_sdk-1.70.0.dist-info/METADATA +1415 -0
- wingify_fme_python_sdk-1.70.0.dist-info/RECORD +186 -0
- wingify_fme_python_sdk-1.70.0.dist-info/WHEEL +5 -0
- wingify_fme_python_sdk-1.70.0.dist-info/licenses/LICENSE +202 -0
- wingify_fme_python_sdk-1.70.0.dist-info/licenses/NOTICE +18 -0
- wingify_fme_python_sdk-1.70.0.dist-info/top_level.txt +3 -0
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
# Copyright 2024-2026 Wingify Software Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from ..constants.Constants import Constants
|
|
17
|
+
from ..enums.campaign_type_enum import CampaignTypeEnum
|
|
18
|
+
from ..models.campaign.campaign_model import CampaignModel
|
|
19
|
+
from ..models.campaign.feature_model import FeatureModel
|
|
20
|
+
from ..models.campaign.variation_model import VariationModel
|
|
21
|
+
from ..models.settings.settings_model import SettingsModel
|
|
22
|
+
from ..models.campaign.rule_model import RuleModel
|
|
23
|
+
from ..packages.logger.core.log_manager import LogManager
|
|
24
|
+
from .log_message_util import info_messages
|
|
25
|
+
from typing import Optional, Dict, List
|
|
26
|
+
import math
|
|
27
|
+
from ..models.user.context_model import ContextModel
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _resolve_feature_rule_key(
|
|
31
|
+
campaign: CampaignModel, feature_key: Optional[str] = None
|
|
32
|
+
) -> Optional[str]:
|
|
33
|
+
"""
|
|
34
|
+
Resolves ``{featureKey}_{ruleKey}`` when rules share a parent campaign key.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
campaign (CampaignModel): The campaign containing the rule key.
|
|
38
|
+
feature_key (Optional[str]): Feature key; inferred from campaign key if omitted.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
Optional[str]: Resolved rule key, or ``None`` if rule key is missing.
|
|
42
|
+
"""
|
|
43
|
+
if not campaign.get_rule_key():
|
|
44
|
+
return None
|
|
45
|
+
resolved_feature_key = feature_key
|
|
46
|
+
if not resolved_feature_key and campaign.get_key():
|
|
47
|
+
resolved_feature_key = campaign.get_key().rsplit("_", 1)[0]
|
|
48
|
+
if resolved_feature_key:
|
|
49
|
+
return f"{resolved_feature_key}_{campaign.get_rule_key()}"
|
|
50
|
+
return None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def get_experiment_key(
|
|
54
|
+
campaign: CampaignModel, feature_key: Optional[str] = None
|
|
55
|
+
) -> str:
|
|
56
|
+
"""
|
|
57
|
+
Returns the experiment key for integrations callbacks and storage.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
campaign (CampaignModel): The campaign to resolve the key for.
|
|
61
|
+
feature_key (Optional[str]): Feature key for personalize rules.
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
str: ``{featureKey}_{ruleKey}`` for personalize rules; otherwise campaign key.
|
|
65
|
+
"""
|
|
66
|
+
if campaign.get_type() == CampaignTypeEnum.PERSONALIZE.value:
|
|
67
|
+
rule_key = _resolve_feature_rule_key(campaign, feature_key)
|
|
68
|
+
if rule_key:
|
|
69
|
+
return rule_key
|
|
70
|
+
return campaign.get_key()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def get_rollout_key(
|
|
74
|
+
campaign: CampaignModel, feature_key: Optional[str] = None
|
|
75
|
+
) -> str:
|
|
76
|
+
"""
|
|
77
|
+
Returns the rollout key for integrations callbacks and storage.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
campaign (CampaignModel): The campaign to resolve the key for.
|
|
81
|
+
feature_key (Optional[str]): Feature key for rollout rules.
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
str: ``{featureKey}_{ruleKey}`` for rollout rules; otherwise campaign key.
|
|
85
|
+
"""
|
|
86
|
+
if campaign.get_type() == CampaignTypeEnum.ROLLOUT.value:
|
|
87
|
+
rule_key = _resolve_feature_rule_key(campaign, feature_key)
|
|
88
|
+
if rule_key:
|
|
89
|
+
return rule_key
|
|
90
|
+
return campaign.get_key()
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def set_variation_allocation(campaign: CampaignModel) -> None:
|
|
94
|
+
"""
|
|
95
|
+
Allocates traffic ranges to variations within a campaign.
|
|
96
|
+
|
|
97
|
+
If the campaign is of type ROLLOUT or PERSONALIZE, it handles the allocation specifically
|
|
98
|
+
for rollout campaigns. Otherwise, it allocates the traffic range for each variation
|
|
99
|
+
within the campaign by calling `assign_range_values`.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
campaign (CampaignModel): The campaign object containing variations and their weights.
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
None
|
|
106
|
+
"""
|
|
107
|
+
if campaign.get_type() in [
|
|
108
|
+
CampaignTypeEnum.ROLLOUT.value,
|
|
109
|
+
CampaignTypeEnum.PERSONALIZE.value,
|
|
110
|
+
]:
|
|
111
|
+
_handle_rollout_campaign(campaign)
|
|
112
|
+
else:
|
|
113
|
+
current_allocation = 0
|
|
114
|
+
for variation in campaign.get_variations():
|
|
115
|
+
step_factor = assign_range_values(variation, current_allocation)
|
|
116
|
+
current_allocation += step_factor
|
|
117
|
+
LogManager.get_instance().info(
|
|
118
|
+
info_messages.get("VARIATION_RANGE_ALLOCATION").format(
|
|
119
|
+
variationKey=variation.get_name(),
|
|
120
|
+
campaignKey=campaign.get_key(),
|
|
121
|
+
variationWeight=variation.get_weight(),
|
|
122
|
+
startRange=variation.get_start_range_variation(),
|
|
123
|
+
endRange=variation.get_end_range_variation(),
|
|
124
|
+
)
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def assign_range_values(data: VariationModel, current_allocation: int) -> int:
|
|
129
|
+
"""
|
|
130
|
+
Sets the start and end range values for a variation based on its weight.
|
|
131
|
+
|
|
132
|
+
The function calculates the bucket range for the given variation weight and
|
|
133
|
+
updates the start and end range for the variation.
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
data (VariationModel): The variation object containing the weight.
|
|
137
|
+
current_allocation (int): The current allocation value from which the range starts.
|
|
138
|
+
|
|
139
|
+
Returns:
|
|
140
|
+
int: The step factor indicating the range size allocated to the variation.
|
|
141
|
+
"""
|
|
142
|
+
step_factor = _get_variation_bucket_range(data.get_weight())
|
|
143
|
+
|
|
144
|
+
if step_factor:
|
|
145
|
+
data.set_start_range_variation(current_allocation + 1)
|
|
146
|
+
data.set_end_range_variation(current_allocation + step_factor)
|
|
147
|
+
else:
|
|
148
|
+
data.set_start_range_variation(-1)
|
|
149
|
+
data.set_end_range_variation(-1)
|
|
150
|
+
|
|
151
|
+
return step_factor
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def scale_variation_weights(variations: List[VariationModel]) -> None:
|
|
155
|
+
"""
|
|
156
|
+
Scales the weights of variations to ensure they sum to 100.
|
|
157
|
+
|
|
158
|
+
If the total weight of all variations is zero, each variation is assigned an equal weight.
|
|
159
|
+
Otherwise, each variation's weight is scaled proportionally to ensure the total is 100.
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
variations (List[VariationModel]): List of variation objects to be scaled.
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
None
|
|
166
|
+
"""
|
|
167
|
+
total_weight = sum(variation.get_weight() for variation in variations)
|
|
168
|
+
|
|
169
|
+
if total_weight == 0:
|
|
170
|
+
equal_weight = 100 / len(variations)
|
|
171
|
+
for variation in variations:
|
|
172
|
+
variation.set_weight(equal_weight)
|
|
173
|
+
else:
|
|
174
|
+
for variation in variations:
|
|
175
|
+
variation.set_weight((variation.get_weight() / total_weight) * 100)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def get_bucketing_seed(
|
|
179
|
+
user_id: str, campaign: CampaignModel, group_id: Optional[int] = None
|
|
180
|
+
) -> str:
|
|
181
|
+
"""
|
|
182
|
+
Generates a seed for bucketing based on user ID and campaign/group context.
|
|
183
|
+
|
|
184
|
+
The seed is used for deterministic bucketing of users into variations or groups.
|
|
185
|
+
If a group ID is provided, it combines the group ID and user ID. Otherwise,
|
|
186
|
+
it combines the campaign ID and user ID.
|
|
187
|
+
|
|
188
|
+
Args:
|
|
189
|
+
user_id (str): The unique identifier for the user.
|
|
190
|
+
campaign (CampaignModel): The campaign object for bucketing context.
|
|
191
|
+
group_id (Optional[int]): The optional group ID if the campaign is part of a group.
|
|
192
|
+
|
|
193
|
+
Returns:
|
|
194
|
+
str: The generated bucketing seed.
|
|
195
|
+
"""
|
|
196
|
+
if group_id is not None:
|
|
197
|
+
return f"{group_id}_{user_id}"
|
|
198
|
+
|
|
199
|
+
is_rollout_or_personalize = campaign.get_type() in [
|
|
200
|
+
CampaignTypeEnum.ROLLOUT.value,
|
|
201
|
+
CampaignTypeEnum.PERSONALIZE.value,
|
|
202
|
+
]
|
|
203
|
+
if is_rollout_or_personalize:
|
|
204
|
+
salt = campaign.get_variations()[0].get_salt()
|
|
205
|
+
else:
|
|
206
|
+
salt = campaign.get_salt()
|
|
207
|
+
|
|
208
|
+
if salt:
|
|
209
|
+
return f"{salt}_{user_id}"
|
|
210
|
+
else:
|
|
211
|
+
return f"{campaign.get_id()}_{user_id}"
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def get_variation_from_campaign_key(
|
|
215
|
+
settings: SettingsModel, campaign_key: str, variation_id: int
|
|
216
|
+
) -> Optional[VariationModel]:
|
|
217
|
+
"""
|
|
218
|
+
Retrieves a variation from a campaign by its key and variation ID.
|
|
219
|
+
|
|
220
|
+
Searches through all campaigns in the settings to find the specified campaign by its key,
|
|
221
|
+
and then looks for the variation within that campaign by its ID.
|
|
222
|
+
|
|
223
|
+
Args:
|
|
224
|
+
settings (SettingsModel): The settings object containing campaign information.
|
|
225
|
+
campaign_key (str): The key identifier for the campaign.
|
|
226
|
+
variation_id (int): The unique identifier for the variation.
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
Optional[VariationModel]: The variation object if found, otherwise None.
|
|
230
|
+
"""
|
|
231
|
+
campaign = next(
|
|
232
|
+
(c for c in settings.get_campaigns() if c.get_key() == campaign_key), None
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
if campaign:
|
|
236
|
+
variation = next(
|
|
237
|
+
(v for v in campaign.get_variations() if v.get_id() == variation_id), None
|
|
238
|
+
)
|
|
239
|
+
if variation:
|
|
240
|
+
return variation
|
|
241
|
+
|
|
242
|
+
for feature in settings.get_features() or []:
|
|
243
|
+
feature_key = feature.get_key()
|
|
244
|
+
for linked_campaign in feature.get_rules_linked_campaign() or []:
|
|
245
|
+
if (
|
|
246
|
+
get_experiment_key(linked_campaign, feature_key) == campaign_key
|
|
247
|
+
or get_rollout_key(linked_campaign, feature_key) == campaign_key
|
|
248
|
+
):
|
|
249
|
+
variation = next(
|
|
250
|
+
(
|
|
251
|
+
v
|
|
252
|
+
for v in linked_campaign.get_variations()
|
|
253
|
+
if v.get_id() == variation_id
|
|
254
|
+
),
|
|
255
|
+
None,
|
|
256
|
+
)
|
|
257
|
+
if variation:
|
|
258
|
+
return variation
|
|
259
|
+
|
|
260
|
+
return None
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def set_campaign_allocation(campaigns: List[VariationModel]) -> None:
|
|
264
|
+
"""
|
|
265
|
+
Sets the allocation ranges for a List of campaigns.
|
|
266
|
+
|
|
267
|
+
Iterates through the provided campaigns and assigns range values for each campaign
|
|
268
|
+
by calling `assign_range_values_meg`.
|
|
269
|
+
|
|
270
|
+
Args:
|
|
271
|
+
campaigns (List[VariationModel]): List of campaign objects to allocate.
|
|
272
|
+
|
|
273
|
+
Returns:
|
|
274
|
+
None
|
|
275
|
+
"""
|
|
276
|
+
current_allocation = 0
|
|
277
|
+
for campaign in campaigns:
|
|
278
|
+
step_factor = assign_range_values_meg(campaign, current_allocation)
|
|
279
|
+
current_allocation += step_factor
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def get_group_details_if_campaign_part_of_it(
|
|
283
|
+
settings: SettingsModel, campaign_id: str, variationId: Optional[int] = None
|
|
284
|
+
) -> Dict:
|
|
285
|
+
"""
|
|
286
|
+
Retrieves group details if a campaign is part of a group.
|
|
287
|
+
|
|
288
|
+
Looks up the group ID for the given campaign ID in the settings and returns
|
|
289
|
+
the group details including the group ID and group name.
|
|
290
|
+
|
|
291
|
+
Args:
|
|
292
|
+
settings (SettingsModel): The settings object containing group information.
|
|
293
|
+
campaign_id (int): The unique identifier for the campaign.
|
|
294
|
+
variationId (Optional[int]): The unique identifier for the variation.
|
|
295
|
+
|
|
296
|
+
Returns:
|
|
297
|
+
Dict: A dictionary containing group ID and group name if the campaign is part of a group, otherwise an empty dictionary.
|
|
298
|
+
"""
|
|
299
|
+
campaign_to_check = campaign_id
|
|
300
|
+
if variationId:
|
|
301
|
+
campaign_to_check = campaign_id + "_" + str(variationId)
|
|
302
|
+
if (
|
|
303
|
+
settings.get_campaign_groups()
|
|
304
|
+
and campaign_to_check in settings.get_campaign_groups()
|
|
305
|
+
):
|
|
306
|
+
group_id = str(settings.get_campaign_groups()[campaign_to_check])
|
|
307
|
+
group_name = settings.get_groups()[group_id]["name"]
|
|
308
|
+
return {"groupId": group_id, "groupName": group_name}
|
|
309
|
+
|
|
310
|
+
return {}
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def find_groups_feature_part_of(settings: SettingsModel, feature_key: str) -> List:
|
|
314
|
+
"""
|
|
315
|
+
Finds all groups that a feature is part of.
|
|
316
|
+
|
|
317
|
+
Searches through the features in the settings to find the feature by its key,
|
|
318
|
+
then collects the group details for all campaigns associated with the feature.
|
|
319
|
+
|
|
320
|
+
Args:
|
|
321
|
+
settings (SettingsModel): The settings object containing feature information.
|
|
322
|
+
feature_key (str): The key identifier for the feature.
|
|
323
|
+
|
|
324
|
+
Returns:
|
|
325
|
+
List: A List of dictionaries containing group details for each group the feature is part of.
|
|
326
|
+
"""
|
|
327
|
+
ruleArrayList: List[RuleModel] = []
|
|
328
|
+
|
|
329
|
+
for feature in settings.get_features():
|
|
330
|
+
if feature.get_key() == feature_key:
|
|
331
|
+
for rule in feature.get_rules():
|
|
332
|
+
# Add rule to the array if it's not already present
|
|
333
|
+
if rule not in ruleArrayList:
|
|
334
|
+
ruleArrayList.append(rule)
|
|
335
|
+
|
|
336
|
+
groups = []
|
|
337
|
+
|
|
338
|
+
# Iterate over each rule to find the group details
|
|
339
|
+
for rule in ruleArrayList:
|
|
340
|
+
group = get_group_details_if_campaign_part_of_it(
|
|
341
|
+
settings,
|
|
342
|
+
str(rule.get_campaign_id()),
|
|
343
|
+
(
|
|
344
|
+
rule.get_variation_id()
|
|
345
|
+
if rule.get_type() == CampaignTypeEnum.PERSONALIZE.value
|
|
346
|
+
else None
|
|
347
|
+
),
|
|
348
|
+
)
|
|
349
|
+
# Add group to the array if it's not already present
|
|
350
|
+
if group.get("groupId") and group not in groups:
|
|
351
|
+
groups.append(group)
|
|
352
|
+
|
|
353
|
+
return groups
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
def get_campaigns_by_group_id(settings: SettingsModel, group_id: int) -> List:
|
|
357
|
+
"""
|
|
358
|
+
Retrieves all campaigns associated with a given group ID.
|
|
359
|
+
|
|
360
|
+
Looks up the group by its ID in the settings and returns the List of campaigns
|
|
361
|
+
that are part of the group.
|
|
362
|
+
|
|
363
|
+
Args:
|
|
364
|
+
settings (SettingsModel): The settings object containing group information.
|
|
365
|
+
group_id (int): The unique identifier for the group.
|
|
366
|
+
|
|
367
|
+
Returns:
|
|
368
|
+
List: A List of campaigns associated with the group.
|
|
369
|
+
"""
|
|
370
|
+
group = settings.get_groups().get(group_id)
|
|
371
|
+
if group:
|
|
372
|
+
return group["campaigns"]
|
|
373
|
+
return []
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def get_feature_keys_from_campaign_ids(
|
|
377
|
+
settings: SettingsModel, campaign_id_with_variation: List
|
|
378
|
+
) -> List:
|
|
379
|
+
"""
|
|
380
|
+
Retrieves the feature keys associated with a List of campaign IDs.
|
|
381
|
+
|
|
382
|
+
Iterates through the features in the settings and collects the keys of features
|
|
383
|
+
that have rules linked to the provided campaign IDs.
|
|
384
|
+
|
|
385
|
+
Args:
|
|
386
|
+
settings (SettingsModel): The settings object containing feature information.
|
|
387
|
+
campaign_ids (List): A List of campaign IDs to search for.
|
|
388
|
+
|
|
389
|
+
Returns:
|
|
390
|
+
List: A List of feature keys associated with the given campaign IDs.
|
|
391
|
+
"""
|
|
392
|
+
feature_keys = []
|
|
393
|
+
|
|
394
|
+
for campaign in campaign_id_with_variation:
|
|
395
|
+
# split key with _ to separate campaignId and variationId
|
|
396
|
+
campaign_id_variation_id = campaign.split("_")
|
|
397
|
+
campaign_id = int(campaign_id_variation_id[0])
|
|
398
|
+
variation_id = (
|
|
399
|
+
int(campaign_id_variation_id[1])
|
|
400
|
+
if len(campaign_id_variation_id) > 1
|
|
401
|
+
else None
|
|
402
|
+
)
|
|
403
|
+
# Iterate over each feature to find the feature key
|
|
404
|
+
for feature in settings.get_features():
|
|
405
|
+
# check if feature is already present in the list
|
|
406
|
+
if feature.get_key() in feature_keys:
|
|
407
|
+
continue
|
|
408
|
+
for rule in feature.get_rules():
|
|
409
|
+
if rule.get_campaign_id() == campaign_id:
|
|
410
|
+
# Check if variationId is provided and matches the rule's variationId
|
|
411
|
+
if variation_id is not None:
|
|
412
|
+
# Add feature key if variationId matches
|
|
413
|
+
if rule.get_variation_id() == variation_id:
|
|
414
|
+
feature_keys.append(feature.get_key())
|
|
415
|
+
else:
|
|
416
|
+
# Add feature key if no variationId is provided
|
|
417
|
+
feature_keys.append(feature.get_key())
|
|
418
|
+
|
|
419
|
+
return feature_keys
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
def get_campaign_ids_from_feature_key(
|
|
423
|
+
settings: SettingsModel, feature_key: str
|
|
424
|
+
) -> List:
|
|
425
|
+
"""
|
|
426
|
+
Retrieves the campaign IDs associated with a given feature key.
|
|
427
|
+
|
|
428
|
+
Searches through the features in the settings to find the feature by its key,
|
|
429
|
+
then collects the campaign IDs linked to that feature.
|
|
430
|
+
|
|
431
|
+
Args:
|
|
432
|
+
settings (SettingsModel): The settings object containing feature information.
|
|
433
|
+
feature_key (str): The key identifier for the feature.
|
|
434
|
+
|
|
435
|
+
Returns:
|
|
436
|
+
List: A List of campaign IDs associated with the given feature key.
|
|
437
|
+
"""
|
|
438
|
+
campaign_ids = []
|
|
439
|
+
|
|
440
|
+
for feature in settings.get_features():
|
|
441
|
+
if feature.get_key() == feature_key:
|
|
442
|
+
for rule in feature.get_rules():
|
|
443
|
+
campaign_ids.append(rule.get_campaign_id())
|
|
444
|
+
|
|
445
|
+
return campaign_ids
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
def assign_range_values_meg(data: VariationModel, current_allocation: int) -> int:
|
|
449
|
+
"""
|
|
450
|
+
Sets the start and end range values for a variation based on its weight (MEG version).
|
|
451
|
+
|
|
452
|
+
The function calculates the bucket range for the given variation weight and
|
|
453
|
+
updates the start and end range for the variation, starting from the current allocation.
|
|
454
|
+
|
|
455
|
+
Args:
|
|
456
|
+
data (VariationModel): The variation object containing the weight.
|
|
457
|
+
current_allocation (int): The current allocation value from which the range starts.
|
|
458
|
+
|
|
459
|
+
Returns:
|
|
460
|
+
int: The step factor indicating the range size allocated to the variation.
|
|
461
|
+
"""
|
|
462
|
+
step_factor = _get_variation_bucket_range(data.get_weight())
|
|
463
|
+
|
|
464
|
+
if step_factor:
|
|
465
|
+
data.set_start_range_variation(current_allocation)
|
|
466
|
+
data.set_end_range_variation(current_allocation + step_factor)
|
|
467
|
+
else:
|
|
468
|
+
data.set_start_range_variation(-1)
|
|
469
|
+
data.set_end_range_variation(-1)
|
|
470
|
+
|
|
471
|
+
return step_factor
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
def get_rule_type_using_campaign_id_from_feature(
|
|
475
|
+
feature: FeatureModel, campaign_id: int
|
|
476
|
+
) -> str:
|
|
477
|
+
"""
|
|
478
|
+
Retrieves the rule type associated with a specific campaign ID from a feature.
|
|
479
|
+
|
|
480
|
+
Searches through the rules of the feature to find the one linked to the given campaign ID,
|
|
481
|
+
and returns the type of that rule.
|
|
482
|
+
|
|
483
|
+
Args:
|
|
484
|
+
feature (FeatureModel): The feature object containing rules.
|
|
485
|
+
campaign_id (int): The unique identifier for the campaign.
|
|
486
|
+
|
|
487
|
+
Returns:
|
|
488
|
+
str: The type of the rule associated with the campaign ID, or an empty string if not found.
|
|
489
|
+
"""
|
|
490
|
+
rule = next(
|
|
491
|
+
(r for r in feature.get_rules() if r.get_campaign_id() == campaign_id), None
|
|
492
|
+
)
|
|
493
|
+
return rule.get_type() if rule else ""
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
def _get_variation_bucket_range(variation_weight: int) -> int:
|
|
497
|
+
"""
|
|
498
|
+
Calculates the bucket range for a given variation weight.
|
|
499
|
+
|
|
500
|
+
The function computes the range size based on the variation weight, ensuring
|
|
501
|
+
it does not exceed the maximum traffic value.
|
|
502
|
+
|
|
503
|
+
Args:
|
|
504
|
+
variation_weight (int): The weight of the variation as an integer.
|
|
505
|
+
|
|
506
|
+
Returns:
|
|
507
|
+
int: The calculated range size for the variation weight.
|
|
508
|
+
"""
|
|
509
|
+
if not variation_weight:
|
|
510
|
+
return 0
|
|
511
|
+
|
|
512
|
+
start_range = min(math.ceil(variation_weight * 100), Constants.MAX_TRAFFIC_VALUE)
|
|
513
|
+
return start_range
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
def _handle_rollout_campaign(campaign: CampaignModel) -> None:
|
|
517
|
+
"""
|
|
518
|
+
Handles the allocation of ranges for a rollout campaign.
|
|
519
|
+
|
|
520
|
+
This function specifically deals with setting the range values for variations
|
|
521
|
+
in a rollout campaign based on their weights.
|
|
522
|
+
|
|
523
|
+
Args:
|
|
524
|
+
campaign (CampaignModel): The rollout campaign object containing variations.
|
|
525
|
+
|
|
526
|
+
Returns:
|
|
527
|
+
None
|
|
528
|
+
"""
|
|
529
|
+
for variation in campaign.get_variations():
|
|
530
|
+
end_range = variation.get_weight() * 100
|
|
531
|
+
variation.set_start_range_variation(1)
|
|
532
|
+
variation.set_end_range_variation(end_range)
|
|
533
|
+
|
|
534
|
+
LogManager.get_instance().info(
|
|
535
|
+
info_messages.get("VARIATION_RANGE_ALLOCATION").format(
|
|
536
|
+
variationKey=variation.get_name(),
|
|
537
|
+
campaignKey=campaign.get_key(),
|
|
538
|
+
variationWeight=variation.get_weight(),
|
|
539
|
+
startRange=1,
|
|
540
|
+
endRange=end_range,
|
|
541
|
+
)
|
|
542
|
+
)
|
|
543
|
+
|
|
544
|
+
def get_campaign_key_from_campaign_id(settings: SettingsModel, campaign_id: int) -> str:
|
|
545
|
+
"""
|
|
546
|
+
Retrieves the campaign key associated with a given campaign ID.
|
|
547
|
+
|
|
548
|
+
Searches through the campaigns in the settings to find the campaign by its ID,
|
|
549
|
+
and returns the key of that campaign.
|
|
550
|
+
"""
|
|
551
|
+
campaign = next((c for c in settings.get_campaigns() if c.get_id() == campaign_id), None)
|
|
552
|
+
return campaign.get_key() if campaign else ""
|
|
553
|
+
|
|
554
|
+
def get_variation_name_from_campaign_id_and_variation_id(
|
|
555
|
+
settings: SettingsModel, campaign_id: int, variation_id: int) -> str:
|
|
556
|
+
"""
|
|
557
|
+
Retrieves the variation name associated with a given campaign ID and variation ID.
|
|
558
|
+
|
|
559
|
+
Searches through the campaigns in the settings to find the campaign by its ID,
|
|
560
|
+
and returns the name of the variation that matches the given variation ID.
|
|
561
|
+
"""
|
|
562
|
+
campaign = next((c for c in settings.get_campaigns() if c.get_id() == campaign_id), None)
|
|
563
|
+
variation = next((v for v in campaign.get_variations() if v.get_id() == variation_id), None)
|
|
564
|
+
return variation.get_name() if variation else ""
|
|
565
|
+
|
|
566
|
+
def get_campaign_type_from_campaign_id(settings: SettingsModel, campaign_id: int) -> str:
|
|
567
|
+
"""
|
|
568
|
+
Retrieves the type of a campaign associated with a given campaign ID.
|
|
569
|
+
|
|
570
|
+
Searches through the campaigns in the settings to find the campaign by its ID,
|
|
571
|
+
and returns the type of that campaign.
|
|
572
|
+
"""
|
|
573
|
+
campaign = next((c for c in settings.get_campaigns() if c.get_id() == campaign_id), None)
|
|
574
|
+
return campaign.get_type() if campaign else ""
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
def get_bucketing_id_for_user(context: ContextModel) -> str:
|
|
578
|
+
"""
|
|
579
|
+
Resolves the bucketing ID for a user based on the custom bucketing seed configuration.
|
|
580
|
+
|
|
581
|
+
Args:
|
|
582
|
+
context (ContextModel): The user context containing ID and custom seed.
|
|
583
|
+
|
|
584
|
+
Returns:
|
|
585
|
+
str: The resolved bucketing ID (either custom seed or user ID).
|
|
586
|
+
"""
|
|
587
|
+
|
|
588
|
+
user_id = context.get_id()
|
|
589
|
+
bucketing_seed = context.get_bucketing_seed()
|
|
590
|
+
|
|
591
|
+
bucketing_id = bucketing_seed if bucketing_seed else user_id
|
|
592
|
+
return bucketing_id
|