CC-5254 : Listener Status for SHOUTcast doesn't work

This commit is contained in:
Naomi Aro 2013-06-24 17:24:43 -04:00
parent 3858371b16
commit c5221aae6a
2 changed files with 35 additions and 29 deletions

View file

@ -9,36 +9,36 @@ class ListenerstatController extends Zend_Controller_Action
->addActionContext('get-data', 'json') ->addActionContext('get-data', 'json')
->initContext(); ->initContext();
} }
public function indexAction() public function indexAction()
{ {
$CC_CONFIG = Config::getConfig(); $CC_CONFIG = Config::getConfig();
$request = $this->getRequest(); $request = $this->getRequest();
$baseUrl = Application_Common_OsPath::getBaseDir(); $baseUrl = Application_Common_OsPath::getBaseDir();
$this->view->headScript()->appendFile($baseUrl.'js/flot/jquery.flot.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/flot/jquery.flot.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/flot/jquery.flot.crosshair.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/flot/jquery.flot.crosshair.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/airtime/listenerstat/listenerstat.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/airtime/listenerstat/listenerstat.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$offset = date("Z") * -1; $offset = date("Z") * -1;
$this->view->headScript()->appendScript("var serverTimezoneOffset = {$offset}; //in seconds"); $this->view->headScript()->appendScript("var serverTimezoneOffset = {$offset}; //in seconds");
$this->view->headScript()->appendFile($baseUrl.'js/timepicker/jquery.ui.timepicker.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/timepicker/jquery.ui.timepicker.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/airtime/buttons/buttons.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/airtime/buttons/buttons.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/airtime/utilities/utilities.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/airtime/utilities/utilities.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.ui.timepicker.css?'.$CC_CONFIG['airtime_version']); $this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.ui.timepicker.css?'.$CC_CONFIG['airtime_version']);
//default time is the last 24 hours. //default time is the last 24 hours.
$now = time(); $now = time();
$from = $request->getParam("from", $now - (24*60*60)); $from = $request->getParam("from", $now - (24*60*60));
$to = $request->getParam("to", $now); $to = $request->getParam("to", $now);
$start = DateTime::createFromFormat("U", $from, new DateTimeZone("UTC")); $start = DateTime::createFromFormat("U", $from, new DateTimeZone("UTC"));
$start->setTimezone(new DateTimeZone(date_default_timezone_get())); $start->setTimezone(new DateTimeZone(date_default_timezone_get()));
$end = DateTime::createFromFormat("U", $to, new DateTimeZone("UTC")); $end = DateTime::createFromFormat("U", $to, new DateTimeZone("UTC"));
$end->setTimezone(new DateTimeZone(date_default_timezone_get())); $end->setTimezone(new DateTimeZone(date_default_timezone_get()));
$form = new Application_Form_DateRange(); $form = new Application_Form_DateRange();
$form->populate(array( $form->populate(array(
'his_date_start' => $start->format("Y-m-d"), 'his_date_start' => $start->format("Y-m-d"),
@ -46,7 +46,7 @@ class ListenerstatController extends Zend_Controller_Action
'his_date_end' => $end->format("Y-m-d"), 'his_date_end' => $end->format("Y-m-d"),
'his_time_end' => $end->format("H:i") 'his_time_end' => $end->format("H:i")
)); ));
$errorStatus = Application_Model_StreamSetting::GetAllListenerStatErrors(); $errorStatus = Application_Model_StreamSetting::GetAllListenerStatErrors();
Logging::info($errorStatus); Logging::info($errorStatus);
$out = array(); $out = array();
@ -57,25 +57,24 @@ class ListenerstatController extends Zend_Controller_Action
} }
$out[$key[0]] = $v['value']; $out[$key[0]] = $v['value'];
} }
$this->view->errorStatus = $out; $this->view->errorStatus = $out;
$this->view->date_form = $form; $this->view->date_form = $form;
} }
public function getDataAction(){ public function getDataAction(){
$request = $this->getRequest(); $request = $this->getRequest();
$current_time = time(); $current_time = time();
$params = $request->getParams(); $params = $request->getParams();
$starts_epoch = $request->getParam("startTimestamp", $current_time - (60*60*24)); $starts_epoch = $request->getParam("startTimestamp", $current_time - (60*60*24));
$ends_epoch = $request->getParam("endTimestamp", $current_time); $ends_epoch = $request->getParam("endTimestamp", $current_time);
$mountName = $request->getParam("mountName", null);
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC")); $startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC")); $endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
$data = Application_Model_ListenerStat::getDataPointsWithinRange($startsDT->format("Y-m-d H:i:s"), $endsDT->format("Y-m-d H:i:s"), $mountName); $data = Application_Model_ListenerStat::getDataPointsWithinRange($startsDT->format("Y-m-d H:i:s"), $endsDT->format("Y-m-d H:i:s"));
$this->_helper->json->sendJson($data); $this->_helper->json->sendJson($data);
} }
} }

