SAAS-223: Airtime Usage Metric: Amount of time spent broadcasting
-calculated scheduled usage
This commit is contained in:
parent
624ba85212
commit
195d0d8311
|
@ -7,31 +7,23 @@ class Application_Model_LiveLog
|
||||||
try {
|
try {
|
||||||
$con = Propel::getConnection();
|
$con = Propel::getConnection();
|
||||||
|
|
||||||
$count = self::GetNumLogs();
|
$sql = "SELECT * FROM CC_LIVE_LOG"
|
||||||
|
." WHERE state = 'L'"
|
||||||
if ($count > 1) {
|
." and (start_time >= (now() - INTERVAL '1 day'))"
|
||||||
$sql = "SELECT * FROM CC_LIVE_LOG"
|
." ORDER BY id";
|
||||||
." WHERE state = 'L'"
|
|
||||||
." and (start_time >= (now() - INTERVAL '1 day'))"
|
|
||||||
." ORDER BY id";
|
|
||||||
|
|
||||||
$rows = $con->query($sql)->fetchAll();
|
$rows = $con->query($sql)->fetchAll();
|
||||||
$duration = self::GetDuration($rows);
|
|
||||||
return $duration;
|
/* Check if last log has end time.
|
||||||
}
|
* If not, set end time to current time
|
||||||
else if ($count == 1) {
|
*/
|
||||||
$sql = "SELECT state FROM CC_LIVE_LOG";
|
if ($rows != null) {
|
||||||
$state = $con->query($sql)->fetchColumn(0);
|
$last_row = self::UpdateLastLogEndTime(array_pop($rows));
|
||||||
if ($state == 'S') {
|
array_push($rows, $last_row);
|
||||||
$duration = new DateTime("00:00:00");
|
|
||||||
return $duration->format("H:i:s");
|
|
||||||
}
|
|
||||||
else if ($state == 'L') {
|
|
||||||
$duration = new DateTime("23:59:59");
|
|
||||||
return $duration->format("H:i:s");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$duration = self::GetDuration($rows);
|
||||||
|
return $duration;
|
||||||
} 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.");
|
||||||
|
@ -43,22 +35,72 @@ class Application_Model_LiveLog
|
||||||
try {
|
try {
|
||||||
$con = Propel::getConnection();
|
$con = Propel::getConnection();
|
||||||
|
|
||||||
if (self::GetNumLogs() > 1) {
|
$sql_get_logs = "SELECT * FROM CC_LIVE_LOG"
|
||||||
|
." WHERE state = 'S'"
|
||||||
$sql = "SELECT * FROM CC_LIVE_LOG"
|
." and (start_time >= (now() - INTERVAL '1 day'))"
|
||||||
." WHERE state = 'S'"
|
." ORDER BY id";
|
||||||
." and (start_time >= (now() - INTERVAL '1 day'))"
|
|
||||||
." ORDER BY id";
|
|
||||||
|
|
||||||
$rows = $con->query($sql)->fetchAll();
|
$rows = $con->query($sql_get_logs)->fetchAll();
|
||||||
$duration = self::GetDuration($rows);
|
|
||||||
return $duration;
|
/* Check if last log has end time.
|
||||||
|
* If not, set end time to current time
|
||||||
|
*/
|
||||||
|
if ($rows != null) {
|
||||||
|
$last_row = self::UpdateLastLogEndTime(array_pop($rows));
|
||||||
|
array_push($rows, $last_row);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
$duration = new DateTime("23:59:59");
|
$duration = new DateTime("00:00:00");
|
||||||
return $duration->format("H:i:s");
|
|
||||||
|
/* Get all tracks from cc_schedule that played
|
||||||
|
* during a scheduled state
|
||||||
|
*/
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
//Get all show instances
|
||||||
|
$sql_get_shows = "SELECT * FROM cc_show_instances"
|
||||||
|
." WHERE starts >= '{$row['start_time']}'"
|
||||||
|
." AND ends < '{$row['end_time']}'";
|
||||||
|
$shows = $con->query($sql_get_shows)->fetchAll();
|
||||||
|
|
||||||
|
//Get all tracks from each show and calculate total duration
|
||||||
|
foreach ($shows as $show) {
|
||||||
|
$sql_get_tracks = "SELECT * FROM cc_schedule"
|
||||||
|
." WHERE starts >= '{$show['starts']}'"
|
||||||
|
." AND starts < '{$show['ends']}'"
|
||||||
|
." AND file_id IS NOT NULL"
|
||||||
|
." AND media_item_played IS TRUE"
|
||||||
|
." AND instance_id = '{$show['show_id']}'";
|
||||||
|
$tracks = $con->query($sql_get_tracks)->fetchAll();
|
||||||
|
$last_track = array_pop($tracks);
|
||||||
|
foreach ($tracks as $track) {
|
||||||
|
$track_start = new DateTime($track['starts']);
|
||||||
|
$track_end = new DateTime($track['ends']);
|
||||||
|
$duration->add($track_start->diff($track_end));
|
||||||
|
}
|
||||||
|
if ($last_track['ends'] > $show['ends']) {
|
||||||
|
/*
|
||||||
|
$show_end = new DateTime($show['ends']);
|
||||||
|
$last_track_start = new DateTime($last_track['starts']);
|
||||||
|
$last_track_end = new DateTime($last_track['ends']);
|
||||||
|
|
||||||
|
$last_track_length = new DateTime($last_track_start->diff($last_track_end));
|
||||||
|
|
||||||
|
$trackdiff = new DateTime($show_end->diff($last_track_end));
|
||||||
|
|
||||||
|
$new_track_length = new DateTime($trackdiff->diff($last_track_length));
|
||||||
|
|
||||||
|
$duration->add($new_track_length);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$last_track_start = new DateTime($last_track['starts']);
|
||||||
|
$last_track_end = new DateTime($last_track['ends']);
|
||||||
|
$duration->add($last_track_start->diff($last_track_end));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$duration = $duration->format("H:i:s");
|
||||||
|
return $duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
} 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.");
|
||||||
|
@ -77,26 +119,16 @@ class Application_Model_LiveLog
|
||||||
return $duration;
|
return $duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns number of entries in cc_live_log
|
public static function UpdateLastLogEndTime($log) {
|
||||||
* within the last 24 hours
|
$current_time = new DateTime("now", new DateTimeZone('UTC'));
|
||||||
*/
|
$log['end_time'] = $current_time;
|
||||||
public static function GetNumLogs() {
|
$log['end_time'] = $log['end_time']->format("Y-m-d H:i:s");
|
||||||
try {
|
self::SetEndTime($log['state'], $current_time);
|
||||||
$con = Propel::getConnection();
|
self::SetNewLogTime($log['state'], $current_time);
|
||||||
$sql = "SELECT count(*) FROM CC_LIVE_LOG"
|
return $log;
|
||||||
." WHERE (start_time >= (now() - INTERVAL '1 day'))";
|
|
||||||
|
|
||||||
$count = $con->query($sql)->fetchColumn(0);
|
|
||||||
return $count;
|
|
||||||
|
|
||||||
} catch (Exception $e) {
|
|
||||||
header('HTTP/1.0 503 Service Unavailable');
|
|
||||||
Logging::log("GetNumLogs - Could not connect to database.");
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function SetNewLogTime($state, $dateTime){
|
public static function SetNewLogTime($state, $dateTime, $end_scheduled=true){
|
||||||
try {
|
try {
|
||||||
$con = Propel::getConnection();
|
$con = Propel::getConnection();
|
||||||
|
|
||||||
|
@ -128,10 +160,10 @@ class Application_Model_LiveLog
|
||||||
try {
|
try {
|
||||||
$con = Propel::getConnection();
|
$con = Propel::getConnection();
|
||||||
|
|
||||||
if ($state == 'L') {
|
//if ($state == 'L') {
|
||||||
$dj_live = Application_Model_Preference::GetSourceSwitchStatus('live_dj');
|
$dj_live = Application_Model_Preference::GetSourceSwitchStatus('live_dj');
|
||||||
$master_live = Application_Model_Preference::GetSourceSwitchStatus('master_dj');
|
$master_live = Application_Model_Preference::GetSourceSwitchStatus('master_dj');
|
||||||
}
|
//}
|
||||||
|
|
||||||
if (($dj_live=='off' && $master_live=='off') || $state == 'S') {
|
if (($dj_live=='off' && $master_live=='off') || $state == 'S') {
|
||||||
$sql = "SELECT id, state from cc_live_log"
|
$sql = "SELECT id, state from cc_live_log"
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -2,6 +2,8 @@ INSERT INTO cc_subjs ("login", "type", "pass") VALUES ('admin', 'A', md5('admin'
|
||||||
|
|
||||||
-- added in 2.1
|
-- added in 2.1
|
||||||
INSERT INTO cc_pref("keystr", "valstr") VALUES('scheduled_play_switch', 'on');
|
INSERT INTO cc_pref("keystr", "valstr") VALUES('scheduled_play_switch', 'on');
|
||||||
|
|
||||||
|
INSERT INTO cc_live_log("state", "start_time") VALUES('S', now() at time zone 'UTC');
|
||||||
-- end of added in 2.1
|
-- end of added in 2.1
|
||||||
|
|
||||||
-- added in 2.0.0
|
-- added in 2.0.0
|
||||||
|
|
Loading…
Reference in New Issue