Beispiel #1
0
 /**
  * A method to prune the data_summary_ad_zone_assoc table
  * Pruning can be performed where zone_id = 0 (i.e. for direct selection) and where the entry is older than MAX_PREVIOUS_AD_DELIVERY_INFO_LIMIT minutes ago.
  *
  * @return integer : number of records deleted
  */
 function _pruneDataSummaryAdZoneAssocOldData()
 {
     $doDSAZA = OA_Dal::factoryDO('data_summary_ad_zone_assoc');
     $doDSAZA->whereAdd('zone_id=0', 'AND');
     $doDSAZA->whereAdd('created < DATE_ADD(' . $this->oDbh->quote(OA::getNow()) . ', ' . OA_Dal::quoteInterval(-MAX_PREVIOUS_AD_DELIVERY_INFO_LIMIT, 'SECOND') . ')', 'AND');
     return $doDSAZA->delete(true, false);
 }
Beispiel #2
0
 /**
  * Get all zones forecasts by querying last hour's impressions for each zone
  * This function will look at the hour before the specified OI
  * to determine how much traffic to expected in the specified OI.
  *
  * @param string $intervalStart  Interval start date of OI to forecast
  * @param string $intervalEnd  Interval end date of OI to forecast
  * @return array  array( zoneId => forecastForThisZone, ... )
  */
 public function getZonesForecasts($intervalStart, $intervalEnd)
 {
     OA::debug('  - Selecting Zones forecasts for all managers for OI from ' . $intervalStart . ' to ' . $intervalEnd, PEAR_LOG_INFO);
     $operationInterval = $GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'];
     $oneHourInterval = OA_Dal::quoteInterval(1, 'hour');
     $query = "SELECT\n                      d.zone_id AS zone_id,\n                      sum(impressions) AS impressions,\n                      count(DISTINCT operation_interval_id) as count\n                  FROM\n                  {$this->_getTablename('data_intermediate_ad')} AS d\n                  WHERE\n                          d.operation_interval = '{$operationInterval}'\n                      AND d.date_time < '{$intervalStart}'\n                      AND d.date_time >= DATE_SUB('{$intervalStart}', {$oneHourInterval})\n                  GROUP BY d.zone_id\n                  ORDER BY zone_id\n                  ";
     $rc = $this->oDbh->query($query);
     $aResult = array();
     while ($aRow = $rc->fetchRow()) {
         // we divide by count in the case where we picked up several OIs that last less than one hour
         $aResult[$aRow['zone_id']] = round($aRow['impressions'] / $aRow['count']);
     }
     return $aResult;
 }