diff --git a/airtime_mvc/application/controllers/ListenerstatController.php b/airtime_mvc/application/controllers/ListenerstatController.php index 2b0fcb6f7..d0af81593 100644 --- a/airtime_mvc/application/controllers/ListenerstatController.php +++ b/airtime_mvc/application/controllers/ListenerstatController.php @@ -25,11 +25,8 @@ class ListenerstatController extends Zend_Controller_Action $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/utilities/utilities.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - //$this->view->headScript()->appendFile($baseUrl.'/js/airtime/playouthistory/historytable.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - //$this->view->headLink()->appendStylesheet($baseUrl.'/js/datatables/plugin/TableTools/css/TableTools.css?'.$CC_CONFIG['airtime_version']); $this->view->headLink()->appendStylesheet($baseUrl.'/css/jquery.ui.timepicker.css?'.$CC_CONFIG['airtime_version']); - //$this->view->headLink()->appendStylesheet($baseUrl.'/css/playouthistory.css?'.$CC_CONFIG['airtime_version']); //default time is the last 24 hours. $now = time(); @@ -49,6 +46,9 @@ class ListenerstatController extends Zend_Controller_Action 'his_time_end' => $end->format("H:i") )); + $allMPs = Application_Model_ListenerStat::getAllMPNames(); + + $this->view->mps = $allMPs; $this->view->date_form = $form; } @@ -60,11 +60,12 @@ class ListenerstatController extends Zend_Controller_Action $starts_epoch = $request->getParam("startTimestamp", $current_time - (60*60*24)); $ends_epoch = $request->getParam("endTimestamp", $current_time); + $mountName = $request->getParam("mountName", null); $startsDT = DateTime::createFromFormat("U", $starts_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")); + $data = Application_Model_ListenerStat::getDataPointsWithinRange($startsDT->format("Y-m-d H:i:s"), $endsDT->format("Y-m-d H:i:s"), $mountName); die(json_encode($data)); } } diff --git a/airtime_mvc/application/models/ListenerStat.php b/airtime_mvc/application/models/ListenerStat.php index bedd82453..36446b142 100644 --- a/airtime_mvc/application/models/ListenerStat.php +++ b/airtime_mvc/application/models/ListenerStat.php @@ -7,14 +7,32 @@ class Application_Model_ListenerStat public static function getDataPointsWithinRange($p_start, $p_end) { $sql = <<=:p1 AND cc_timestamp.TIMESTAMP<=:p2) -ORDER BY cc_timestamp.TIMESTAMP +ORDER BY cc_listener_count.mount_name, cc_timestamp.TIMESTAMP SQL; $data = Application_Common_Database::prepareAndExecute($sql, array('p1'=>$p_start, 'p2'=>$p_end)); - return $data; + $out = array(); + foreach ($data as $d) { + $out[$d['mount_name']][] = $d; + } + + return $out; + } + + public static function getAllMPNames() { + $sql = << - Timestamp vs Listener Count + Timestamp vs Listener Count
+
date_form; ?> + \ No newline at end of file diff --git a/airtime_mvc/public/js/airtime/listenerstat/listenerstat.js b/airtime_mvc/public/js/airtime/listenerstat/listenerstat.js index c09011147..3911dbad3 100644 --- a/airtime_mvc/public/js/airtime/listenerstat/listenerstat.js +++ b/airtime_mvc/public/js/airtime/listenerstat/listenerstat.js @@ -7,24 +7,43 @@ $(document).ready(function() { getDataAndPlot(); - listenerstat_content.find("#his_submit").click(function(ev){ + listenerstat_content.find("#his_submit").click(function(){ startTimestamp = AIRTIME.utilities.fnGetTimestamp(dateStartId, timeStartId); endTimestamp = AIRTIME.utilities.fnGetTimestamp(dateEndId, timeEndId); getDataAndPlot(startTimestamp, endTimestamp); }); + + listenerstat_content.find("#all_mps").change(function(){ + var mpName = $(this).val(); + startTimestamp = AIRTIME.utilities.fnGetTimestamp(dateStartId, timeStartId); + endTimestamp = AIRTIME.utilities.fnGetTimestamp(dateEndId, timeEndId); + getDataAndPlot(startTimestamp, endTimestamp); + getDataAndPlot(startTimestamp, endTimestamp, mpName); + }) }); -function getDataAndPlot(startTimestamp, endTimestamp){ +function getDataAndPlot(startTimestamp, endTimestamp, mountName){ // get data $.get('/Listenerstat/get-data', {startTimestamp: startTimestamp, endTimestamp: endTimestamp}, function(data){ data = JSON.parse(data); out = new Array(); - $.each(data, function(index, v){ - temp = new Array(); - temp[0] = new Date(v.timestamp.replace(/-/g,"/")); - temp[1] = v.listener_count; - out.push(temp); + $.each(data, function(mpName, v){ + plotData = new Array(); + if (mountName != null && mpName != mountName){ + console.log(mountName); + return true; + } + $.each(v, function(i, ele){ + temp = new Array(); + temp[0] = new Date(ele.timestamp.replace(/-/g,"/")); + temp[1] = ele.listener_count; + plotData.push(temp); + }) + out.push(plotData); }); + if (out.length == 0) { + out.push(new Array()); + } plot(out); }) } @@ -32,7 +51,7 @@ function getDataAndPlot(startTimestamp, endTimestamp){ function plot(d){ oBaseDatePickerSettings = { dateFormat: 'yy-mm-dd', - onSelect: function(sDate, oDatePicker) { + onSelect: function(sDate, oDatePicker) { $(this).datepicker( "setDate", sDate ); } }; @@ -49,10 +68,6 @@ function plot(d){ listenerstat_content.find(dateEndId).datepicker(oBaseDatePickerSettings); listenerstat_content.find(timeEndId).timepicker(oBaseTimePickerSettings); - $.plot($("#flot_placeholder"), [d], { xaxis: { mode: "time", timeformat: "%y/%m/%0d %H:%M:%S" } }); - - $("#whole").click(function () { - $.plot($("#flot_placeholder"), [d], { xaxis: { mode: "time" } }); - }); + $.plot($("#flot_placeholder"), d, { xaxis: { mode: "time", timeformat: "%y/%m/%0d %H:%M:%S" } }); } \ No newline at end of file