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

-added cc_live_log inserts
This commit is contained in:
denise 2012-05-09 14:56:21 -04:00
parent bcf11bcb95
commit 99738fad30
3 changed files with 55 additions and 19 deletions

View File

@ -65,14 +65,18 @@ class DashboardController extends Zend_Controller_Action
Application_Model_RabbitMq::SendMessageToPypo("switch_source", $data); Application_Model_RabbitMq::SendMessageToPypo("switch_source", $data);
if(strtolower($current_status) == "on"){ if(strtolower($current_status) == "on"){
Application_Model_Preference::SetSourceSwitchStatus($sourcename, "off"); Application_Model_Preference::SetSourceSwitchStatus($sourcename, "off");
$this->view->status = "OFF";
//Log table updates
Application_Model_LiveLog::SetEndTime($sourcename == 'scheduled_play'?'S':'L', Application_Model_LiveLog::SetEndTime($sourcename == 'scheduled_play'?'S':'L',
new DateTime("now", new DateTimeZone('UTC'))); new DateTime("now", new DateTimeZone('UTC')));
$this->view->status = "OFF";
}else{ }else{
Application_Model_Preference::SetSourceSwitchStatus($sourcename, "on"); Application_Model_Preference::SetSourceSwitchStatus($sourcename, "on");
$this->view->status = "ON";
//Log table updates
Application_Model_LiveLog::SetNewLogTime($sourcename == 'scheduled_play'?'S':'L', Application_Model_LiveLog::SetNewLogTime($sourcename == 'scheduled_play'?'S':'L',
new DateTime("now", new DateTimeZone('UTC'))); new DateTime("now", new DateTimeZone('UTC')));
$this->view->status = "ON";
} }
} }
else{ else{

View File

@ -7,7 +7,8 @@ class Application_Model_LiveLog
try { try {
$con = Propel::getConnection(); $con = Propel::getConnection();
$data = self::GetNumLogs(); $rows = self::GetNumLogs();
Logging::log($rows);
if ($data['count'] > 1) { if ($data['count'] > 1) {
$sql = "SELECT * FROM CC_LIVE_LOG" $sql = "SELECT * FROM CC_LIVE_LOG"
." WHERE state = 'L'" ." WHERE state = 'L'"
@ -78,13 +79,14 @@ class Application_Model_LiveLog
public static function GetNumLogs() { public static function GetNumLogs() {
try { try {
$con = Propel::getConnection(); $con = Propel::getConnection();
/*
$sql = "SELECT count(*), state FROM CC_LIVE_LOG" $sql = "SELECT count(*), state FROM CC_LIVE_LOG"
." WHERE (start_time >= (now() - INTERVAL '1 day'))" ." WHERE (start_time >= (now() - INTERVAL '1 day'))"
." GROUP BY state"; ." GROUP BY state";
$row = $con->query($sql)->fetch(); $rows = $con->query($sql)->fetchAll();
return $result; return $rows;
*/
} catch (Exception $e) { } catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable'); header('HTTP/1.0 503 Service Unavailable');
@ -97,10 +99,24 @@ class Application_Model_LiveLog
try { try {
$con = Propel::getConnection(); $con = Propel::getConnection();
$sql = "INSERT INTO CC_LIVE_LOG (state, start_time)" if ($state == 'L') {
." VALUES ('$state', '{$dateTime->format("Y-m-d H:i:s")}')"; self::SetEndTime('S', $dateTime);
}
$con->exec($sql);
/* Check if airtime is currently broadcasting live.
* Only insert new state if scheduled switch is on
* or live broadcasting is off
*/
$sql_select = "SELECT max(id) from CC_LIVE_LOG"
." WHERE state='L' and end_time is NULL";
$id = $con->query($sql_select)->fetchColumn(0);
if ($id == null) {
$sql_insert = "INSERT INTO CC_LIVE_LOG (state, start_time)"
." VALUES ('$state', '{$dateTime->format("Y-m-d H:i:s")}')";
$con->exec($sql_insert);
}
} catch (Exception $e) { } catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable'); header('HTTP/1.0 503 Service Unavailable');
@ -113,15 +129,31 @@ class Application_Model_LiveLog
try { try {
$con = Propel::getConnection(); $con = Propel::getConnection();
$sql = "SELECT max(id) FROM CC_LIVE_LOG" if ($state == 'L') {
." WHERE state = '$state'"; $dj_live = Application_Model_Preference::GetSourceSwitchStatus('live_dj');
$master_live = Application_Model_Preference::GetSourceSwitchStatus('master_dj');
$id = $con->query($sql)->fetchColumn(0); }
$update_sql = "UPDATE CC_LIVE_LOG" if (($dj_live=='off' && $master_live=='off') || $state == 'S') {
." SET end_time = '{$dateTime->format("Y-m-d H:i:s")}'" $sql = "SELECT max(id) FROM CC_LIVE_LOG"
." WHERE id = '$id'"; ." WHERE state = '$state'"
$con->exec($update_sql); ." UNION"
." SELECT max(id) FROM CC_LIVE_LOG";
$row = $con->query($sql)->fetch();
if ($row != null && $row['max'] == $row[0]) {
$update_sql = "UPDATE CC_LIVE_LOG"
." SET end_time = '{$dateTime->format("Y-m-d H:i:s")}'"
." WHERE id = '$row[0]'";
$con->exec($update_sql);
}
//if live broadcasting is off, turn scheduled play on
$scheduled = Application_Model_Preference::GetSourceSwitchStatus('scheduled_play');
if ($state == 'L' && $scheduled=='on') {
self::SetNewLogTime('S', $dateTime);
}
}
} catch (Exception $e) { } catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable'); header('HTTP/1.0 503 Service Unavailable');

View File

@ -415,7 +415,7 @@ class Application_Model_Preference
$outputArray = array(); $outputArray = array();
$outputArray['LIVE_DURATION'] = Application_Model_LiveLog::GetLiveShowDuration(); $outputArray['LIVE_DURATION'] = Application_Model_LiveLog::GetLiveShowDuration();
$outputArray['SCHEDULED_DURATION'] = Application_Model_LiveLog::GetScheduledDuration(); //$outputArray['SCHEDULED_DURATION'] = Application_Model_LiveLog::GetScheduledDuration();
$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();