add train type information
Thanks to derf for providing the train type information for Germany (https://lib.finalrewind.org/dbdb/)
This commit is contained in:
parent
1644fda532
commit
1c9fde6bfd
|
@ -11,6 +11,13 @@ const formatTime = (date) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const textFor = (leg) => leg.line && leg.line.name || "";
|
const textFor = (leg) => leg.line && leg.line.name || "";
|
||||||
|
const typeTextFor = (leg) => {
|
||||||
|
let res = "(" + leg.line.trainType + ")";
|
||||||
|
while (res.length < 12) {
|
||||||
|
res = " " + res + " ";
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
};
|
||||||
const colorFor = (leg, type) => {
|
const colorFor = (leg, type) => {
|
||||||
let product = leg.line && leg.line.product || "walk";
|
let product = leg.line && leg.line.product || "walk";
|
||||||
return colors[type][product] || colors[type].default;
|
return colors[type][product] || colors[type].default;
|
||||||
|
@ -107,6 +114,7 @@ const updateTextCache = () => {
|
||||||
for (let journey of canvasState.journeys) {
|
for (let journey of canvasState.journeys) {
|
||||||
for (let leg of journey.legs) {
|
for (let leg of journey.legs) {
|
||||||
addTextToCache(textFor(leg), colorFor(leg, "text"));
|
addTextToCache(textFor(leg), colorFor(leg, "text"));
|
||||||
|
if (leg.line.trainType) addTextToCache(typeTextFor(leg), "#555");
|
||||||
|
|
||||||
let times = [];
|
let times = [];
|
||||||
if (journey.legs.indexOf(leg) == 0) times.push(leg.departure);
|
if (journey.legs.indexOf(leg) == 0) times.push(leg.departure);
|
||||||
|
@ -215,6 +223,14 @@ const renderJourneys = () => {
|
||||||
ctx.drawImage(preRenderedText, dpr * (x + 5), Math.floor(dpr * (y + duration / 2) - preRenderedText.height / 2.3));
|
ctx.drawImage(preRenderedText, dpr * (x + 5), Math.floor(dpr * (y + duration / 2) - preRenderedText.height / 2.3));
|
||||||
ctx.scale(dpr, dpr);
|
ctx.scale(dpr, dpr);
|
||||||
}
|
}
|
||||||
|
if (leg.line.trainType) {
|
||||||
|
let preRenderedTypeText = textCache[typeTextFor(leg)];
|
||||||
|
if ((preRenderedTypeText.height / dpr + preRenderedText.height / dpr) < duration - 5) {
|
||||||
|
ctx.scale(1 / dpr, 1 / dpr);
|
||||||
|
ctx.drawImage(preRenderedTypeText, dpr * (x + 5), Math.floor(dpr * (y + duration / 2 + preRenderedText.height / 2 + 10) - preRenderedTypeText.height / 2.3));
|
||||||
|
ctx.scale(dpr, dpr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (leg.cancelled) {
|
if (leg.cancelled) {
|
||||||
ctx.strokeStyle = '#cc4444ff';
|
ctx.strokeStyle = '#cc4444ff';
|
||||||
|
|
|
@ -3,6 +3,22 @@ import ../util
|
||||||
import ./products
|
import ./products
|
||||||
import json
|
import json
|
||||||
import options
|
import options
|
||||||
|
import tables
|
||||||
|
import httpClient
|
||||||
|
import asyncdispatch
|
||||||
|
|
||||||
|
|
||||||
|
var trainTypes = initTable[string, string]()
|
||||||
|
|
||||||
|
proc fetchTrainTypes() {.async.} =
|
||||||
|
var client = newAsyncHttpClient()
|
||||||
|
let resp = await client.getContent("https://lib.finalrewind.org/dbdb/ice_type.json")
|
||||||
|
let data = parseJson(resp)
|
||||||
|
for key, info in pairs(data):
|
||||||
|
trainTypes[key] = info{"type"}.getStr
|
||||||
|
|
||||||
|
asyncCheck fetchTrainTypes()
|
||||||
|
|
||||||
|
|
||||||
proc parseLine*(common: CommonData, i: int): Option[Line] =
|
proc parseLine*(common: CommonData, i: int): Option[Line] =
|
||||||
let l = common.lines[i]
|
let l = common.lines[i]
|
||||||
|
@ -26,6 +42,10 @@ proc parseLine*(common: CommonData, i: int): Option[Line] =
|
||||||
|
|
||||||
# DB
|
# DB
|
||||||
|
|
||||||
|
if res.productName == "IC" or res.productName == "ICE" or res.productName == "EE" or res.productName == "ECE":
|
||||||
|
if trainTypes.contains(res.tripNum):
|
||||||
|
res.trainType = some(trainTypes[res.tripNum])
|
||||||
|
|
||||||
if line.nameS.isSome and (res.product == bus or res.product == tram or res.product == ferry):
|
if line.nameS.isSome and (res.product == bus or res.product == tram or res.product == ferry):
|
||||||
res.name = line.nameS.get
|
res.name = line.nameS.get
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,7 @@ type
|
||||||
fullProductName*: string
|
fullProductName*: string
|
||||||
operator*: Option[Operator]
|
operator*: Option[Operator]
|
||||||
additionalName*: Option[string]
|
additionalName*: Option[string]
|
||||||
|
trainType*: Option[string]
|
||||||
|
|
||||||
Operator* = object
|
Operator* = object
|
||||||
id*: string
|
id*: string
|
||||||
|
|
Loading…
Reference in a new issue