当前位置: 首页>>代码示例>>PHP>>正文


PHP Date::copy方法代码示例

本文整理汇总了PHP中Date::copy方法的典型用法代码示例。如果您正苦于以下问题:PHP Date::copy方法的具体用法?PHP Date::copy怎么用?PHP Date::copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Date的用法示例。


在下文中一共展示了Date::copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setProcessLastRunInfo

 /**
  * A method to store data about the times that various Maintenance
  * processes ran.
  *
  * @param Date $oStart The time that the script run started.
  * @param Date $oEnd The time that the script run ended.
  * @param mixed $oUpdateTo PEAR::Date representing the end of the last
  *                         operation interval ID that has been updated,
  *                         or NULL, in the case that this information
  *                         does not actually apply, and only the
  *                         start/end dates of the process run are
  *                         relevant.
  * @param string $tableName The name of the log_matinenance_* table to log into.
  *                          Must NOT be a complete table name, ie. no prefix.
  * @param boolean $setOperationInterval Should the operation intverval value be
  *                                      logged, or not?
  * @param string $runTypeField Optional name of DB field to hold $type value.
  * @param integer $type Optional type of process run performed.
  */
 function setProcessLastRunInfo($oStart, $oEnd, $oUpdateTo, $tableName, $setOperationInterval, $runTypeField = null, $type = null)
 {
     $aConf = $GLOBALS['_MAX']['CONF'];
     // Test input values $oStart and $oEnd are dates
     if (!is_a($oStart, 'Date') || !is_a($oEnd, 'Date')) {
         return false;
     }
     // Test $oUpdateTo is a date, or null
     if (!is_a($oUpdateTo, 'Date')) {
         if (!is_null($oUpdateTo)) {
             return false;
         }
     }
     // Test $setOperationInterval value is a boolean
     if (!is_bool($setOperationInterval)) {
         return false;
     }
     // Prepare the duraction to log from the start and end dates
     $oDuration = new Date_Span();
     $oStartDateCopy = new Date();
     $oStartDateCopy->copy($oStart);
     $oEndDateCopy = new Date();
     $oEndDateCopy->copy($oEnd);
     $oDuration->setFromDateDiff($oStartDateCopy, $oEndDateCopy);
     // Prepare the logging query
     $tableName = $this->_getTablename($tableName);
     $query = "\n            INSERT INTO\n                {$tableName}\n                (\n                    start_run,\n                    end_run,";
     if ($setOperationInterval) {
         $query .= "\n                    operation_interval,";
     }
     $query .= "\n                    duration";
     if (!is_null($runTypeField) && !is_null($type)) {
         $query .= ",\n                    {$runTypeField}";
     }
     if (!is_null($oUpdateTo)) {
         $query .= ",\n                    updated_to";
     }
     $query .= "\n                )\n            VALUES\n                (\n                    '" . $oStart->format('%Y-%m-%d %H:%M:%S') . "',\n                    '" . $oEnd->format('%Y-%m-%d %H:%M:%S') . "',";
     if ($setOperationInterval) {
         $query .= "\n                    {$aConf['maintenance']['operationInterval']},";
     }
     $query .= "\n                    " . $oDuration->toSeconds();
     if (!is_null($runTypeField) && !is_null($type)) {
         $query .= ",\n                    {$type}";
     }
     if (!is_null($oUpdateTo)) {
         $query .= ",\n                    '" . $oUpdateTo->format('%Y-%m-%d %H:%M:%S') . "'";
     }
     $query .= "\n                )";
     OA::debug('- Logging maintenance process run information into ' . $tableName, PEAR_LOG_DEBUG);
     $rows = $this->oDbh->exec($query);
     if (PEAR::isError($rows)) {
         return false;
     } else {
         return $rows;
     }
 }
开发者ID:ballistiq,项目名称:revive-adserver,代码行数:76,代码来源:Common.php

示例2: run

 /**
  * The implementation of the OA_Task::run() method that performs
  * the required task of managing conversions.
  */
 function run()
 {
     if ($this->oController->updateIntermediate) {
         // Preapre the start date for the management of conversions
         $oStartDate = new Date();
         $oStartDate->copy($this->oController->oLastDateIntermediate);
         $oStartDate->addSeconds(1);
         // Get the MSE DAL to perform the conversion management
         $oServiceLocator =& OA_ServiceLocator::instance();
         $oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
         // Manage conversions
         $oDal->manageConversions($oStartDate, $this->oController->oUpdateIntermediateToDate);
     }
 }
