Esempio n. 1
0
});
$tumbling_vars->on('emit', function ($value) {
    echo "vars:\t", $value, "\n";
});
echo "\nIndividual tumbling windows\n\n";
// Pump data into the tumbling windows
foreach ($values as $v) {
    $tumbling_count->enqueue($v);
    $tumbling_sum->enqueue($v);
    $tumbling_min->enqueue($v);
    $tumbling_max->enqueue($v);
    $tumbling_mean->enqueue($v);
    $tumbling_stdevs->enqueue($v);
    $tumbling_vars->enqueue($v);
}
// Alternatively, use a composite aggregate function
$stats = array($count_fn, $sum_fn, $min_fn, $max_fn, $mean_fn, $stdevs_fn, $vars_fn);
$headers = array("Count\t", "Sum\t", "Min\t", "Max\t", "Mean\t", "Stdev\t", "Vars\t");
$comp_fn = new React\EEP\Composite($stats);
$tumbling = new React\EEP\Window\Tumbling($comp_fn, count($values));
$tumbling->on('emit', function ($value) use($headers) {
    for ($i = 0; $i < count($value); $i++) {
        echo $headers[$i], "\t", $value[$i], "\n";
    }
});
echo "\nComposite tumbling window\n\n";
// Pump data into the tumbling window
foreach ($values as $v) {
    $tumbling->enqueue($v);
}
echo "\n";
Esempio n. 2
0
<?php

require __DIR__ . '/../vendor/autoload.php';
$mean_fn = new React\EEP\Stats\Mean();
$awin = new React\EEP\Window\Tumbling($mean_fn, 100);
$awin->on('emit', function ($avg) {
    if ($avg > 290) {
        printf("Average %dms - ALERT!\n", $avg);
    }
});
$start = microtime(true);
for ($i = 0; $i < 50000; $i++) {
    $var = 275 + rand(-150, 150);
    $awin->enqueue($var);
}
echo "\n\n#########\n\n";
echo "Monitor combined variables\n";
$all_fn = new React\EEP\Stats\All();
$all_win = new React\EEP\Window\Tumbling($all_fn, 100);
$all_win->on('emit', function ($vals) {
    if ($vals['stdevs'] > 92 && $vals['mean'] > 280 && $vals['max'] > 400) {
        printf("Stddev %.2fms Average %dms Max %dms - ALERT!\n", $vals['stdevs'], $vals['mean'], $vals['max']);
    }
});
$start = microtime(true);
for ($i = 0; $i < 50000; $i++) {
    $var = 275 + rand(-150, 150);
    $all_win->enqueue($var);
}