CC-5727 : History search range using incorrect timezone offset (also Nowplaying & Listener Stats)

fixing listener stat search
This commit is contained in:
Naomi 2014-03-11 13:24:22 -04:00
parent cd55ed5ee4
commit f8935a312f
3 changed files with 112 additions and 94 deletions

View File

@ -9,6 +9,49 @@ class ListenerstatController extends Zend_Controller_Action
->addActionContext('get-data', 'json') ->addActionContext('get-data', 'json')
->initContext(); ->initContext();
} }
private function getStartEnd()
{
$request = $this->getRequest();
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
$utcTimezone = new DateTimeZone("UTC");
$utcNow = new DateTime("now", $utcTimezone);
$start = $request->getParam("start");
$end = $request->getParam("end");
if (empty($start) || empty($end)) {
$startsDT = clone $utcNow;
$startsDT->sub(new DateInterval("P1D"));
$endsDT = clone $utcNow;
}
else {
try {
$startsDT = new DateTime($start, $userTimezone);
$startsDT->setTimezone($utcTimezone);
$endsDT = new DateTime($end, $userTimezone);
$endsDT->setTimezone($utcTimezone);
if ($startsDT > $endsDT) {
throw new Exception("start greater than end");
}
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
$startsDT = clone $utcNow;
$startsDT->sub(new DateInterval("P1D"));
$endsDT = clone $utcNow;
}
}
return array($startsDT, $endsDT);
}
public function indexAction() public function indexAction()
{ {
@ -26,25 +69,17 @@ class ListenerstatController extends Zend_Controller_Action
$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. list($startsDT, $endsDT) = $this->getStartEnd();
$now = time(); $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
$from = $request->getParam("from", $now - (24*60*60)); $startsDT->setTimezone($userTimezone);
$to = $request->getParam("to", $now); $endsDT->setTimezone($userTimezone);
$utcTimezone = new DateTimeZone("UTC");
$displayTimeZone = new DateTimeZone(Application_Model_Preference::GetTimezone());
$start = DateTime::createFromFormat("U", $from, $utcTimezone);
$start->setTimezone($displayTimeZone);
$end = DateTime::createFromFormat("U", $to, $utcTimezone);
$end->setTimezone($displayTimeZone);
$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' => $startsDT->format("Y-m-d"),
'his_time_start' => $start->format("H:i"), 'his_time_start' => $startsDT->format("H:i"),
'his_date_end' => $end->format("Y-m-d"), 'his_date_end' => $endsDT->format("Y-m-d"),
'his_time_end' => $end->format("H:i") 'his_time_end' => $endsDT->format("H:i")
)); ));
$errorStatus = Application_Model_StreamSetting::GetAllListenerStatErrors(); $errorStatus = Application_Model_StreamSetting::GetAllListenerStatErrors();
@ -63,17 +98,8 @@ class ListenerstatController extends Zend_Controller_Action
} }
public function getDataAction(){ public function getDataAction(){
$request = $this->getRequest(); list($startsDT, $endsDT) = $this->getStartEnd();
$current_time = time();
$params = $request->getParams();
$starts_epoch = $request->getParam("startTimestamp", $current_time - (60*60*24));
$ends_epoch = $request->getParam("endTimestamp", $current_time);
$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"));
$this->_helper->json->sendJson($data); $this->_helper->json->sendJson($data);
} }

View File

