public static function genStatsReportHourRange(\DateTime $time_start, \DateTime $time_end) { $stats_report = new \ebussola\ads\reports\statsreport\StatsReport(); $period = new DatePeriod($time_start, new DateInterval('PT1H'), $time_end); foreach ($period as $date) { $stats_report->addStats(self::genStats(array('time_start' => $date, 'time_end' => new DateTime('now')))); } return $stats_report; }
public static function genStatsReport() { $stats_report = new \ebussola\ads\reports\statsreport\StatsReport(); $size = rand(50, 200); for ($i = 0; $i <= $size; $i++) { $stats_report->addStats(self::genStats()); } $stats_report = new \ebussola\ads\reports\adwords\statsreport\StatsReport($stats_report); $stats_report->refreshValues(); return $stats_report; }
public function testAddStats() { $latest_time_end = new DateTime('now'); $early_time_start = new DateTime('2013-08-19'); $stats1 = StatsGen::genStats(array('time_start' => $early_time_start)); $stats2 = StatsGen::genStats(array('time_end' => $latest_time_end)); $stats3 = StatsGen::genStats(); $stats_report = new \ebussola\ads\reports\statsreport\StatsReport(); $stats_report->addStats($stats1); $stats_report->addStats($stats2); $stats_report->addStats($stats3); $this->assertEquals($stats1->cost + $stats2->cost + $stats3->cost, $stats_report->cost); $this->assertEquals($stats1->clicks + $stats2->clicks + $stats3->clicks, $stats_report->clicks); $this->assertEquals($stats1->impressions + $stats2->impressions + $stats3->impressions, $stats_report->impressions); $this->assertEquals(MathHelper::calcCpc($stats_report->cost, $stats_report->clicks), $stats_report->cpc); $this->assertEquals(MathHelper::calcCtr($stats_report->clicks, $stats_report->impressions), $stats_report->ctr); $this->assertEquals($early_time_start, $stats_report->time_start); $this->assertEquals($latest_time_end, $stats_report->time_end); return $stats_report; }
public function testGroupByHour() { $stats_reports = array(); $stats_reports[1] = StatsGen::genStatsReportHourRange(new DateTime('2013-10-01'), new DateTime('2013-10-30')); $stats_reports[2] = StatsGen::genStatsReportHourRange(new DateTime('2013-10-01'), new DateTime('2013-10-30')); $stats_reports[3] = StatsGen::genStatsReportHourRange(new DateTime('2013-10-01'), new DateTime('2013-10-30')); $stats_reports[4] = StatsGen::genStatsReportHourRange(new DateTime('2013-09-01'), new DateTime('2013-09-30')); $stats_reports[5] = StatsGen::genStatsReportHourRange(new DateTime('2013-09-01'), new DateTime('2013-09-30')); $stats_reports[6] = StatsGen::genStatsReportHourRange(new DateTime('2013-09-01'), new DateTime('2013-09-30')); $main_report = new \ebussola\ads\reports\statsreport\StatsReport(); foreach ($stats_reports as $stats_report) { foreach ($stats_report as $stats) { $main_report->addStats($stats); } } $this->assertCount(4173, $main_report->stats); $this->reports->groupBy('hour', $main_report); $this->assertCount(24, $main_report->stats); }
public function testAveragePosition() { $stats_report = new \ebussola\ads\reports\statsreport\StatsReport(); for ($i = 0; $i <= 100; $i++) { $stats = new \stdClass(); $stats->avgPosition = rand(3, 5); $stats = new \ebussola\ads\reports\adwords\stats\AbstractStats($stats); $stats_report->addStats($stats); } $stats_report = new \ebussola\ads\reports\adwords\statsreport\StatsReport($stats_report); $stats_report->refreshValues(); $this->assertLessThanOrEqual(5, $stats_report->average_position); $this->assertGreaterThanOrEqual(3, $stats_report->average_position); }