开发者ID:hostinger,项目名称:revive-adserver,代码行数:18,代码来源:ManageConversions.php

示例3: run

 /**
  * The implementation of the OA_Task::run() method that performs
  * the required task of migrating data_intermediate_% table data
  * into the data_summary_% tables.
  */
 function run()
 {
     if ($this->oController->updateIntermediate || $this->oController->updateFinal) {
         $message = '- Saving request, impression, click and conversion data into the final tables.';
         $this->oController->report .= $message . "\n";
         OA::debug($message, PEAR_LOG_DEBUG);
     }
     if ($this->oController->updateFinal) {
         // Update the hourly summary table
         $oStartDate = new Date();
         $oStartDate->copy($this->oController->oLastDateFinal);
         $oStartDate->addSeconds(1);
         $this->_saveSummary($oStartDate, $this->oController->oUpdateFinalToDate);
     }
 }
开发者ID:akirsch,项目名称:revive-adserver,代码行数:20,代码来源:SummariseFinal.php

示例4: run

 /**
  * The implementation of the OA_Task::run() method that performs
  * the required task of de-duplicating and rejecting conversions.
  */
 function run()
 {
     if ($this->oController->updateIntermediate) {
         // Preapre the start date for the de-duplication/rejection
         $oStartDate = new Date();
         $oStartDate->copy($this->oController->oLastDateIntermediate);
         $oStartDate->addSeconds(1);
         // Get the MSE DAL to perform the de-duplication
         $oServiceLocator =& OA_ServiceLocator::instance();
         $oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
         // De-duplicate conversions
         $oDal->deduplicateConversions($oStartDate, $this->oController->oUpdateIntermediateToDate);
         // Reject empty variable conversions
         $oDal->rejectEmptyVarConversions($oStartDate, $this->oController->oUpdateIntermediateToDate);
     }
 }
开发者ID:akirsch,项目名称:revive-adserver,代码行数:20,代码来源:DeduplicateConversions.php

