SAAS-223: Airtime Usage Metric: Amount of time spent broadcasting
-added cc_live_log inserts
This commit is contained in:
parent
bcf11bcb95
commit
99738fad30
|
@ -65,14 +65,18 @@ class DashboardController extends Zend_Controller_Action
|
|||
Application_Model_RabbitMq::SendMessageToPypo("switch_source", $data);
|
||||
if(strtolower($current_status) == "on"){
|
||||
Application_Model_Preference::SetSourceSwitchStatus($sourcename, "off");
|
||||
$this->view->status = "OFF";
|
||||
|
||||
//Log table updates
|
||||
Application_Model_LiveLog::SetEndTime($sourcename == 'scheduled_play'?'S':'L',
|
||||
new DateTime("now", new DateTimeZone('UTC')));
|
||||
$this->view->status = "OFF";
|
||||
}else{
|
||||
Application_Model_Preference::SetSourceSwitchStatus($sourcename, "on");
|
||||
$this->view->status = "ON";
|
||||
|
||||
//Log table updates
|
||||
Application_Model_LiveLog::SetNewLogTime($sourcename == 'scheduled_play'?'S':'L',
|
||||
new DateTime("now", new DateTimeZone('UTC')));
|
||||
$this->view->status = "ON";
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
|
|
@ -7,7 +7,8 @@ class Application_Model_LiveLog
|
|||
try {
|
||||
$con = Propel::getConnection();
|
||||
|
||||
$data = self::GetNumLogs();
|
||||
$rows = self::GetNumLogs();
|
||||
Logging::log($rows);
|
||||
if ($data['count'] > 1) {
|
||||
$sql = "SELECT * FROM CC_LIVE_LOG"
|
||||
." WHERE state = 'L'"
|
||||
|
@ -78,13 +79,14 @@ class Application_Model_LiveLog
|
|||
public static function GetNumLogs() {
|
||||
try {
|
||||
$con = Propel::getConnection();
|
||||
|
||||
/*
|
||||
$sql = "SELECT count(*), state FROM CC_LIVE_LOG"
|
||||
." WHERE (start_time >= (now() - INTERVAL '1 day'))"
|
||||
." GROUP BY state";
|
||||
|
||||
$row = $con->query($sql)->fetch();
|
||||
return $result;
|
||||
$rows = $con->query($sql)->fetchAll();
|
||||
return $rows;
|
||||
*/
|
||||
|
||||
} catch (Exception $e) {
|
||||
header('HTTP/1.0 503 Service Unavailable');
|
||||
|
@ -97,10 +99,24 @@ class Application_Model_LiveLog
|
|||
try {
|
||||
$con = Propel::getConnection();
|
||||
|
||||
$sql = "INSERT INTO CC_LIVE_LOG (state, start_time)"
|
||||
." VALUES ('$state', '{$dateTime->format("Y-m-d H:i:s")}')";
|
||||
if ($state == 'L') {
|
||||
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) {
|
||||
header('HTTP/1.0 503 Service Unavailable');
|
||||
|
@ -113,15 +129,31 @@ class Application_Model_LiveLog
|
|||
try {
|
||||
$con = Propel::getConnection();
|
||||
|
||||
if ($state == 'L') {
|
||||
$dj_live = Application_Model_Preference::GetSourceSwitchStatus('live_dj');
|
||||
$master_live = Application_Model_Preference::GetSourceSwitchStatus('master_dj');
|
||||
}
|
||||
|
||||
if (($dj_live=='off' && $master_live=='off') || $state == 'S') {
|
||||
$sql = "SELECT max(id) FROM CC_LIVE_LOG"
|
||||
." WHERE state = '$state'";
|
||||
|
||||
$id = $con->query($sql)->fetchColumn(0);
|
||||
." WHERE state = '$state'"
|
||||
." 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 = '$id'";
|
||||
." 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) {
|
||||
header('HTTP/1.0 503 Service Unavailable');
|
||||
|
|
|
@ -415,7 +415,7 @@ class Application_Model_Preference
|
|||
$outputArray = array();
|
||||
|
||||
$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();
|
||||
if ($outputArray['SOUNDCLOUD_ENABLED']) {
|
||||
$outputArray['NUM_SOUNDCLOUD_TRACKS_UPLOADED'] = Application_Model_StoredFile::getSoundCloudUploads();
|
||||
|
|
Loading…
Reference in New Issue