Mon, 11 Feb 2019 22:39:44 +0200
update
77 | 1 | {% from "macros.html" import route_rep %} |
0 | 2 | <html> |
3 | <head> | |
35 | 4 | <link rel="icon" type="image/png" href="../static/favicon.png" /> |
5 | <link rel="stylesheet" type="text/css" href="../static/style.css" /> | |
0 | 6 | <meta charset='UTF-8' /> |
33
f448f291c1dd
Korjattu pysäkkisivun otsikko
Teemu Piippo <teemu@hecknology.net>
parents:
32
diff
changeset
|
7 | <title>{{name}}</title> |
32
ca1a0ea81cf6
Yhdistetty pysäkki.png ja iso-pysäkki.png
Teemu Piippo <teemu@hecknology.net>
parents:
27
diff
changeset
|
8 | <meta http-equiv='refresh' content='60'> |
0 | 9 | <style> |
21 | 10 | .sarake-määränpää |
11 | { | |
12 | text-align: left; | |
13 | } | |
127 | 14 | |
15 | .dataentry | |
16 | { | |
17 | display: none; | |
18 | } | |
19 | ||
20 | .sarake-aika | |
21 | { | |
136 | 22 | width: 175pt; |
127 | 23 | } |
24 | ||
25 | .gone | |
26 | { | |
27 | background-color: #666; | |
28 | color: silver; | |
29 | font-style: italic; | |
30 | display: none; | |
31 | } | |
32 | ||
33 | tbody tr:nth-child(even).gone | |
34 | { | |
35 | background-color: #585858; | |
36 | } | |
0 | 37 | </style> |
127 | 38 | <script> |
134 | 39 | var getJSON = function(url, callback) |
40 | { | |
127 | 41 | var xhr = new XMLHttpRequest(); |
42 | xhr.open('GET', url, true); | |
43 | xhr.responseType = 'json'; | |
44 | xhr.onload = function() { | |
45 | var status = xhr.status; | |
46 | if (status === 200) { | |
47 | callback(xhr.response); | |
48 | } | |
49 | }; | |
50 | xhr.send(); | |
51 | }; | |
52 | ||
134 | 53 | function timeConverter(UNIX_timestamp) |
54 | { | |
136 | 55 | const d = new Date(); |
56 | const now = (d.getTime() + d.getTimezoneOffset()) / 1000; | |
127 | 57 | var a = new Date(UNIX_timestamp * 1000); |
58 | var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; | |
136 | 59 | var weekdays = ['Su', 'Mo', 'Tu', 'Wed', 'Th', 'Fr', 'Sa']; |
127 | 60 | var year = a.getFullYear(); |
61 | var month = months[a.getMonth()]; | |
62 | var date = a.getDate(); | |
63 | var hour = a.getHours(); | |
64 | var min = a.getMinutes(); | |
65 | var sec = a.getSeconds(); | |
136 | 66 | var time = ''; |
67 | ||
68 | if (date != d.getDate()) | |
69 | { | |
70 | if (UNIX_timestamp - 7 * 24 * 60 * 60 < now) | |
71 | time = weekdays[a.getDay()] + ' '; | |
72 | else | |
73 | time = '' + date + '.' + (a.getMonth() + 1) + '. '; | |
74 | } | |
75 | time += hour + ':' + (min < 10 ? '0' : '') + min; | |
127 | 76 | return time; |
77 | } | |
78 | ||
134 | 79 | function epoch() |
80 | { | |
81 | var d = new Date(); | |
82 | if (d.getHours() < 4) | |
83 | d.setDate(d.getDate() - 1); | |
84 | d.setHours(0); | |
85 | d.setMinutes(0); | |
86 | d.setSeconds(0); | |
87 | return Math.floor(d.getTime() / 1000); | |
88 | } | |
89 | ||
90 | function primarykey(data) | |
91 | { | |
92 | var key = data['blockref'] + '-'; | |
93 | key += (data['originaimeddeparturetime'] - epoch()).toString() + '-'; | |
94 | key += data['visitnumber']; | |
95 | return key; | |
96 | } | |
97 | ||
98 | function updateTime(key, time) | |
99 | { | |
127 | 100 | const d = new Date(); |
101 | const now = (d.getTime() + d.getTimezoneOffset()) / 1000; | |
134 | 102 | row = document.getElementById(key); |
103 | timeCell = document.getElementById(key + '-time'); | |
104 | t0 = parseInt(document.getElementById(key + '-stamp').innerHTML); | |
105 | if (Math.abs(time - t0) > 90) | |
106 | { | |
127 | 107 | oldTime = timeConverter(t0); |
108 | newTime = timeConverter(time); | |
109 | timeCell.innerHTML = '<s style="color:gray">' + oldTime + '</s> ⟶ <b>' + newTime + '</b>'; | |
110 | } | |
134 | 111 | |
127 | 112 | if (time + 15 > now) |
113 | row.classList.remove('gone'); | |
114 | else | |
115 | row.classList.add('gone'); | |
116 | } | |
117 | </script> | |
0 | 118 | </head> |
119 | <body> | |
93 | 120 | <table class='aikataulu service-{{service}}' cellspacing="0"> |
55
0f1d046b3f78
Suppeampi näkymä, pikatiet ja mootoritiet
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
121 | <thead> |
0 | 122 | <tr> |
55
0f1d046b3f78
Suppeampi näkymä, pikatiet ja mootoritiet
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
123 | <th colspan='4' class='primary-heading'> |
90 | 124 | <span><img src="../static/{{typename}}.png" height="96" /> {{name}}</span> |
55
0f1d046b3f78
Suppeampi näkymä, pikatiet ja mootoritiet
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
125 | </th> |
0f1d046b3f78
Suppeampi näkymä, pikatiet ja mootoritiet
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
126 | </tr> |
0f1d046b3f78
Suppeampi näkymä, pikatiet ja mootoritiet
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
127 | <tr class='headings'> |
20
3199e289ae62
- Sivusto hieman edustuksellisempi
Teemu Piippo <teemu@hecknology.net>
parents:
19
diff
changeset
|
128 | <th class='sarake-aika'>{{tr('time', 'headings')}}</th> |
3199e289ae62
- Sivusto hieman edustuksellisempi
Teemu Piippo <teemu@hecknology.net>
parents:
19
diff
changeset
|
129 | <th class='sarake-linja'>{{tr('route', 'headings')}}</th> |
3199e289ae62
- Sivusto hieman edustuksellisempi
Teemu Piippo <teemu@hecknology.net>
parents:
19
diff
changeset
|
130 | <th class='sarake-määränpää'>{{tr('destination', 'headings')}}</th> |
55
0f1d046b3f78
Suppeampi näkymä, pikatiet ja mootoritiet
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
131 | <th> |
0f1d046b3f78
Suppeampi näkymä, pikatiet ja mootoritiet
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
132 | <span class='actions'> |
0f1d046b3f78
Suppeampi näkymä, pikatiet ja mootoritiet
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
133 | <a class="pysäkki-sijainti" href="{{link_to_map}}" target="_blank">📌</a> |
0f1d046b3f78
Suppeampi näkymä, pikatiet ja mootoritiet
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
134 | {% if cluster %} |
0f1d046b3f78
Suppeampi näkymä, pikatiet ja mootoritiet
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
135 | <a href="../stop_cluster/{{cluster}}">🞊</a> |
0f1d046b3f78
Suppeampi näkymä, pikatiet ja mootoritiet
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
136 | {% endif %} |
109 | 137 | <a href='../stop_week/{{ref}}'>▤</a> |
55
0f1d046b3f78
Suppeampi näkymä, pikatiet ja mootoritiet
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
138 | </th> |
0 | 139 | </tr> |
55
0f1d046b3f78
Suppeampi näkymä, pikatiet ja mootoritiet
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
140 | </thead> |
127 | 141 | <tbody id='departures-table'> |
24
e6bdb9c54096
Yhtenäistetty ohjelmakoodin kieli englanniksi
Teemu Piippo <teemu@hecknology.net>
parents:
22
diff
changeset
|
142 | {% for halt in schedule %} |
127 | 143 | <tr class="{% if halt['night'] %} yö {% endif %}{% if halt['gone'] %}gone{% endif %}" id="{{halt['id']}}"> |
41 | 144 | <td class='sarake-aika'> |
127 | 145 | <!-- |
41 | 146 | {% if halt['imminent'] %} |
147 | <span class='imminent-leave'>●</span> | |
148 | {% endif %} | |
127 | 149 | --> |
150 | <span id="{{halt['id']}}-time"></span> | |
151 | <span class='dataentry' id="{{halt['id']}}-stamp">{{halt['timestamp']}}</span> | |
152 | <!--{{halt['time']}}--></td> | |
0 | 153 | <td class='sarake-linja linja'> |
77 | 154 | <a href="../trip/{{halt['trip']}}">{{route_rep(halt['route-splice'])}}</a> |
0 | 155 | </td> |
55
0f1d046b3f78
Suppeampi näkymä, pikatiet ja mootoritiet
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
156 | <td class='sarake-määränpää' colspan='2'> |
48
428cfdf64ccc
Lisätty uudelleenohjauksia
Teemu Piippo <teemu@hecknology.net>
parents:
41
diff
changeset
|
157 | <a href="../trip/{{halt['trip']}}">{{halt['sign']}}</a> |
0 | 158 | </td> |
159 | </tr> | |
160 | {% endfor %} | |
55
0f1d046b3f78
Suppeampi näkymä, pikatiet ja mootoritiet
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
161 | </tbody> |
0 | 162 | </table> |
127 | 163 | <script> |
164 | var list = document.getElementById('departures-table').children; | |
165 | for (var i = 0; i < list.length; i += 1) { | |
166 | id = list[i].id; | |
167 | timestamp = parseInt(document.getElementById(id + '-stamp').innerHTML); | |
168 | document.getElementById(id + '-time').innerHTML = timeConverter(timestamp); | |
169 | } | |
170 | //updateTime('fbf6f367-069c-4f8d-831b-bd36cd643f3b', 1544092500); | |
133 | 171 | getJSON('https://data.foli.fi/siri/sm/{{ref}}', function(data){ |
127 | 172 | var arrayLength = data['result'].length; |
173 | for (var i = 0; i < arrayLength; i++) { | |
174 | var blockref = data['result'][i]['blockref']; | |
175 | var originaimeddeparturetime = data['result'][i]['originaimeddeparturetime']; | |
176 | var expecteddeparturetime = data['result'][i]['expecteddeparturetime']; | |
134 | 177 | var key = primarykey(data['result'][i]); |
178 | updateTime(key, expecteddeparturetime); | |
127 | 179 | } |
180 | }); | |
181 | </script> | |
0 | 182 | </body> |
4 | 183 | </html> |