本文整理汇总了PHP中OX_OperationInterval类的典型用法代码示例。如果您正苦于以下问题:PHP OX_OperationInterval类的具体用法?PHP OX_OperationInterval怎么用?PHP OX_OperationInterval使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OX_OperationInterval类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkRangeData
/**
* A mathod to quickly check the data in the database for the date
* range given, to ensure that the range being tested & corrected
* seems reasonable.
*
* @param Date $oStartDate The start date/time of the range to test & correct.
* @param Date $oEndDate The end date/time of the range to test & correct.
* @return boolean True if the date range seems okay, false otherwise.
*/
function checkRangeData($oStartDate, $oEndDate)
{
// Test that there are no rows in the data_intermediate_ad table where the
// operation interval value does not match that in the configuration file
$doData_intermediate_ad = OA_Dal::factoryDO('data_intermediate_ad');
$doData_intermediate_ad->whereAdd('date_time >= ' . $this->oDbh->quote($oStartDate->format('%Y-%m-%d %H:%M:%S'), 'timestamp'));
$doData_intermediate_ad->whereAdd('date_time <= ' . $this->oDbh->quote($oEndDate->format('%Y-%m-%d %H:%M:%S'), 'timestamp'));
$doData_intermediate_ad->whereAdd('operation_interval != ' . $this->oDbh->quote(OX_OperationInterval::getOperationInterval(), 'integer'));
$doData_intermediate_ad->find();
$rows = $doData_intermediate_ad->getRowCount();
if ($rows > 0) {
$message = "\n Detected at least one row in the data_intermediate_ad table with operation interval != " . OX_OperationInterval::getOperationInterval() . ".\n";
echo $message;
return false;
}
// Test that all of the date/time values in the data_summary_ad_hourly
// table align with the start of operation intervals
$doData_summary_ad_hourly = OA_Dal::factoryDO('data_summary_ad_hourly');
$doData_summary_ad_hourly->selectAdd();
$doData_summary_ad_hourly->selectAdd('DISTINCT date_time');
$doData_summary_ad_hourly->whereAdd('date_time >= ' . $this->oDbh->quote($oStartDate->format('%Y-%m-%d %H:%M:%S'), 'timestamp'));
$doData_summary_ad_hourly->whereAdd('date_time <= ' . $this->oDbh->quote($oEndDate->format('%Y-%m-%d %H:%M:%S'), 'timestamp'));
$doData_summary_ad_hourly->find();
while ($doData_summary_ad_hourly->fetch()) {
$oDate = new Date($doData_summary_ad_hourly->date_time);
$result = OX_OperationInterval::checkDateIsStartDate($oDate);
if (!$result) {
$message = "\n Detected at least one row in the data_summary_ad_hourly table with date_time value not on the hour start interval.\n";
echo $message;
return false;
}
}
return true;
}
示例2: run
/**
* A method to run maintenance.
*/
function run()
{
// Print a blank line in the debug log file when maintenance starts
OA::debug();
// Do not run if distributed stats are enabled
if (!empty($this->aConf['lb']['enabled'])) {
OA::debug('Distributed stats enabled, not running maintenance tasks', PEAR_LOG_INFO);
return;
}
// Acquire the maintenance lock
$oLock =& OA_DB_AdvisoryLock::factory();
if ($oLock->get(OA_DB_ADVISORYLOCK_MAINTENANCE)) {
OA::switchLogIdent('maintenance');
OA::debug();
OA::debug('Running Maintenance Engine', PEAR_LOG_INFO);
// Attempt to increase PHP memory
OX_increaseMemoryLimit(OX_getMinimumRequiredMemory('maintenance'));
// Set UTC timezone
OA_setTimeZoneUTC();
// Get last run
$oLastRun = $this->getLastRun();
// Update the timestamp for old maintenance code and auto-maintenance
$this->updateLastRun();
// Record the current time, and register with the OA_ServiceLocator
$oDate = new Date();
$oServiceLocator =& OA_ServiceLocator::instance();
$oServiceLocator->register('now', $oDate);
// Check the operation interval is valid
$result = OX_OperationInterval::checkOperationIntervalValue($this->aConf['maintenance']['operationInterval']);
if (PEAR::isError($result)) {
// Unable to continue!
$oLock->release();
OA::debug('Aborting maintenance: Invalid Operation Interval length', PEAR_LOG_CRIT);
exit;
}
// Run the Maintenance Statistics Engine (MSE) process
$this->_runMSE();
// Run the "midnight" tasks, if required
if ($this->isMidnightMaintenance($oLastRun)) {
$this->_runMidnightTasks();
}
// Release lock before starting MPE
$oLock->release();
// Run the Maintenance Priority Engine (MPE) process, ensuring that the
// process always runs, even if instant update of priorities is disabled
$this->_runMPE();
// Log the completion of the entire ME process
OA::switchLogIdent('maintenance');
$oEndDate = new Date();
$oDateSpan = new Date_Span();
$oDateSpan->setFromDateDiff($oDate, $oEndDate);
OA::debug('Maintenance Engine Completed (Started at ' . $oDate->format('%Y-%m-%d %H:%M:%S') . ' ' . $oDate->tz->getShortName() . ', taking ' . $oDateSpan->format('%H:%M:%S') . ')', PEAR_LOG_INFO);
OA::switchLogIdent();
} else {
OA::switchLogIdent('maintenance');
OA::debug('Maintenance Engine not run: could not acquire lock', PEAR_LOG_INFO);
OA::switchLogIdent();
}
}
示例3: 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;
}
示例4: run
/**
* A method to run distributed maintenance.
*/
function run()
{
if (empty($GLOBALS['_MAX']['CONF']['lb']['enabled'])) {
OA::debug('Distributed stats disabled, not running Maintenance Distributed Engine', PEAR_LOG_INFO);
return;
}
if (!empty($GLOBALS['_MAX']['CONF']['rawDatabase'])) {
$GLOBALS['_MAX']['CONF']['database'] = $GLOBALS['_MAX']['CONF']['rawDatabase'] + $GLOBALS['_MAX']['CONF']['database'];
OA::debug('rawDatabase functionality is being used, switching settings', PEAR_LOG_INFO);
}
$oLock =& OA_DB_AdvisoryLock::factory();
if (!$oLock->get(OA_DB_ADVISORYLOCK_DISTRIBUTED)) {
OA::debug('Maintenance Distributed Engine Already Running', PEAR_LOG_INFO);
return;
}
OA::debug('Running Maintenance Distributed Engine', PEAR_LOG_INFO);
// Attempt to increase PHP memory
OX_increaseMemoryLimit(OX_getMinimumRequiredMemory('maintenance'));
// Ensure the current time is registered with the OA_ServiceLocator
$oServiceLocator =& OA_ServiceLocator::instance();
$oNow =& $oServiceLocator->get('now');
if (!$oNow) {
// Record the current time, and register with the OA_ServiceLocator
$oNow = new Date();
$oServiceLocator->register('now', $oNow);
}
OA::debug(' - Current time is ' . $oNow->format('%Y-%m-%d %H:%M:%S') . ' ' . $oNow->tz->getShortName(), PEAR_LOG_DEBUG);
// Get the components of the deliveryLog extension
$aBuckets = OX_Component::getComponents('deliveryLog');
// Copy buckets' records with "interval_start" up to and including previous OI start,
// and then prune the data processed
$aPreviousOperationIntervalDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oNow);
OA::debug(' - Will process data for all operation intervals before and up to start', PEAR_LOG_DEBUG);
OA::debug(' time of ' . $aPreviousOperationIntervalDates['start']->format('%Y-%m-%d %H:%M:%S') . ' ' . $aPreviousOperationIntervalDates['start']->tz->getShortName(), PEAR_LOG_DEBUG);
foreach ($aBuckets as $sBucketName => $oBucketClass) {
if ($oBucketClass->testStatisticsMigration($oBucketClass->getStatisticsMigration())) {
$oBucketClass->processBucket($aPreviousOperationIntervalDates['start']);
$oBucketClass->pruneBucket($aPreviousOperationIntervalDates['start']);
} else {
OA::debug(' - Skipping ' . $sBucketName, PEAR_LOG_DEBUG);
}
}
$oLock->release();
OA::debug('Maintenance Distributed Engine Completed', PEAR_LOG_INFO);
}
示例5: _getCumulativeZoneForecast
/**
* A private method to return the current cumulative zone forecast data for all zones
* associated with a given advertisement. The returned array is keyed by operation interval
* ID (i.e. from 0 [zero] to the maximum operation interval ID value, depending on the current
* configuration value for the operation interval length). The zone forecast values used
* in calculating the cumulative forecast are taken from the end of the current operation
* interval to one week prior (i.e. the most recent week's worth of forecasts).
*
* @access private
* @param integer $adId The advertisement ID.
* @param array $aAdZones An array of arrays, no particular index in the outer array, in the
* inner arrays, each as an index "zone_id" containing one zone ID that
* the ad is linked to.
* @return mixed Array on success, false on failure. If an array, it is of the format:
* array(
* [operation_interval_id] => forecast_impressions,
* [operation_interval_id] => forecast_impressions
* .
* .
* .
* )
*/
function _getCumulativeZoneForecast($adId, $aAdZones)
{
$aConf = $GLOBALS['_MAX']['CONF'];
if (empty($adId) || !is_numeric($adId)) {
OA::debug('- Invalid advertisement ID argument', PEAR_LOG_ERR);
return false;
}
if (!is_array($aAdZones)) {
OA::debug('- Invalid zone array argument', PEAR_LOG_ERR);
return false;
}
// Initialise the results array with the number operation intervals in a week
$aResults = array_fill(0, OX_OperationInterval::operationIntervalsPerWeek(), 0);
// Get the forcast impressions for the previous week
if (!empty($aAdZones)) {
foreach ($aAdZones as $aZone) {
if (!is_array($this->aZoneForecasts[$aZone['zone_id']])) {
$this->aZoneForecasts[$aZone['zone_id']] = $this->oDal->getPreviousWeekZoneForcastImpressions($aZone['zone_id']);
}
if (is_array($this->aZoneForecasts[$aZone['zone_id']]) && !empty($this->aZoneForecasts[$aZone['zone_id']])) {
foreach ($this->aZoneForecasts[$aZone['zone_id']] as $aValues) {
$aResults[$aValues['operation_interval_id']] += (int) $aValues['forecast_impressions'];
}
}
}
}
return $aResults;
}
示例6: 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);
//.........这里部分代码省略.........
示例7: _testParameters
/**
* A private method to test the parameters of the getAdTargetingStatistics()
* and getZoneTargetingStatistics methods.
*
* @access private
* @param integer $id The ad or zone ID.
* @param PEAR::Date $oStartDate The start date of the operation interval.
* @param PEAR::Date $oEndDate The end date of the operation interval.
* @return boolean True if the parameters are okay, false otherwise.
*/
function _testParameters($id, $oStartDate, $oEndDate)
{
// Ensure the parameters are valid
if (empty($id) || !is_int($id)) {
return false;
}
if (empty($oStartDate) || !is_a($oStartDate, 'Date')) {
return false;
}
if (empty($oEndDate) || !is_a($oEndDate, 'Date')) {
return false;
}
// Ensure that the date range specified is indeed an operation interval
if (!OX_OperationInterval::checkIntervalDates($oStartDate, $oEndDate)) {
return false;
}
return true;
}
示例8: manageConversions
/**
* A method to manage the migration of conversions from the final conversion
* tables to the old-style intermediate table.
*
* @TODO Deprecate, when conversion data is no longer required in the
* old format intermediate and summary tables.
*
* @param PEAR::Date $oStart The start date/time to migrate from.
* @param PEAR::Date $oEnd The end date/time to migrate to.
*/
function manageConversions($oStart, $oEnd)
{
$aConf = $GLOBALS['_MAX']['CONF'];
// The custom IF function in PgSQL is not suitable for this query, we need explicit use of CASE
if ($this->oDbh->dbsyntax == 'pgsql') {
$sqlBasketValue = "CASE WHEN v.purpose = 'basket_value' AND diac.connection_status = " . MAX_CONNECTION_STATUS_APPROVED . " THEN diavv.value::numeric ELSE 0 END";
$sqlNumItems = "CASE WHEN v.purpose = 'num_items' AND diac.connection_status = " . MAX_CONNECTION_STATUS_APPROVED . " THEN diavv.value::integer ELSE 0 END";
} else {
$sqlBasketValue = "IF(v.purpose = 'basket_value' AND diac.connection_status = " . MAX_CONNECTION_STATUS_APPROVED . ", diavv.value, 0)";
$sqlNumItems = "IF(v.purpose = 'num_items' AND diac.connection_status = " . MAX_CONNECTION_STATUS_APPROVED . ", diavv.value, 0)";
}
// Prepare the query to obtain all of the conversions, and their associated total number
// of items and total basket values (where they exist), ready for update/insertion into
// the data_intermediate_ad table
$query = "\n SELECT\n DATE_FORMAT(diac.tracker_date_time, '%Y-%m-%d %H:00:00'){$this->timestampCastString} AS date_f,\n diac.ad_id AS ad_id,\n diac.zone_id AS zone_id,\n COUNT(DISTINCT(diac.data_intermediate_ad_connection_id)) AS conversions,\n SUM({$sqlBasketValue}) AS total_basket_value,\n SUM({$sqlNumItems}) AS total_num_items\n FROM\n " . $this->oDbh->quoteIdentifier($aConf['table']['prefix'] . 'data_intermediate_ad_connection', true) . " AS diac\n LEFT JOIN\n " . $this->oDbh->quoteIdentifier($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', true) . " AS diavv\n USING\n (\n data_intermediate_ad_connection_id\n )\n LEFT JOIN\n " . $this->oDbh->quoteIdentifier($aConf['table']['prefix'] . 'variables', true) . " AS v\n ON\n (\n diavv.tracker_variable_id = v.variableid\n AND v.purpose IN ('basket_value', 'num_items')\n )\n WHERE\n diac.connection_status = " . MAX_CONNECTION_STATUS_APPROVED . "\n AND diac.inside_window = 1\n AND diac.tracker_date_time >= " . $this->oDbh->quote($oStart->format('%Y-%m-%d %H:%M:%S'), 'timestamp') . "\n AND diac.tracker_date_time <= " . $this->oDbh->quote($oEnd->format('%Y-%m-%d %H:%M:%S'), 'timestamp') . "\n GROUP BY\n diac.data_intermediate_ad_connection_id,\n date_f,\n diac.ad_id,\n diac.zone_id";
OA::debug('- Selecting conversion data for migration to the "old style" intermediate table for ', PEAR_LOG_DEBUG);
OA::debug(' conversion in the range ' . $oStart->format('%Y-%m-%d %H:%M:%S') . ' ' . $oStart->tz->getShortName() . ' to ' . $oEnd->format('%Y-%m-%d %H:%M:%S') . ' ' . $oEnd->tz->getShortName(), PEAR_LOG_DEBUG);
$rsResult = $this->oDbh->query($query);
if (PEAR::isError($rsResult)) {
return MAX::raiseError($rsResult, MAX_ERROR_DBFAILURE, PEAR_ERROR_DIE);
}
while ($aRow = $rsResult->fetchRow()) {
// Prepare the update query
$query = "\n UPDATE\n " . $this->oDbh->quoteIdentifier($aConf['table']['prefix'] . 'data_intermediate_ad', true) . "\n SET\n conversions = conversions + " . $this->oDbh->quote($aRow['conversions'], 'integer') . ",\n total_basket_value = total_basket_value + " . $this->oDbh->quote($aRow['total_basket_value'], 'float') . ",\n total_num_items = total_num_items + " . $this->oDbh->quote($aRow['total_num_items'], 'integer') . "\n WHERE\n date_time = " . $this->oDbh->quote($aRow['date_f'], 'timestamp') . "\n AND ad_id = " . $this->oDbh->quote($aRow['ad_id'], 'integer') . "\n AND zone_id = " . $this->oDbh->quote($aRow['zone_id'], 'integer');
$rsUpdateResult = $this->oDbh->exec($query);
if (PEAR::isError($rsUpdateResult)) {
return MAX::raiseError($rsUpdateResult, MAX_ERROR_DBFAILURE, PEAR_ERROR_DIE);
}
if ($rsUpdateResult == 0) {
// Could not perform the update - try an insert instead
$oDate = new Date($aRow['date_f']);
$operationIntervalId = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
$query = "\n INSERT INTO\n " . $this->oDbh->quoteIdentifier($aConf['table']['prefix'] . 'data_intermediate_ad', true) . "\n (\n date_time,\n operation_interval,\n operation_interval_id,\n interval_start,\n interval_end,\n ad_id,\n creative_id,\n zone_id,\n conversions,\n total_basket_value,\n total_num_items\n )\n VALUES\n (\n " . $this->oDbh->quote($aRow['date_f'], 'timestamp') . ",\n " . $this->oDbh->quote($aConf['maintenance']['operationInterval'], 'integer') . ",\n " . $this->oDbh->quote($operationIntervalId, 'integer') . ",\n " . $this->oDbh->quote($aDates['start']->format('%Y-%m-%d %H:%M:%S'), 'timestamp') . ",\n " . $this->oDbh->quote($aDates['end']->format('%Y-%m-%d %H:%M:%S'), 'timestamp') . ",\n " . $this->oDbh->quote($aRow['ad_id'], 'integer') . ",\n 0,\n " . $this->oDbh->quote($aRow['zone_id'], 'integer') . ",\n " . $this->oDbh->quote($aRow['conversions'], 'integer') . ",\n " . $this->oDbh->quote($aRow['total_basket_value'], 'float') . ",\n " . $this->oDbh->quote($aRow['total_num_items'], 'integer') . "\n )";
$rsInsertResult = $this->oDbh->exec($query);
}
}
}
示例9: Date
if (PEAR::isError($result)) {
$message = "\nThe operation interval in your OpenX configuration file is not valid. Please see the OpenX\ndocumentation for more details on valid operation interval values.\n";
echo $message;
echo $haltMessage;
exit;
}
$oStartDate = new Date(INTERVAL_START);
$result = OX_OperationInterval::checkDateIsStartDate($oStartDate);
if (!$result) {
$message = "\nThe start date defined in the {$scriptName} script is not a valid operation interval start date.\nPlease edit the statisticsTestAndCorrect.php script before running.\n";
echo $message;
echo $haltMessage;
exit;
}
$oEndDate = new Date(INTERVAL_END);
$result = OX_OperationInterval::checkDateIsEndDate($oEndDate);
if (!$result) {
$message = "\nThe end date defined in the {$scriptName} script is not a valid operation interval start date.\nPlease edit the statisticsTestAndCorrect.php script before running.\n";
echo $message;
echo $haltMessage;
exit;
}
$oMigrateBucketData = new OX_Maintenance_Statistics_MigrateBucketData();
if (PEAR::isError($oMigrateBucketData->oDbh)) {
$message = "\nUnable to connect to the OpenX database.\n";
echo $message;
echo $haltMessage;
exit;
}
// Check date range?
// Advise the user of the operations that will be performed, and ask for
示例10: 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);
}
示例11: testgetZonesForecasts
/**
* The method to test the getZonesForecasts() method.
*/
function testgetZonesForecasts()
{
$this->_createTestData();
$operationInterval = $GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'];
$oDal = new OA_Dal_Maintenance_Priority();
$oLowerDate = new Date('2007-09-16 12:00:00');
$oUpperDate = new Date('2007-09-16 17:00:00');
$lowerDateStr = $oLowerDate->format(self::DATE_TIME_FORMAT);
$upperDateStr = $oUpperDate->format(self::DATE_TIME_FORMAT);
$weeks = 2;
// Test with bad input
$badAgencyId = -1;
$result = $oDal->getZonesForecasts($lowerDateStr, $upperDateStr);
$expected = array();
$this->assertEqual($result, $expected);
// Test with data outside the range
$oDate = new Date('2007-09-16 11:00:00');
$operationIntervalId = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
$previousOIDate = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
$startDateStr = $aDates['start']->format(self::DATE_TIME_FORMAT);
$endDateStr = $aDates['end']->format(self::DATE_TIME_FORMAT);
$doDIA = OA_Dal::factoryDO('data_intermediate_ad');
$aDIAs = DataGenerator::generate($doDIA, 1);
$doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[0]);
$doDIA->date_time = $startDateStr;
$doDIA->operation_interval = $operationInterval;
$doDIA->zone_id = $this->zoneId1;
$doDIA->ad_id = 1;
$doDIA->impressions = 1000;
$doDIA->update();
$result = $oDal->getZonesForecasts($startDateStr, $endDateStr);
$expected = array();
$this->assertEqual($result, $expected);
// Test with data inside the range
$oDate = new Date('2007-09-16 13:00:00');
$operationIntervalId = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
$previousOIDate = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
$startDateStr = $aDates['start']->format(self::DATE_TIME_FORMAT);
$endDateStr = $aDates['end']->format(self::DATE_TIME_FORMAT);
$aDIAs = DataGenerator::generate($doDIA, 1);
$doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[0]);
$doDIA->date_time = $previousOIDate['start']->format(self::DATE_TIME_FORMAT);
$doDIA->operation_interval = $operationInterval;
$doDIA->zone_id = $this->zoneId1;
$doDIA->ad_id = 1;
$doDIA->impressions = 70;
$doDIA->update();
$result = $oDal->getZonesForecasts($startDateStr, $endDateStr);
$expected = array($this->zoneId1 => 70);
$this->assertEqual($result, $expected);
// Test with more data from the same zone
$oDate = new Date('2007-09-16 14:00:00');
$operationIntervalId = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
$previousOIDate = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
$startDateStr = $aDates['start']->format(self::DATE_TIME_FORMAT);
$endDateStr = $aDates['end']->format(self::DATE_TIME_FORMAT);
$aDIAs = DataGenerator::generate($doDIA, 3);
$doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[0]);
$doDIA->date_time = $previousOIDate['start']->format(self::DATE_TIME_FORMAT);
$doDIA->operation_interval = $operationInterval;
$doDIA->zone_id = $this->zoneId1;
$doDIA->ad_id = 2;
$doDIA->impressions = 90;
$doDIA->update();
$doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[1]);
$doDIA->date_time = $previousOIDate['start']->format(self::DATE_TIME_FORMAT);
$doDIA->operation_interval = $operationInterval;
$doDIA->zone_id = $this->zoneId1;
$doDIA->ad_id = 4;
$doDIA->impressions = 110;
$doDIA->update();
$doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[2]);
$doDIA->date_time = $previousOIDate['start']->format(self::DATE_TIME_FORMAT);
$doDIA->operation_interval = $operationInterval;
$doDIA->zone_id = $this->zoneId2;
$doDIA->ad_id = 4;
$doDIA->impressions = 15000;
$doDIA->update();
$result = $oDal->getZonesForecasts($startDateStr, $endDateStr);
$expected = array($this->zoneId1 => 200, $this->zoneId2 => 15000);
$this->assertEqual($result, $expected);
DataGenerator::cleanUp();
}
示例12: run
/**
* The implementation of the OA_Task::run() method that performs
* the required task of migrating bucket-based logged data to the
* statistics table(s) specified by the appropriate plugin
* components.
*/
function run()
{
$aConf = $GLOBALS['_MAX']['CONF'];
if ($this->oController->updateIntermediate) {
// Locate all plugin components which may require bucket data to be
// migrated from bucket tables to statistics tables
$aSummariseComponents = $this->_locateComponents();
// Are there any components that require data to be migrated?
if (empty($aSummariseComponents)) {
OA::debug('There are no installed plugins that require data migration', PEAR_LOG_DEBUG);
return;
}
$message = '- Migrating bucket-based logged data to the statistics tables.';
$this->oController->report .= $message . "\n";
// Get the MSE DAL to perform the data migration
$oServiceLocator =& OA_ServiceLocator::instance();
$oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
// Prepare the "now" date
$oNowDate =& $oServiceLocator->get('now');
if (!$oNowDate) {
$oNowDate = new Date();
}
// Prepare an array of possible start and end dates for the migration, unless they have been set already
if (empty($this->aRunDates)) {
$this->aRunDates = array();
$oStartDate = new Date();
$oStartDate->copy($this->oController->oLastDateIntermediate);
$oStartDate->addSeconds(1);
while (Date::compare($oStartDate, $this->oController->oUpdateIntermediateToDate) < 0) {
// Calcuate the end of the operation interval
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oStartDate);
$oEndDate = new Date();
$oEndDate->copy($aDates['end']);
// Store the dates
$oStoreStartDate = new Date();
$oStoreStartDate->copy($oStartDate);
$oStoreEndDate = new Date();
$oStoreEndDate->copy($oEndDate);
$this->aRunDates[] = array('start' => $oStoreStartDate, 'end' => $oStoreEndDate);
// Go to the next operation interval
$oStartDate->copy($oEndDate);
$oStartDate->addSeconds(1);
}
}
// Check to see if any historical raw data needs to be migrated,
// post-upgrade, and if so, migrate the data; requires that the
// default openXDeliveryLog plugin is installed, so the migration
// will not be called if it is not
if (key_exists('openXDeliveryLog', $this->aPackages)) {
$this->_postUpgrade();
}
// Prepare arrays of all of the migration maps of raw migrations
$aRunComponents = $this->_prepareMaps($aSummariseComponents, 'raw');
// Run each migration map separately, even if it's for the same table
foreach ($aRunComponents as $statisticsTable => $aMaps) {
foreach ($aMaps as $componentClassName => $aMigrationDetails) {
foreach ($this->aRunDates as $aDates) {
$message = "- Migrating raw bucket data from the '{$aMigrationDetails['bucketTable']}' bucket table";
OA::debug($message, PEAR_LOG_DEBUG);
$message = " to the '{$statisticsTable}' table, for operation interval range";
OA::debug($message, PEAR_LOG_DEBUG);
$message = ' ' . $aDates['start']->format('%Y-%m-%d %H:%M:%S') . ' ' . $aDates['start']->tz->getShortName() . ' to ' . $aDates['end']->format('%Y-%m-%d %H:%M:%S') . ' ' . $aDates['end']->tz->getShortName();
OA::debug($message, PEAR_LOG_DEBUG);
$result = $oDal->summariseBucketsRaw($statisticsTable, $aMigrationDetails, $aDates);
if (PEAR::isError($result)) {
// Oh noz! The bucket data could not be migrated
// Tell the user all about it, but then just keep on truckin'...
$message = " ERROR: Could not migrate raw bucket data from the '{$aMigrationDetails['bucketTable']}' bucket table";
OA::debug($message, PEAR_LOG_ERR);
$message = " Error message was: {$result->message}";
OA::debug($message, PEAR_LOG_ERR);
} else {
$message = " - Migrated {$result} row(s)";
OA::debug($message, PEAR_LOG_DEBUG);
$pruneResult = $aSummariseComponents[$statisticsTable][$componentClassName]->pruneBucket($aDates['end'], $aDates['start']);
if (PEAR::isError($pruneResult)) {
// Oh noz! The bucket data could not be pruned, and this is
// critical - if we can't prune the data, we'll end up double
// counting, so exit with a critical error...
$message = " ERROR: Could not prune aggregate bucket data from the '" . $aSummariseComponents[$statisticsTable][$componentClassName]->getBucketName() . "' bucket table";
OA::debug($message, PEAR_LOG_CRIT);
$message = " Error message was: {$pruneResult->message}";
OA::debug($message, PEAR_LOG_CRIT);
$message = " Aborting maintenance execution";
OA::debug($message, PEAR_LOG_CRIT);
exit;
} else {
$message = " - Pruned {$pruneResult} row(s)";
OA::debug($message, PEAR_LOG_DEBUG);
}
}
}
}
}
//.........这里部分代码省略.........
示例13: _getTrendUpperDate
/**
* 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;
}
示例14: 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;
}
}
示例15: 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;
}