Skip to content
Snippets Groups Projects
Commit 83e4167d authored by Tilman Vatteroth's avatar Tilman Vatteroth :robot:
Browse files

config der departure nach departure verlegt

cache in departure erstellt
uhr "gefixt"?
departure wieder dynamisch
parent c472fabe
No related branches found
No related tags found
No related merge requests found
......@@ -57,7 +57,6 @@ this.loaded = function(panel, config) {
smlFontPost = "time-medium"; // width * 18.75%
init = function() {
if (fontsReady) {
digiBackground = document.createElement('canvas');
analBackground = document.createElement('canvas');
......@@ -75,6 +74,8 @@ this.loaded = function(panel, config) {
}
this.resize = function(width, height) {
console.log("width " + width);
console.log("height " + height);
if (height > width) {
var size = height / 2;
if (!!analClock) {
......@@ -89,7 +90,7 @@ this.loaded = function(panel, config) {
$(analClock).attr('width', size).attr('height', height);
}
if (!!digiClock) {
$(digiClock).attr('width', width - size - 5).attr('height', height);
$(digiClock).attr('width', width - size - 6).attr('height', height);
}
}
calc();
......
<?php
error_reporting (-1);
ini_set ('display_errors', 1);
// initialize frontend
header('Content-type: text/javascript');
// set root
chdir($_SERVER['DOCUMENT_ROOT']);
// version-info
$version = "0.05";
$vrrf_version = "0.07";
// options
$options = array();
// max entries
$max = 1000000;
// configuration
if (isset($_GET['config'])) {
$file = $_GET['config'];
if (!file_exists($file)) {
$result['error'] = 'config file "'.$file.'" not found';
$result['config']['name'] = $file;
$result['options'] = $options;
echo json_encode($result);
exit;
}
$config = file_get_contents($file);
$buffer = json_decode($config, true);
$options['stops'] = $buffer['stops'];
$options['filter'] = $buffer['filter'];
if (is_numeric($buffer['max'])) {
$max = $buffer['max'];
}
if (count($options['stops']) == 0) {
$result['error'] = 'no stops defined';
$result['config']['name'] = $config_name;
$result['config']['type'] = 'panel/departure';
$result['options'] = $options;
echo json_encode($result);
exit;
}
} else {
$result['error'] = 'no config defined';
$result['config']['name'] = $config_name;
$result['config']['type'] = 'panel/departure';
$result['options'] = $options;
echo json_encode($result);
exit;
}
usort($options['stops'], function($a, $b) {
return strcmp($a, $b);
});
// cache
$name = json_encode($options);
$cachefile = "cache/vrr_".md5($name).".json";
$cachetime = 60;
$cache_ablauf = 0;
$cacheused = false;
$rawdata = array();
$alldata = array();
if (is_file($cachefile))
$cache_ablauf=filemtime($cachefile)+$cachetime;
if (!isset($_GET["nocache"]) && is_file($cachefile) && (time() < filemtime($cachefile)+$cachetime)) {
$plain = file_get_contents($cachefile);
$alldata = json_decode($plain, true);
$cacheused = true;
} else {
foreach ($options['stops'] as $n => $stop) {
$stopsplit = explode(":",$stop);
// errors?
if ($stopsplit == $stop)
echo "<div error><h1>NAME ERROR!</h1>$stop<br/>Not a propper stop name. Usage: city:stop[;city:stop]*</div>";
// get departures
$plain = file_get_contents("http://vrrf.finalrewind.org/$stopsplit[0]/$stopsplit[1].json?frontend=json");
$data = json_decode($plain, true);
// version
$alldata["version"] = $version;
$alldata["vrrf_version"] = $data['version'];
$alldata["used_vrrf_version"] = $vrrf_version;
// api_errors
$alldata["errors"]["$stopsplit[0] - $stopsplit[1]"] = $data['error'];
// info
$alldata["info"] = ""; // TODO generate informations
// data
$rawdata["$stopsplit[0] - $stopsplit[1]"] = $data['raw'];
}
$reftime = date("dHi");
$alldata['lines'] = array();
foreach ($rawdata as $stop => $data) {
// process
foreach ($data as $i => $entry) {
// filter
if (isset($options['filter']['bl'])) {
if (isset($options['filter']['bl']['line']) ) {
if (in_array($entry['line'], $options['filter']['bl']['line'])) {
continue;
}
}
if (isset($options['filter']['bl']['type']) ) {
if (in_array($entry['type'], $options['filter']['bl']['type'])) {
continue;
}
}
if (isset($options['filter']['bl']['platform']) ) {
if (in_array($entry['platform'], $options['filter']['bl']['platform'])) {
continue;
}
}
}
if (isset($options['filter']['wl'])) {
if (isset($options['filter']['wl']['line']) ) {
if (!in_array($entry['line'], $options['filter']['wl']['line'])) {
continue;
}
}
if (isset($options['filter']['wl']['type']) ) {
if (!in_array($entry['type'], $options['filter']['wl']['type'])) {
continue;
}
}
if (isset($options['filter']['wl']['platform']) ) {
if (!in_array($entry['platform'], $options['filter']['wl']['platform'])) {
continue;
}
}
}
// !filter
$scheddate = explode(".",$entry['sched_date']);
$schedtime = explode(":",$entry['sched_time']);
$deptime = $scheddate[0].$schedtime[0].$schedtime[1];
//echo intval($deptime)." + ".intval($entry['delay'])." - ".intval($reftime)." = ".(intval($deptime) + intval($entry['delay']) - intval($reftime))."<br/>";
if (intval($deptime) + intval($entry['delay']) - intval($reftime) > 0) {
$buf = array('date' => $entry['sched_date'], 'time' => $entry['sched_time'], 'delay' => $entry['delay'], 'cancel' => $entry['is_cancelled'], 'name' => $stop, 'info' => $entry['info']);
foreach ($alldata['lines'] as $key => $value) {
if (($entry['key'] == $value['key']) && ($entry['lineref']['identifier'] == $value['identifier']) && ($entry['line'] == $value['line'])) {
$ibuf = sizeof($alldata['lines'][$key]['stops']);
while ($buf != null) {
if ($ibuf < 1 || strcmp($buf['time'], $alldata['lines'][$key]['stops'][$ibuf - 1]['time']) > 0) {
$alldata['lines'][$key]['stops'][$ibuf] = $buf;
$buf = null;
} else {
$alldata['lines'][$key]['stops'][$ibuf] = $alldata['lines'][$key]['stops'][$ibuf - 1];
$ibuf--;
}
}
break;
}
}
if ($buf != null) {
$dbuf = array('line' => $entry['line'], 'destination' => $entry['destination'], 'type' => $entry['type'], 'key' => $entry['key'], 'identifier' => $entry['lineref']['identifier'], 'stops' => array($buf));
$alldata['lines'][] = $dbuf;
}
}
}
}
// sort
usort($alldata['lines'], function($a, $b) {
// atime
$scheddate = explode(".",$a['stops'][0]['date']);
$schedtime = explode(":",$a['stops'][0]['time']);
$atime = $scheddate[2].$scheddate[1].$scheddate[0].$schedtime[0].$schedtime[1];
// btime
$scheddate = explode(".",$b['stops'][0]['date']);
$schedtime = explode(":",$b['stops'][0]['time']);
$btime = $scheddate[2].$scheddate[1].$scheddate[0].$schedtime[0].$schedtime[1];
// compare
return intval($atime) - intval($btime);
});
// clean
foreach ($alldata['lines'] as $id => $line) {
unset($alldata['lines'][$id]['key']);
unset($alldata['lines'][$id]['identifier']);
}
// save cache
file_put_contents($cachefile,json_encode($alldata));
}
echo json_encode($alldata);
?>
<?php
error_reporting (-1);
ini_set ('display_errors', 1);
// initialize frontend
header('Content-type: text/json');
// version-info
$version = "0.05";
$vrrf_version = "0.07";
// options
$options = array();
// max entries
$max = 1000000;
// configuration
if (isset($_GET['config'])) {
$file = "config/" . $_GET['config'] . ".json";
if (!file_exists($file)) {
$result['error'] = 'config file "'.$file.'" not found';
$result['config']['name'] = $file;
$result['options'] = $options;
echo json_encode($result);
exit;
}
$config = file_get_contents($file);
$buffer = json_decode($config, true);
$options['stops'] = $buffer['stops'];
$options['filter'] = $buffer['filter'];
if (is_numeric($buffer['max'])) {
$max = $buffer['max'];
}
if (count($options['stops']) == 0) {
$result['error'] = 'no stops defined';
$result['config']['name'] = $config_name;
$result['config']['type'] = 'panel/departure';
$result['options'] = $options;
echo json_encode($result);
exit;
}
} else {
$result['error'] = 'no config defined';
$result['config']['name'] = $config_name;
$result['config']['type'] = 'panel/departure';
$result['options'] = $options;
echo json_encode($result);
exit;
}
usort($options['stops'], function($a, $b) {
return strcmp($a, $b);
});
// cache
$name = json_encode($options);
$cachefile = "cache/vrr_".md5($name).".json";
$cachetime = 60;
$cache_ablauf = 0;
$cacheused = false;
$rawdata = array();
$alldata = array();
if (is_file($cachefile))
$cache_ablauf=filemtime($cachefile)+$cachetime;
if (!isset($_GET["nocache"]) && is_file($cachefile) && (time() < filemtime($cachefile)+$cachetime)) {
$plain = file_get_contents($cachefile);
$alldata = json_decode($plain, true);
$cacheused = true;
} else {
foreach ($options['stops'] as $n => $stop) {
$stopsplit = explode(":",$stop);
// errors?
if ($stopsplit == $stop)
echo "<div error><h1>NAME ERROR!</h1>$stop<br/>Not a propper stop name. Usage: city:stop[;city:stop]*</div>";
// get departures
$plain = file_get_contents("http://vrrf.finalrewind.org/$stopsplit[0]/$stopsplit[1].json?frontend=json");
$data = json_decode($plain, true);
// version
$alldata["version"] = $version;
$alldata["vrrf_version"] = $data['version'];
$alldata["used_vrrf_version"] = $vrrf_version;
// api_errors
$alldata["errors"]["$stopsplit[0] - $stopsplit[1]"] = $data['error'];
// info
$alldata["info"] = ""; // TODO generate informations
// data
$rawdata["$stopsplit[0] - $stopsplit[1]"] = $data['raw'];
}
$reftime = date("dHi");
$alldata['lines'] = array();
foreach ($rawdata as $stop => $data) {
// process
foreach ($data as $i => $entry) {
// filter
if (isset($options['filter']['bl'])) {
if (isset($options['filter']['bl']['line']) ) {
if (in_array($entry['line'], $options['filter']['bl']['line'])) {
continue;
}
}
if (isset($options['filter']['bl']['type']) ) {
if (in_array($entry['type'], $options['filter']['bl']['type'])) {
continue;
}
}
if (isset($options['filter']['bl']['platform']) ) {
if (in_array($entry['platform'], $options['filter']['bl']['platform'])) {
continue;
}
}
}
if (isset($options['filter']['wl'])) {
if (isset($options['filter']['wl']['line']) ) {
if (!in_array($entry['line'], $options['filter']['wl']['line'])) {
continue;
}
}
if (isset($options['filter']['wl']['type']) ) {
if (!in_array($entry['type'], $options['filter']['wl']['type'])) {
continue;
}
}
if (isset($options['filter']['wl']['platform']) ) {
if (!in_array($entry['platform'], $options['filter']['wl']['platform'])) {
continue;
}
}
}
// !filter
$scheddate = explode(".",$entry['sched_date']);
$schedtime = explode(":",$entry['sched_time']);
$deptime = $scheddate[0].$schedtime[0].$schedtime[1];
//echo intval($deptime)." + ".intval($entry['delay'])." - ".intval($reftime)." = ".(intval($deptime) + intval($entry['delay']) - intval($reftime))."<br/>";
if (intval($deptime) + intval($entry['delay']) - intval($reftime) > 0) {
$buf = array('date' => $entry['sched_date'], 'time' => $entry['sched_time'], 'delay' => $entry['delay'], 'cancel' => $entry['is_cancelled'], 'name' => $stop, 'info' => $entry['info']);
foreach ($alldata['lines'] as $key => $value) {
if (($entry['key'] == $value['key']) && ($entry['lineref']['identifier'] == $value['identifier']) && ($entry['line'] == $value['line'])) {
$ibuf = sizeof($alldata['lines'][$key]['stops']);
while ($buf != null) {
if ($ibuf < 1 || strcmp($buf['time'], $alldata['lines'][$key]['stops'][$ibuf - 1]['time']) > 0) {
$alldata['lines'][$key]['stops'][$ibuf] = $buf;
$buf = null;
} else {
$alldata['lines'][$key]['stops'][$ibuf] = $alldata['lines'][$key]['stops'][$ibuf - 1];
$ibuf--;
}
}
break;
}
}
if ($buf != null) {
$dbuf = array('line' => $entry['line'], 'destination' => $entry['destination'], 'type' => $entry['type'], 'key' => $entry['key'], 'identifier' => $entry['lineref']['identifier'], 'stops' => array($buf));
$alldata['lines'][] = $dbuf;
}
}
}
}
// sort
usort($alldata['lines'], function($a, $b) {
// atime
$scheddate = explode(".",$a['stops'][0]['date']);
$schedtime = explode(":",$a['stops'][0]['time']);
$atime = $scheddate[2].$scheddate[1].$scheddate[0].$schedtime[0].$schedtime[1];
// btime
$scheddate = explode(".",$b['stops'][0]['date']);
$schedtime = explode(":",$b['stops'][0]['time']);
$btime = $scheddate[2].$scheddate[1].$scheddate[0].$schedtime[0].$schedtime[1];
// compare
return intval($atime) - intval($btime);
});
// clean
foreach ($alldata['lines'] as $id => $line) {
unset($alldata['lines'][$id]['key']);
unset($alldata['lines'][$id]['identifier']);
}
// save cache
file_put_contents($cachefile,json_encode($alldata));
}
echo json_encode($alldata);
?>
......@@ -65,7 +65,7 @@ this.loaded = function(panel, config) {
var update = function(config, fields) {
console.log("departures: get data [" + config + "]");
$.get("panels/departure/departures.php?config=config/panel/departure/" + config + ".json", function(decodedData) {
$.get("panels/departure/departures.php?config=" + config , function(decodedData) {
console.log("departures: check vrrf errors [" + config + "]");
if (!!decodedData.errors) {
......@@ -286,4 +286,4 @@ var buildDOM = function(config, fields) {
elements.push(buf.self);
}
$(fields.cont).append(elements);
}
\ No newline at end of file
}
......@@ -10,7 +10,7 @@
box-sizing: border-box;
overflow: hidden;
font-family: display;
font-weight: bold;
/* font-weight: bold */
[data-departure] {
position: relative;
......@@ -137,4 +137,4 @@
width: 100%;
}
}
}
\ No newline at end of file
}
......@@ -2,7 +2,7 @@ var CM;
this.loaded = function(panel, config) {
console.log("scrollbar: register with config [" + config + "]");
function CanvasMarquee() {
var
me = this,
......@@ -20,7 +20,7 @@ this.loaded = function(panel, config) {
mctx = null,
strings = [],
texts = [];
init = function() {
marquee = $(panel).find('[data-marquee]')[0];
width = $(panel).width();
......@@ -28,14 +28,14 @@ this.loaded = function(panel, config) {
$(marquee).attr('width', width).attr('height', height);
mctx = marquee.getContext('2d');
}
this.setTexts = function(t) {
strings = t;
prerender();
textID = -1;
nextText();
}
this.resize = function() {
oldWidth = width;
width = $(panel).width();
......@@ -45,30 +45,35 @@ this.loaded = function(panel, config) {
prerender();
left = left * width / oldWidth;
}
render = function() {
render = function(delta) {
if (left > -texts[textID].width) {
left = left - (amount > 0 ? amount : 1);
mctx.fillStyle = bgColor;
mctx.fillRect(0, 0, width, height);
mctx.drawImage(texts[textID].text, (left = left - (amount > 0 ? amount : 1)), 0);
mctx.drawImage(texts[textID].text, left, 0);
window.requestAnimationFrame(render);
} else {
setTimeout(nextText, (delay >= 0 ? delay : 0) * 1000);
}
}
nextText = function() {
textID = (textID + 1) % texts.length;
left = width;
start = new Date();
start=null;
window.requestAnimationFrame(render);
}
prerender = function() {
mctx.font = height + "px " + font;
texts = [];
for (var i = 0; i < strings.length; ++i) {
var
var
text = '+++ ' + strings[i].join(' +++ +++ ') + ' +++',
bWidth = mctx.measureText(text).width,
buffer = document.createElement('canvas'),
......@@ -84,23 +89,23 @@ this.loaded = function(panel, config) {
});
}
}
init();
}
$.get("config/panel/scrollbar/oh14.json", function(decodedData) {
CM = new CanvasMarquee();
CM.setTexts(decodedData.texts);
});
r = function() {
resize();
}
$(window).resize(r);
}
var resize = function() {
if (CM)
CM.resize();
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment