Commit 2afda728 authored by Volker Krause's avatar Volker Krause
Browse files

Implement parsing of Hafas disruption information for intermediate stops

The current weather situation is helping by producing extensive test data.
parent eb280f09
This diff is collapsed.
This diff is collapsed.
......@@ -133,6 +133,35 @@ private Q_SLOTS:
QVERIFY(!jsonRes.empty());
QCOMPARE(jsonRes, ref);
}
void testParseJourneys_data()
{
QTest::addColumn<QString>("inFileName");
QTest::addColumn<QString>("refFileName");
QTest::newRow("de-db-canceled-with-path")
<< s(SOURCE_DIR "/data/hafas/canceled-journey-with-path.in.json")
<< s(SOURCE_DIR "/data/hafas/canceled-journey-with-path.out.json");
}
void testParseJourneys()
{
QFETCH(QString, inFileName);
QFETCH(QString, refFileName);
HafasMgateParser p;
p.setLocationIdentifierTypes(QStringLiteral("unit-test"));
const auto res = p.parseJourneys(readFile(inFileName));
const auto jsonRes = Journey::toJson(res);
const auto ref = QJsonDocument::fromJson(readFile(refFileName)).array();
if (jsonRes != ref) {
qDebug().noquote() << QJsonDocument(jsonRes).toJson();
}
QVERIFY(!jsonRes.empty());
QCOMPARE(jsonRes, ref);
}
};
QTEST_GUILESS_MAIN(HafasMgateParserTest)
......
......@@ -506,7 +506,6 @@ std::vector<Journey> HafasMgateParser::parseTripSearch(const QJsonObject &obj) c
stops.reserve(stopL.size() - 2);
for (auto it = std::next(stopL.begin()); it != std::prev(stopL.end()); ++it) {
const auto stopObj = (*it).toObject();
// TODO how does this look for individual stop skips during disruptions?
Stopover stop;
const auto locIdx = stopObj.value(QLatin1String("locX")).toInt();
if ((unsigned int)locIdx < locs.size()) {
......@@ -518,6 +517,10 @@ std::vector<Journey> HafasMgateParser::parseTripSearch(const QJsonObject &obj) c
stop.setExpectedArrivalTime(parseDateTime(dateStr, stopObj.value(QLatin1String("aTimeR")), stopObj.value(QLatin1String("aTZOffset"))));
stop.setScheduledPlatform(stopObj.value(QLatin1String("dPlatfS")).toString());
stop.setExpectedPlatform(stopObj.value(QLatin1String("dPlatfR")).toString());
if (stopObj.value(QLatin1String("aCncl")).toBool() || stopObj.value(QLatin1String("dCncl")).toBool()) {
stop.setDisruptionEffect(Disruption::NoService);
}
parseMessageList(stop, stopObj, remarks, warnings);
stop.setLoadInformation(parseLoad(stopObj, loadInfos));
stops.push_back(stop);
}
......
......@@ -256,6 +256,7 @@ Stopover JourneySection::departure() const
dep.setScheduledPlatform(scheduledDeparturePlatform());
dep.setExpectedPlatform(expectedDeparturePlatform());
dep.addNotes(notes());
dep.setDisruptionEffect(disruptionEffect());
return dep;
}
......@@ -268,6 +269,7 @@ Stopover JourneySection::arrival() const
arr.setExpectedArrivalTime(expectedArrivalTime());
arr.setScheduledPlatform(scheduledArrivalPlatform());
arr.setExpectedPlatform(expectedArrivalPlatform());
arr.setDisruptionEffect(disruptionEffect());
return arr;
}
......
......@@ -74,6 +74,7 @@ Kirigami.Page {
Layout.fillWidth: true
clip: true
header: RowLayout {
enabled: journeySection.departure.disruptionEffect != Disruption.NoService
width: parent.width - 2 * Kirigami.Units.largeSpacing
x: Kirigami.Units.largeSpacing
Rectangle {
......@@ -108,10 +109,11 @@ Kirigami.Page {
delegate: Kirigami.AbstractListItem {
property var stop: modelData
enabled: stop.disruptionEffect != Disruption.NoService
highlighted: false
GridLayout {
columns: 5
rows: 2
rows: 3
Rectangle {
Layout.column: 0
Layout.row: 0
......@@ -216,10 +218,21 @@ Kirigami.Page {
text: stop.hasExpectedPlatform ? stop.expectedPlatform : stop.scheduledPlatform
color: stop.hasExpectedPlatform ? (stop.platformChanged ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.positiveTextColor) : Kirigami.Theme.textColor
}
QQC2.Label {
Layout.column: 0
Layout.row: 2
Layout.columnSpan: 4
text: stop.notes.join("<br/>")
textFormat: Text.RichText
visible: stop.notes.length > 0
font.italic: true
}
}
}
footer: RowLayout {
enabled: journeySection.arrival.disruptionEffect != Disruption.NoService
width: parent.width - 2 * Kirigami.Units.largeSpacing
x: Kirigami.Units.largeSpacing
Rectangle {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment