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); }
/** * @param string[] $ad_group_ids * @param \DateTime $start_date * @param \DateTime $end_date * @param bool $group_similar_ads * * @return AdGroupStatsReport */ public function createAdStats($ad_group_ids, \DateTime $start_date, \DateTime $end_date, $group_similar_ads) { $groups = $this->ads->getAdGroups($ad_group_ids); $creative_ids = []; foreach ($groups as $group) { foreach ($group->creative_ids as $creative_id) { $creative_ids[] = $creative_id; } } $creatives = $this->ads->getCreatives($creative_ids); $data_columns = $this->getAdFields(); $filters = array(ReportStatsHelper::createFilter('adgroup_id', 'in', $ad_group_ids)); $stats = $this->ads->getReportStats($this->account_id, $data_columns, $filters, $start_date, $end_date); $this->completeGroupObj($groups, $creatives, $stats); // build ad_stats $adgroup_stats_report = new AdGroupStatsReport(); foreach ($groups as $group) { $creative = reset($group->creatives); $stats = new AdGroupStats($group->stats, $creative); $stats->refreshValues(); $adgroup_stats_report->addStats($stats); } if ($group_similar_ads) { $reports = new Reports(new StatsGrouper()); $reports->groupBy('body', $adgroup_stats_report); } return $adgroup_stats_report; }
/** * @param array $data * * @return StatsReport */ public function makeHourlyCampaignReport(array $data) { $stats_report = $this->abstractMakeReport($data, '\\ebussola\\ads\\reports\\adwords\\stats\\HourlyCampaignStats'); $this->reports->groupBy('hour', $stats_report); return $stats_report; }