jeremyFreeAgent / Bitter

Bitter is a simple but powerful analytics library
http://bitter.free-agent.fr
MIT License
129 stars 18 forks source link

Call bitDateRange twice #17

Closed dxops closed 11 years ago

dxops commented 11 years ago

is it possible to use bitDateRange twice within one bitter intance?

        $this->bitter->bitDateRange('active:users', 'active_users_period', $from, $to);

        $count = $this->bitter->count('active_users_period');

        $this->assertEquals(3, $count);

        $this->bitter->bitDateRange('blocked:users', 'blocked_users_period', $from, $to);

        $count = $this->bitter->count('blocked_users_period');

        $this->assertEquals(3, $count);

second count is 0

jeremyFreeAgent commented 11 years ago

Yes you can! This is why there is a destKey (2nd arg). You can also use the destKey as a key in another call. In the 'blocked:users do you have elements within the date range?

dxops commented 11 years ago

Sure, full test:

    public function testThatBitterMarkIncrementAndGetValue()
    {
        $dateTime = new \DateTime();

        $dayActive = new Day('active', $dateTime);
        $dayBlocked = new Day('blocked', $dateTime);

        $this->bitter->mark('active', 1);
        $this->bitter->mark('active', 2);
        $this->assertEquals(2, $this->bitter->count($dayActive));

        $from = new \DateTime('-1 day');
        $to   = new \DateTime('+1 day');

        $this->bitter->mark('active', 3);
        $this->bitter->mark('blocked', 4);
        $this->bitter->mark('blocked', 5);
        $this->bitter->mark('blocked', 6);
        $this->bitter->mark('blocked', 7);

        $this->assertEquals(3, $this->bitter->count($dayActive));
        $this->assertEquals(4, $this->bitter->count($dayBlocked));
        $this->assertEquals(7, $this->bitter->count($dayBlocked) + $this->bitter->count($dayActive));

        $this->bitter->bitDateRange('active', 'active_users_period', $from, $to);
        $this->assertEquals(3, $this->bitter->count('active_users_period'));

        $this->bitter->bitDateRange('blocked', 'blocked_users_period', $from, $to);
        $this->assertEquals(4, $this->bitter->count('blocked_users_period'));
    }

@jeremyFreeAgent getting error on last assert

dxops commented 11 years ago

@jeremyFreeAgent any suggestions?

jeremyFreeAgent commented 11 years ago

@sergeyz I'm on it. I've the same issue... very strange.

dxops commented 11 years ago

i found that second period key blocked_users_period is not created

dxops commented 11 years ago

$from and $to date were modified in method and second call was made with wrong dates