Example #1
0
    }
    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));
}
Example #2
0
    public function compensate($v)
    {
        $key = $v->value[0];
        $this->stream[$v->stream][$key]--;
        if ($this->stream[$v->stream][$key] == 0) {
            unset($this->stream[$v->stream][$key]);
        }
    }
    public function emit()
    {
        return $this->last_value;
    }
}
$fn = new Semijoin();
$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.