File indexing completed on 2024-12-29 04:51:06
0001 /* 0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 function parseSsbBarcode(ssb, node) 0008 { 0009 // vending machine bought and/or newer tickets claim version 2, but they aren't... 0010 if (ssb.version == 2) { 0011 let data = ssb.rawData.slice(0); 0012 let view = new Int8Array(data); 0013 view[0] = (view[0] & 0x0F) | 0x10; 0014 return ExtractorEngine.extract(data).result; 0015 } 0016 if (ssb.version != 1) { 0017 return; 0018 } 0019 var res = JsonLd.newTrainReservation(); 0020 if (ssb.trainNumber > 0) { 0021 res.reservationFor.trainNumber = ssb.trainNumber; 0022 } 0023 res.reservationFor.departureDay = ssb.firstDayOfValidity(node.contextDateTime); 0024 res.reservationFor.departureTime = ssb.departureTime(node.contextDateTime); 0025 res.reservationFor.departureStation.name = ssb.departureStationAlpha; 0026 res.reservationFor.arrivalStation.name = ssb.arrivalStationAlpha; 0027 // for station codes see: https://rata.digitraffic.fi/api/v1/metadata/stations 0028 res.reservationFor.departureStation.identifier = "vrfi:" + ssb.departureStationAlpha; 0029 res.reservationFor.arrivalStation.identifier = "vrfi:" + ssb.arrivalStationAlpha; 0030 res.reservationFor.provider.identifier = "uic:" + ssb.issuerCode; 0031 0032 res.reservedTicket.ticketToken = "aztecbin:" + ByteArray.toBase64(ssb.rawData); 0033 res.reservedTicket.ticketedSeat.seatingType = ssb.classOfTransport; 0034 0035 if (ssb.coachNumber > 0) { 0036 res.reservedTicket.ticketedSeat.seatSection = ssb.coachNumber; 0037 res.reservedTicket.ticketedSeat.seatNumber = ssb.seatNumber; 0038 } 0039 0040 res.reservationNumber = ssb.reservationReference + ""; 0041 return res; 0042 } 0043 0044 function parseTicket(pdf, node, trigger) { 0045 var res = trigger.result[0]; 0046 if (trigger.content.trainNumber == 0) 0047 return; // TODO this misses bus legs! 0048 0049 var text = pdf.pages[trigger.location].text; 0050 var trip = text.match("(.*) - (.*)\n.*(\\d{4}).*?(\\d{2}:\\d{2}).*?(\\d{2}:\\d{2})\n(.*?" + trigger.content.trainNumber + ")"); 0051 res.reservationFor.trainNumber = trip[6]; 0052 0053 res.reservationFor.departureTime = JsonLd.toDateTime(trip[4], "hh:mm", "en"); 0054 res.reservationFor.arrivalTime = JsonLd.toDateTime(trip[5], "hh:mm", "en"); 0055 res.reservationFor.departureStation.name = trip[1]; 0056 res.reservationFor.arrivalStation.name = trip[2]; 0057 return res; 0058 }