Ejemplo n.º 1
0
 /**
  * Test zones performance statistics.
  *
  */
 function testGetZonesPerformanceStatistics()
 {
     $doCampaign1 = null;
     $doCampaign2 = null;
     $doZone1 = null;
     $doZone2 = null;
     $doDataSummaryAdHourly1 = null;
     $doDataSummaryAdHourly2 = null;
     $doDataSummaryAdHourly3 = null;
     $this->_generateDataForPerformanceStatisticsTests($doCampaign1, $doCampaign2, $doZone1, $doZone2, $doDataSummaryAdHourly1, $doDataSummaryAdHourly2, $doDataSummaryAdHourly3);
     // Get statistics for 2 zones
     $aZonesStatistics = $this->_dalZoneStatistics->getZonesPerformanceStatistics(array($doZone1->zoneid, $doZone2->zoneid), null, new Date('2008-04-27'), new Date('2008-05-27'));
     $this->assertTrue(count($aZonesStatistics) == 2, '2 rows should be returned');
     $expectedCTR = round(($doDataSummaryAdHourly1->clicks + $doDataSummaryAdHourly2->clicks) / ($doDataSummaryAdHourly1->impressions + $doDataSummaryAdHourly2->impressions), 4);
     $this->assertEqual($aZonesStatistics[$doZone1->zoneid]['CTR'], $expectedCTR);
     $this->assertEqual($aZonesStatistics[$doZone2->zoneid]['CTR'], round($doDataSummaryAdHourly3->clicks / $doDataSummaryAdHourly3->impressions, 4));
     $expectedECPM = round(($doDataSummaryAdHourly1->total_revenue + $doDataSummaryAdHourly2->total_revenue) * 1000 / ($doDataSummaryAdHourly1->impressions + $doDataSummaryAdHourly2->impressions), 4);
     $this->assertEqual($aZonesStatistics[$doZone1->zoneid]['eCPM'], $expectedECPM);
     $this->assertEqual($aZonesStatistics[$doZone2->zoneid]['eCPM'], round($doDataSummaryAdHourly3->total_revenue * 1000 / $doDataSummaryAdHourly3->impressions, 4));
     $this->assertEqual($aZonesStatistics[$doZone1->zoneid]['CR'], round($doDataSummaryAdHourly1->conversions / $doDataSummaryAdHourly1->impressions, 4));
     $this->assertEqual($aZonesStatistics[$doZone2->zoneid]['CR'], round($doDataSummaryAdHourly3->conversions / $doDataSummaryAdHourly3->impressions, 4));
     // Get statistics for 2 zones - increase impressions threshold to 100000 (only one zone meets requirements)
     $aZonesStatistics = $this->_dalZoneStatistics->getZonesPerformanceStatistics(array($doZone1->zoneid, $doZone2->zoneid), null, new Date('2008-04-27'), new Date('2008-05-27'), 100000);
     $this->assertTrue(count($aZonesStatistics) == 2, '2 rows should be returned');
     $this->assertTrue(count($aZonesStatistics[$doZone1->zoneid]) == 3);
     $this->assertNull($aZonesStatistics[$doZone1->zoneid]['CTR']);
     $this->assertEqual($aZonesStatistics[$doZone2->zoneid]['CTR'], round($doDataSummaryAdHourly3->clicks / $doDataSummaryAdHourly3->impressions, 4));
     $this->assertNull($aZonesStatistics[$doZone1->zoneid]['eCPM']);
     $this->assertEqual($aZonesStatistics[$doZone2->zoneid]['eCPM'], round($doDataSummaryAdHourly3->total_revenue * 1000 / $doDataSummaryAdHourly3->impressions, 4));
     $this->assertNull($aZonesStatistics[$doZone1->zoneid]['CR']);
     $this->assertEqual($aZonesStatistics[$doZone2->zoneid]['CR'], round($doDataSummaryAdHourly3->conversions / $doDataSummaryAdHourly3->impressions, 4));
     // Get statistics - time span <30 days, one zone
     $aZonesStatistics = $this->_dalZoneStatistics->getZonesPerformanceStatistics(array($doZone1->zoneid), null, new Date('2008-05-01'), new Date('2008-05-27'));
     $this->assertTrue(count($aZonesStatistics) == 1, '1 row should be returned');
     $this->assertTrue(count($aZonesStatistics[$doZone1->zoneid]) == 3);
     $this->assertNull($aZonesStatistics[$doZone1->zoneid]['CTR']);
     $this->assertNull($aZonesStatistics[$doZone1->zoneid]['eCPM']);
     $this->assertNull($aZonesStatistics[$doZone1->zoneid]['CR']);
 }
