本文整理汇总了PHP中OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates方法的典型用法代码示例。如果您正苦于以下问题:PHP OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates方法的具体用法?PHP OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates怎么用?PHP OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OX_OperationInterval
的用法示例。
在下文中一共展示了OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkDates
/**
* Check start/end dates - note that check is the reverse of normal check:
* if the operation interval is <= 60, must be start/end of an hour, to
* make sure we update all the operation intervals in the hour, and if
* the operation interval > 60, must be the start/end of an operation
* interval, to make sure we update all the hours in the operation interval.
*
* @static
* @param Date $oStartDate
* @param Date $oEndDate
* @return boolean
*/
function checkDates($oStartDate, $oEndDate)
{
$aConf = $GLOBALS['_MAX']['CONF'];
$operationInterval = $aConf['maintenance']['operation_interval'];
if ($operationInterval <= 60) {
// Must ensure that only one hour is being summarised
if (!OX_OperationInterval::checkDatesInSameHour($oStartDate, $oEndDate)) {
return false;
}
// Now check that the start and end dates are match the start and
// end of the hour
$oHourStart = new Date();
$oHourStart->setYear($oStartDate->getYear());
$oHourStart->setMonth($oStartDate->getMonth());
$oHourStart->setDay($oStartDate->getDay());
$oHourStart->setHour($oStartDate->getHour());
$oHourStart->setMinute('00');
$oHourStart->setSecond('00');
$oHourEnd = new Date();
$oHourEnd->setYear($oEndDate->getYear());
$oHourEnd->setMonth($oEndDate->getMonth());
$oHourEnd->setDay($oEndDate->getDay());
$oHourEnd->setHour($oEndDate->getHour());
$oHourEnd->setMinute('59');
$oHourEnd->setSecond('59');
if (!$oStartDate->equals($oHourStart)) {
return false;
}
if (!$oEndDate->equals($oHourEnd)) {
return false;
}
} else {
// Must ensure that only one operation interval is being summarised
$operationIntervalID = OX_OperationInterval::convertDaySpanToOperationIntervalID($oStartDate, $oEndDate, $operationInterval);
if (is_bool($operationIntervalID) && !$operationIntervalID) {
return false;
}
// Now check that the start and end dates match the start and end
// of the operation interval
list($oOperationIntervalStart, $oOperationIntervalEnd) = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oStartDate, $operationInterval);
if (!$oStartDate->equals($oOperationIntervalStart)) {
return false;
}
if (!$oEndDate->equals($oOperationIntervalEnd)) {
return false;
}
}
return true;
}
示例2: getDailyTargetingStatistics
/**
* A method for obtaining the targeting statistics of an ad or placement
* for a single day, where the data is summarised by operation interval.
*
* @param integer $id The ad or placement ID.
* @param string $type Either "ad" or "placement".
* @param PEAR::Date $oDate A date representing the day required.
*
* @return mixed Returns false in the event of incorrect input, or in the case
* of being unable to connect to the database, otherwise, returns
* an array of arrays:
*
*
* array(
* [$operationIntervalId] => array(
* ['interval_start'] => PEAR::Date
* ['interval_end'] => PEAR::Date
* ['ad_required_impressions'] => integer
* ['ad_requested_impressions'] => integer
* ['ad_actual_impressions'] => integer
* ['zones_forecast_impressions'] => integer
* ['zones_actual_impressions'] => integer
* ['average'] => integer
* )
* .
* .
* .
* )
*
* or:
*
* array(
* [$operationIntervalId] => array(
* ['interval_start'] => PEAR::Date
* ['interval_end'] => PEAR::Date
* ['placement_required_impressions'] => integer
* ['placement_requested_impressions'] => integer
* ['placement_actual_impressions'] => integer
* ['zones_forecast_impressions'] => integer
* ['zones_actual_impressions'] => integer
* ['average'] => integer
* )
* .
* .
* .
* )
*
* For the ad or placement and day specified, returns an array for each
* operation interval in the day, consisting of the operation interval start
* and end dates, and the total number of impressions requested by the ad, or
* all ads in the placement (for all zones the ads are linked to), as well as
* the total number of impressions actually delivered by the ad, or all ads
* in the placement (for all zones the ads are linked to).
*
* The individual ad/zone impressions requested values may need to be
* calculated as an "averge" value, in the event that there are multiple,
* differing values for an ad in a zone for an operation interval -- in
* much the same way as is done in
* OA_Dal_Maintenance_Priority::getPreviousAdDeliveryInfo() -- before
* the total impressions requested value can be calculated.
*/
function getDailyTargetingStatistics($id, $type, $oDate)
{
if (!$this->_testGetTargetingStatisticsDayParameters($id, $type, $oDate)) {
return false;
}
// Ensure that, if a placement, the placement has advertisements
$aAdIds = $this->_testGetTargetingStatisticsSpanPlacement($id, $type);
if ($aAdIds === false) {
return false;
}
// Prepare the results array
$aResult = array();
// Get a date for the start of the day
$oStartDate = new Date();
$oStartDate->copy($oDate);
$oStartDate->setHour(0);
$oStartDate->setMinute(0);
$oStartDate->setSecond(0);
// Get a date for the end of the day
$oEndOfDayDate = new Date();
$oEndOfDayDate->copy($oDate);
$oEndOfDayDate->setHour(23);
$oEndOfDayDate->setMinute(59);
$oEndOfDayDate->setSecond(59);
// Get the first operation interval of the day
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oStartDate);
// Get dates to be used in date comparisons
$oCompareDate = new Date();
$oCompareDate->copy($aDates['start']);
$oCompareEndDate = new Date();
$oCompareEndDate->copy($oEndOfDayDate);
while ($oCompareDate->before($oEndOfDayDate)) {
// Get the operation interval ID
$operationIntervalId = OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']);
// Get the results for this operation interval
$aResult[$operationIntervalId] = $this->getOperationIntervalTargetingStatistics($aAdIds, $type, $aDates['start'], $aDates['end']);
if ($aResult[$operationIntervalId] === false) {
return false;
}
//.........这里部分代码省略.........
示例3: _getOperationIntervalInfo
function _getOperationIntervalInfo(&$operationIntervalId, &$operationInterval, &$dateStart, &$dateEnd)
{
$date = new Date();
$operationInterval = new OX_OperationInterval();
$operationIntervalId = $operationInterval->convertDateToOperationIntervalID($date);
$operationInterval = OX_OperationInterval::getOperationInterval();
$aOperationIntervalDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($date);
$dateStart = DBC::makeLiteral($aOperationIntervalDates['start']->format(TIMESTAMP_FORMAT));
$dateEnd = DBC::makeLiteral($aOperationIntervalDates['end']->format(TIMESTAMP_FORMAT));
}
示例4: testGetAdLifetimeZoneImpressionsRemaining
/**
* A method to test the getAdLifetimeZoneImpressionsRemaining() method.
*
* Test 1: Test with invalid parameters, and ensure that zero is returned.
* Test 2: Test with equal start and end dates, and ensure just that OI's
* data is returned.
* Test 3: Test with a small range of dates in one week, that the correct
* sum is returned.
* Test 4: Test with a small range of dates over three days, covering two
* weeks, and ensure that the correct result is returned.
* Test 5: Test with a limitation that blocks less than 50% of the remaining
* range, and ensure that the correct result is returned.
* Test 6: Test with a limitation that blocks more than 50% of the remaining
* range, and ensure that the correct result is returned.
*/
function testGetAdLifetimeZoneImpressionsRemaining()
{
$aConf =& $GLOBALS['_MAX']['CONF'];
$aConf['maintenance']['operationInterval'] = 60;
$aDeliveryLimitations = array();
$oDeliveryLimitationManager = new OA_Maintenance_Priority_DeliveryLimitation($aDeliveryLimitations);
// Test 1
$oDate = new Date('2006-02-15 11:07:15');
$aCumulativeZoneForecast = array();
$aCumulativeZoneForecast = $this->_fillForecastArray($aCumulativeZoneForecast);
$result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining('foo', $oDate, $aCumulativeZoneForecast);
$this->assertEqual($result, 0);
$result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining($oDate, 'foo', $aCumulativeZoneForecast);
$this->assertEqual($result, 0);
$result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining($oDate, $oDate, 'foo');
$this->assertEqual($result, 0);
// Test 2
$oDate = new Date('2006-02-15 23:07:15');
$aCumulativeZoneForecast = array();
$aCumulativeZoneForecast = $this->_fillForecastArray($aCumulativeZoneForecast);
$result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining($oDate, $oDate, $aCumulativeZoneForecast);
$this->assertEqual($result, 1);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']);
$aCumulativeZoneForecast[$operationIntervalID] = 50;
$previousOperationIntervalId = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
$aCumulativeZoneForecast[$previousOperationIntervalId] = 5;
$nextOperationIntervalId = OX_OperationInterval::nextOperationIntervalID($operationIntervalID);
$aCumulativeZoneForecast[$nextOperationIntervalId] = 7;
$aCumulativeZoneForecast = $this->_fillForecastArray($aCumulativeZoneForecast);
$result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining($oDate, $oDate, $aCumulativeZoneForecast);
$this->assertEqual($result, 50);
// Test 3
$oStartDate = new Date('2006-02-15 11:07:15');
$oEndDate = new Date('2006-02-15 23:59:59');
$aCumulativeZoneForecast = array();
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-15 10:00:01'));
$aCumulativeZoneForecast[$operationIntervalID] = 1;
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-15 11:00:01'));
$aCumulativeZoneForecast[$operationIntervalID] = 10;
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-15 12:00:01'));
$aCumulativeZoneForecast[$operationIntervalID] = 100;
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-15 13:00:01'));
$aCumulativeZoneForecast[$operationIntervalID] = 1000;
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-15 14:00:01'));
$aCumulativeZoneForecast[$operationIntervalID] = 10000;
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-15 15:00:01'));
$aCumulativeZoneForecast[$operationIntervalID] = 100000;
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-15 16:00:01'));
$aCumulativeZoneForecast[$operationIntervalID] = 1000000;
$aCumulativeZoneForecast = $this->_fillForecastArray($aCumulativeZoneForecast);
$result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining($oStartDate, $oEndDate, $aCumulativeZoneForecast);
$this->assertEqual($result, 1111110 + 7);
// Test 4
$oStartDate = new Date('2006-02-18 22:07:15');
$oEndDate = new Date('2006-02-20 23:59:59');
$aCumulativeZoneForecast = array();
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-18 21:00:01'));
$aCumulativeZoneForecast[$operationIntervalID] = 1;
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-18 22:00:01'));
$aCumulativeZoneForecast[$operationIntervalID] = 10;
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-18 23:00:01'));
$aCumulativeZoneForecast[$operationIntervalID] = 100;
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-19 00:00:01'));
$aCumulativeZoneForecast[$operationIntervalID] = 1000;
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-19 01:00:01'));
$aCumulativeZoneForecast[$operationIntervalID] = 10000;
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-19 02:00:01'));
$aCumulativeZoneForecast[$operationIntervalID] = 100000;
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-19 03:00:01'));
$aCumulativeZoneForecast[$operationIntervalID] = 1000000;
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-19 04:00:01'));
$aCumulativeZoneForecast[$operationIntervalID] = 10000000;
$aCumulativeZoneForecast = $this->_fillForecastArray($aCumulativeZoneForecast);
$result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining($oStartDate, $oEndDate, $aCumulativeZoneForecast);
$this->assertEqual($result, 110 + 11111000 + 19 + 24);
// Test 5
$oStartDate = new Date('2006-02-07 12:07:15');
$oEndDate = new Date('2006-02-07 23:59:59');
$aDeliveryLimitations = array(array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Hour', 'comparison' => '!~', 'data' => '23', 'executionorder' => 0));
$oDeliveryLimitationManager = new OA_Maintenance_Priority_DeliveryLimitation($aDeliveryLimitations);
$oDeliveryLimitationManager->getActiveAdOperationIntervals(12, $oStartDate, $oEndDate);
$aCumulativeZoneForecast = array();
$aCumulativeZoneForecast = $this->_fillForecastArray($aCumulativeZoneForecast);
$result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining($oStartDate, $oEndDate, $aCumulativeZoneForecast);
//.........这里部分代码省略.........
示例5: testGetAllZonesImpInv
/**
* Method to test the getZonesForecastsForAllZones method.
*
* Requirements:
* Test 1: Test with no Date registered in the service locator, ensure false returned.
* Test 2: Test with a Date registered in the service locator, no data in the database,
* and ensure no data is returned.
* Test 3: Test with forecast data but no actual impressions
* Test 3.5: Test with actual data but no forecast impressions
* Test 4: Test with data both in, and not in, the current OI, and ensure the correct
* data is returned.
* Test 5: Repeat Test 4, but with additional zones (that don't have data) in the zones
* table.
*/
function testGetAllZonesImpInv()
{
$conf = $GLOBALS['_MAX']['CONF'];
$oDbh =& OA_DB::singleton();
$oMaxDalMaintenance = new OA_Dal_Maintenance_Priority();
$zoneForecastDefaultZoneImpressions = 0;
// $oMaxDalMaintenance->getZoneForecastDefaultZoneImpressions();
// Test 1
$oServiceLocator =& OA_ServiceLocator::instance();
$oServiceLocator->remove('now');
$result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
$this->assertFalse($result);
// Test 2
$oDate = new Date();
$oServiceLocator->register('now', $oDate);
$result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
$this->assertEqual($result, array(0 => $zoneForecastDefaultZoneImpressions));
// Zone 0
// Test 3
// generate the first zone
$aZones = $this->_generateTestZones(1);
// only generate previous OI delivered impressions, should return zone 0 only
$oDate =& $oServiceLocator->get('now');
$oNewDate = new Date();
$oNewDate->copy($oDate);
$oNewDate->subtractSeconds($conf['maintenance']['operationInterval'] * 60 + 1);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oNewDate);
$this->_generateTestHistory(1, $aDates, 42, 0);
$result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
$expected = array(0 => $zoneForecastDefaultZoneImpressions, 1 => $zoneForecastDefaultZoneImpressions);
$this->assertEqual($result, $expected);
// Test 3.5
// generate the second zone
$aZones = $this->_generateTestZones(1);
// only generate previous OI forecasted impressions, should return zone 0 only
$oNewDate = new Date();
$oNewDate->copy($aDates['start']);
$oNewDate->subtractSeconds(1);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oNewDate);
$this->_generateTestHistory(2, $aDates, 0, 37);
$result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
$expected = array(0 => $zoneForecastDefaultZoneImpressions, 1 => $zoneForecastDefaultZoneImpressions, 2 => $zoneForecastDefaultZoneImpressions);
$this->assertEqual($result, $expected);
$oDate =& $oServiceLocator->get('now');
DataGenerator::cleanUp();
$oServiceLocator->register('now', $oDate);
// Test 4
$oDate =& $oServiceLocator->get('now');
// generate three zone
$this->_generateTestZones(3);
// set forecast and impressions for OI - 1
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
$this->_generateTestHistory(1, $aDates, 42, 100);
$this->_generateTestHistory(2, $aDates, 5, 2);
$this->_generateTestHistory(3, $aDates, 9999, 9999);
$result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
$expected = array(0 => $zoneForecastDefaultZoneImpressions, 1 => 42, 2 => 5, 3 => 9999);
$this->assertEqual($result, $expected);
// Test 5
// New zone must appear in the array with default forecast
$aZones = $this->_generateTestZones(1);
$result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
$expected = array(0 => $zoneForecastDefaultZoneImpressions, 1 => 42, 2 => 5, 3 => 9999, 4 => $zoneForecastDefaultZoneImpressions);
$result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
$this->assertEqual($result, $expected);
// register forecast for the OI before, this should not affect current OI forecast
$oDate =& $oServiceLocator->get('now');
$aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
$currentOpIntID = OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']);
$this->_generateTestHistory(1, $aDates, 3700, 0);
$this->_generateTestHistory(2, $aDates, 300, 0);
$this->_generateTestHistory(3, $aDates, 500, 0);
$result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
$this->assertEqual($result, $expected);
DataGenerator::cleanUp();
}
开发者ID:Spark-Eleven,项目名称:revive-adserver,代码行数:90,代码来源:Priority_getZonesForecastsForAllZones.dal.test.php
示例6: test_MAX_Delivery_log_logConversion
/**
* A method to test the MAX_Delivery_log_logConversion() function.
*/
function test_MAX_Delivery_log_logConversion()
{
$aConf =& $GLOBALS['_MAX']['CONF'];
$aConf['maintenance']['operationInterval'] = 60;
$GLOBALS['_MAX']['NOW'] = time();
$oNowDate = new Date($GLOBALS['_MAX']['NOW']);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oNowDate);
$intervalStart = $aDates['start']->format('%Y-%m-%d %H:%M:%S');
$oConversionDate = new Date();
$oConversionDate->copy($oNowDate);
$oConversionDate->subtractSeconds(60);
$_SERVER['REMOTE_ADDR'] = '127.0.0.99';
// Test to ensure that the openXDeliveryLog plugin's data bucket
// table does not exist
$oTable = new OA_DB_Table();
$tableExists = $oTable->extistsTable($aConf['table']['prefix'] . 'data_bkt_a');
$this->assertFalse($tableExists);
// Test calling the main logging function without any plugins installed,
// to ensure that this does not result in any kind of error
$aConversion = array('action_type' => MAX_CONNECTION_AD_CLICK, 'tracker_type' => MAX_CONNECTION_TYPE_SALE, 'status' => MAX_CONNECTION_STATUS_APPROVED, 'cid' => 2, 'zid' => 3, 'dt' => $GLOBALS['_MAX']['NOW'] - 60, 'window' => 60);
MAX_Delivery_log_logConversion(1, $aConversion);
// Install the openXDeliveryLog plugin
TestEnv::installPluginPackage('openXDeliveryLog', false);
// Test to ensure that the openXDeliveryLog plugin's data bucket
// table now does exist
$tableExists = $oTable->extistsTable($aConf['table']['prefix'] . 'data_bkt_a');
$this->assertTrue($tableExists);
// Ensure that there are is nothing logged in the data bucket table
$doData_bkt_a = OA_Dal::factoryDO('data_bkt_a');
$doData_bkt_a->find();
$rows = $doData_bkt_a->getRowCount();
$this->assertEqual($rows, 0);
// Call the conversion logging function
$aConversionInfo = MAX_Delivery_log_logConversion(1, $aConversion);
// Ensure that the data was logged correctly
$doData_bkt_a = OA_Dal::factoryDO('data_bkt_a');
$doData_bkt_a->find();
$rows = $doData_bkt_a->getRowCount();
$this->assertEqual($rows, 1);
$doData_bkt_a = OA_Dal::factoryDO('data_bkt_a');
$doData_bkt_a->server_conv_id = 1;
$doData_bkt_a->find();
$rows = $doData_bkt_a->getRowCount();
$this->assertEqual($rows, 1);
$doData_bkt_a->fetch();
$this->assertEqual($doData_bkt_a->server_ip, 'singleDB');
$this->assertEqual($doData_bkt_a->tracker_id, 1);
$this->assertEqual($doData_bkt_a->date_time, $oNowDate->format('%Y-%m-%d %H:%M:%S'));
$this->assertEqual($doData_bkt_a->action_date_time, $oConversionDate->format('%Y-%m-%d %H:%M:%S'));
$this->assertEqual($doData_bkt_a->creative_id, 2);
$this->assertEqual($doData_bkt_a->zone_id, 3);
$this->assertEqual($doData_bkt_a->ip_address, '127.0.0.99');
$this->assertEqual($doData_bkt_a->action, MAX_CONNECTION_AD_CLICK);
$this->assertEqual($doData_bkt_a->window, 60);
$this->assertEqual($doData_bkt_a->status, MAX_CONNECTION_STATUS_APPROVED);
$this->assertTrue(is_array($aConversionInfo));
$this->assertTrue(is_array($aConversionInfo['deliveryLog:oxLogConversion:logConversion']));
$this->assertEqual($aConversionInfo['deliveryLog:oxLogConversion:logConversion']['server_conv_id'], 1);
$this->assertEqual($aConversionInfo['deliveryLog:oxLogConversion:logConversion']['server_raw_ip'], 'singleDB');
$aConversion['cid'] = 5;
// Call the conversion logging function
$aConversionInfo = MAX_Delivery_log_logConversion(1, $aConversion);
// Ensure that the data was logged correctly
$doData_bkt_a = OA_Dal::factoryDO('data_bkt_a');
$doData_bkt_a->find();
$rows = $doData_bkt_a->getRowCount();
$this->assertEqual($rows, 2);
$doData_bkt_a = OA_Dal::factoryDO('data_bkt_a');
$doData_bkt_a->server_conv_id = 1;
$doData_bkt_a->find();
$rows = $doData_bkt_a->getRowCount();
$this->assertEqual($rows, 1);
$doData_bkt_a->fetch();
$this->assertEqual($doData_bkt_a->server_ip, 'singleDB');
$this->assertEqual($doData_bkt_a->tracker_id, 1);
$this->assertEqual($doData_bkt_a->date_time, $oNowDate->format('%Y-%m-%d %H:%M:%S'));
$this->assertEqual($doData_bkt_a->action_date_time, $oConversionDate->format('%Y-%m-%d %H:%M:%S'));
$this->assertEqual($doData_bkt_a->creative_id, 2);
$this->assertEqual($doData_bkt_a->zone_id, 3);
$this->assertEqual($doData_bkt_a->ip_address, '127.0.0.99');
$this->assertEqual($doData_bkt_a->action, MAX_CONNECTION_AD_CLICK);
$this->assertEqual($doData_bkt_a->window, 60);
$this->assertEqual($doData_bkt_a->status, MAX_CONNECTION_STATUS_APPROVED);
$doData_bkt_a = OA_Dal::factoryDO('data_bkt_a');
$doData_bkt_a->server_conv_id = 2;
$doData_bkt_a->find();
$rows = $doData_bkt_a->getRowCount();
$this->assertEqual($rows, 1);
$doData_bkt_a->fetch();
$this->assertEqual($doData_bkt_a->server_ip, 'singleDB');
$this->assertEqual($doData_bkt_a->tracker_id, 1);
$this->assertEqual($doData_bkt_a->date_time, $oNowDate->format('%Y-%m-%d %H:%M:%S'));
$this->assertEqual($doData_bkt_a->action_date_time, $oConversionDate->format('%Y-%m-%d %H:%M:%S'));
$this->assertEqual($doData_bkt_a->creative_id, 5);
$this->assertEqual($doData_bkt_a->zone_id, 3);
$this->assertEqual($doData_bkt_a->ip_address, '127.0.0.99');
$this->assertEqual($doData_bkt_a->action, MAX_CONNECTION_AD_CLICK);
//.........这里部分代码省略.........
示例7: pruneBucket
/**
* A method to prune a bucket of all records up to and
* including the time given.
*
* @param Date $oEnd Prune until this interval_start (inclusive).
* @param Date $oStart Only prune before this interval_start date (inclusive)
* as well. Optional.
* @return mixed Either the number of rows pruned, or an MDB2_Error objet.
*/
public function pruneBucket($oBucket, $oEnd, $oStart = null)
{
$sTableName = $oBucket->getBucketTableName();
if (!is_null($oStart)) {
OA::debug(' - Pruning the ' . $sTableName . ' table for data with operation interval start between ' . $oStart->format('%Y-%m-%d %H:%M:%S') . ' ' . $oStart->tz->getShortName() . ' and ' . $oEnd->format('%Y-%m-%d %H:%M:%S') . ' ' . $oEnd->tz->getShortName(), PEAR_LOG_DEBUG);
} else {
OA::debug(' - Pruning the ' . $sTableName . ' table for all data with operation interval start equal to or before ' . $oEnd->format('%Y-%m-%d %H:%M:%S') . ' ' . $oEnd->tz->getShortName(), PEAR_LOG_DEBUG);
}
// As this is raw data being processed, data will not be logged based on the operation interval,
// but based on the time the raw data was collected. Adjust the $oEnd value accordingly...
if (!is_null($oStart)) {
$aStartDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oStart);
}
$aEndDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oEnd);
OA::debug(' - The ' . $sTableName . ' table is a raw data table. Data logged in real-time, not operation intervals.', PEAR_LOG_INFO);
if (!is_null($oStart)) {
OA::debug(' - Accordingly, pruning of the ' . $sTableName . ' table will be performed based on data that has a logged date between ', PEAR_LOG_INFO);
OA::debug(' ' . $aStartDates['start']->format('%Y-%m-%d %H:%M:%S') . ' ' . $aStartDates['start']->tz->getShortName() . ' and ' . $aEndDates['end']->format('%Y-%m-%d %H:%M:%S') . ' ' . $aEndDates['end']->tz->getShortName(), PEAR_LOG_INFO);
} else {
OA::debug(' - Accordingly, pruning of the ' . $sTableName . ' table will be performed based on data that has a logged date equal to', PEAR_LOG_INFO);
OA::debug(' or before ' . $aEndDates['end']->format('%Y-%m-%d %H:%M:%S') . ' ' . $aEndDates['end']->tz->getShortName(), PEAR_LOG_INFO);
}
$query = "\n DELETE FROM\n {$sTableName}\n WHERE\n date_time <= " . DBC::makeLiteral($aEndDates['end']->format('%Y-%m-%d %H:%M:%S'));
if (!is_null($oStart)) {
$query .= "\n AND\n date_time >= " . DBC::makeLiteral($aStartDates['start']->format('%Y-%m-%d %H:%M:%S'));
}
$oDbh = OA_DB::singleton();
return $oDbh->exec($query);
}
示例8: checkIntervalDates
/**
* A method to check that two Dates represent either the start and end
* of an operation interval, if the operation interval is less than an
* hour, or the start and end of an hour otherwise.
*
* @static
* @param Date $oStart The interval start date.
* @param Date $oEnd The interval end date.
* @param integer $operationInterval The operation interval in minutes.
* @return bool Returns true if the dates are correct interval
* start/end dates, false otherwise.
*/
function checkIntervalDates($oStart, $oEnd, $operationInterval = 0)
{
if ($operationInterval < 1) {
$operationInterval = OX_OperationInterval::getOperationInterval();
}
if ($operationInterval <= 60) {
// Must ensure that only one operation interval is being summarised
$operationIntervalID = OX_OperationInterval::convertDateRangeToOperationIntervalID($oStart, $oEnd, $operationInterval);
if (is_bool($operationIntervalID) && !$operationIntervalID) {
return false;
}
// Now check that the start and end dates match the start and end
// of the operation interval
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oStart, $operationInterval);
if (!$oStart->equals($aDates['start'])) {
return false;
}
if (!$oEnd->equals($aDates['end'])) {
return false;
}
} else {
// Must ensure that only one hour is being summarised
if (!OX_OperationInterval::checkDatesInSameHour($oStart, $oEnd)) {
return false;
}
// Now check that the start and end dates are match the start and
// end of the hour
$oHourStart = new Date();
$oHourStart->copy($oStart);
$oHourStart->setMinute('00');
$oHourStart->setSecond('00');
$oHourEnd = new Date();
$oHourEnd->copy($oEnd);
$oHourEnd->setMinute('59');
$oHourEnd->setSecond('59');
if (!$oStart->equals($oHourStart)) {
return false;
}
if (!$oEnd->equals($oHourEnd)) {
return false;
}
}
return true;
}
示例9: getAdConversionsLeft
/**
* A method to determine the lifetime ad conversions left before expiration.
*
* @param integer $campaignId The campaign ID.
* @param PEAR::Date $oDate An optional date. If present, sets an upper
* date boundary of the end of the operation
* interval the date is in to limit the delivery
* statistics used in determining how many
* conversions have delivered. Can be used to
* determine the the lifetime ad conversions left
* before expiration at a previous time.
* @return mixed The number of ad conversions remaining, or the
* string "unlimited".
*/
function getAdConversionsLeft($campaignId, $oDate = null)
{
global $strUnlimited;
$prefix = $this->getTablePrefix();
// Get the campaign info
$doCampaigns = OA_Dal::factoryDO('campaigns');
$doCampaigns->get($campaignId);
$aData = $doCampaigns->toArray();
if ($aData['clicks'] > 0) {
// Get the campaign delivery info
if (!is_null($oDate)) {
// Get the end of operation interval the date represents
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
$oDate = $aDates['end'];
}
$dalDataIntermediateAd = OA_Dal::factoryDAL('data_intermediate_ad');
$record = $dalDataIntermediateAd->getDeliveredByCampaign($campaignId, $oDate);
$aDeliveryData = $record->toArray();
return $aData['conversions'] - $aDeliveryData['conversions_delivered'];
} else {
return $strUnlimited;
}
}
示例10: getPreviousWeekZoneForcastImpressions
/**
* A method to return the forcast impressions for a zone, indexed by operation interval,
* from the current operation interval through the past week. If no forecast stored in
* the database, uses the defualt value from the configuration file.
*
* @param integer $zoneId The Zone ID.
* @return mixed An array on success, false on failure. The array is of the format:
* array(
* [operation_interval_id] => array(
* ['zone_id'] => zone_id,
* ['forecast_impressions'] => forecast_impressions,
* ['operation_interval_id'] => operation_interval_id
* )
* [operation_interval_id] => array(
* ['zone_id'] => zone_id,
* ['forecast_impressions'] => forecast_impressions,
* ['operation_interval_id'] => operation_interval_id
* )
* .
* .
* .
* )
*/
function getPreviousWeekZoneForcastImpressions($zoneId)
{
if (empty($zoneId) || !is_numeric($zoneId)) {
OA::debug('Invalid zone ID argument', PEAR_LOG_ERR);
return false;
}
$aConf = $GLOBALS['_MAX']['CONF'];
$oServiceLocator =& OA_ServiceLocator::instance();
$oDate =& $oServiceLocator->get('now');
if (!$oDate) {
return false;
}
// Get the start and end ranges of the current week
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
$oDateWeekStart = new Date();
$oDateWeekStart->copy($aDates['end']);
$oDateWeekStart->subtractSeconds(SECONDS_PER_WEEK - 1);
$oDateWeekEnd = new Date();
$oDateWeekEnd->copy($aDates['end']);
// Select the zone forecasts from the database
$tableName = $this->_getTablename('data_summary_zone_impression_history');
$query = "\n SELECT\n zone_id AS zone_id,\n forecast_impressions AS forecast_impressions,\n operation_interval_id AS operation_interval_id,\n interval_start AS interval_start,\n interval_end AS interval_end\n FROM\n {$tableName}\n WHERE\n zone_id = {$zoneId}\n AND operation_interval = {$aConf['maintenance']['operationInterval']}\n AND interval_start >= '" . $oDateWeekStart->format('%Y-%m-%d %H:%M:%S') . "'\n AND interval_end <= '" . $oDateWeekEnd->format('%Y-%m-%d %H:%M:%S') . "'\n AND zone_id != 0\n ORDER BY\n interval_start";
$rc = $this->oDbh->query($query);
if (!PEAR::isError($rc)) {
// Sort the results into an array indexed by the operation interval ID
$aFinalResult = array();
while ($aRow = $rc->fetchRow()) {
$aFinalResult[$aRow['operation_interval_id']] = array('zone_id' => $aRow['zone_id'], 'forecast_impressions' => $aRow['forecast_impressions'], 'operation_interval_id' => $aRow['operation_interval_id']);
}
}
// Check each operation interval ID has a forecast impression value,
// and if not, set to the system default.
for ($operationIntervalID = 0; $operationIntervalID < OX_OperationInterval::operationIntervalsPerWeek(); $operationIntervalID++) {
if (!isset($aFinalResult[$operationIntervalID])) {
$aFinalResult[$operationIntervalID] = array('zone_id' => $zoneId, 'forecast_impressions' => ZONE_FORECAST_DEFAULT_ZONE_IMPRESSIONS, 'operation_interval_id' => $operationIntervalID);
}
}
return $aFinalResult;
}
示例11: getProcessLastRunInfo
/**
* A method to return data about the times that various Maintenance
* processes ran.
*
* @param string $tableName The name of the log_maintenance_* table to get data from.
* Must be a complete table name, including prefix, if
* required.
* @param array $aAdditionalFields An array of strings, representing any additional
* data fields to return, along with the default
* 'updated_to' field.
* @param string $whereClause Optional string, containing a valid SQL WHERE clause,
* if this is required to limit the results of the log data
* before ordering and returning.
* @param string $orderBy Optional string to specify the DB field used to sort the data
* into DESCENDING order, before selecting the first value. Default
* is 'start_run'.
* @param array $aAlternateInfo Optional array containing two fields, 'tableName', which
* is a string of the name of a raw table which will be searched
* for the earliest date/time, in the event that no valid
* 'updated_to' field could be found in the main table, and 'type',
* which is a string of either value 'oi' or 'hour'. The returned
* 'updated_to' value will either be the end of the operation
* interval (if 'type' is 'oi') or the end of the hour (if 'type'
* is 'hour') prior to any date/time found in the alternate raw
* table. Note that if the alternate raw table is used, then ONLY
* the 'updated_to' value is returned - any $aAdditionalFields
* values will be ignored.
* @return mixed False on error, null no no result, otherwise, an array containing the
* 'updated_to' field, which represents the time that the Maintenance
* process last completed updating data until, as well as any additional
* fields (see $aAdditionalFields parameter), unless the alternate raw table
* was used (see $alternateRawTableName parameter).
*/
function getProcessLastRunInfo($tableName, $aAdditionalFields = array(), $whereClause = null, $orderBy = 'start_run', $aAlternateInfo = array())
{
$aConf = $GLOBALS['_MAX']['CONF'];
// Test input values $aAdditionalFields and $aAlternateInfo are arrays
if (!is_array($aAdditionalFields) || !is_array($aAlternateInfo)) {
return false;
}
$query = "\n SELECT\n updated_to";
if (!empty($aAdditionalFields)) {
$query .= ', ' . implode(', ', $aAdditionalFields);
}
$tableName = $this->_getTablename($tableName);
$query .= "\n FROM\n {$tableName}";
if (!is_null($whereClause)) {
$query .= "\n {$whereClause}";
}
$query .= "\n ORDER BY {$orderBy} DESC\n LIMIT 1";
OA::debug('- Obtaining maintenance process run information from ' . $tableName, PEAR_LOG_DEBUG);
$rc = $this->oDbh->query($query);
if (PEAR::isError($rc)) {
return false;
}
$aResult = $rc->fetchRow();
if (!is_null($aResult)) {
// The process run information was found, return.
return $aResult;
}
if (!empty($aAlternateInfo['tableName']) && !empty($aAlternateInfo['type'])) {
// No result was found above, and an alternate raw table was specified,
// so search the raw table to see if a valid result can be generated
// on the basis of the earliest raw data value
$tableName = $this->_getTablename($aAlternateInfo['tableName']);
$query = "\n SELECT\n date_time AS date\n FROM\n {$tableName}\n ORDER BY date ASC\n LIMIT 1";
OA::debug('- Maintenance process run information not found - trying to get data from ' . $aAlternateInfo['tableName'], PEAR_LOG_DEBUG);
$rc = $this->oDbh->query($query);
if (PEAR::isError($rc)) {
return false;
}
if ($rc->numRows() > 0) {
// A raw data result was found - convert it to the end of the previous
// operation interval, or hour
$aResult = $rc->fetchRow();
$oDate = new Date($aResult['date']);
if ($aAlternateInfo['type'] == 'oi') {
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
$oResultDate = $aDates['start'];
} else {
if ($aAlternateInfo['type'] == 'hour') {
$oResultDate = new Date($oDate->format('%Y-%m-%d %H:00:00'));
}
}
$oResultDate->subtractSeconds(1);
return array('updated_to' => $oResultDate->format('%Y-%m-%d %H:%M:%S'));
}
}
// No result found, return null
return null;
}
示例12: testGetPreviousAdDeliveryInfo
//.........这里部分代码省略.........
* - That prioritisation information where multiple sets of INDENTICAL
* data exists is returned correctly.
* - That prioritisation information where multiple sets of DIFFERENT
* data exists is returned correctly.
* - That prioritisation information from older sets of data is
* returned correctly.
* Test 18a: Re-test, but also include ad/zone pairs that are in/not in the above
* set of data, and ensure that these ad/zone pairs are also included
* in the results.
*/
function testGetPreviousAdDeliveryInfo()
{
$conf = $GLOBALS['_MAX']['CONF'];
$oDbh =& OA_DB::singleton();
$oMaxDalMaintenance = new OA_Dal_Maintenance_Priority();
$aEmptyZoneAdArray = array();
$aAdParams = array('ad_id' => 1, 'active' => 't', 'type' => 'sql', 'weight' => 1);
$oAd = new OA_Maintenance_Priority_Ad($aAdParams);
$oZone = new OX_Maintenance_Priority_Zone(array('zoneid' => 1));
$oZone->addAdvert($oAd);
$aZoneAdArray = array($oZone->id => $oZone);
// Test 1
$oServiceLocator =& OA_ServiceLocator::instance();
$oServiceLocator->remove('now');
$result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
$this->assertFalse($result);
// Test 2
$oDate = new Date();
$oServiceLocator->register('now', $oDate);
$result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
$this->assertEqual(count($result), 0);
// Test 3
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
$oNow = new Date();
$bannerId1 = $this->_insertCampaignBanner();
$aData = array($conf['maintenance']['operationInterval'], $operationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
$idDia = $this->_insertDataIntermediateAd($aData);
$result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
$this->assertEqual(count($result), 0);
$oDate =& $oServiceLocator->get('now');
DataGenerator::cleanUp();
$oServiceLocator->register('now', $oDate);
// Test 4
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
$previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
$aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
$bannerId1 = $this->_insertCampaignBanner();
$aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
$idDia = $this->_insertDataIntermediateAd($aData);
$result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
$this->assertEqual(count($result), 1);
$this->assertEqual($result[1][1]['ad_id'], $bannerId1);
$this->assertEqual($result[1][1]['zone_id'], 1);
$this->assertNull($result[1][1]['required_impressions']);
$this->assertNull($result[1][1]['requested_impressions']);
$this->assertNull($result[1][1]['priority_factor']);
$this->assertNull($result[1][1]['past_zone_traffic_fraction']);
$this->assertEqual($result[1][1]['impressions'], 1);
$oDate =& $oServiceLocator->get('now');
DataGenerator::cleanUp();
$oServiceLocator->register('now', $oDate);
// Test 5, 5a
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
$previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
$previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($previousOperationIntervalID);
示例13: run
/**
* The main method of the class, that is run by the controlling
* task runner class.
*/
function run()
{
OA::debug('Running Maintenance Priority Engine: ' . $this->taskName, PEAR_LOG_DEBUG);
// Record the start of this ECPM run
$oStartDate = new Date();
// Get the details of the last time Priority Compensation started running
$aDates = $this->oDal->getMaintenancePriorityLastRunInfo(DAL_PRIORITY_UPDATE_ECPM, array('start_run', 'end_run'));
if (!is_null($aDates)) {
// Set the details of the last time Priority Compensation started running
$this->aLastRun['start_run'] = new Date($aDates['start_run']);
// Set the details of the current date/time
$oServiceLocator =& OA_ServiceLocator::instance();
$this->aLastRun['now'] =& $oServiceLocator->get('now');
}
$this->oDateNow = $this->getDateNow();
$this->aOIDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($this->oDateNow);
$this->runAlgorithm();
// Record the completion of the task in the database
// Note that the $oUpdateTo parameter is "null", as this value is not
// appropriate when recording Priority Compensation task runs - all that
// matters is the start/end dates.
OA::debug('- Recording completion of the ' . $this->taskName, PEAR_LOG_DEBUG);
$oEndDate = new Date();
$this->oDal->setMaintenancePriorityLastRunInfo($oStartDate, $oEndDate, null, DAL_PRIORITY_UPDATE_ECPM);
}
示例14: testUpdatePriorities
/**
* Method to test the updatePriorities method.
*
* Test 1: Test with no Date registered in the service locator, ensure false returned.
* Test 2: Test with no data in the database, ensure data is correctly stored.
* Test 3: Test with previous test data in the database, ensure data is correctly stored.
* Test 4: Test with an obscene number of items, and ensure that the packet size is
* not exceeded (no asserts, test suite will simply fail if unable to work).
*/
function testUpdatePriorities()
{
/**
* @TODO Locate where clean up doesn't happen before this test, and fix!
*/
TestEnv::restoreEnv();
$conf = $GLOBALS['_MAX']['CONF'];
$oDbh =& OA_DB::singleton();
$oMaxDalMaintenance = new OA_Dal_Maintenance_Priority();
// Insert the data into the ad_zone_assoc table, as an ad is linked to a zone
$this->_generateTestData();
// Test 1
$oServiceLocator =& OA_ServiceLocator::instance();
$oServiceLocator->remove('now');
$aData = array(array('ads' => array(array('ad_id' => $this->aIds['ad'], 'zone_id' => $this->aIds['zone'], 'required_impressions' => '1000', 'requested_impressions' => '1000', 'priority' => '0.45', 'priority_factor' => null, 'priority_factor_limited' => false, 'past_zone_traffic_fraction' => null))));
$result = $oMaxDalMaintenance->updatePriorities($aData);
$this->assertFalse($result);
// Test 2
$oDate = new Date();
$oServiceLocator->register('now', $oDate);
$result = $oMaxDalMaintenance->updatePriorities($aData);
$this->assertTrue($result);
$query = "\n SELECT\n ad_id,\n zone_id,\n priority\n FROM\n " . $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['ad_zone_assoc'], true) . "\n WHERE\n ad_id = {$this->aIds['ad']} AND zone_id = {$this->aIds['zone']}";
$rc = $oDbh->query($query);
$aRow = $rc->fetchRow();
$this->assertEqual($aRow['ad_id'], $this->aIds['ad']);
$this->assertEqual($aRow['zone_id'], $this->aIds['zone']);
$this->assertEqual($aRow['priority'], 0.45);
$query = "\n SELECT\n operation_interval,\n operation_interval_id,\n interval_start,\n interval_end,\n ad_id,\n zone_id,\n required_impressions,\n requested_impressions,\n priority,\n priority_factor,\n priority_factor_limited,\n past_zone_traffic_fraction,\n created,\n created_by,\n expired,\n expired_by\n FROM\n " . $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['data_summary_ad_zone_assoc'], true) . "\n WHERE\n ad_id = {$this->aIds['ad']}";
$rc = $oDbh->query($query);
$aRow = $rc->fetchRow();
$currentOperationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
$this->assertEqual($aRow['operation_interval'], $conf['maintenance']['operationInterval']);
$this->assertEqual($aRow['operation_interval_id'], $currentOperationIntervalID);
$this->assertEqual($aRow['interval_start'], $aDates['start']->format('%Y-%m-%d %H:%M:%S'));
$this->assertEqual($aRow['interval_end'], $aDates['end']->format('%Y-%m-%d %H:%M:%S'));
$this->assertEqual($aRow['ad_id'], $this->aIds['ad']);
$this->assertEqual($aRow['zone_id'], $this->aIds['zone']);
$this->assertEqual($aRow['required_impressions'], 1000);
$this->assertEqual($aRow['requested_impressions'], 1000);
$this->assertEqual($aRow['priority'], 0.45);
$this->assertNull($aRow['priority_factor']);
$this->assertFalse($aRow['priority_factor_limited']);
$this->assertNull($aRow['past_zone_traffic_fraction']);
$this->assertEqual($aRow['created'], $oDate->format('%Y-%m-%d %H:%M:%S'));
$this->assertEqual($aRow['created_by'], 0);
$this->assertNull($aRow['expired']);
$this->assertNull($aRow['expired_by']);
// Test 3
$aData = array(array('ads' => array(array('ad_id' => $this->aIds['ad'], 'zone_id' => $this->aIds['zone'], 'required_impressions' => 2000, 'requested_impressions' => 2000, 'priority' => 0.9, 'priority_factor' => 0.1, 'priority_factor_limited' => false, 'past_zone_traffic_fraction' => 0.99), array('ad_id' => $this->aIds['ad'] + 1, 'zone_id' => $this->aIds['ad'] + 1, 'required_impressions' => 500, 'requested_impressions' => 500, 'priority' => 0.1, 'priority_factor' => 0.2, 'priority_factor_limited' => true, 'past_zone_traffic_fraction' => 0.45))));
$oOldDate = new Date();
$oOldDate->copy($oDate);
$oDate = new Date();
$oServiceLocator->register('now', $oDate);
$result = $oMaxDalMaintenance->updatePriorities($aData);
$this->assertTrue($result);
$query = "\n SELECT\n ad_id,\n zone_id,\n priority\n FROM\n " . $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['ad_zone_assoc'], true) . "\n WHERE\n ad_id = {$this->aIds['ad']} AND zone_id = {$this->aIds['zone']}";
$rc = $oDbh->query($query);
$aRow = $rc->fetchRow();
$this->assertEqual($aRow['ad_id'], $this->aIds['ad']);
$this->assertEqual($aRow['zone_id'], $this->aIds['zone']);
$this->assertEqual($aRow['priority'], 0.9);
$query = "\n SELECT\n operation_interval,\n operation_interval_id,\n interval_start,\n interval_end,\n ad_id,\n zone_id,\n required_impressions,\n requested_impressions,\n priority,\n priority_factor,\n priority_factor_limited,\n past_zone_traffic_fraction,\n created,\n created_by,\n expired,\n expired_by\n FROM\n " . $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['data_summary_ad_zone_assoc'], true) . "\n WHERE\n ad_id = {$this->aIds['ad']}\n AND expired IS NOT NULL";
$rc = $oDbh->query($query);
$aRow = $rc->fetchRow();
$currentOperationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oOldDate);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oOldDate);
$this->assertEqual($aRow['operation_interval'], $conf['maintenance']['operationInterval']);
$this->assertEqual($aRow['operation_interval_id'], $currentOperationIntervalID);
$this->assertEqual($aRow['interval_start'], $aDates['start']->format('%Y-%m-%d %H:%M:%S'));
$this->assertEqual($aRow['interval_end'], $aDates['end']->format('%Y-%m-%d %H:%M:%S'));
$this->assertEqual($aRow['ad_id'], $this->aIds['ad']);
$this->assertEqual($aRow['zone_id'], $this->aIds['ad']);
$this->assertEqual($aRow['required_impressions'], 1000);
$this->assertEqual($aRow['requested_impressions'], 1000);
$this->assertEqual($aRow['priority'], 0.45);
$this->assertNull($aRow['priority_factor']);
$this->assertFalse($aRow['priority_factor_limited']);
$this->assertNull($aRow['past_zone_traffic_fraction']);
$this->assertEqual($aRow['created'], $oOldDate->format('%Y-%m-%d %H:%M:%S'));
$this->assertEqual($aRow['created_by'], 0);
$this->assertEqual($aRow['expired'], $oDate->format('%Y-%m-%d %H:%M:%S'));
$this->assertEqual($aRow['expired_by'], 0);
$query = "\n SELECT\n operation_interval,\n operation_interval_id,\n interval_start,\n interval_end,\n ad_id,\n zone_id,\n required_impressions,\n requested_impressions,\n priority,\n priority_factor,\n priority_factor_limited,\n past_zone_traffic_fraction,\n created,\n created_by,\n expired,\n expired_by\n FROM\n " . $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['data_summary_ad_zone_assoc'], true) . "\n WHERE\n ad_id = {$this->aIds['ad']}\n AND expired IS NULL";
$rc = $oDbh->query($query);
$aRow = $rc->fetchRow();
$currentOperationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
$this->assertEqual($aRow['operation_interval'], $conf['maintenance']['operationInterval']);
$this->assertEqual($aRow['operation_interval_id'], $currentOperationIntervalID);
//.........这里部分代码省略.........
示例15: getAdLifetimeZoneImpressionsRemaining
/**
* A method to obtain the sum of the zone forecast impression value, for all the zones
* an advertisement is linked to, cloned out over the advertisement's entire remaining
* lifetime in the campaign, with any blocked operation intervals removed.
*
* Requires that the getActiveAdOperationIntervals() method have previously been
* called to function correctly.
*
* @param PEAR::Date $oNowDate The current date.
* @param PEAR::Date $oEndDate The end date of the campaign. Note that if the end
* date supplied is not at the end of a day, it will be
* converted to be treated as such.
* @param array $aCumulativeZoneForecast The cumulative forecast impressions, indexed
* by operation interval ID, of all the zones the
* advertisement is linked to.
* array(
* [operation_interval_id] => forecast_impressions,
* [operation_interval_id] => forecast_impressions
* .
* .
* .
* )
* @return integer The ad's total remaining zone impression forecast for all zone for
* the remaining life of the ad.
*/
function getAdLifetimeZoneImpressionsRemaining($oNowDate, $oEndDate, $aCumulativeZoneForecast)
{
$totalAdLifetimeZoneImpressionsRemaining = 0;
// Test the parameters, if invalid, return zero
if (!is_a($oNowDate, 'date') || !is_a($oEndDate, 'date') || !is_array($aCumulativeZoneForecast) || count($aCumulativeZoneForecast) != OX_OperationInterval::operationIntervalsPerWeek()) {
OA::debug(' - Invalid parameters to getAdLifetimeZoneImpressionsRemaining, returning 0', PEAR_LOG_ERR);
return $totalAdLifetimeZoneImpressionsRemaining;
}
// Ensure that the end of campaign date is at the end of the day
$oEndDateCopy = new Date($oEndDate);
$oEndDateCopy->setHour(23);
$oEndDateCopy->setMinute(59);
$oEndDateCopy->setSecond(59);
// Ensure that the $aCumulativeZoneForecast array is sorted by key, so that it can
// be accessed by array_slice, regardless of the order that the forecast data was added
// to the array
ksort($aCumulativeZoneForecast);
// Step 1: Calculate the sum of the forecast values from "now" until the end of "today"
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oNowDate);
$oEndOfToday = new Date($aDates['start']);
$oEndOfToday->setTZ($oEndDate->tz);
$oEndOfToday->setHour(23);
$oEndOfToday->setMinute(59);
$oEndOfToday->setSecond(59);
$oStart = $aDates['start'];
while ($oStart->before($oEndOfToday)) {
// Find the Operation Interval ID for this Operation Interval
$operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oStart);
// As iteration over every OI is required anyway, test to see if
// the ad is blocked in this OI; if not, add the forecast values to the
// running total
if (empty($this->aBlockedOperationIntervalDates[$oStart->format('%Y-%m-%d %H:%M:%S')])) {
$totalAdLifetimeZoneImpressionsRemaining += $aCumulativeZoneForecast[$operationIntervalID];
}
// Go to the next operation interval in "today"
$oStart = OX_OperationInterval::addOperationIntervalTimeSpan($oStart);
}
// Step 2: Calculate how many times each day of the week occurs between the end of
// "today" (i.e. starting "tomorrow morning") and the last day the ad can run
$aDays = array();
$oStartOfTomorrow = new Date($oEndOfToday);
$oStartOfTomorrow->addSeconds(1);
$oTempDate = new Date();
$oTempDate->copy($oStartOfTomorrow);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oTempDate);
while ($aDates['start']->before($oEndDateCopy)) {
// Increase the count for this day of the week
$aDays[$aDates['start']->getDayOfWeek()]++;
// Go to the next day
$oTempDate->addSeconds(SECONDS_PER_DAY);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oTempDate);
}
// Step 3: For every possible day of the week (assuming that day of the week is in the
// ad's remaining lifetime), calculate the sum of the forecast values for every
// operation interval in that day
if (!empty($aDays)) {
$operationIntervalsPerDay = OX_OperationInterval::operationIntervalsPerDay();
$oTempDate = new Date($oStartOfTomorrow);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oTempDate);
for ($counter = 0; $counter < 7; $counter++) {
// Are there any instances of this day in the campaign?
if ($aDays[$oTempDate->getDayOfWeek()] > 0) {
// Calculate the sum of the zone forecasts for this day of week
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oTempDate);
$dayStartOperationIntervalId = OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']);
$aDayCumulativeZoneForecast = array_slice($aCumulativeZoneForecast, $dayStartOperationIntervalId, $operationIntervalsPerDay);
$forecastSum = array_sum($aDayCumulativeZoneForecast);
// Multiply this day's forecast sum value by the number of times this
// day of week appears in the remainder of the campaign and add the
// value to the running total
$totalAdLifetimeZoneImpressionsRemaining += $forecastSum * $aDays[$oTempDate->getDayOfWeek()];
}
// Go to the next day
$oTempDate->addSeconds(SECONDS_PER_DAY);
}
//.........这里部分代码省略.........