@ -17,35 +17,68 @@ class PlayouthistoryController extends Zend_Controller_Action
->addActionContext('update-list-item', 'json') ->addActionContext('update-list-item', 'json')
->addActionContext('update-file-item', 'json') ->addActionContext('update-file-item', 'json')
->initContext(); ->initContext();
} }
private function getStartEnd()
{
$request = $this->getRequest();
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
$utcTimezone = new DateTimeZone("UTC");
$utcNow = new DateTime("now", $utcTimezone);
$start = $request->getParam("start");
$end = $request->getParam("end");
if (empty($start) || empty($end)) {
$startsDT = clone $utcNow;
$startsDT->sub(new DateInterval("P1D"));
$endsDT = clone $utcNow;
}
else {
try {
$startsDT = new DateTime($start, $userTimezone);
$startsDT->setTimezone($utcTimezone);
$endsDT = new DateTime($end, $userTimezone);
$endsDT->setTimezone($utcTimezone);
if ($startsDT > $endsDT) {
throw new Exception("start greater than end");
}
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
$startsDT = clone $utcNow;
$startsDT->sub(new DateInterval("P1D"));
$endsDT = clone $utcNow;
}
}
return array($startsDT, $endsDT);
}
public function indexAction() public function indexAction()
{ {
$CC_CONFIG = Config::getConfig(); $CC_CONFIG = Config::getConfig();
$request = $this->getRequest();
$baseUrl = Application_Common_OsPath::getBaseDir(); $baseUrl = Application_Common_OsPath::getBaseDir();
//default time is the last 24 hours. list($startsDT, $endsDT) = $this->getStartEnd();
$now = time();
$from = $request->getParam("from", $now - (24*60*60)); $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
$to = $request->getParam("to", $now); $startsDT->setTimezone($userTimezone);
$endsDT->setTimezone($userTimezone);
$utcTimezone = new DateTimeZone("UTC");
$displayTimeZone = new DateTimeZone(Application_Model_Preference::GetTimezone());
$start = DateTime::createFromFormat("U", $from, $utcTimezone);
$start->setTimezone($displayTimeZone);
$end = DateTime::createFromFormat("U", $to, $utcTimezone);
$end->setTimezone($displayTimeZone);
$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' => $startsDT->format("Y-m-d"),
'his_time_start' => $start->format("H:i"), 'his_time_start' => $startsDT->format("H:i"),
'his_date_end' => $end->format("Y-m-d"), 'his_date_end' => $endsDT->format("Y-m-d"),
'his_time_end' => $end->format("H:i") 'his_time_end' => $endsDT->format("H:i")
)); ));
$this->view->date_form = $form; $this->view->date_form = $form;
@ -82,49 +115,6 @@ class PlayouthistoryController extends Zend_Controller_Action
$user = Application_Model_User::getCurrentUser(); $user = Application_Model_User::getCurrentUser();
$this->view->userType = $user->getType(); $this->view->userType = $user->getType();
} }
private function getStartEnd()
{
$request = $this->getRequest();
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
$utcTimezone = new DateTimeZone("UTC");
$utcNow = new DateTime("now", $utcTimezone);
$start = $request->getParam("start");
$end = $request->getParam("end");
if (empty($start) || empty($end)) {
$startsDT = clone $utcNow;
$startsDT->sub(new DateInterval("P1D"));
$endsDT = clone $utcNow;
}
else {
try {
$startsDT = new DateTime($start, $userTimezone);
$startsDT->setTimezone($utcTimezone);
$endsDT = new DateTime($end, $userTimezone);
$endsDT->setTimezone($utcTimezone);
if ($startsDT > $endsDT) {
throw new Exception("start greater than end");
}
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
$startsDT = clone $utcNow;
$startsDT->sub(new DateInterval("P1D"));
$endsDT = clone $utcNow;
}
}
return array($startsDT, $endsDT);
}
public function fileHistoryFeedAction() public function fileHistoryFeedAction()
{ {

View File

@ -14,15 +14,17 @@ $(document).ready(function() {
getDataAndPlot(); getDataAndPlot();
listenerstat_content.find("#his_submit").click(function(){ listenerstat_content.find("#his_submit").click(function(){
startTimestamp = AIRTIME.utilities.fnGetTimestamp(dateStartId, timeStartId); var oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId);
endTimestamp = AIRTIME.utilities.fnGetTimestamp(dateEndId, timeEndId); var start = oRange.start;
getDataAndPlot(startTimestamp, endTimestamp); var end = oRange.end;
getDataAndPlot(start, end);
}); });
}); });
function getDataAndPlot(startTimestamp, endTimestamp){ function getDataAndPlot(startTimestamp, endTimestamp){
// get data // get data
$.get(baseUrl+'Listenerstat/get-data', {startTimestamp: startTimestamp, endTimestamp: endTimestamp}, function(data){ $.get(baseUrl+'Listenerstat/get-data', {start: startTimestamp, end: endTimestamp}, function(data){
out = new Object(); out = new Object();
$.each(data, function(mpName, v){ $.each(data, function(mpName, v){
plotData = new Object(); plotData = new Object();