コード例 #1
0
ファイル: rss-to-twitter.php プロジェクト: stof/pearweb
$httpRequest = new HTTP_Request2('http://pear.php.net/feeds/latest.rss');
$response = $httpRequest->send();
$rss = new XML_Feed_Parser($response->getBody());
$oauth = new HTTP_OAuth_Consumer($argv[1], $argv[2], $argv[3], $argv[4]);
$twitter = new Services_Twitter();
$twitter->setOAuth($oauth);
// Figure out the current time
$tz = new Date_TimeZone(date_default_timezone_get());
$now = new Date();
$now->setTZ($tz);
$all = array();
foreach ($rss as $feed) {
    // Is this more than an hour old?  If so, skip it.
    $rssDate = new Date($feed->date);
    $span = new Date_Span($rssDate, $now);
    $hoursOld = (int) ceil($span->toHours());
    if ($hoursOld > 1) {
        continue;
    }
    $all[$feed->title] = $feed->link;
}
// Reverse so that we tweet the oldest first
$reversed = array_reverse($all, true);
$exclamations = array('Cool!', 'Awesome!', 'Great Scott!', 'Sweet!', 'Holy Crap!', 'Sweet sassy molassy!', 'Huzzah!', 'Jiminey crickets!', 'Great horny toads!');
foreach ($reversed as $title => $link) {
    $key = md5($link);
    if ($cache->get($key) === false) {
        $exclamation = $exclamations[rand(0, count($exclamations) - 1)];
        $status = "{$exclamation} {$title} was just released! {$link}";
        $twitter->statuses->update($status);
        $cache->save($title, $key);
コード例 #2
0
 /**
  * A method to get the hourly revenuo of a monthly tenancy campaign
  *
  * Monthly tenancy calculation sponsored by www.admost.nl
  *
  * @param array $aInfo The finance information, as returned by _saveSummaryGetAdFinanceInfo
  * @param Date $oStartDate
  * @param Date $oEndDate
  * @param string $table
  * @return double
  */
 function getMtRevenue($aInfo, $oStartDate, $oEndDate, $table)
 {
     OA::debug(sprintf("  - Calculating MT revenue for banner [id%d] between %s and %s:", $aInfo['ad_id'], $oStartDate->format('%Y-%m-%d %H:%M:%S %Z'), $oEndDate->format('%Y-%m-%d %H:%M:%S %Z')), PEAR_LOG_DEBUG);
     $aConf = $GLOBALS['_MAX']['CONF'];
     $oMonthStart = new Date($oStartDate);
     // Set timezone
     if (!empty($aInfo['advertiser_id'])) {
         $doClient = OA_Dal::staticGetDO('clients', $aInfo['advertiser_id']);
         $aAdvertiserPrefs = OA_Preferences::loadAccountPreferences($doClient->account_id, true);
         if (!empty($aAdvertiserPrefs['timezone'])) {
             $oMonthStart->convertTZbyID($aAdvertiserPrefs['timezone']);
         }
     }
     // Get ad/zone combinations for the campaign
     if (!isset($this->aMtRevenueCache[$aInfo['campaign_id']])) {
         $query = "\n                SELECT\n                    COUNT(*) as cnt\n                FROM\n                    " . $this->oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table'][$table], true) . " d JOIN\n                    " . $this->oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['banners'], true) . " a ON (a.bannerid = d.ad_id)\n                WHERE\n                    a.campaignid = {$aInfo['campaign_id']}\n                    AND d.date_time >= " . $this->oDbh->quote($oStartDate->format('%Y-%m-%d %H:%M:%S'), 'timestamp') . "\n                    AND d.date_time <= " . $this->oDbh->quote($oEndDate->format('%Y-%m-%d %H:%M:%S'), 'timestamp');
         $this->aMtRevenueCache[$aInfo['campaign_id']] = $this->oDbh->query($query)->fetchOne();
     }
     $oMonthStart->setDay(1);
     $oMonthStart->setHour(0);
     $oMonthStart->setMinute(0);
     $oMonthStart->setSecond(0);
     OA::debug(sprintf("    - Month start: %s", $oMonthStart->format('%Y-%m-%d %H:%M:%S %Z')), PEAR_LOG_DEBUG);
     $daysInMonth = $oMonthStart->getDaysInMonth();
     OA::debug(sprintf("    - Days in month: %d", $daysInMonth), PEAR_LOG_DEBUG);
     $oMonthEnd = new Date($oMonthStart);
     $oMonthEnd->setDay($daysInMonth);
     $oMonthEnd = $oMonthEnd->getNextDay();
     $oMonthEnd->setTZ($oMonthStart->tz);
     OA::debug(sprintf("    - Month end: %s", $oMonthEnd->format('%Y-%m-%d %H:%M:%S %Z')), PEAR_LOG_DEBUG);
     $oDiff = new Date_Span();
     $oDiff->setFromDateDiff($oMonthEnd, $oMonthStart);
     $hoursPerMonth = ceil($oDiff->toHours());
     OA::debug(sprintf("    - Hours per month: %d", $hoursPerMonth), PEAR_LOG_DEBUG);
     $oDiff = new Date_Span();
     $oDiff->setFromDateDiff($oEndDate, $oStartDate);
     $hoursPerInterval = ceil($oDiff->toHours());
     OA::debug(sprintf("    - Hours per interval: %d", $hoursPerInterval), PEAR_LOG_DEBUG);
     $adZoneCombinations = $this->aMtRevenueCache[$aInfo['campaign_id']];
     OA::debug(sprintf("    - Ad/zone/OI combinations for campaign [id%d]: %d", $aInfo['campaign_id'], $this->aMtRevenueCache[$aInfo['campaign_id']]), PEAR_LOG_DEBUG);
     $result = $aInfo['revenue'] / $hoursPerMonth * $hoursPerInterval / $adZoneCombinations;
     OA::debug(sprintf("    - Result: %0.4f", $result), PEAR_LOG_DEBUG);
     return $result;
 }
コード例 #3
0
 /**
  * A method to perform basic end-to-end integration testing of the Maintenance
  * Priority Engine classes for the Ad Server.
  *
  * Test 0: Test that no zone forecast or priority data exists to begin with.
  * Test 1: Run the MPE without any stats, and without the stats engine ever
  *         having been run before. Test that zone forecasts are updated
  *         with the appropriate values, and that the correct priorities are
  *         generated.
  * Test 2: Run the MPE without any stats, but with the stats engine having
  *         reported that it has run. Test that zone forecasts are updated
  *         with the appropriate values, and that the correct priorities are
  *         generated.
  * Test 3: Run the MPE again, as for Test 2, but with a later date used as
  *         for when the stats engine reported having run.
  */
 function testAdServer()
 {
     // Test 0: Ensure correct number of links in the ad_zone_assoc table
     $this->assertEqual($this->_azaRows(), 7);
     // 4 proper associations + 3 default with zone 0
     // Test 0: Ensure no links in the ad_zone_assoc table have priority > 0
     $this->assertEqual($this->_azaRows(true), 0);
     // Test 0: Ensure no links in the data_summary_ad_zone_assoc table have priority > 0
     $this->assertEqual($this->_dsazaRows(true), 0);
     // Test 0: Ensure no data in the log_maintenance_priority table
     $this->_assertLogMaintenance();
     // Test 1: Set "current" date for the MPE run
     $oDate = new Date('2005-06-15 13:01:01');
     $this->oServiceLocator->register('now', $oDate);
     // Test 1: Prepare the MPE object
     $oMaintenancePriority = new OA_Maintenance_Priority_AdServer();
     // Test 1: Store the date before the MPE runs
     $oTest1BeforeUpdateDate = new Date();
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     // Test 1: Run the MPE
     $oMaintenancePriority->updatePriorities();
     // Test 1: Store the date after the MPE runs
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     $oTest1AfterUpdateDate = new Date();
     // Test 1: Ensure correct number of links in the ad_zone_assoc table
     $this->assertEqual($this->_azaRows(), 7);
     // 4 proper associations + 3 default with zone 0
     // Test 1: Ensure correct number of links in the ad_zone_assoc table with priority > 0
     $this->assertEqual($this->_azaRows(true), 7);
     // Test 1: Ensure correct number of links in the data_summary_ad_zone_assoc table with priority >
     $this->assertEqual($this->_dsazaRows(true), 7);
     // Test 1: Ensure that the priorities in the ad_zone_assoc and data_summary_ad_zone_assoc
     // tables are set correctly
     $aTestOneZero = array();
     $aTestOneZero['ad_id'] = 1;
     $aTestOneZero['zone_id'] = 0;
     $aTestOneZero['priority'] = 11 / 200;
     // 200 is 10 (default forecast) / 0.05 (factor)
     $aTestOneZero['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestOneZero['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 11, 'requested_impressions' => 11, 'priority' => $aTestOneZero['priority'], 'priority_factor' => $aTestOneZero['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestOneZero);
     $aTestTwoZero = array();
     $aTestTwoZero['ad_id'] = 2;
     $aTestTwoZero['zone_id'] = 0;
     $aTestTwoZero['priority'] = 12 / 200;
     $aTestTwoZero['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestTwoZero['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 12, 'requested_impressions' => 12, 'priority' => $aTestTwoZero['priority'], 'priority_factor' => $aTestTwoZero['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestTwoZero);
     $aTestThreeZero = array();
     $aTestThreeZero['ad_id'] = 3;
     $aTestThreeZero['zone_id'] = 0;
     $aTestThreeZero['priority'] = 6 / 200;
     $aTestThreeZero['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestThreeZero['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 6, 'requested_impressions' => 6, 'priority' => $aTestThreeZero['priority'], 'priority_factor' => $aTestThreeZero['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestThreeZero);
     $aTestOneOne = array();
     $aTestOneOne['ad_id'] = 1;
     $aTestOneOne['zone_id'] = 1;
     $aTestOneOne['priority'] = 10 / 200;
     // Constant, only priority_factor increases
     $aTestOneOne['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestOneOne['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 11, 'requested_impressions' => 10, 'priority' => $aTestOneOne['priority'], 'priority_factor' => $aTestOneOne['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestOneOne);
     $aTestTwoThree = array();
     $aTestTwoThree['ad_id'] = 2;
     $aTestTwoThree['zone_id'] = 3;
     $aTestTwoThree['priority'] = 8 / 200;
     // Constant, only priority_factor increases
     $aTestTwoThree['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestTwoThree['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 12, 'requested_impressions' => 8, 'priority' => $aTestTwoThree['priority'], 'priority_factor' => $aTestTwoThree['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestTwoThree);
     $aTestThreeThree = array();
     $aTestThreeThree['ad_id'] = 3;
     $aTestThreeThree['zone_id'] = 3;
     $aTestThreeThree['priority'] = 2 / 200;
     // Constant, only priority_factor increases
     $aTestThreeThree['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestThreeThree['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 3, 'requested_impressions' => 2, 'priority' => $aTestThreeThree['priority'], 'priority_factor' => $aTestThreeThree['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestThreeThree);
     $aTestThreeFour = array();
     $aTestThreeFour['ad_id'] = 3;
     $aTestThreeFour['zone_id'] = 4;
     $aTestThreeFour['priority'] = 3 / 200;
     // Constant, only priority_factor increases
     $aTestThreeFour['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestThreeFour['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 3, 'requested_impressions' => 3, 'priority' => $aTestThreeFour['priority'], 'priority_factor' => $aTestThreeFour['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestThreeFour);
     // Test 1: Ensure that the values in the log_maintenance_priority table are correct
     $this->_assertLogMaintenance(2, $oTest1BeforeUpdateDate, $oTest1AfterUpdateDate, 60, DAL_PRIORITY_UPDATE_ECPM);
     // Insert data that indicates that the Maintenance Statistics Engine
     // has recently updated the available stats, but don't insert any
     // stats into the tables
     $this->oServiceLocator =& OA_ServiceLocator::instance();
     $startDate = new Date('2005-06-15 14:00:01');
     $this->oServiceLocator->register('now', $startDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->updateFinal = true;
     $aOiDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($startDate);
     $oMaintenanceStatistics->oUpdateIntermediateToDate = $aOiDates['end'];
     $oMaintenanceStatistics->oUpdateFinalToDate = $aOiDates['end'];
     $this->oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     $oLogCompletion = new OX_Maintenance_Statistics_Task_LogCompletion();
     $oLogCompletion->run();
     // Test 2: Set "previous" date for the MPE run
     $oPreviousDate = new Date('2005-06-15 13:01:01');
     $previousOperationIntervalID = $currentOperationIntervalID;
     // Test 2: Set "current" date for the MPE run
     $oDate = new Date('2005-06-15 14:01:01');
     $this->oServiceLocator->register('now', $oDate);
     // Test 2: Prepare the MPE object
     $oMaintenancePriority = new OA_Maintenance_Priority_AdServer();
     // Test 2: Store the date before the MPE runs
     $oTest2BeforeUpdateDate = new Date();
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     // Test 2: Run the MPE
     $oMaintenancePriority->updatePriorities();
     // Test 2: Store the date after the MPE runs
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     $oTest2AfterUpdateDate = new Date();
     // Test 2: Ensure correct number of links in the ad_zone_assoc table
     $this->assertEqual($this->_azaRows(), 7);
     // 4 proper associations + 3 default with zone 0
     // Test 2: Ensure correct number of links in the ad_zone_assoc table with priority > 0
     $this->assertEqual($this->_azaRows(true), 7);
     // Test 2: Ensure correct number of links in the data_summary_ad_zone_assoc table with priority > 0
     $this->assertEqual($this->_dsazaRows(true), 14);
     // Test 2: Ensure that the priorities in the ad_zone_assoc and data_summary_ad_zone_assoc
     // tables are set correctly
     $aTestOneZero['priority'] = 12 / 200;
     $aTestOneZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestOneZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 12, 'requested_impressions' => 12, 'priority' => $aTestOneZero['priority'], 'priority_factor' => $aTestOneZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestOneZero);
     $aTestTwoZero['priority'] = 12 / 200;
     $aTestTwoZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestTwoZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 12, 'requested_impressions' => 12, 'priority' => $aTestTwoZero['priority'], 'priority_factor' => $aTestTwoZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestTwoZero);
     $aTestThreeZero['priority'] = 6 / 200;
     $aTestThreeZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestThreeZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 6, 'requested_impressions' => 6, 'priority' => $aTestThreeZero['priority'], 'priority_factor' => $aTestThreeZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestThreeZero);
     $aTestOneOne['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestOneOne['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 12, 'requested_impressions' => 10, 'priority' => $aTestOneOne['priority'], 'priority_factor' => $aTestOneOne['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestOneOne);
     $aTestTwoThree['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestTwoThree['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 12, 'requested_impressions' => 8, 'priority' => $aTestTwoThree['priority'], 'priority_factor' => $aTestTwoThree['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestTwoThree);
     $aTestThreeThree['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestThreeThree['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 3, 'requested_impressions' => 2, 'priority' => $aTestThreeThree['priority'], 'priority_factor' => $aTestThreeThree['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestThreeThree);
     $aTestThreeFour['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestThreeFour['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 3, 'requested_impressions' => 3, 'priority' => $aTestThreeFour['priority'], 'priority_factor' => $aTestThreeFour['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestThreeFour);
     // Test 2: Ensure that the values in the log_maintenance_priority table are correct
     $this->_assertLogMaintenance(2, $oTest1BeforeUpdateDate, $oTest1AfterUpdateDate, 60, DAL_PRIORITY_UPDATE_ECPM);
     $this->_assertLogMaintenance(6, $oTest2BeforeUpdateDate, $oTest2AfterUpdateDate, 60, DAL_PRIORITY_UPDATE_ECPM);
     // Insert data that indicates that the Maintenance Statistics Engine
     // has recently updated the available stats
     $this->oServiceLocator =& OA_ServiceLocator::instance();
     $startDate = new Date('2005-06-19 00:00:01');
     $this->oServiceLocator->register('now', $startDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->updateFinal = true;
     $aOiDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($startDate);
     $oMaintenanceStatistics->oUpdateIntermediateToDate = $aOiDates['end'];
     $oMaintenanceStatistics->oUpdateFinalToDate = $aOiDates['end'];
     $this->oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     $oLogCompletion = new OX_Maintenance_Statistics_Task_LogCompletion();
     $oLogCompletion->run();
     // Insert some stats for an ad zone combination
     $doDIA = OA_DAL::factoryDO('data_intermediate_ad');
     $doDIA->ad_id = 3;
     $doDIA->zone_id = 3;
     $doDIA->impressions = 20;
     $doDIA->date_time = $aOiDates['start']->getDate();
     $doDIA->interval_start = $aOiDates['start']->getDate();
     $doDIA->interval_end = $aOiDates['end']->getDate();
     $doDIA->operation_interval = 60;
     $doDIA->operation_interval_id = OX_OperationInterval::convertDateToOperationIntervalID($aOiDates['start']);
     $doDIA->insert();
     // Test 3: Set "current" date for the MPE run
     $oDate = new Date('2005-06-19 00:01:01');
     $this->oServiceLocator->register('now', $oDate);
     // Test 3: Prepare the MPE object
     $oMaintenancePriority = new OA_Maintenance_Priority_AdServer();
     // Test 3: Store the date before the MPE runs
     $oTest3BeforeUpdateDate = new Date();
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     // Test 3: Run the MPE
     $oMaintenancePriority->updatePriorities();
     // Test 3: Store the date after the MPE runs
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     $oTest3AfterUpdateDate = new Date();
     $oLastUpdatedTo1 = new Date('2005-06-15 14:00:00');
     $oNowUpdatedTo1 = new Date('2005-06-15 15:00:00');
     $oSpan = new Date_Span();
     $oLastUpdatedTo1Copy = new Date();
     $oLastUpdatedTo1Copy->copy($oLastUpdatedTo1);
     $oNowUpdatedTo1Copy = new Date();
     $oNowUpdatedTo1Copy->copy($oNowUpdatedTo1);
     $oSpan->setFromDateDiff($oLastUpdatedTo1Copy, $oNowUpdatedTo1Copy);
     $hours1 = $oSpan->toHours();
     $oLastUpdatedTo2 = new Date('2005-06-15 15:00:00');
     $oNowUpdatedTo2 = new Date('2005-06-19 01:00:00');
     $oSpan = new Date_Span();
     $oLastUpdatedTo2Copy = new Date();
     $oLastUpdatedTo2Copy->copy($oLastUpdatedTo2);
     $oNowUpdatedTo2Copy = new Date();
     $oNowUpdatedTo2Copy->copy($oNowUpdatedTo2);
     $oSpan->setFromDateDiff($oLastUpdatedTo2Copy, $oNowUpdatedTo2Copy);
     $hours2 = $oSpan->toHours();
     // Test 3: Ensure correct number of links in the ad_zone_assoc table
     $this->assertEqual($this->_azaRows(), 7);
     // 4 proper associations + 3 default with zone 0
     // Test 3: Ensure correct number of links in the ad_zone_assoc table with priority > 0
     $this->assertEqual($this->_azaRows(true), 7);
     // Test 3: Ensure correct number of links in the data_summary_ad_zone_assoc table with priority > 0
     $this->assertEqual($this->_dsazaRows(true), 21);
     // Test 3: Ensure that the priorities in the ad_zone_assoc and data_summary_ad_zone_assoc
     // tables are set correctly
     $aTestOneZero['priority'] = 5 / 200;
     $aTestOneZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestOneZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 5, 'requested_impressions' => 5, 'priority' => $aTestOneZero['priority'], 'priority_factor' => $aTestOneZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestOneZero);
     $aTestTwoZero['priority'] = 12 / 200;
     $aTestTwoZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestTwoZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 12, 'requested_impressions' => 12, 'priority' => $aTestTwoZero['priority'], 'priority_factor' => $aTestTwoZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestTwoZero);
     $aTestThreeZero['priority'] = 6 / 200;
     $aTestThreeZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestThreeZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 6, 'requested_impressions' => 6, 'priority' => $aTestThreeZero['priority'], 'priority_factor' => $aTestThreeZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestThreeZero);
     $aTestOneOne['priority'] = 5 / 200;
     // Changed, skipped OIs
     $aTestOneOne['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestOneOne['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 5, 'requested_impressions' => 5, 'priority' => $aTestOneOne['priority'], 'priority_factor' => $aTestOneOne['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestOneOne);
     $aTestTwoThree['priority'] = 12 / 20;
     // Zone has had some impressions, we have a forecast now
     $aTestTwoThree['priority_factor'] = 10;
     // But this ad didn't deliver. Factor increased
     $aTestTwoThree['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 12, 'requested_impressions' => 12, 'priority' => $aTestTwoThree['priority'], 'priority_factor' => $aTestTwoThree['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestTwoThree);
     $aTestThreeThree['priority'] = 4 / 20;
     // Ad/Zone has delivered!
     $aTestThreeThree['priority_factor'] = 2 / 20;
     // Overdelivered quite a bit!
     $aTestThreeThree['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 4, 'requested_impressions' => 4, 'priority' => $aTestThreeThree['priority'], 'priority_factor' => $aTestThreeThree['priority_factor'], 'past_zone_traffic_fraction' => 1);
     $this->_assertPriority($aTestThreeThree);
     $aTestThreeFour['priority'] = 2 / 200;
     // Ad has delivered, but not in this zone
     $aTestThreeFour['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestThreeFour['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 2, 'requested_impressions' => 2, 'priority' => $aTestThreeFour['priority'], 'priority_factor' => $aTestThreeFour['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestThreeFour);
     // Test 3: Ensure that the values in the log_maintenance_priority table are correct
     $this->_assertLogMaintenance(2, $oTest1BeforeUpdateDate, $oTest1AfterUpdateDate, 60, DAL_PRIORITY_UPDATE_ECPM);
     $this->_assertLogMaintenance(6, $oTest2BeforeUpdateDate, $oTest2AfterUpdateDate, 60, DAL_PRIORITY_UPDATE_ECPM);
 }