PHP code example of mufuphlex / raqualizer

1. Go to this page and download the library: Download mufuphlex/raqualizer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mufuphlex / raqualizer example snippets



use Mufuphlex\Raqualizer;

o be correct
$dataSource2Price = 200;
$dataSource2Clicks = 60;

// Init detailed values
// Note the difference between 200 != (150 + 60)
$dataSource1Traffic1Price = 150;
$dataSource1Traffic2Price = 60;
// Note the difference between 60 != (45 + 20)
$dataSource1Traffic1Clicks = 45;
$dataSource1Traffic2Clicks = 20;

// Instantiate Raqualizer values to be corrected
$valueSource1Traffic1Price = new Raqualizer\EqualizableValue($dataSource1Traffic1Price);
$valueSource1Traffic2Price = new Raqualizer\EqualizableValue($dataSource1Traffic2Price);

// Combine Raqualizer values to a Raqualizer Values Set
$priceSet = new Raqualizer\EqualizableValueSet();
$priceSet
    ->addValue($valueSource1Traffic1Price)
    ->addValue($valueSource1Traffic2Price);

// Instantiate Raqualizer processor
$raqualizer = new Raqualizer\Raqualizer();

// Instantiate Raqualizer etalon value
$etalonPrice = new Raqualizer\EtalonValue($dataSource2Price);

// Process values
$correctedPriceValues = $raqualizer->processSet($priceSet, $etalonPrice);

// Ensure that the original values were corrected as expected: 143 + 57 = 200
print_r($correctedPriceValues);
// Note that the values are float due to not round ratios, so in case of need you can round them later
/*
Array
(
    [0] => 142.85714285714  // ~= 143
    [1] => 57.142857142857  // ~= 57
)
*/

// And now we need to edit the clicks data with the same ratio which was applied to price
$valueSource1Traffic1Clicks = new Raqualizer\EqualizableValue($dataSource1Traffic1Clicks);
$valueSource1Traffic2Clicks = new Raqualizer\EqualizableValue($dataSource1Traffic2Clicks);

$clicksSet = new Raqualizer\EqualizableValueSet();
$clicksSet
    ->addValue($valueSource1Traffic1Clicks)
    ->addValue($valueSource1Traffic2Clicks);

$clicksSet->dependsOn($priceSet);
$etalonClicks = new Raqualizer\EtalonValue($dataSource2Clicks);
$correctedClicksValues = $raqualizer->processSet($clicksSet, $etalonClicks);

// Ensure that the original clicks values were corrected as expected as well: 43 + 7 = 60
print_r($correctedClicksValues);
/*
Array
(
    [0] => 42.857142857143  // ~= 43
    [1] => 17.142857142857  // ~= 17
)
*/