/** * A private method to calculate the operation interval start date at the * upper bound of a range of operation intervals that require a ZIF update, * where the upper bound has been set back by the required number of * operation intervals so that current trends in differences between * forecast and actual delivery can be calculated. * * @access private * @param PEAR::Date $oDate The start date of the operation interval at the * upper bound of the operation interval range * requiring a ZIF update. * @return PEAR::Date The new upper bound date. */ function _getTrendUpperDate($oDate) { $seconds = ZONE_FORECAST_TREND_OFFSET * OX_OperationInterval::secondsPerOperationInterval(); $oDate->subtractSeconds($seconds); return $oDate; }
/** * A method to get all zones that have, within the last week, Zone Impression * Forecast data in the data_summary_zone_impression_history table that is * based on the default forecast, from a given list of zone IDs. * * @param array $aZoneIDs An array of zone IDs. * @param PEAR::Date $oNowDate The current date/time. * @return mixed Either: * - An array of zone IDs, or * - A PEAR::Error. */ function getRecentZones($aZoneIDs, $oNowDate) { $aResult = array(); // Check parameters if (!is_array($aZoneIDs) || is_array($aZoneIDs) && count($aZoneIDs) == 0) { return $aResult; } foreach ($aZoneIDs as $zoneId) { if (!is_integer($zoneId) || $zoneId < 0) { return $aResult; } } if (!is_a($oNowDate, 'Date')) { return $aResult; } // Convert the "now" date into a date range of the last week $aUpperDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oNowDate); $oLowerDate = new Date(); $oLowerDate->copy($aUpperDates['start']); $oLowerDate->subtractSeconds(SECONDS_PER_WEEK - OX_OperationInterval::secondsPerOperationInterval()); // Select those zone IDs where data does exist $table = $this->_getTablename('data_summary_zone_impression_history'); $query = "\n SELECT DISTINCT\n zone_id\n FROM\n {$table}\n WHERE\n zone_id IN (" . implode(', ', $aZoneIDs) . ")\n AND\n est = 1\n AND\n interval_start > " . $this->oDbh->quote($oLowerDate->format('%Y-%m-%d %H:%M:%S'), 'timestamp') . "\n AND\n interval_end <= " . $this->oDbh->quote($aUpperDates['start']->format('%Y-%m-%d %H:%M:%S'), 'timestamp'); $rc = $this->oDbh->query($query); if (PEAR::isError($rc)) { return $rc; } // Add zones found to the result array while ($aRow = $rc->fetchRow()) { $aResult[] = $aRow['zone_id']; } return $aResult; }
/** * A method to return the number of operation intervals * during per day. * * @static * @return integer The number of operation intervals per day. */ function operationIntervalsPerDay() { return SECONDS_PER_DAY / OX_OperationInterval::secondsPerOperationInterval(); }
/** * A method to calculate the number of operation intervals, from a given * date to the end date of the campaign, an advertisement will be blocked * from delivering in. * * @param PEAR::Date $oStartDate A Date object representing the start of the * current operation interval. * @param PEAR::Date $oEndDate A Date object representing the end date of the * campaign the advertisement is in. * @return integer The number of operation intervals in which the advertisement * will be blocked from delivering in. */ function getBlockedOperationIntervalCount($oStartDate, $oEndDate) { // Ensure the campaign end date is at the END of the day $oCampaignEndDate = new Date(); $oCampaignEndDate->copy($oEndDate); $oCampaignEndDate->setHour(23); $oCampaignEndDate->setMinute(59); $oCampaignEndDate->setSecond(59); // Copy the starting date to use in a loop $oLoopDate = new Date(); $oLoopDate->copy($oStartDate); // Count the number of blocked operation intervals $blockedIntervals = 0; while (!$oLoopDate->after($oCampaignEndDate)) { if ($this->deliveryBlocked($oLoopDate)) { // Update the count of blocked intervals, but // also store the start/end dates of the blocked // interval for later use $blockedIntervals++; $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oLoopDate); $this->aBlockedOperationIntervalDates[$aDates['start']->format('%Y-%m-%d %H:%M:%S')] = $aDates; } $oLoopDate->addSeconds(OX_OperationInterval::secondsPerOperationInterval()); } return $blockedIntervals; }