Skip to content

Instantly share code, notes, and snippets.

@Bertware
Last active December 18, 2018 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bertware/d61470e0687a116f17fa95974df97ceb to your computer and use it in GitHub Desktop.
Save Bertware/d61470e0687a116f17fa95974df97ceb to your computer and use it in GitHub Desktop.
Liveboard, Train and Earliest Arrival Time demos based on Linked Connections
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Linked Connections Trains</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<style>
tr:first-of-type {
background-color: #c7292933 !important;
}
.delay {
color: #c72929;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" type="text/javascript"></script>
<script src="https://momentjs.com/downloads/moment.min.js" type="text/javascript"></script>
<script type="text/javascript">
var t=setInterval(function(){
var table = $('.sorted').eq(0)
var rows = table.find('tr:gt(0)').toArray().sort(comparer(1))
for (var i = 0; i < rows.length; i++){table.append(rows[i])}
}, 1000)
function comparer(index) {
return function(a, b) {
var valA = getCellValue(a, index), valB = getCellValue(b, index)
return $.isNumeric(valA) && $.isNumeric(valB) ? valA - valB : valA.toString().localeCompare(valB)
}
}
function getCellValue(row, index){ return $(row).children('td').eq(index).text() }
</script>
</head>
<body>
<div class='container'>
<h2>Earliest arrival times when leaving now from <span id="here">here</span></h2>
<table class='sorted striped highlight responsive-table' id="liveboard-data">
<tr>
<th>Station</th>
<th>Arrival Time</th>
</tr>
</div>
<script type="text/javascript">
var worker = new Worker("eat.js");
var stopResolver = new Worker("fetchUri.js");
let stop ="http://se.lc.bertmarcelis.be/stops/740000002";
worker.postMessage({
'station': stop,
'graph': 'https://se.lc.bertmarcelis.be/vasttrafik/connections',
});
$('#here').html(stop);
$('#here').attr("data-uri",stop);
stopResolver.postMessage({ 'uri': stop });
worker.onmessage = function(event) {
console.log(event.data);
var connection = event.data;
var timestr = moment(connection['departureTime']).format('HH:mm');
var arrivaltimestr = moment(connection['arrivalTime']).format('HH:mm');
$( "<tr id='" + connection['@id'] + "'><td data-uri='" + connection['arrivalStop'] + "'>" + connection['arrivalStop'] + "</td><td>" + arrivaltimestr + "</td></tr>" ).appendTo("#liveboard-data");
stopResolver.postMessage({ 'uri': connection['arrivalStop'] });
};
stopResolver.onmessage = function(event) {
$('[data-uri="' + event.data['@id'] + '"]').html(event.data.name);
}
</script>
</body>
</html>
self.onmessage = function (event) {
let station_uri = event.data['station'];
//let stations_graph = event.data['station_graph'];
//let target_count = event.data['count'];
let page_url = event.data['graph'];
let c = 0
let eat = [];
eat[station_uri] = new Date().toISOString();
while (c < 50 &&page_url < "https://se.lc.bertmarcelis.be/vasttrafik/connections?departureTime=2018-12-19T03:15:00.000Z") {
var xhr = new XMLHttpRequest();
xhr.open("GET", page_url, false); // synchronous request
xhr.send(null);
let page = JSON.parse(xhr.responseText);
page['@graph'].forEach(function (connection) {
let arrivalTime = new Date();
if (connection.departureStop in eat){
if (connection.departureTime > eat[connection.departureStop] && (!(connection.arrivalStop in eat) || eat[connection.arrivalStop] > connection.arrivalTime)){
eat[connection.arrivalStop] = connection.arrivalTime;
self.postMessage(connection);
c++;
}
}
});
page_url = page['hydra:next'];
}
};
self.onmessage = function (event) {
let station_uri = event.data['station'];
let target_count = event.data['count'];
let page_url = event.data['graph'];
let result_count = 0;
while (result_count < target_count) {
var xhr = new XMLHttpRequest();
xhr.open("GET", page_url, false); // synchronous request
xhr.send(null);
let page = JSON.parse(xhr.responseText);
page['@graph'].forEach(function (connection) {
if (connection.departureStop == station_uri){
self.postMessage(connection);
result_count++;
}
});
page_url = page['hydra:next'];
}
};
self.onmessage = function (event) {
let trip_uri = event.data['trip'];
let page_url = event.data['graph'];
let result_count = 0;
let last_seen = new Date(22222222220000); //2040-...
let last_connection = new Date(0); //1970-...
while (last_connection.getTime() - last_seen.getTime() < 3 * 3600 * 1000 ) {
console.log(page_url);
var xhr = new XMLHttpRequest();
xhr.open("GET", page_url, false); // synchronous request
xhr.send(null);
let page = JSON.parse(xhr.responseText);
page['@graph'].forEach(function (connection) {
last_connection = new Date(connection['departureTime']);
if (connection['gtfs:trip'] == trip_uri){
last_seen=last_connection;
self.postMessage(connection);
result_count++;
}
});
if(last_connection.getTime() - last_seen.getTime() < 3 * 3600 * 1000 ){
console.log("Next page needed!");
} else {
console.log("Done! " + last_connection.getTime() + ' ' + last_seen.getTime());
}
page_url = page['hydra:next'];
}
};
self.onmessage = async function (event) {
let trip_uri = event.data['uri'];
// clearly show the changing uris
await sleep(2000);
console.log(trip_uri);
var xhr = new XMLHttpRequest();
xhr.open("GET", trip_uri.replace("http:","https:"), false); // synchronous request
xhr.send(null);
let stop = JSON.parse(xhr.responseText);
self.postMessage(stop);
};
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
<html>
<head>
<title>LC demo</title>
</head>
<body>
<a href="liveboard.html">Liveboard</a><br>
<a href="train.html">Vehicle route</a><br>
<a href="eat.html">Earliest arrival time</a><br>
</html>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Linked Connections liveboard</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<style>
tr:first-of-type {
background-color: #c7292933 !important;
}
.delay {
color: #c72929;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" type="text/javascript"></script>
<script src="https://momentjs.com/downloads/moment.min.js" type="text/javascript"></script>
</head>
<body>
<div class='container'>
<h2>Departures from <span id="here">here</span></h2>
<table class='striped highlight responsive-table' id="liveboard-data">
<tr>
<th>Departure</th>
<th>Destination</th>
</tr>
</div>
<script type="text/javascript">
var worker = new Worker("fetchDepartures.js");
var stopResolver = new Worker("fetchUri.js");
let stop ="http://se.lc.bertmarcelis.be/stops/740000002";
worker.postMessage({
'station': stop,
'graph': 'https://se.lc.bertmarcelis.be/vasttrafik/connections',
'count': 30
});
$('#here').html(stop);
$('#here').attr("data-uri",stop);
stopResolver.postMessage({ 'uri': stop });
worker.onmessage = function(event) {
console.log(event.data);
var connection = event.data;
var timestr = moment(connection['departureTime']).format('HH:mm');
var hasDelay = (('departureDelay' in connection) && (connection['departureDelay']) > 0);
$( "<tr id='" + connection['@id'] + "'><td>" + timestr + (hasDelay ? " <span class='delay'>+" + (connection['departureDelay']/60) + "'</span>" : "") + "</td><td>" + connection['direction'] + "</td></tr>" ).appendTo("#liveboard-data");
};
stopResolver.onmessage = function(event) {
$('[data-uri="' + event.data['@id'] + '"]').html(event.data.name);
}
</script>
</body>
</html>
{
"@context": {
"xsd": "http://www.w3.org/2001/XMLSchema#",
"dcat": "http://www.w3.org/ns/dcat#",
"dct": "http://purl.org/dc/terms/",
"foaf": "http://xmlns.com/foaf/0.1/",
"owl": "http://www.w3.org/2002/07/owl#",
"schema": "http://schema.org/",
"dct:modified": {
"@type": "xsd:dateTime"
},
"dct:issued": {
"@type": "xsd:dateTime"
},
"dct:spatial": {
"@type": "@id"
},
"dct:license": {
"@type": "@id"
},
"dct:conformsTo": {
"@type": "@id"
},
"dcat:mediaType": {
"@type": "xsd:string"
},
"schema:startDate": {
"@type": "xsd:dateTime"
},
"schema:endDate": {
"@type": "xsd:dateTime"
},
"minLatitude": {
"@id": "http://aims.fao.org/aos/geopolitical.owl#hasMinLatitude",
"@type": "@id"
},
"maxLatitude": {
"@id": "http://aims.fao.org/aos/geopolitical.owl#hasMaxLatitude",
"@type": "@id"
},
"minLongitude": {
"@id": "http://aims.fao.org/aos/geopolitical.owl#hasMinLongitude",
"@type": "@id"
},
"maxLongitude": {
"@id": "http://aims.fao.org/aos/geopolitical.owl#hasMaxLongitude",
"@type": "@id"
},
},
"@id": "http://se.lc.bertmarcelis.be/catalog",
"@type": "dcat:Catalog",
"dct:title": "Catalog of Samtrafiken datasets",
"dct:description": "Catalog of datasets published by Samtrafiken / Trafiklab",
"dct:modified": "2018-11-01T10:00:00.000+01:00",
"dct:license": "http://creativecommons.org/publicdomain/zero/1.0/",
"dct:rights": "public",
"dct:publisher": {
"@id": "http://samtrafiken.se",
"@type": "foaf:Organization",
"foaf:name": "Samtrafiken"
},
"dcat:dataset": [
{
"@id": "http://se.lc.bertmarcelis.be/sl/connections",
"@type": "dcat:Dataset",
"dct:description": "Linked Connections dataset for SL",
"dct:title": "Linked Connections - SL",
"dct:spatial": "http://sws.geonames.org/2673722/",
"minLatitude": 58.712259954661,
"maxLatitude": 60.2771500755361,
"minLongitude": 17.2436707492366,
"maxLongitude": 19.6418499369236,
"dcat:keyword": [
"Train",
"Bus",
"Tram",
"Metro",
"Ferry",
"Light Rail"
],
"dct:conformsTo": "http://linkedconnections.org/specification/1-0",
"dct:accessRights": "public",
"dcat:distribution": [
{
"@id": "http://se.lc.bertmarcelis.be/sncb/2018-08-24T03:10:30.000Z",
"@type": "dcat:Distribution",
"dcat:accessURL": "http://se.lc.bertmarcelis.be/sncb/connections",
"dct:license": "http://creativecommons.org/publicdomain/zero/1.0/",
"dcat:mediaType": "application/ld+json",
"dct:issued": "2018-11-01T10:00:00.000+01:00",
"schema:startDate": "2018-10-01T00:00:00.000Z",
"schema:endDate": "2018-12-31T23:59:59.999Z"
}
]
},
{
"@id": "http://se.lc.bertmarcelis.be/sl/stops",
"@type": "dcat:Dataset",
"dct:description": "Stop locations dataset for SL",
"dct:title": "Stop locations - SL",
"dct:spatial": "http://sws.geonames.org/2673722/",
"minLatitude": 58.712259954661,
"maxLatitude": 60.2771500755361,
"minLongitude": 17.2436707492366,
"maxLongitude": 19.6418499369236,
"dcat:keyword": [
"Stops"
],
"dct:accessRights": "public",
"dcat:distribution": [
{
"@id": "http://se.lc.bertmarcelis.be/sncb/stops",
"@type": "dcat:Distribution",
"dcat:accessURL": "http://se.lc.bertmarcelis.be/sncb/stops.jsonld",
"dct:license": "http://creativecommons.org/publicdomain/zero/1.0/",
"dcat:mediaType": "application/ld+json",
"dct:issued": "2018-11-01T10:00:00.000+01:00"
}
]
},
{
"@id": "http://se.lc.bertmarcelis.be/vasttrafik/connections",
"@type": "dcat:Dataset",
"dct:description": "Linked Connections dataset for Västtrafik",
"dct:title": "Linked Connections - Västtrafik",
"dct:spatial": "http://www.geonames.org/3337386/",
"minLatitude": 57.145549670074864,
"maxLatitude": 59.26369227097521,
"minLongitude": 10.963484537623518,
"maxLongitude": 14.739601688959032,
"dcat:keyword": [
"Train",
"Bus",
"Tram",
"Metro",
"Ferry",
"Light Rail"
],
"dct:conformsTo": "http://linkedconnections.org/specification/1-0",
"dct:accessRights": "public",
"dcat:distribution": [
{
"@id": "http://se.lc.bertmarcelis.be/vasttrafik/2018-08-24T03:10:30.000Z",
"@type": "dcat:Distribution",
"dcat:accessURL": "http://se.lc.bertmarcelis.be/vasttrafik/connections",
"dct:license": "http://creativecommons.org/publicdomain/zero/1.0/",
"dcat:mediaType": "application/ld+json",
"dct:issued": "2018-11-01T10:00:00.000+01:00",
"schema:startDate": "2018-10-01T00:00:00.000Z",
"schema:endDate": "2018-12-31T23:59:59.999Z"
}
]
},
{
"@id": "http://se.lc.bertmarcelis.be/vasttrafik/stops",
"@type": "dcat:Dataset",
"dct:description": "Stop locations dataset for Västtrafik",
"dct:title": "Stops - Västtrafik",
"dct:spatial": "http://www.geonames.org/3337386/",
"minLatitude": 57.145549670074864,
"maxLatitude": 59.26369227097521,
"minLongitude": 10.963484537623518,
"maxLongitude": 14.739601688959032,
"dcat:keyword": [
"Stops"
],
"dct:accessRights": "public",
"dcat:distribution": [
{
"@id": "http://se.lc.bertmarcelis.be/vasttrafik/stops",
"@type": "dcat:Distribution",
"dcat:accessURL": "http://se.lc.bertmarcelis.be/vasttrafik/stops.jsonld",
"dct:license": "http://creativecommons.org/publicdomain/zero/1.0/",
"dcat:mediaType": "application/ld+json",
"dct:issued": "2018-11-01T10:00:00.000+01:00"
}
]
},
{
"@id": "http://se.lc.bertmarcelis.be/sj/connections",
"@type": "dcat:Dataset",
"dct:description": "Linked Connections dataset for SJ",
"dct:title": "Linked Connections - SJ",
"dct:spatial": "http://www.geonames.org/2661886/",
"minLatitude": 55.3374438220002,
"maxLatitude": 69.0599672666879,
"minLongitude": 10.963484537623518,
"maxLongitude": 24.1663846943218,
"dcat:keyword": [
"Train",
"Bus",
"Tram",
"Metro",
"Ferry",
"Light Rail"
],
"dct:conformsTo": "http://linkedconnections.org/specification/1-0",
"dct:accessRights": "public",
"dcat:distribution": [
{
"@id": "http://se.lc.bertmarcelis.be/sj/2018-08-24T03:10:30.000Z",
"@type": "dcat:Distribution",
"dcat:accessURL": "http://se.lc.bertmarcelis.be/sj/connections",
"dct:license": "http://creativecommons.org/publicdomain/zero/1.0/",
"dcat:mediaType": "application/ld+json",
"dct:issued": "2018-11-01T10:00:00.000+01:00",
"schema:startDate": "2018-10-01T00:00:00.000Z",
"schema:endDate": "2018-12-31T23:59:59.999Z"
}
]
},
{
"@id": "http://se.lc.bertmarcelis.be/sj/stops",
"@type": "dcat:Dataset",
"dct:description": "Stop locations dataset for SJ",
"dct:title": "Stops - SJ",
"dct:spatial": "http://www.geonames.org/3337386/",
"minLatitude": 55.3374438220002,
"maxLatitude": 69.0599672666879,
"minLongitude": 10.963484537623518,
"maxLongitude": 24.1663846943218,
"dcat:keyword": [
"Stops"
],
"dct:accessRights": "public",
"dcat:distribution": [
{
"@id": "http://se.lc.bertmarcelis.be/sj/stops",
"@type": "dcat:Distribution",
"dcat:accessURL": "http://se.lc.bertmarcelis.be/sj/stops.jsonld",
"dct:license": "http://creativecommons.org/publicdomain/zero/1.0/",
"dcat:mediaType": "application/ld+json",
"dct:issued": "2018-11-01T10:00:00.000+01:00"
}
]
},
]
}
<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dcat="http://www.w3.org/ns/dcat#"
xmlns:dct="http://purl.org/dc/terms/"
xmlns:geo="http://www.georss.org/georss/"
xmlns:schema="http://schema.org/"
>
<dcat:Catalog rdf:about="http://se.lc.bertmarcelis.be/catalog">
<dct:description>Catalog of datasets published by Samtrafiken / Trafiklab</dct:description>
<dct:license rdf:resource="http://creativecommons.org/publicdomain/zero/1.0/"/>
<dct:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2018-11-01T10:00:00+01:00</dct:modified>
<dct:rights>public</dct:rights>
<dct:publisher>
<foaf:Organization rdf:about="http://samtrafiken.se/">
<foaf:name>Samtrafiken</foaf:name>
</foaf:Organization>
</dct:publisher>
<dcat:dataset>
<dcat:Dataset rdf:about="http://se.lc.bertmarcelis.be/sl">
<dct:description>Linked Connections dataset for SL</dct:description>
<geo:box rdf:datatype="http://www.w3.org/2001/XMLSchema#double">58.7122599547</geo:box>
<dcat:keyword>Ferry</dcat:keyword>
<dcat:distribution rdf:resource="http://se.lc.bertmarcelis.be/sncb/2018-08-24T03:10:30.000Z"/>
<dct:accessRights>public</dct:accessRights>
<dct:spatial rdf:resource="http://sws.geonames.org/2673722/"/>
<geo:box rdf:datatype="http://www.w3.org/2001/XMLSchema#double">60.2771500755</geo:box>
<dcat:keyword>Metro</dcat:keyword>
<dcat:keyword>Stops</dcat:keyword>
<dct:conformsTo rdf:resource="http://linkedconnections.org/specification/1-0"/>
<dct:title>Linked Connections - SL</dct:title>
<dcat:keyword>Bus</dcat:keyword>
<dcat:keyword>Light Rail</dcat:keyword>
<geo:box rdf:datatype="http://www.w3.org/2001/XMLSchema#double">17.2436707492</geo:box>
<geo:box rdf:datatype="http://www.w3.org/2001/XMLSchema#double">19.6418499369</geo:box>
<dcat:keyword>Tram</dcat:keyword>
<dcat:keyword>Train</dcat:keyword>
</dcat:Dataset>
</dcat:dataset>
<dct:title>Catalog of Samtrafiken datasets</dct:title>
</dcat:Catalog>
<dcat:Distribution rdf:about="http://se.lc.bertmarcelis.be/sncb/2018-08-24T03:10:30.000Z">
<dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2018-11-01T10:00:00+01:00</dct:issued>
<dcat:accessURL>http://se.lc.bertmarcelis.be/sncb/connections</dcat:accessURL>
<schema:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2018-10-01T00:00:00+00:00</schema:startDate>
<dct:license rdf:resource="http://creativecommons.org/publicdomain/zero/1.0/"/>
<dcat:mediaType rdf:datatype="http://www.w3.org/2001/XMLSchema#string">application/ld+json</dcat:mediaType>
<schema:endDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2018-12-31T23:59:59.999000+00:00</schema:endDate>
</dcat:Distribution>
</rdf:RDF>
@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix geo: <http://www.georss.org/georss/> .
@prefix georss: <http://www.georss.org/georss/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <http://schema.org/> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://se.lc.bertmarcelis.be/catalog> a dcat:Catalog ;
dct:description "Catalog of datasets published by Samtrafiken / Trafiklab" ;
dct:license <http://creativecommons.org/publicdomain/zero/1.0/> ;
dct:modified "2018-11-01T10:00:00+01:00"^^xsd:dateTime ;
dct:publisher <http://samtrafiken.se/> ;
dct:rights "public" ;
dct:title "Catalog of Samtrafiken datasets" ;
dcat:dataset <http://se.lc.bertmarcelis.be/sl> .
<http://samtrafiken.se/> a foaf:Organization ;
foaf:name "Samtrafiken" .
<http://se.lc.bertmarcelis.be/sl> a dcat:Dataset ;
dct:accessRights "public" ;
dct:conformsTo <http://linkedconnections.org/specification/1-0> ;
dct:description "Linked Connections dataset for SL" ;
dct:spatial <http://sws.geonames.org/2673722/> ;
dct:title "Linked Connections - SL" ;
geo:box 1.724367e+01,
1.964185e+01,
5.871226e+01,
6.027715e+01 ;
dcat:distribution <http://se.lc.bertmarcelis.be/sncb/2018-08-24T03:10:30.000Z> ;
dcat:keyword "Bus",
"Ferry",
"Light Rail",
"Metro",
"Stops",
"Train",
"Tram" .
<http://se.lc.bertmarcelis.be/sncb/2018-08-24T03:10:30.000Z> a dcat:Distribution ;
dct:issued "2018-11-01T10:00:00+01:00"^^xsd:dateTime ;
dct:license <http://creativecommons.org/publicdomain/zero/1.0/> ;
schema:endDate "2018-12-31T23:59:59.999000+00:00"^^xsd:dateTime ;
schema:startDate "2018-10-01T00:00:00+00:00"^^xsd:dateTime ;
dcat:accessURL "http://se.lc.bertmarcelis.be/sncb/connections" ;
dcat:mediaType "application/ld+json"^^xsd:string .
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Linked Connections Trains</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<style>
tr:first-of-type {
background-color: #c7292933 !important;
}
.delay {
color: #c72929;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" type="text/javascript"></script>
<script src="https://momentjs.com/downloads/moment.min.js" type="text/javascript"></script>
<script type="text/javascript">
var worker = new Worker("fetchTrain.js");
var stopResolver = new Worker("fetchUri.js");
worker.postMessage({
'trip': 'http://se.lc.bertmarcelis.be/vehicle/vasttrafik/22792005565244/20181213',
'graph': 'https://se.lc.bertmarcelis.be/vasttrafik/connections?departureTime=2018-12-13T10:00:00.000Z',
});
worker.onmessage = function(event) {
console.log(event.data);
var connection = event.data;
var timestr = moment(connection['departureTime']).format('HH:mm');
var arrivaltimestr = moment(connection['arrivalTime']).format('HH:mm');
var hasDelay = (('departureDelay' in connection) && (connection['departureDelay']) > 0);
var hasArrivalDelay = (('arrivalDelay' in connection) && (connection['arrivalDelay']) > 0);
$( "<tr id='" + connection['@id'] + "'><td>" + timestr + (hasDelay ? " <span class='delay'>+" + (connection['departureDelay']/60) + "'</span>" : "") + "</td><td data-uri='" + connection['departureStop'] + "'>" + connection['departureStop'] + "</td><td data-uri='" + connection['arrivalStop'] + "'>" + connection['arrivalStop'] + "</td><td>" + arrivaltimestr + (hasArrivalDelay ? " <span class='delay'>+" + (connection['arrivalDelay']/60) + "'</span>" : "") + "</td></tr>" ).appendTo("#liveboard-data");
stopResolver.postMessage({ 'uri': connection['arrivalStop'] });
stopResolver.postMessage({ 'uri': connection['departureStop'] });
};
stopResolver.onmessage = function(event) {
$('[data-uri="' + event.data['@id'] + '"]').html(event.data.name);
}
</script>
</head>
<body>
<div class='container'>
<table class='striped highlight responsive-table' id="liveboard-data">
<tr>
<th>Departure</th>
<th>From</th>
<th>To</th>
<th>Arrival</th>
</tr>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment