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 typeTextFor = (leg) => {
|
||||
let res = "(" + leg.line.trainType + ")";
|
||||
while (res.length < 12) {
|
||||
res = " " + res + " ";
|
||||
}
|
||||
return res;
|
||||
};
|
||||
const colorFor = (leg, type) => {
|
||||
let product = leg.line && leg.line.product || "walk";
|
||||
return colors[type][product] || colors[type].default;
|
||||
|
@ -107,6 +114,7 @@ const updateTextCache = () => {
|
|||
for (let journey of canvasState.journeys) {
|
||||
for (let leg of journey.legs) {
|
||||
addTextToCache(textFor(leg), colorFor(leg, "text"));
|
||||
if (leg.line.trainType) addTextToCache(typeTextFor(leg), "#555");
|
||||
|
||||
let times = [];
|
||||
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.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) {
|
||||
ctx.strokeStyle = '#cc4444ff';
|
||||
|
|
|
@ -3,6 +3,22 @@ import ../util
|
|||
import ./products
|
||||
import json
|
||||
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] =
|
||||
let l = common.lines[i]
|
||||
|
@ -26,6 +42,10 @@ proc parseLine*(common: CommonData, i: int): Option[Line] =
|
|||
|
||||
# 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):
|
||||
res.name = line.nameS.get
|
||||
|
||||
|
|
|
@ -88,6 +88,7 @@ type
|
|||
fullProductName*: string
|
||||
operator*: Option[Operator]
|
||||
additionalName*: Option[string]
|
||||
trainType*: Option[string]
|
||||
|
||||
Operator* = object
|
||||
id*: string
|
||||
|
|
Loading…
Reference in a new issue