示例5: foreach

 /**
  * A private method that calcualtes the ZIF value(s) for a given zone.
  *
  * For each operation interval that requires the zone's ZIF value to be updated,
  * the ZIF value for the zone is calculated via the following algorithm:
  *
  * - If the zone has been operational for at least ZONE_FORECAST_BASELINE_WEEKS weeks
  *   (i.e. the zone has actual impressions for the past ZONE_FORECAST_BASELINE_WEEKS
  *   occurrences of the same operation interval as is currently being updated), then
  *   the expected impressions value is the average of the past two operation intervals'
  *   actual impressions of the zone, multiplied by a moving average trend value.
  * - Else, if the zone has not been operational for at least
  *   ZONE_FORECAST_BASELINE_WEEKS weeks, then the expected impressions is set to the
  *   actual number of impressions in the previous operation interval for that zone.
  * - Else the previous operation interval for that zone does not have an actual
  *   number of impressions, then the expected number of impressions for that
  *   zone is set to ZONE_FORECAST_DEFAULT_ZONE_IMPRESSIONS.
  *
  * Note also:
  *  - If the zone ID exists in the $this->aNewZoneIDs array, then all operation
  *    intervals for the past week will be updated, not just those in $aRanges.
  *
  * @access private
  * @param integer $zoneId The ID of the zone which may require its ZIF value(s)
  *                        to be calculated.
  * @param array   $aRanges An array of arrays, containing ranges of operation
  *                         intervals that the zone will need its ZIF values
  *                         updated for.
  * @param boolean $newZone The zone is considered to be "new"; store this
  *                         information along with the forecasts.
  *
  * @return void
  */
 function _calculateZoneImpressionForecastValues($zoneId, $aRanges, $newZone)
 {
     // Check the parameters
     if (!is_integer($zoneId) || $zoneId < 0) {
         return;
     }
     if (!is_array($aRanges) || empty($aRanges)) {
         return;
     }
     // Update the ZIF for all ranges
     foreach ($aRanges as $aRange) {
         // Get the two dates representing operation interval start
         // dates for the two operation interval IDs at the lower and
         // upper bounds of the range
         $tmp = array_keys($aRange);
         $min = min($tmp);
         $max = max($tmp);
         $oRangeLowerDate = new Date();
         $oRangeLowerDate->copy($aRange[$min]['start']);
         $oRangeUpperDate = new Date();
         $oRangeUpperDate->copy($aRange[$max]['start']);
         // Get the average impressions delivered by the zone in previous
         // operation intervals, for the required operation interval range
         $aZoneImpressionAverages = $this->_getZoneImpressionAverages($zoneId, $oRangeLowerDate, $oRangeUpperDate);
         // Get the details of all forecast and actual impressions of the
         // zone for the required operation interval range, offset by the
         // required time interval, so that current trends in differences
         // between forecast and actual delivery can be calculated
         $oTrendLowerDate = $this->_getTrendLowerDate($oRangeLowerDate);
         $oTrendUpperDate = $this->_getTrendUpperDate($oRangeUpperDate);
         $aZoneForecastAndImpressionHistory = $this->oDal->getZonePastForecastAndImpressionHistory($zoneId, $oTrendLowerDate, $oTrendUpperDate);
         foreach ($aRange as $intervalId => $aInterval) {
             if (!isset($aZoneImpressionAverages[$intervalId])) {
                 // This zone does not have a past average actual impressions delivered
                 // value for this operation interval ID, and so cannot have been running
                 // for longer than ZONE_FORECAST_BASELINE_WEEKS - as a result, either
                 // forecast the value based on the past operation interval's data, or
                 // use the default value
                 $previousIntervalID = OX_OperationInterval::previousOperationIntervalID($intervalId);
                 if (isset($aZoneForecastAndImpressionHistory[$previousIntervalID]['actual_impressions']) && $aZoneForecastAndImpressionHistory[$previousIntervalID]['actual_impressions'] > 0) {
                     // Use the previous operation interval's actual impressions value as the
                     // new forecast
                     OA::debug("  - Forecasting for OI {$intervalId} (starting '" . $aInterval['start']->format('%Y-%m-%d %H:%M:%S') . ' ' . $aInterval['start']->tz->getShortName() . "') based on previous OI value", PEAR_LOG_DEBUG);
                     $this->_storeForecast($this->aForecastResults, $aZoneForecastAndImpressionHistory, $zoneId, $intervalId, $aInterval, $aZoneForecastAndImpressionHistory[$previousIntervalID]['actual_impressions'], $newZone);
                 } else {
                     // Use the default value as the new forecast, and note that the forecast
                     // is so based
                     OA::debug("  - Forecasting for OI {$intervalId} (starting '" . $aInterval['start']->format('%Y-%m-%d %H:%M:%S') . ' ' . $aInterval['start']->tz->getShortName() . "') based on default value", PEAR_LOG_DEBUG);
                     $this->_storeForecast($this->aForecastResults, $aZoneForecastAndImpressionHistory, $zoneId, $intervalId, $aInterval, $this->ZONE_FORECAST_DEFAULT_ZONE_IMPRESSIONS, $newZone, true);
                 }
             } else {
                 // Get the lower bound operation interval ID of the trend calculation
                 // range required for this operation interval ID
                 $offetOperationId = OX_OperationInterval::previousOperationIntervalID($intervalId, null, $this->_getTrendOperationIntervalStartOffset());
                 // Set the initial forecast and actual impressions values
                 $forecastImpressions = 0;
                 $actualImpressions = 0;
                 // Loop over the trend adjustment range data appropriate to this operation
                 // interval ID, and sum up the forecast and actual impression values
                 for ($i = 0; $i < ZONE_FORECAST_TREND_OPERATION_INTERVALS; $i++) {
                     if (!isset($aZoneForecastAndImpressionHistory[$offetOperationId])) {
                         // The forecast/impression history of this zone is incomplete, so the
                         // trend adjustment information cannot be calculated
                         $forecastImpressions = false;
                         $actualImpressions = false;
                         break;
                     }
//.........这里部分代码省略.........
开发者ID:villos,项目名称:tree_admin,代码行数:101,代码来源:ForecastZoneImpressions.php

示例6: get_weekly_volume_graph

function get_weekly_volume_graph()
{
    global $wpdb;
    global $userdata;
    get_currentuserinfo();
    $beg_date = new Date();
    $end_date = new Date();
    $wk = array(0, 0, 0, 0);
    $label = array(0, 0, 0, 0);
    $filename = array("filename" => "/var/www/vanhlebarsoftware/wp-content/plugins/fitnesslog/graphs/wklygraph.png");
    // Get current weeks and prior three weeks volume numbers.
    $day_of_wk = $beg_date->getDayOfWeek();
    $beg_date->addDays(-($day_of_wk - 1));
    $end_date->copy($beg_date);
    $end_date->addDays(6);
    for ($i = 0; $i < 4; $i++) {
        $query = "SELECT user_id, SUM(seconds) AS seconds FROM " . $wpdb->prefix . "flmain WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userdata->ID . " GROUP BY user_id";
        $result = $wpdb->get_results($query, ARRAY_A);
        if ($result) {
            foreach ($result as $row) {
                $wk[$i] = convert_seconds_minutes($row["seconds"]);
            }
        } else {
            $wk[$i] = 0;
        }
        // Add any strength training that we have done to the total.
        $query = "SELECT user_id, SUM(seconds) AS seconds FROM " . $wpdb->prefix . "flstrength WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userdata->ID . " GROUP BY user_id";
        $result = $wpdb->get_results($query, ARRAY_A);
        if ($result) {
            foreach ($result as $row) {
                $wk[$i] = $wk[$i] + convert_seconds_minutes($row["seconds"]);
            }
        }
        // Create the labels.
        $label[$i] = $end_date->format("%m/%d");
        // Move the dates back by one week.
        $beg_date->addDays(-7);
        $end_date->addDays(-7);
    }
    //Setup the graph.
    $Graph =& Image_Graph::factory('graph', array(175, 175), true);
    $Plotarea =& $Graph->addNew('plotarea');
    $Dataset =& Image_Graph::factory('dataset');
    $Dataset->addPoint($label[3], $wk[3]);
    $Dataset->addPoint($label[2], $wk[2]);
    $Dataset->addPoint($label[1], $wk[1]);
    $Dataset->addPoint($label[0], $wk[0]);
    $Plot =& $Plotarea->addNew('bar', &$Dataset);
    $Plot->setFillColor('green');
    $YAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
    $YAxis->setTitle('Minutes', 'vertical');
    $XAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
    //	$XAxis->setFontAngle( "vertical" );
    $XAxis->setTitle("Week", array('angle' => 0));
    //Output the finished graph to the graphs directory.
    $result = $Graph->done($filename);
    if ($result) {
        var_dump("error creating graph!");
    }
}
开发者ID:EABonney,项目名称:Fitlog,代码行数:60,代码来源:fitnesslog.php

示例7: 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;
 }
开发者ID:villos,项目名称:tree_admin,代码行数:56,代码来源:OperationInterval.php

示例8: 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

示例9: 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);
         }
//.........这里部分代码省略.........
开发者ID:Spark-Eleven,项目名称:revive-adserver,代码行数:101,代码来源:DeliveryLimitation.php

示例10: testRun

 /**
  * A method to test the run() method.
  */
 function testRun()
 {
     $oServiceLocator =& OA_ServiceLocator::instance();
     $aTypes = array('types' => array(0 => 'request', 1 => 'impression', 2 => 'click'), 'connections' => array(1 => MAX_CONNECTION_AD_IMPRESSION, 2 => MAX_CONNECTION_AD_CLICK));
     // Mock the DAL, and set expectations
     Mock::generate('OX_Dal_Maintenance_Statistics');
     $oDal = new MockOX_Dal_Maintenance_Statistics($this);
     $oDal->expectNever('saveSummary');
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     // Set the controller class
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     // Test
     $oSummariseFinal = new OX_Maintenance_Statistics_Task_SummariseFinal();
     $oSummariseFinal->oController->updateIntermediate = false;
     $oSummariseFinal->oController->updateFinal = false;
     $oSummariseFinal->run();
     $oDal->tally();
     // Prepare the dates
     $olastDateIntermediate = new Date('2006-03-09 10:59:59');
     $oStartDate = new Date();
     $oStartDate->copy($olastDateIntermediate);
     $oStartDate->addSeconds(1);
     $oUpdateIntermediateToDate = new Date('2006-03-09 11:59:59');
     // Mock the DAL, and set expectations
     Mock::generate('OX_Dal_Maintenance_Statistics');
     $oDal = new MockOX_Dal_Maintenance_Statistics($this);
     $oDal->expectNever('saveSummary');
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     // Set the controller class
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     // Test
     $oSummariseFinal = new OX_Maintenance_Statistics_Task_SummariseFinal();
     $oSummariseFinal->oController->updateIntermediate = true;
     $oSummariseFinal->oController->oLastDateIntermediate = $olastDateIntermediate;
     $oSummariseFinal->oController->oUpdateIntermediateToDate = $oUpdateIntermediateToDate;
     $oSummariseFinal->oController->updateFinal = false;
     $oSummariseFinal->run();
     $oDal->tally();
     // Prepare the dates
     $olastDateFinal = new Date('2006-03-09 10:59:59');
     $oStartDate = new Date();
     $oStartDate->copy($olastDateFinal);
     $oStartDate->addSeconds(1);
     $oUpdateFinalToDate = new Date('2006-03-09 11:59:59');
     // Mock the DAL, and set expectations
     Mock::generate('OX_Dal_Maintenance_Statistics');
     $oDal = new MockOX_Dal_Maintenance_Statistics($this);
     $oDal->expectOnce('saveSummary', array($oStartDate, $oUpdateFinalToDate, $aTypes, 'data_intermediate_ad', 'data_summary_ad_hourly'));
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     // Set the controller class
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     // Test
     $oSummariseFinal = new OX_Maintenance_Statistics_Task_SummariseFinal();
     $oSummariseFinal->oController->updateIntermediate = false;
     $oSummariseFinal->oController->updateFinal = true;
     $oSummariseFinal->oController->oLastDateFinal = $olastDateFinal;
     $oSummariseFinal->oController->oUpdateFinalToDate = $oUpdateFinalToDate;
     $oSummariseFinal->run();
     $oDal->tally();
     // Prepare the dates
     $olastDateIntermediate = new Date('2006-03-09 10:59:59');
     $oStartDate = new Date();
     $oStartDate->copy($olastDateIntermediate);
     $oStartDate->addSeconds(1);
     $oUpdateIntermediateToDate = new Date('2006-03-09 11:59:59');
     $olastDateFinal = new Date('2006-03-09 10:59:59');
     $oStartDate = new Date();
     $oStartDate->copy($olastDateFinal);
     $oStartDate->addSeconds(1);
     $oUpdateFinalToDate = new Date('2006-03-09 11:59:59');
     // Mock the DAL, and set expectations
     Mock::generate('OX_Dal_Maintenance_Statistics');
     $oDal = new MockOX_Dal_Maintenance_Statistics($this);
     $oDal->expectOnce('saveSummary', array($oStartDate, $oUpdateFinalToDate, $aTypes, 'data_intermediate_ad', 'data_summary_ad_hourly'));
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     // Set the controller class
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     // Test
     $oSummariseFinal = new OX_Maintenance_Statistics_Task_SummariseFinal();
     $oSummariseFinal->oController->updateIntermediate = true;
     $oSummariseFinal->oController->oLastDateIntermediate = $olastDateIntermediate;
     $oSummariseFinal->oController->oUpdateIntermediateToDate = $oUpdateIntermediateToDate;
     $oSummariseFinal->oController->updateFinal = true;
     $oSummariseFinal->oController->oLastDateFinal = $olastDateFinal;
     $oSummariseFinal->oController->oUpdateFinalToDate = $oUpdateFinalToDate;
     $oSummariseFinal->run();
     $oDal->tally();
 }
开发者ID:Jaree,项目名称:revive-adserver,代码行数:95,代码来源:SummariseFinal.mtsdb.test.php

示例11: saveSummary

 /**
  * A method to update the summary table from the intermediate tables.
  *
  * @param PEAR::Date $oStartDate The start date/time to update from.
  * @param PEAR::Date $oEndDate   The end date/time to update to.
  * @param array $aActions        An array of data types to summarise. Contains
  *                               two array, the first containing the data types,
  *                               and the second containing the connection type
  *                               values associated with those data types, if
  *                               appropriate. For example:
  *          array(
  *              'types'       => array(
  *                                  0 => 'request',
  *                                  1 => 'impression',
  *                                  2 => 'click'
  *                               ),
  *              'connections' => array(
  *                                  1 => MAX_CONNECTION_AD_IMPRESSION,
  *                                  2 => MAX_CONNECTION_AD_CLICK
  *                               )
  *          )
  *                               Note that the order of the items must match
  *                               the order of the items in the database tables
  *                               (e.g. in data_intermediate_ad and
  *                               data_summary_ad_hourly for the above example).
  * @param string $fromTable      The name of the intermediate table to summarise
  *                               from (e.g. 'data_intermediate_ad').
  * @param string $toTable        The name of the summary table to summarise to
  *                               (e.g. 'data_summary_ad_hourly').
  */
 function saveSummary($oStartDate, $oEndDate, $aActions, $fromTable, $toTable)
 {
     $aConf = $GLOBALS['_MAX']['CONF'];
     // Check that there are types to summarise
     if (empty($aActions['types']) || empty($aActions['connections'])) {
         return;
     }
     // How many days does the start/end period span?
     $days = Date_Calc::dateDiff($oStartDate->getDay(), $oStartDate->getMonth(), $oStartDate->getYear(), $oEndDate->getDay(), $oEndDate->getMonth(), $oEndDate->getYear());
     if ($days == 0) {
         // Save the data
         $this->_saveSummary($oStartDate, $oEndDate, $aActions, $fromTable, $toTable);
     } else {
         // Save each day's data separately
         for ($counter = 0; $counter <= $days; $counter++) {
             if ($counter == 0) {
                 // This is the first day
                 $oInternalStartDate = new Date();
                 $oInternalStartDate->copy($oStartDate);
                 $oInternalEndDate = new Date($oStartDate->format('%Y-%m-%d') . ' 23:59:59');
             } elseif ($counter == $days) {
                 // This is the last day
                 $oInternalStartDate = new Date($oEndDate->format('%Y-%m-%d') . ' 00:00:00');
                 $oInternalEndDate = new Date();
                 $oInternalEndDate->copy($oEndDate);
             } else {
                 // This is a day in the middle
                 $oDayDate = new Date();
                 $oDayDate->copy($oStartDate);
                 $oDayDate->addSeconds(SECONDS_PER_DAY * $counter);
                 $oInternalStartDate = new Date($oDayDate->format('%Y-%m-%d') . ' 00:00:00');
                 $oInternalEndDate = new Date($oDayDate->format('%Y-%m-%d') . ' 23:59:59');
             }
             $this->_saveSummary($oInternalStartDate, $oInternalEndDate, $aActions, $fromTable, $toTable);
         }
     }
 }
开发者ID:ballistiq,项目名称:revive-adserver,代码行数:67,代码来源:Statistics.php

示例12: array

 /**
  * A private method to calculate average values when an operation interval
  * has more than one targeting value.
  *
  * @access private
  * @param array      $aValues  The array of arrays of values to calculate the
  *                             averages from.
  * @param PEAR::Date $oEndDate The end date/time of the operation interval,
  *                             to be used for those values where no expiration
  *                             date is set.
  * @return array The array of "average" values.
  */
 function _calculateAverages($aValues, $oEndDate)
 {
     if (empty($aValues) || !is_array($aValues)) {
         return array();
     }
     reset($aValues);
     while (list(, $aAdValues) = each($aValues)) {
         if (empty($aAdValues) || !is_array($aAdValues)) {
             return array();
         }
         if (count($aAdValues) != 10) {
             return array();
         }
     }
     if (empty($oEndDate) || !is_a($oEndDate, 'Date')) {
         return array();
     }
     $counter = 0;
     $totalSeconds = 0;
     $aResult = array('ad_required_impressions' => 0, 'ad_requested_impressions' => 0, 'ad_priority' => 0, 'ad_priority_factor' => 0, 'ad_priority_factor_limited' => 0, 'ad_past_zone_traffic_fraction' => 0, 'average' => true);
     reset($aValues);
     while (list(, $aAdValues) = each($aValues)) {
         if ($counter == 0) {
             $aResult['interval_start'] = $aAdValues['interval_start'];
             $aResult['interval_end'] = $aAdValues['interval_end'];
         }
         $oCreatedDate = new Date($aAdValues['created']);
         if (is_null($aAdValues['expired'])) {
             $oExpiredDate = new Date();
             $oExpiredDate->copy($oEndDate);
         } else {
             $oExpiredDate = new Date($aAdValues['expired']);
         }
         $oSpan = new Date_Span();
         $oSpan->setFromDateDiff($oCreatedDate, $oExpiredDate);
         $seconds = $oSpan->toSeconds();
         $aResult['ad_required_impressions'] += $aAdValues['ad_required_impressions'] * $seconds;
         $aResult['ad_requested_impressions'] += $aAdValues['ad_requested_impressions'] * $seconds;
         $aResult['ad_priority'] += $aAdValues['ad_priority'] * $seconds;
         $aResult['ad_priority_factor'] += $aAdValues['ad_priority_factor'] * $seconds;
         $aResult['ad_past_zone_traffic_fraction'] += $aAdValues['ad_past_zone_traffic_fraction'] * $seconds;
         if ($aAdValues['ad_priority_factor_limited'] == 1) {
             $aResult['ad_priority_factor_limited'] = 1;
         }
         $counter++;
         $totalSeconds += $seconds;
     }
     $aResult['ad_required_impressions'] /= $totalSeconds;
     $aResult['ad_requested_impressions'] /= $totalSeconds;
     $aResult['ad_priority'] /= $totalSeconds;
     $aResult['ad_priority_factor'] /= $totalSeconds;
     $aResult['ad_past_zone_traffic_fraction'] /= $totalSeconds;
     return $aResult;
 }
开发者ID:villos,项目名称:tree_admin,代码行数:66,代码来源:Targeting.php

示例13: 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);
                         }
                     }
                 }
             }
         }
