SAAS-223: Airtime Usage Metric: Amount of time spent broadcasting

- added phone_home_stat testing parameter
- fixed problem if missing data in airtime_latest_version file
This commit is contained in:
denise 2012-05-11 17:27:14 -04:00
parent b38bde6565
commit eb182cf887
3 changed files with 80 additions and 45 deletions

View file

@ -3,7 +3,7 @@
class Application_Model_LiveLog class Application_Model_LiveLog
{ {
public static function GetLiveShowDuration() { public static function GetLiveShowDuration($p_keepData=false) {
try { try {
$con = Propel::getConnection(); $con = Propel::getConnection();
@ -32,7 +32,7 @@ class Application_Model_LiveLog
$duration = $start->diff($end); $duration = $start->diff($end);
$duration = $duration->format("%H:%i:%s"); $duration = $duration->format("%H:%i:%s");
$intervals = explode(":", $duration); $intervals = explode(":", $duration);
// Trim milliseconds (DateInteral does not support) // Trim milliseconds (DateInterval does not support)
$sec = explode(".", $intervals[2]); $sec = explode(".", $intervals[2]);
$intervals[2] = $sec[0]; $intervals[2] = $sec[0];
@ -50,16 +50,19 @@ class Application_Model_LiveLog
$hours += $intervals[0]; $hours += $intervals[0];
if (!$p_keepData) {
// Delete data we just used to start a new log history // Delete data we just used to start a new log history
$sql_delete = "DELETE FROM CC_LIVE_LOG" $sql_delete = "DELETE FROM CC_LIVE_LOG"
." WHERE id = '{$row['id']}'"; ." WHERE id = '{$row['id']}'";
$con->exec($sql_delete); $con->exec($sql_delete);
} }
}
//Trim milliseconds
$seconds = explode(".", $seconds); $seconds = explode(".", $seconds);
$duration = new DateInterval("PT". $hours . "H" . $minutes . "M" . $seconds[0] ."S"); $minutes = (double)(($hours*60)+$minutes . "." . $seconds[0]);
return $duration->format("%H:%i:%s"); //$duration = new DateInterval("PT" . $minutes . "M" . $seconds[0] ."S");
return $duration; //return $duration->format("%i.%s");
return $minutes;
} catch (Exception $e) { } catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable'); header('HTTP/1.0 503 Service Unavailable');
Logging::log("GetLiveShowDuration - Could not connect to database."); Logging::log("GetLiveShowDuration - Could not connect to database.");
@ -67,7 +70,8 @@ class Application_Model_LiveLog
} }
} }
public static function GetScheduledDuration() { public static function GetScheduledDuration($p_keepData = false)
{
try { try {
$con = Propel::getConnection(); $con = Propel::getConnection();
@ -167,17 +171,20 @@ class Application_Model_LiveLog
$hours += $intervals[0]; $hours += $intervals[0];
} }
if (!$p_keepData) {
//Delete row because we do not need data anymore //Delete row because we do not need data anymore
$sql_delete = "DELETE FROM CC_LIVE_LOG" $sql_delete = "DELETE FROM CC_LIVE_LOG"
." WHERE id = '{$row['id']}'"; ." WHERE id = '{$row['id']}'";
$con->exec($sql_delete); $con->exec($sql_delete);
}
} }
$seconds = explode(".", $seconds); $seconds = explode(".", $seconds);
$duration = new DateInterval("PT". $hours . "H" . $minutes . "M" . $seconds[0] ."S"); $minutes = (double)(($hours*60)+$minutes . "." . $seconds[0]);
return $duration->format("%H:%i:%s"); //$duration = new DateInterval("PT". $minutes . "M" . $seconds[0] ."S");
//return $duration->format("%i.%s");
return $minutes;
} catch (Exception $e) { } catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable'); header('HTTP/1.0 503 Service Unavailable');
Logging::log("GetScheduledDuration - Could not connect to database."); Logging::log("GetScheduledDuration - Could not connect to database.");

View file

