From 859b2c7630089b8dfff5ceb1238d3ef160561990 Mon Sep 17 00:00:00 2001 From: Saksham Gupta Date: Fri, 4 Oct 2024 13:19:23 +0530 Subject: [PATCH] fix: Pre-segmentation result comparison logic --- CHANGELOG.md | 7 +++++ src/Constants/Constants.php | 2 +- .../Evaluators/SegmentOperandEvaluator.php | 28 +++++++++++-------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c96a1c3..186265b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +[1.3.1] - 2024-10-04 + +### Fixed + +- Improved Pre-segmentation result comparison logic to handle numeric values more accurately by trimming trailing zeroes and decimal points across various operand types + + [1.3.0] - 2024-10-03 ### Added diff --git a/src/Constants/Constants.php b/src/Constants/Constants.php index 2dade9c..6cacc1c 100644 --- a/src/Constants/Constants.php +++ b/src/Constants/Constants.php @@ -39,7 +39,7 @@ class Constants { const DEFAULT_REQUEST_TIME_INTERVAL = 600; // 10 * 60(secs) = 600 secs i.e. 10 minutes const DEFAULT_EVENTS_PER_REQUEST = 100; const SDK_NAME = 'vwo-fme-php-sdk'; - const SDK_VERSION = '1.3.0'; + const SDK_VERSION = '1.3.1'; const AP = 'server'; const SETTINGS = 'settings'; diff --git a/src/Packages/SegmentationEvaluator/Evaluators/SegmentOperandEvaluator.php b/src/Packages/SegmentationEvaluator/Evaluators/SegmentOperandEvaluator.php index e5121cd..a7e7130 100644 --- a/src/Packages/SegmentationEvaluator/Evaluators/SegmentOperandEvaluator.php +++ b/src/Packages/SegmentationEvaluator/Evaluators/SegmentOperandEvaluator.php @@ -180,37 +180,43 @@ public function processValues($operandValue, $tagValue) { public function extractResult($operandType, $operandValue, $tagValue) { $result = false; + $normalizedOperandValue = is_numeric($operandValue) ? rtrim(rtrim($operandValue, '0'), '.') : $operandValue; + $normalizedTagValue = is_numeric($tagValue) ? rtrim(rtrim($tagValue, '0'), '.') : $tagValue; + switch ($operandType) { case SegmentOperandValueEnum::LOWER_VALUE: if ($tagValue !== null) { - $result = strtolower($operandValue) === strtolower($tagValue); + $result = strtolower($normalizedOperandValue) === strtolower($normalizedTagValue); } break; case SegmentOperandValueEnum::STARTING_ENDING_STAR_VALUE: if ($tagValue !== null) { - $result = strpos($tagValue, $operandValue) !== false; + $result = strpos($normalizedTagValue, $normalizedOperandValue) !== false; } break; case SegmentOperandValueEnum::STARTING_STAR_VALUE: if ($tagValue !== null) { - $result = substr($tagValue, -strlen($operandValue)) === $operandValue; + $result = substr($normalizedTagValue, -strlen($normalizedOperandValue)) === $normalizedOperandValue; } break; case SegmentOperandValueEnum::ENDING_STAR_VALUE: if ($tagValue !== null) { - $result = substr($tagValue, 0, strlen($operandValue)) === $operandValue; + $result = substr($normalizedTagValue, 0, strlen($normalizedOperandValue)) === $normalizedOperandValue; } break; case SegmentOperandValueEnum::REGEX_VALUE: - // Check if operandValue is a valid regex pattern if (@preg_match('/' . $operandValue . '/', '') === false) { $result = false; } else { $result = preg_match('/' . $operandValue . '/', $tagValue); } - break; + break; case SegmentOperandValueEnum::EQUAL_VALUE: - $result = $tagValue === $operandValue; + if (is_numeric($operandValue) && is_numeric($tagValue)) { + $result = (float)$operandValue === (float)$tagValue; + } else { + $result = $normalizedOperandValue === $normalizedTagValue; + } break; case SegmentOperandValueEnum::GREATER_THAN_VALUE: $result = $this->isValidNumericComparison($operandValue, $tagValue, function ($opValue, $tValue) { @@ -226,17 +232,17 @@ public function extractResult($operandType, $operandValue, $tagValue) { $result = $this->isValidNumericComparison($operandValue, $tagValue, function ($opValue, $tValue) { return $opValue > $tValue; }); - break; + break; case SegmentOperandValueEnum::LESS_THAN_EQUAL_TO_VALUE: $result = $this->isValidNumericComparison($operandValue, $tagValue, function ($opValue, $tValue) { return $opValue >= $tValue; }); - break; + break; default: $result = false; break; } - + return $result; } @@ -253,4 +259,4 @@ private function isValidNumericComparison($operandValue, $tagValue, callable $co } } -?> +?> \ No newline at end of file