Skip to content

Commit abefc43

Browse files
Merge pull request #15 from statsig-io/v0-16-8
v0.16.8
2 parents 1f2e739 + 9e771a7 commit abefc43

File tree

4 files changed

+362
-33
lines changed

4 files changed

+362
-33
lines changed

statsig/evaluator.py

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ def __evaluate_delegate(self, user, rule, exposures):
269269

270270
def __evaluate_condition(self, user, condition):
271271
value = None
272-
273272
type = condition.get("type", "").upper()
274273
target = condition.get("targetValue")
275274
field = condition.get("field", "")
@@ -347,27 +346,27 @@ def __evaluate_condition(self, user, condition):
347346
return _ConfigEvaluation(False, val <= target)
348347
if op == "version_gt":
349348
res = self.__version_compare_helper(
350-
value, target, lambda a, b: self.__version_compare(a, b) > 0)
349+
value, target, lambda result: result > 0)
351350
return _ConfigEvaluation(False, res)
352351
if op == "version_gte":
353352
res = self.__version_compare_helper(
354-
value, target, lambda a, b: self.__version_compare(a, b) >= 0)
353+
value, target, lambda result: result >= 0)
355354
return _ConfigEvaluation(False, res)
356355
if op == "version_lt":
357356
res = self.__version_compare_helper(
358-
value, target, lambda a, b: self.__version_compare(a, b) < 0)
357+
value, target, lambda result: result < 0)
359358
return _ConfigEvaluation(False, res)
360359
if op == "version_lte":
361360
res = self.__version_compare_helper(
362-
value, target, lambda a, b: self.__version_compare(a, b) <= 0)
361+
value, target, lambda result: result <= 0)
363362
return _ConfigEvaluation(False, res)
364363
if op == "version_eq":
365364
res = self.__version_compare_helper(
366-
value, target, lambda a, b: self.__version_compare(a, b) == 0)
365+
value, target, lambda result: result == 0)
367366
return _ConfigEvaluation(False, res)
368367
if op == "version_neq":
369368
res = self.__version_compare_helper(
370-
value, target, lambda a, b: self.__version_compare(a, b) != 0)
369+
value, target, lambda result: result != 0)
371370
return _ConfigEvaluation(False, res)
372371
if op == "any":
373372
return _ConfigEvaluation(
@@ -482,8 +481,11 @@ def __get_unit_id(self, user, id_type):
482481
if id_type is not None and id_type.lower() != "userid":
483482
if user.custom_ids is None:
484483
return None
485-
return user.custom_ids.get(
486-
id_type, None) or user.custom_ids.get(id_type.lower(), None)
484+
custom_id = user.custom_ids.get(
485+
id_type, None)
486+
if custom_id is not None:
487+
return custom_id
488+
return user.custom_ids.get(id_type.lower(), None)
487489
return user.user_id
488490

489491
def __match_string_in_array(self, value, target, compare):
@@ -498,25 +500,28 @@ def __match_string_in_array(self, value, target, compare):
498500
return True
499501
return False
500502

501-
def __version_compare(self, v1, v2):
503+
def __version_compare(self, v1, v2, compare):
502504
p1 = v1.split(".")
503505
p2 = v2.split(".")
504506

505507
i = 0
506-
while i < max(len(p1), len(p2)):
507-
c1 = 0
508-
c2 = 0
509-
if i < len(p1):
510-
c1 = int(float(p1[i]))
511-
if i < len(p2):
512-
c2 = int(float(p2[i]))
513-
if c1 < c2:
514-
return -1
515-
if c1 > c2:
516-
return 1
517-
i += 1
518-
519-
return 0
508+
try:
509+
while i < max(len(p1), len(p2)):
510+
c1 = 0
511+
c2 = 0
512+
if i < len(p1):
513+
c1 = int(float(p1[i]))
514+
if i < len(p2):
515+
c2 = int(float(p2[i]))
516+
if c1 < c2:
517+
return compare(-1)
518+
if c1 > c2:
519+
return compare(1)
520+
i += 1
521+
except ValueError:
522+
return False
523+
524+
return compare(0)
520525

521526
def __version_compare_helper(self, v1, v2, compare):
522527
v1_str = self.__get_value_as_string(v1)
@@ -533,7 +538,7 @@ def __version_compare_helper(self, v1, v2, compare):
533538
if d2 > 0:
534539
v2_str = v2_str[0:d2]
535540

536-
return compare(v1_str, v2_str)
541+
return self.__version_compare(v1_str, v2_str, compare)
537542

538543
def __get_value_as_string(self, input):
539544
if input is None:
@@ -564,16 +569,27 @@ def __get_from_user_agent(self, user, field):
564569
def __get_version_string(self, version):
565570
if version is None:
566571
return None
567-
major = version.get("major", "0")
572+
573+
major = self.__get_numeric_subver(version, "major")
568574
if major is None:
569-
major = "0"
570-
minor = version.get("minor", "0")
575+
return None
576+
minor = self.__get_numeric_subver(version, "minor")
571577
if minor is None:
572-
minor = "0"
573-
patch = version.get("patch", "0")
578+
return None
579+
patch = self.__get_numeric_subver(version, "patch")
574580
if patch is None:
575-
patch = "0"
576-
return major + "." + minor + "." + patch
581+
return None
582+
return str.format("{}.{}.{}", major, minor,patch)
583+
584+
def __get_numeric_subver(self, version, subver):
585+
ver = version.get(subver, "0")
586+
if ver is None:
587+
return 0
588+
try:
589+
numeric = int(ver)
590+
return numeric
591+
except ValueError:
592+
return None
577593

578594
def __compare_dates(self, first, second, compare):
579595
if first is None and second is None:

statsig/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.16.7'
1+
__version__ = '0.16.8'
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
{
2+
"dynamic_configs": [
3+
{
4+
"name": "test_config",
5+
"type": "dynamic_config",
6+
"salt": "50ad5c60-9e7a-42ce-86c6-c49035185b14",
7+
"enabled": true,
8+
"defaultValue": { "number": 4, "string": "default", "boolean": true },
9+
"rules": [
10+
{
11+
"name": "1kNmlB23wylPFZi1M0Divl",
12+
"groupName": "statsig email",
13+
"passPercentage": 100,
14+
"conditions": [
15+
{
16+
"type": "user_field",
17+
"targetValue": ["@statsig.com"],
18+
"operator": "str_contains_any",
19+
"field": "email",
20+
"additionalValues": {}
21+
}
22+
],
23+
"returnValue": { "number": 7, "string": "statsig", "boolean": false },
24+
"id": "1kNmlB23wylPFZi1M0Divl",
25+
"salt": "f2ac6975-174d-497e-be7f-599fea626132"
26+
}
27+
]
28+
}
29+
],
30+
"feature_gates": [
31+
{
32+
"name": "python_ua_debug",
33+
"type": "feature_gate",
34+
"salt": "af8140b2-5eab-44da-b3d0-50326e69547e",
35+
"enabled": true,
36+
"defaultValue": false,
37+
"rules": [
38+
{
39+
"name": "GrsHpfXdprNny0Ij23Gnt:100.00:1",
40+
"groupName": "New Users less than 48H - iOS",
41+
"passPercentage": 100,
42+
"conditions": [
43+
{
44+
"type": "ua_based",
45+
"targetValue": [
46+
"Windows"
47+
],
48+
"operator": "any",
49+
"field": "os_name",
50+
"additionalValues": {},
51+
"isDeviceBased": false,
52+
"idType": "userID"
53+
},
54+
{
55+
"type": "ua_based",
56+
"targetValue": "7.0",
57+
"operator": "version_gte",
58+
"field": "os_version",
59+
"additionalValues": {},
60+
"isDeviceBased": false,
61+
"idType": "userID"
62+
}
63+
],
64+
"returnValue": true,
65+
"id": "GrsHpfXdprNny0Ij23Gnt:100.00:1",
66+
"salt": "14df24b4-729b-4fc5-96b9-764da38fd009",
67+
"isDeviceBased": false,
68+
"idType": "userID"
69+
}
70+
],
71+
"isDeviceBased": false,
72+
"idType": "userID",
73+
"entity": "feature_gate"
74+
}
75+
],
76+
"layer_configs": [
77+
{
78+
"name": "a_layer",
79+
"type": "dynamic_config",
80+
"salt": "f8aeba58-18fb-4f36-9bbd-4c611447a912",
81+
"enabled": true,
82+
"defaultValue": { "experiment_param": "control" },
83+
"rules": [
84+
{
85+
"name": "experimentAssignment",
86+
"groupName": "Experiment Assignment",
87+
"passPercentage": 100,
88+
"conditions": [
89+
{
90+
"type": "user_bucket",
91+
"targetValue": [
92+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
93+
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
94+
34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
95+
50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
96+
66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
97+
82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
98+
98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
99+
111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123,
100+
124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
101+
137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
102+
150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162,
103+
163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
104+
176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188,
105+
189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201,
106+
202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214,
107+
215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227,
108+
228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240,
109+
241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253,
110+
254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
111+
267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279,
112+
280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292,
113+
293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305,
114+
306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318,
115+
319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331,
116+
332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
117+
345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357,
118+
358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370,
119+
371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383,
120+
384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396,
121+
397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409,
122+
410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422,
123+
423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435,
124+
436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448,
125+
449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461,
126+
462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474,
127+
475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487,
128+
488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500,
129+
501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513,
130+
514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526,
131+
527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539,
132+
540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552,
133+
553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565,
134+
566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578,
135+
579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591,
136+
592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604,
137+
605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617,
138+
618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630,
139+
631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643,
140+
644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656,
141+
657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669,
142+
670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682,
143+
683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695,
144+
696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708,
145+
709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721,
146+
722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734,
147+
735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747,
148+
748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760,
149+
761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773,
150+
774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786,
151+
787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799,
152+
800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812,
153+
813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825,
154+
826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838,
155+
839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851,
156+
852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864,
157+
865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877,
158+
878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890,
159+
891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903,
160+
904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916,
161+
917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929,
162+
930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942,
163+
943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955,
164+
956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968,
165+
969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 981,
166+
982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994,
167+
995, 996, 997, 998, 999
168+
],
169+
"operator": "any",
170+
"field": null,
171+
"additionalValues": {
172+
"salt": "58d96daa-4d16-467a-b616-7232c45153f4"
173+
},
174+
"isDeviceBased": false,
175+
"idType": "userID"
176+
}
177+
],
178+
"returnValue": {
179+
"layer_param": true,
180+
"second_layer_param": false
181+
},
182+
"id": "experimentAssignment",
183+
"salt": "",
184+
"isDeviceBased": false,
185+
"idType": "userID",
186+
"configDelegate": "sample_experiment"
187+
}
188+
],
189+
"isDeviceBased": false,
190+
"idType": "userID",
191+
"entity": "layer"
192+
},
193+
{
194+
"name": "b_layer_no_alloc",
195+
"type": "dynamic_config",
196+
"salt": "3e361046-bc69-4dfd-bbb1-538afe609157",
197+
"enabled": true,
198+
"defaultValue": {
199+
"b_param": "layer_default"
200+
},
201+
"rules": [],
202+
"isDeviceBased": false,
203+
"idType": "userID",
204+
"entity": "layer"
205+
},
206+
{
207+
"name": "c_layer_with_holdout",
208+
"type": "dynamic_config",
209+
"salt": "ab40c4af-947f-411e-9403-880393703507",
210+
"enabled": true,
211+
"defaultValue": {
212+
"holdout_layer_param": "layer_default"
213+
},
214+
"rules": [
215+
{
216+
"name": "7d2E854TtGmfETdmJFip1L",
217+
"groupName": "master_holdout",
218+
"passPercentage": 100,
219+
"conditions": [
220+
{
221+
"type": "pass_gate",
222+
"targetValue": "always_on_gate",
223+
"operator": "any",
224+
"field": null,
225+
"additionalValues": null,
226+
"isDeviceBased": false,
227+
"idType": "userID"
228+
}
229+
],
230+
"returnValue": {
231+
"holdout_layer_param": "layer_default"
232+
},
233+
"id": "7d2E854TtGmfETdmJFip1L",
234+
"salt": "",
235+
"isDeviceBased": false,
236+
"idType": "userID"
237+
}
238+
],
239+
"isDeviceBased": false,
240+
"idType": "userID",
241+
"entity": "layer"
242+
}
243+
],
244+
"has_updates": true,
245+
"time": 1631638014811,
246+
"id_lists": { "list_1": true, "list_2": true }
247+
}

0 commit comments

Comments
 (0)