View file

@ -4,7 +4,7 @@ class Application_Model_ListenerStat
public function __construct() public function __construct()
{ {
} }
public static function getDataPointsWithinRange($p_start, $p_end) { public static function getDataPointsWithinRange($p_start, $p_end) {
$sql = <<<SQL $sql = <<<SQL
SELECT mount_name, count(*) SELECT mount_name, count(*)
@ -16,13 +16,13 @@ group by mount_name
SQL; SQL;
$data = Application_Common_Database::prepareAndExecute($sql, $data = Application_Common_Database::prepareAndExecute($sql,
array('p1'=>$p_start, 'p2'=>$p_end)); array('p1'=>$p_start, 'p2'=>$p_end));
$out = array(); $out = array();
foreach ($data as $d) { foreach ($data as $d) {
$jump = intval($d['count']/1000); $jump = intval($d['count']/1000);
$jump = max(1, $jump); $jump = max(1, $jump);
$remainder = $jump == 1?0:1; $remainder = $jump == 1?0:1;
$sql = <<<SQL $sql = <<<SQL
SELECT * SELECT *
FROM FROM
@ -41,29 +41,36 @@ SQL;
$t->setTimezone(new DateTimeZone(date_default_timezone_get())); $t->setTimezone(new DateTimeZone(date_default_timezone_get()));
// tricking javascript so it thinks the server timezone is in UTC // tricking javascript so it thinks the server timezone is in UTC
$dt = new DateTime($t->format("Y-m-d H:i:s"), new DateTimeZone("UTC")); $dt = new DateTime($t->format("Y-m-d H:i:s"), new DateTimeZone("UTC"));
$r['timestamp'] = $dt->format("U"); $r['timestamp'] = $dt->format("U");
$out[$r['mount_name']][] = $r; $out[$r['mount_name']][] = $r;
} }
} }
$enabledStreamIds = Application_Model_StreamSetting::getEnabledStreamIds(); $enabledStreamIds = Application_Model_StreamSetting::getEnabledStreamIds();
$enabledOut = array(); $enabledOut = array();
foreach ($enabledStreamIds as $sId) { foreach ($enabledStreamIds as $sId) {
$sql = "SELECT value FROM cc_stream_setting" $sql = "SELECT value FROM cc_stream_setting"
." WHERE keyname = :key"; ." WHERE keyname = :key";
$result = Application_Common_Database::prepareAndExecute($sql, array('key' => $sId."_mount"), "single"); $result = Application_Common_Database::prepareAndExecute($sql, array('key' => $sId."_mount"), "single");
$enabledMountPoint = $result["value"]; $enabledMountPoint = $result["value"];
if (isset($out[$enabledMountPoint])) { if (isset($out[$enabledMountPoint])) {
$enabledOut[$enabledMountPoint] = $out[$enabledMountPoint]; $enabledOut[$enabledMountPoint] = $out[$enabledMountPoint];
} }
else {
//TODO fix this hack (here for CC-5254)
//all shoutcast streams are automatically put under "shoutcast" mount point.
if (isset($out["shoutcast"])) {
$enabledOut["shoutcast"] = $out["shoutcast"];
}
}
} }
return $enabledOut; return $enabledOut;
} }