//.........这里部分代码省略.........
开发者ID:Spark-Eleven,项目名称:revive-adserver,代码行数:101,代码来源:SummariseIntermediate.php

示例14: getPreviousWeekZoneForcastImpressions

 /**
  * A method to return the forecast impressions for a zone, indexed by operation interval,
  * from the current operation interval through the past week. If no forecast stored in
  * the database for a given OI, uses average of forecasts found.
  *
  * @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,
  *                                                      ['_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 previous OI
     $oPreviousOI = new Date($oDate);
     $oPreviousOI->subtractSeconds(OX_OperationInterval::getOperationInterval() * 60);
     // Get the start and end ranges of the current week, up to the previous OI
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oPreviousOI);
     $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_intermediate_ad');
     $oneHourInterval = OA_Dal::quoteInterval(1, 'hour');
     $query = "\n            SELECT\n                SUM(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 date_time > DATE_SUB('" . $oDateWeekStart->format('%Y-%m-%d %H:%M:%S') . "', {$oneHourInterval})\n                AND date_time < DATE_ADD('" . $oDateWeekEnd->format('%Y-%m-%d %H:%M:%S') . "', {$oneHourInterval})\n                AND zone_id != 0\n            GROUP BY\n            \tinterval_start,\n            \tinterval_end,\n            \toperation_interval_id\n            ORDER BY\n                interval_start";
     $rc = $this->oDbh->query($query);
     $totalForecastImpressions = 0;
     $count = 0;
     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' => $zoneId, 'forecast_impressions' => $aRow['forecast_impressions'], 'operation_interval_id' => $aRow['operation_interval_id']);
             $count++;
             $totalForecastImpressions += $aRow['forecast_impressions'];
         }
     }
     $averageForecastImpressions = 0;
     if ($count > 0) {
         $averageForecastImpressions = floor($totalForecastImpressions / $count);
     }
     if ($averageForecastImpressions == 0) {
         $averageForecastImpressions = $this->getZoneForecastDefaultZoneImpressions();
     }
     // 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' => $averageForecastImpressions, 'operation_interval_id' => $operationIntervalID);
         }
     }
     // Overwrite current OI with previous OI to match the zone forecasting algorithm
     $currOI = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $prevOI = OX_OperationInterval::previousOperationIntervalID($currOI);
     $aFinalResult[$currOI]['forecast_impressions'] = $aFinalResult[$prevOI]['forecast_impressions'];
     // Return data
     return $aFinalResult;
 }
开发者ID:ballistiq,项目名称:revive-adserver,代码行数:82,代码来源:Priority.php

示例15: getDayArray

 /**
  * A method to return an array containing the days in the span, including the start
  * and end days, where each day in the array is formatted as a string.
  *
  * @param string $format An optional PEAR::Date compatible format string.
  * @return array An array of the days in the span.
  */
 function getDayArray($format = '%Y-%m-%d')
 {
     $aDays = array();
     $oDate = new Date();
     $oDate->copy($this->oStartDate);
     while (!$oDate->after($this->oEndDate)) {
         $aDays[] = $oDate->format($format);
         $oDate->addSeconds(SECONDS_PER_DAY);
     }
     return $aDays;
 }
开发者ID:ballistiq,项目名称:revive-adserver,代码行数:18,代码来源:DaySpan.php


注:本文中的Date::copy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。