Ejemplo n.º 2
0
 /**
  * Adds statistics data to array of websites and zones ($aWebsitesAndZones)
  *
  * @param array &$aZones array of websites and zones - result of getWebsitesAndZonesList
  * @param int $campaignId campaign Id.
  */
 function mergeStatistics(&$aWebsitesAndZones, $campaignId)
 {
     // Get list of zones IDs
     $aZonesIDs = array();
     $aZonesWebsite = array();
     foreach ($aWebsitesAndZones as $websiteId => $aWebsite) {
         foreach (array_keys($aWebsite['zones']) as $zoneId) {
             $aZonesIDs[] = $zoneId;
             $aZonesWebsite[$zoneId] = $websiteId;
         }
     }
     // Get statistics for zones for this campaign
     $oOaDalStatisticsZone = new OA_Dal_Statistics_Zone();
     $aZoneCampaignStatistics = $oOaDalStatisticsZone->getZonesPerformanceStatistics($aZonesIDs, $campaignId);
     if (isset($campaignId)) {
         // If there are zones that have no statistics for campaign, calculate overall statistics
         $aZoneWithMissingStatsIds = array();
         foreach ($aZonesIDs as $zoneId) {
             if (!isset($aZoneCampaignStatistics[$zoneId]['CTR']) && !isset($aZoneCampaignStatistics[$zoneId]['CR']) && !isset($aZoneCampaignStatistics[$zoneId]['eCPM'])) {
                 $aZoneWithMissingStatsIds[] = $zoneId;
             }
         }
         $aZoneGlobalStatistics = $oOaDalStatisticsZone->getZonesPerformanceStatistics($aZoneWithMissingStatsIds);
     } else {
         // If campaign ID isn't given it means, that overall statistics was calculated
         $aZoneGlobalStatistics = $aZoneCampaignStatistics;
         $aZoneCampaignStatistics = array();
     }
     foreach ($aZonesWebsite as $zoneId => $websiteId) {
         if (isset($aZoneGlobalStatistics[$zoneId])) {
             $aWebsitesAndZones[$websiteId]['zones'][$zoneId]['campaign_stats'] = false;
             $aWebsitesAndZones[$websiteId]['zones'][$zoneId]['ecpm'] = $aZoneGlobalStatistics[$zoneId]['eCPM'];
             $aWebsitesAndZones[$websiteId]['zones'][$zoneId]['cr'] = $aZoneGlobalStatistics[$zoneId]['CR'];
             $aWebsitesAndZones[$websiteId]['zones'][$zoneId]['ctr'] = $aZoneGlobalStatistics[$zoneId]['CTR'];
         } else {
             $aWebsitesAndZones[$websiteId]['zones'][$zoneId]['campaign_stats'] = true;
             $aWebsitesAndZones[$websiteId]['zones'][$zoneId]['ecpm'] = $aZoneCampaignStatistics[$zoneId]['eCPM'];
             $aWebsitesAndZones[$websiteId]['zones'][$zoneId]['cr'] = $aZoneCampaignStatistics[$zoneId]['CR'];
             $aWebsitesAndZones[$websiteId]['zones'][$zoneId]['ctr'] = $aZoneCampaignStatistics[$zoneId]['CTR'];
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Adds statistics data to array of zones ($aZones)
  *
  * @param array &$aZones array of zones - result of getZonesListByCategory
  * @param int $campaignId campaign Id.
  */
 function _getStatistics(&$aZones, $campaignId)
 {
     // Get list of zones IDs
     $aZonesIDs = array();
     foreach ($aZones as $k => $aZone) {
         $aZonesIDs[] = $aZone['zoneid'];
     }
     // Get statistics for zones for this campaign
     $oOaDalStatisticsZone = new OA_Dal_Statistics_Zone();
     $aZoneCampaignStatistics = $oOaDalStatisticsZone->getZonesPerformanceStatistics($aZonesIDs, $campaignId);
     if (!is_null($campaignId)) {
         // If there are zones that have no statistics for campaign, calculate overall statistics
         $aZoneWithMissingStatsIds = array();
         foreach ($aZones as $k => $aZone) {
             if (is_null($aZoneCampaignStatistics[$aZone['zoneid']]['CTR']) && is_null($aZoneCampaignStatistics[$aZone['zoneid']]['CR']) && is_null($aZoneCampaignStatistics[$aZone['zoneid']]['eCPM'])) {
                 $aZoneWithMissingStatsIds[] = $aZone['zoneid'];
             }
         }
         $aZoneGlobalStatistics = $oOaDalStatisticsZone->getZonesPerformanceStatistics($aZoneWithMissingStatsIds);
     } else {
         // If campaign ID isn't given it means, that overall statistics was calculated
         $aZoneGlobalStatistics = $aZoneCampaignStatistics;
         $aZoneCampaignStatistics = array();
     }
     foreach ($aZones as $k => $aZone) {
         $zoneid = $aZones[$k]['zoneid'];
         if (array_key_exists($aZones[$k]['zoneid'], $aZoneGlobalStatistics)) {
             $aZones[$k]['campaign_stats'] = false;
             $aZones[$k]['ecpm'] = $aZoneGlobalStatistics[$zoneid]['eCPM'];
             $aZones[$k]['cr'] = $aZoneGlobalStatistics[$zoneid]['CR'];
             $aZones[$k]['ctr'] = $aZoneGlobalStatistics[$zoneid]['CTR'];
         } else {
             $aZones[$k]['campaign_stats'] = true;
             $aZones[$k]['ecpm'] = $aZoneCampaignStatistics[$zoneid]['eCPM'];
             $aZones[$k]['cr'] = $aZoneCampaignStatistics[$zoneid]['CR'];
             $aZones[$k]['ctr'] = $aZoneCampaignStatistics[$zoneid]['CTR'];
         }
     }
 }