-began adding grouping by shows for the datatable.

This commit is contained in:
martin 2011-03-04 18:26:22 -05:00
parent d22ab329d8
commit 38856c4af7
7 changed files with 126 additions and 12 deletions

View File

@ -29,6 +29,10 @@ class Application_Model_DateHelper
$dayEndTS = strtotime(date("Y-m-d", $this->_timestamp+(86400)));
return $dayEndTS - $this->_timestamp;
}
public static function TimeDiff($time1, $time2){
return strtotime($time2) - strtotime($time1);
}
public static function ConvertMSToHHMMSSmm($time){
$hours = floor($time / 3600000);

View File

@ -2,7 +2,7 @@
class Application_Model_Nowplaying
{
/*
public static function InsertBlankRow($i, $rows){
$startDateFull = $rows[$i-1][3];
$endDateFull = $rows[$i][2];
@ -44,6 +44,40 @@ class Application_Model_Nowplaying
return $rows;
}
*/
public static function FindGapsBetweenShows($showsMap){
return $showsMap;
}
public static function FindGapsAtEndOfShows($showsMap){
foreach($showsMap as $k => $show){
$showStartTime = $show['starts'];
$showEndTime = $show['ends'];
//get the last songs end-time
$items = $show['items'];
if (count($items) > 1){
$lastItem = $items[count($items)-1];
$lastItemEndTime = $lastItem[3];
} else {
$lastItemEndTime = $showStartTime;
}
$diff = Application_Model_DateHelper::TimeDiff($lastItemEndTime, $showEndTime);
//echo $diff."-";
if ($diff <= 0){
//ok!
} else {
//There is a gap at the end of the show
//insert blank row
array_push($items, array("b", $diff, "-", "-", "-", "-", "-", "-", "-", "-", "-", "-"));
$showsMap[$k]['items'] = $items;
}
}
return $showsMap;
}
public static function GetDataGridData($viewType, $dateString){
@ -60,6 +94,8 @@ class Application_Model_Nowplaying
$previous = array_reverse(Schedule::Get_Scheduled_Item_Data($timeNow, -1, 1, "60 seconds"));
$current = Schedule::Get_Scheduled_Item_Data($timeNow, 0);
$next = Schedule::Get_Scheduled_Item_Data($timeNow, 1, 10, "24 hours");
$showsMap = Show_DAL::GetShowsInRange($timeNow, "60 seconds", "24 hours");
} else {
$date = new Application_Model_DateHelper;
$time = $date->getTime();
@ -68,33 +104,39 @@ class Application_Model_Nowplaying
$previous = array_reverse(Schedule::Get_Scheduled_Item_Data($timeNow, -1, "ALL", $date->getNowDayStartDiff()." seconds"));
$current = Schedule::Get_Scheduled_Item_Data($timeNow, 0);
$next = Schedule::Get_Scheduled_Item_Data($timeNow, 1, "ALL", $date->getNowDayEndDiff()." seconds");
$next = Schedule::Get_Scheduled_Item_Data($timeNow, 1, "ALL", $date->getNowDayEndDiff()." seconds");
$showsMap = Show_DAL::GetShowsInRange($timeNow, $date->getNowDayStartDiff(), $date->getNowDayEndDiff());
}
$rows = array();
//$rows = array();
//print_r($showsMap);
foreach ($previous as $item){
array_push($rows, array("p", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
array_push($showsMap[$item["instance_id"]]['items'], array("p", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
$item["album_title"], $item["name"], $item["show_name"], $item["instance_id"], $item["group_id"]));
}
foreach ($current as $item){
array_push($rows, array("c", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
array_push($showsMap[$item["instance_id"]]['items'], array("c", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
$item["album_title"], $item["name"], $item["show_name"], $item["instance_id"], $item["group_id"]));
}
foreach ($next as $item){
array_push($rows, array("n", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
array_push($showsMap[$item["instance_id"]]['items'], array("n", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
$item["album_title"], $item["name"], $item["show_name"], $item["instance_id"], $item["group_id"]));
}
$rows = Application_Model_Nowplaying::FindGaps($rows);
//$showsMap = Application_Model_Nowplaying::FindGapsBetweenShows($showsMap);
$showsMap = Application_Model_Nowplaying::FindGapsAtEndOfShows($showsMap);
//$rows = Application_Model_Nowplaying::FindGaps($rows);
$date = new Application_Model_DateHelper;
$timeNow = $date->getDate();
$data = array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$rows);
$data = array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$showsMap);
return $data;
}

View File

@ -757,5 +757,33 @@ class Show_DAL{
$rows = $CC_DBC->GetAll($sql);
return $rows;
}
public static function GetShowsInRange($timeNow, $start, $end){
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT *,"
." si.starts as start_timestamp,"
." si.ends as end_timestamp,"
." si.id as instance_id"
." FROM "
." $CC_CONFIG[showInstances] si,"
." $CC_CONFIG[showTable] s"
." WHERE si.show_id = s.id"
." AND (si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds' OR si.starts < TIMESTAMP '$timeNow' + INTERVAL '$end seconds')"
." ORDER BY si.starts";
$rows = $CC_DBC->GetAll($sql);
$showsMap = array();
$rowsCount = count($rows);
for ($i=0; $i<$rowsCount; $i++){
$rows[$i]['items'] = array();
array_push($rows[$i]['items'],
array("s", $rows[$i]["starts"], $rows[$i]["starts"], $rows[$i]["ends"], "", "", "", "", "", $rows[$i]["name"], $rows[$i]["instance_id"], ""));
$showsMap[$rows[$i]['instance_id']] = $rows[$i];
}
return $showsMap;
}
}

3
dev/pf.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
su -l pypo -c "tail -F /etc/service/pypo-fetch/log/main/current"

3
dev/pl.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
su -l pypo -c "tail -F /etc/service/pypo-liquidsoap/log/main/current"

3
dev/pp.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
su -l pypo -c "tail -F /etc/service/pypo-push/log/main/current"

View File

@ -60,7 +60,7 @@ var columns = [{"sTitle": "type", "bVisible":false},
{"sTitle":"Album"},
{"sTitle":"Playlist"},
{"sTitle":"Show"},
{"sTitle":"bgcolor", "bVisible":false},
{"sTitle":"instance_id", "bVisible":true},
{"sTitle":"group_id", "bVisible":false}];
function getDateString(){
@ -85,7 +85,9 @@ function updateDataTable(){
//function can be called before ajax call has been returned.
if (datagridData != null){
table.fnClearTable(false);
table.fnAddData(datagridData.rows, false);
for (var show in datagridData.rows){
table.fnAddData(datagridData.rows[show].items, false);
}
table.fnDraw(true);
}
}
@ -133,6 +135,35 @@ function createDataGrid(){
$(nRow).attr("class", "gap");
return nRow;
},
"fnDrawCallback": function(oSettings){
//check if there are any rows to display
if (oSettings.aiDisplay.length == 0)
return;
var nTrs = $('#nowplayingtable tbody tr');
var iColspan = nTrs[0].getElementsByTagName('td').length;
for (var i=0; i<nTrs.length; i++){
var iDisplayIndex = oSettings._iDisplayStart + i;
var sType = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[0];
var showName = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[9];
var startTime = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[2];
var endTime = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[3];
if ( sType == "s" ){
var nGroup = document.createElement('tr');
var nCell = document.createElement('td');
nCell.colSpan = iColspan;
nCell.className = "group";
nCell.innerHTML = showName + ": " + startTime + " - " + endTime;
nGroup.appendChild(nCell);
nTrs[i].parentNode.replaceChild(nGroup, nTrs[i]);
}
}
},
"bAutoWidth":false
} );
}