} public function compensate($v) { // We only care about our example sliding out. if ($this->state > 0 && $v->at == $this->time && $v->value == $this->time) { // If we've expired, reset. $this->init(); } } public function emit() { if ($this->state == 5) { return $this->data; } } } $tick_fn = new TickDetector(); $cb = function ($value) { if ($value) { list($start, $low, $high, $cur) = $value; printf("Value: %d Prev Gain: %d\n", $cur, $high - $low); } }; echo "Test on known data\n\n"; // Pump a little data. $values = array(290, 290, 300, 300, 320, 280, 340, 340, 350, 300, 290, 300); $win = new React\EEP\Window\Sliding($tick_fn, 7); $win->on('emit', $cb); foreach ($values as $at => $value) { $win->enqueue(new React\EEP\Event\Temporal($value, $at)); }
$a_win = new React\EEP\Window\Sliding($fn, 100); $b_win = new React\EEP\Window\Sliding($fn, 100); $counter = 0; $match = function ($match) use(&$counter) { if ($match) { $counter++; printf("%s \n", $match[1]); } }; $a_win->on("emit", $match); $b_win->on("emit", $match); $event_count = 50000; $cats = array("toys", "electrical", "cars", "clothing", "homewares"); $start = microtime(true); $i = 0; for ($i = 0; $i < $event_count; $i++) { // Key - e.g auction ID. $key = rand(1, 5000); // Randomly select a stream. if (rand(0, 1) == 0) { // Generate an list item event. (auction id, category) $value = array($key, $cats[array_rand($cats)]); $a_win->enqueue(new React\EEP\Event\Muxed($value, 0)); } else { // Generate an end auction event. (action id, category, price) $value = array($key, $cats[array_rand($cats)], rand(10, 500)); $b_win->enqueue(new React\EEP\Event\Muxed($value, 1)); } } $time = microtime(true) - $start; // printf("%.2feps - %d matches\n", $event_count/$time, $counter);