@@ -71,28 +71,25 @@ def publish_telemetry(evaluation_event: EvaluationEvent) -> None:
7171 variant = evaluation_event .variant
7272
7373 # VariantAllocationPercentage
74- if reason and reason != VariantAssignmentReason .NONE :
75- if variant :
76- event [VARIANT ] = variant .name
74+ if reason :
7775 event [REASON ] = reason .value
7876
79- allocation_percentage = 0
80- if (
81- reason == VariantAssignmentReason .DEFAULT_WHEN_ENABLED
82- and feature .allocation
83- and feature .allocation .percentile
84- ):
77+ if variant :
78+ event [VARIANT ] = variant .name
79+
80+ allocation_percentage = 0
81+ if reason == VariantAssignmentReason .DEFAULT_WHEN_ENABLED and feature .allocation and feature .allocation .percentile :
82+ for allocation in feature .allocation .percentile :
83+ if allocation .percentile_to :
84+ allocation_percentage += allocation .percentile_to - allocation .percentile_from
85+
86+ event ["VariantAssignmentPercentage" ] = str (100 - allocation_percentage )
87+ elif reason == VariantAssignmentReason .PERCENTILE :
88+ if feature .allocation and feature .allocation .percentile :
8589 for allocation in feature .allocation .percentile :
86- if allocation .percentile_to :
90+ if variant and allocation . variant == variant . name and allocation .percentile_to :
8791 allocation_percentage += allocation .percentile_to - allocation .percentile_from
88-
89- event ["VariantAssignmentPercentage" ] = str (100 - allocation_percentage )
90- elif reason == VariantAssignmentReason .PERCENTILE :
91- if feature .allocation and feature .allocation .percentile :
92- for allocation in feature .allocation .percentile :
93- if variant and allocation .variant == variant .name and allocation .percentile_to :
94- allocation_percentage += allocation .percentile_to - allocation .percentile_from
95- event ["VariantAssignmentPercentage" ] = str (allocation_percentage )
92+ event ["VariantAssignmentPercentage" ] = str (allocation_percentage )
9693
9794 # DefaultWhenEnabled
9895 if feature .allocation and feature .allocation .default_when_enabled :
0 commit comments