@ -397,7 +397,8 @@ class Application_Model_Preference
return $out; return $out;
} }
public static function GetSystemInfo($returnArray=false){ public static function GetSystemInfo($returnArray=false, $p_testing)
{
exec('/usr/bin/airtime-check-system --no-color', $output); exec('/usr/bin/airtime-check-system --no-color', $output);
$output = preg_replace('/\s+/', ' ', $output); $output = preg_replace('/\s+/', ' ', $output);
@ -414,8 +415,8 @@ class Application_Model_Preference
$outputArray = array(); $outputArray = array();
$outputArray['LIVE_DURATION'] = Application_Model_LiveLog::GetLiveShowDuration(); $outputArray['LIVE_DURATION'] = Application_Model_LiveLog::GetLiveShowDuration($p_testing);
$outputArray['SCHEDULED_DURATION'] = Application_Model_LiveLog::GetScheduledDuration(); $outputArray['SCHEDULED_DURATION'] = Application_Model_LiveLog::GetScheduledDuration($p_testing);
$outputArray['SOUNDCLOUD_ENABLED'] = self::GetUploadToSoundcloudOption(); $outputArray['SOUNDCLOUD_ENABLED'] = self::GetUploadToSoundcloudOption();
if ($outputArray['SOUNDCLOUD_ENABLED']) { if ($outputArray['SOUNDCLOUD_ENABLED']) {
$outputArray['NUM_SOUNDCLOUD_TRACKS_UPLOADED'] = Application_Model_StoredFile::getSoundCloudUploads(); $outputArray['NUM_SOUNDCLOUD_TRACKS_UPLOADED'] = Application_Model_StoredFile::getSoundCloudUploads();

View file

@ -43,15 +43,38 @@ require_once($CC_CONFIG['phpDir'].'/application/models/Show.php');
require_once($CC_CONFIG['phpDir'].'/application/models/ShowInstance.php'); require_once($CC_CONFIG['phpDir'].'/application/models/ShowInstance.php');
require_once($CC_CONFIG['phpDir'].'/application/models/Preference.php'); require_once($CC_CONFIG['phpDir'].'/application/models/Preference.php');
require_once($CC_CONFIG['phpDir'].'/application/models/StreamSetting.php'); require_once($CC_CONFIG['phpDir'].'/application/models/StreamSetting.php');
require_once($CC_CONFIG['phpDir'].'/application/models/LiveLog.php');
require_once 'propel/runtime/lib/Propel.php'; require_once 'propel/runtime/lib/Propel.php';
Propel::init($CC_CONFIG['phpDir']."/application/configs/airtime-conf-production.php"); Propel::init($CC_CONFIG['phpDir']."/application/configs/airtime-conf-production.php");
//Zend framework
if (file_exists('/usr/share/php/libzend-framework-php')){
set_include_path('/usr/share/php/libzend-framework-php' . PATH_SEPARATOR . get_include_path());
}
require_once('Zend/Loader/Autoloader.php');
$autoloader = Zend_Loader_Autoloader::getInstance();
try {
$opts = new Zend_Console_Getopt(
array(
'test|t' => "Keep broadcast log data\n"
)
);
$opts->parse();
}
catch (Zend_Console_Getopt_Exception $e) {
print $e->getMessage() .PHP_EOL;
exit(1);
}
if(Application_Model_Preference::GetSupportFeedback() == '1'){ if(Application_Model_Preference::GetSupportFeedback() == '1'){
$infoArray = Application_Model_Preference::GetSystemInfo(true);
$infoArray = Application_Model_Preference::GetSystemInfo(true, isset($opts->t));
$url = 'http://stat.sourcefabric.org/index.php?p=airtime'; $url = 'http://stat.sourcefabric.org/index.php?p=airtime';
//$url = 'http://stat-dev.sourcefabric.org/index.php?p=airtime'; //$url = 'http://localhost:9999/index.php?p=airtime';
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@ -64,13 +87,13 @@ if(Application_Model_Preference::GetSupportFeedback() == '1'){
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataArray); curl_setopt($ch, CURLOPT_POSTFIELDS, $dataArray);
$result = curl_exec($ch); $result = curl_exec($ch);
curl_close($ch); curl_close($ch);
} }
// Get latest version from stat server and store to db // Get latest version from stat server and store to db
if(Application_Model_Preference::GetPlanLevel() == 'disabled'){ if(Application_Model_Preference::GetPlanLevel() == 'disabled'){
$url = 'http://stat.sourcefabric.org/airtime-stats/airtime_latest_version'; $url = 'http://stat.sourcefabric.org/airtime-stats/airtime_latest_version';
//$url = 'http://localhost:9999/index.php?p=airtime';
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@ -81,9 +104,13 @@ if(Application_Model_Preference::GetPlanLevel() == 'disabled'){
echo "curl error: " . curl_error($ch) . "\n"; echo "curl error: " . curl_error($ch) . "\n";
} else { } else {
$resultArray = explode("\n", $result); $resultArray = explode("\n", $result);
if (isset($resultArray[0])) {
Application_Model_Preference::SetLatestVersion($resultArray[0]); Application_Model_Preference::SetLatestVersion($resultArray[0]);
}
if (isset($resultArray[1])) {
Application_Model_Preference::SetLatestLink($resultArray[1]); Application_Model_Preference::SetLatestLink($resultArray[1]);
} }
}
curl_close($ch); curl_close($ch);
} }