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:
parent
b38bde6565
commit
eb182cf887
3 changed files with 80 additions and 45 deletions
|
@ -3,14 +3,14 @@
|
||||||
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();
|
||||||
|
|
||||||
$sql = "SELECT * FROM CC_LIVE_LOG"
|
$sql = "SELECT * FROM CC_LIVE_LOG"
|
||||||
." WHERE state = 'L'"
|
." WHERE state = 'L'"
|
||||||
." and (start_time >= (now() - INTERVAL '1 day'))"
|
." and (start_time >= (now() - INTERVAL '1 day'))"
|
||||||
." ORDER BY id";
|
." ORDER BY id";
|
||||||
|
|
||||||
$rows = $con->query($sql)->fetchAll();
|
$rows = $con->query($sql)->fetchAll();
|
||||||
|
|
||||||
|
@ -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];
|
||||||
|
|
||||||
// Delete data we just used to start a new log history
|
if (!$p_keepData) {
|
||||||
$sql_delete = "DELETE FROM CC_LIVE_LOG"
|
// Delete data we just used to start a new log history
|
||||||
." WHERE id = '{$row['id']}'";
|
$sql_delete = "DELETE FROM CC_LIVE_LOG"
|
||||||
$con->exec($sql_delete);
|
." WHERE id = '{$row['id']}'";
|
||||||
|
$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,14 +70,15 @@ class Application_Model_LiveLog
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function GetScheduledDuration() {
|
public static function GetScheduledDuration($p_keepData = false)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
$con = Propel::getConnection();
|
$con = Propel::getConnection();
|
||||||
|
|
||||||
$sql_get_logs = "SELECT * FROM CC_LIVE_LOG"
|
$sql_get_logs = "SELECT * FROM CC_LIVE_LOG"
|
||||||
." WHERE state = 'S'"
|
." WHERE state = 'S'"
|
||||||
." and (start_time >= (now() - INTERVAL '1 day'))"
|
." and (start_time >= (now() - INTERVAL '1 day'))"
|
||||||
." ORDER BY id";
|
." ORDER BY id";
|
||||||
|
|
||||||
$rows = $con->query($sql_get_logs)->fetchAll();
|
$rows = $con->query($sql_get_logs)->fetchAll();
|
||||||
|
|
||||||
|
@ -95,10 +99,10 @@ class Application_Model_LiveLog
|
||||||
*/
|
*/
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$sql_get_tracks = "SELECT * FROM cc_schedule"
|
$sql_get_tracks = "SELECT * FROM cc_schedule"
|
||||||
." WHERE starts >= '{$row['start_time']}'"
|
." WHERE starts >= '{$row['start_time']}'"
|
||||||
." AND starts < '{$row['end_time']}'"
|
." AND starts < '{$row['end_time']}'"
|
||||||
." AND file_id IS NOT NULL"
|
." AND file_id IS NOT NULL"
|
||||||
." AND media_item_played IS TRUE";
|
." AND media_item_played IS TRUE";
|
||||||
$tracks = $con->query($sql_get_tracks)->fetchAll();
|
$tracks = $con->query($sql_get_tracks)->fetchAll();
|
||||||
foreach ($tracks as $track) {
|
foreach ($tracks as $track) {
|
||||||
if ($track['ends'] > $row['end_time']) {
|
if ($track['ends'] > $row['end_time']) {
|
||||||
|
@ -167,17 +171,20 @@ class Application_Model_LiveLog
|
||||||
$hours += $intervals[0];
|
$hours += $intervals[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delete row because we do not need data anymore
|
if (!$p_keepData) {
|
||||||
$sql_delete = "DELETE FROM CC_LIVE_LOG"
|
//Delete row because we do not need data anymore
|
||||||
." WHERE id = '{$row['id']}'";
|
$sql_delete = "DELETE FROM CC_LIVE_LOG"
|
||||||
$con->exec($sql_delete);
|
." WHERE id = '{$row['id']}'";
|
||||||
|
$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.");
|
||||||
|
@ -208,12 +215,12 @@ class Application_Model_LiveLog
|
||||||
* has ended
|
* has ended
|
||||||
*/
|
*/
|
||||||
$sql_select = "SELECT max(id) from CC_LIVE_LOG"
|
$sql_select = "SELECT max(id) from CC_LIVE_LOG"
|
||||||
." WHERE (state='L' and end_time is NULL) or (state='S' and end_time is NULL)";
|
." WHERE (state='L' and end_time is NULL) or (state='S' and end_time is NULL)";
|
||||||
$id = $con->query($sql_select)->fetchColumn(0);
|
$id = $con->query($sql_select)->fetchColumn(0);
|
||||||
|
|
||||||
if ($id == null) {
|
if ($id == null) {
|
||||||
$sql_insert = "INSERT INTO CC_LIVE_LOG (state, start_time)"
|
$sql_insert = "INSERT INTO CC_LIVE_LOG (state, start_time)"
|
||||||
." VALUES ('$state', '{$dateTime->format("Y-m-d H:i:s")}')";
|
." VALUES ('$state', '{$dateTime->format("Y-m-d H:i:s")}')";
|
||||||
$con->exec($sql_insert);
|
$con->exec($sql_insert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -29,11 +29,11 @@ require_once($CC_CONFIG['phpDir'].'/application/configs/conf.php');
|
||||||
|
|
||||||
$CC_CONFIG['phpDir'] = $values['general']['airtime_dir'];
|
$CC_CONFIG['phpDir'] = $values['general']['airtime_dir'];
|
||||||
|
|
||||||
// Ensure library/ is on include_path
|
// Ensure library/ is on include_path
|
||||||
set_include_path(implode(PATH_SEPARATOR, array(
|
set_include_path(implode(PATH_SEPARATOR, array(
|
||||||
get_include_path(),
|
get_include_path(),
|
||||||
realpath($CC_CONFIG['phpDir'] . '/library')
|
realpath($CC_CONFIG['phpDir'] . '/library')
|
||||||
)));
|
)));
|
||||||
|
|
||||||
require_once($CC_CONFIG['phpDir'].'/application/models/User.php');
|
require_once($CC_CONFIG['phpDir'].'/application/models/User.php');
|
||||||
require_once($CC_CONFIG['phpDir'].'/application/models/StoredFile.php');
|
require_once($CC_CONFIG['phpDir'].'/application/models/StoredFile.php');
|
||||||
|
@ -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,8 +104,12 @@ 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);
|
||||||
Application_Model_Preference::SetLatestVersion($resultArray[0]);
|
if (isset($resultArray[0])) {
|
||||||
Application_Model_Preference::SetLatestLink($resultArray[1]);
|
Application_Model_Preference::SetLatestVersion($resultArray[0]);
|
||||||
|
}
|
||||||
|
if (isset($resultArray[1])) {
|
||||||
|
Application_Model_Preference::SetLatestLink($resultArray[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue