Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Libraries
KPublicTransport
Commits
d8e4678c
Commit
d8e4678c
authored
Feb 27, 2021
by
Volker Krause
Browse files
Correctly parse times when no realtime data is present
parent
e4e84e78
Changes
5
Hide whitespace changes
Inline
Side-by-side
autotests/data/ivvass/journey-long-distance-vrs-input.json
0 → 100644
View file @
d8e4678c
{
"routes"
:[{
"id"
:
"XXX"
,
"segments"
:[{
"type"
:
"walk"
,
"origin"
:{
"type"
:
"coordinate"
,
"x"
:
50.943
,
"y"
:
6.95857
},
"destination"
:{
"id"
:
8
,
"tempId"
:
69196
,
"name"
:
"K
\u
00f6ln Hbf (Gleis 7)"
,
"district"
:
""
,
"city"
:
"K
\u
00f6ln"
,
"x"
:
50.94297
,
"y"
:
6.95857
,
"subtype"
:
"Post"
,
"ifopt"
:
"de:05315:11201:7:77"
,
"fullName"
:
"K
\u
00f6ln Hbf (Gleis 7), K
\u
00f6ln"
,
"type"
:
"stop"
},
"departure"
:
"2021-02-27T12:52:30+01:00"
,
"arrival"
:
"2021-02-27T12:53:00+01:00"
,
"traveltime"
:
30
,
"distance"
:
3
,
"polygon"
:
"50.943000,6.958570 50.942972,6.958574"
},{
"type"
:
"publicTransport"
,
"origin"
:{
"id"
:
8
,
"tempId"
:
69196
,
"name"
:
"K
\u
00f6ln Hbf (Gleis 7)"
,
"district"
:
""
,
"city"
:
"K
\u
00f6ln"
,
"x"
:
50.94297
,
"y"
:
6.95857
,
"subtype"
:
"Post"
,
"ifopt"
:
"de:05315:11201:7:77"
,
"fullName"
:
"K
\u
00f6ln Hbf (Gleis 7), K
\u
00f6ln"
,
"type"
:
"stop"
},
"destination"
:{
"id"
:
687
,
"tempId"
:
70506
,
"name"
:
"Bonn Hbf (Gleis 3)"
,
"district"
:
""
,
"city"
:
"Bonn"
,
"x"
:
50.732
,
"y"
:
7.0968
,
"subtype"
:
"Post"
,
"ifopt"
:
"de:05314:61101:7:73"
,
"fullName"
:
"Bonn Hbf (Gleis 3), Bonn"
,
"type"
:
"stop"
},
"departure"
:
"2021-02-27T12:53:00+01:00"
,
"arrival"
:
"2021-02-27T13:12:00+01:00"
,
"traveltime"
:
1140
,
"distance"
:
33759
,
"line"
:{
"number"
:
"IC"
,
"product"
:
"LongDistanceTrains"
,
"direction"
:
"Stuttgart Hbf"
,
"ifopt"
:
"de:vrs:1287"
},
"reference"
:
"230f6346463ebdea5a3818c25d63fd51"
,
"polygon"
:
"50.942972,6.958574 50.943056,6.958469 50.733818,7.091520 50.732003,7.096796"
,
"vias"
:[],
"infos"
:[{
"text"
:
"Fahrradmitnahme begrenzt m
\u
00f6glich"
}]},{
"type"
:
"walk"
,
"origin"
:{
"id"
:
687
,
"tempId"
:
70506
,
"name"
:
"Bonn Hbf (Gleis 3)"
,
"district"
:
""
,
"city"
:
"Bonn"
,
"x"
:
50.732
,
"y"
:
7.0968
,
"subtype"
:
"Post"
,
"ifopt"
:
"de:05314:61101:7:73"
,
"fullName"
:
"Bonn Hbf (Gleis 3), Bonn"
,
"type"
:
"stop"
},
"destination"
:{
"type"
:
"coordinate"
,
"x"
:
50.732
,
"
y"
:
7.09692
},
"departure"
:
"2021-02-27T13:12:00+01:00"
,
"arrival"
:
"2021-02-27T13:12:30+01:00"
,
"traveltime"
:
30
,
"distance"
:
9
,
"polygon"
:
"50.732003,7.096796 50.732000,7.096920"
}],
"changes"
:
0
,
"costs"
:{
"text"
:
"Keine Tarif-Informationen vorhanden."
}}],
"containsDemand"
:
false
}
autotests/data/ivvass/journey-long-distance-vrs-output.json
0 → 100644
View file @
d8e4678c
[
{
"sections"
:
[
{
"disruptionEffect"
:
"NormalService"
,
"distance"
:
3
,
"from"
:
{
"latitude"
:
50.94300079345703
,
"longitude"
:
6.9585700035095215
},
"mode"
:
"Walking"
,
"path"
:
{
"sections"
:
[
{
"path"
:
{
"coordinates"
:
[
[
50.943
,
6.95857
],
[
50.942972
,
6.958574
]
],
"type"
:
"LineString"
}
}
]
},
"scheduledArrivalTime"
:
"2021-02-27T12:53:00+01:00"
,
"scheduledDepartureTime"
:
"2021-02-27T12:52:30+01:00"
,
"to"
:
{
"identifier"
:
{
"ifopt"
:
"de:05315:11201:7:77"
},
"latitude"
:
50.942970275878906
,
"locality"
:
"Köln"
,
"longitude"
:
6.9585700035095215
,
"name"
:
"Köln Hbf (Gleis 7)"
,
"type"
:
"Stop"
}
},
{
"disruptionEffect"
:
"NormalService"
,
"distance"
:
33759
,
"from"
:
{
"identifier"
:
{
"ifopt"
:
"de:05315:11201:7:77"
},
"latitude"
:
50.942970275878906
,
"locality"
:
"Köln"
,
"longitude"
:
6.9585700035095215
,
"name"
:
"Köln Hbf (Gleis 7)"
,
"type"
:
"Stop"
},
"mode"
:
"PublicTransport"
,
"notes"
:
[
"Fahrradmitnahme begrenzt möglich"
],
"path"
:
{
"sections"
:
[
{
"path"
:
{
"coordinates"
:
[
[
50.942972
,
6.958574
],
[
50.943056
,
6.958469
],
[
50.733818
,
7.09152
],
[
50.732003
,
7.096796
]
],
"type"
:
"LineString"
}
}
]
},
"route"
:
{
"direction"
:
"Stuttgart Hbf"
,
"line"
:
{
"mode"
:
"LongDistanceTrain"
,
"name"
:
"IC"
}
},
"scheduledArrivalTime"
:
"2021-02-27T13:12:00+01:00"
,
"scheduledDepartureTime"
:
"2021-02-27T12:53:00+01:00"
,
"to"
:
{
"identifier"
:
{
"ifopt"
:
"de:05314:61101:7:73"
},
"latitude"
:
50.731998443603516
,
"locality"
:
"Bonn"
,
"longitude"
:
7.096799850463867
,
"name"
:
"Bonn Hbf (Gleis 3)"
,
"type"
:
"Stop"
}
},
{
"disruptionEffect"
:
"NormalService"
,
"distance"
:
9
,
"from"
:
{
"identifier"
:
{
"ifopt"
:
"de:05314:61101:7:73"
},
"latitude"
:
50.731998443603516
,
"locality"
:
"Bonn"
,
"longitude"
:
7.096799850463867
,
"name"
:
"Bonn Hbf (Gleis 3)"
,
"type"
:
"Stop"
},
"mode"
:
"Walking"
,
"path"
:
{
"sections"
:
[
{
"path"
:
{
"coordinates"
:
[
[
50.732003
,
7.096796
],
[
50.732
,
7.09692
]
],
"type"
:
"LineString"
}
}
]
},
"scheduledArrivalTime"
:
"2021-02-27T13:12:30+01:00"
,
"scheduledDepartureTime"
:
"2021-02-27T13:12:00+01:00"
,
"to"
:
{
"latitude"
:
50.731998443603516
}
}
]
}
]
autotests/data/ivvass/journey-vrs-output.json
View file @
d8e4678c
...
...
@@ -4,8 +4,6 @@
{
"disruptionEffect"
:
"NormalService"
,
"distance"
:
3
,
"expectedArrivalTime"
:
"2021-02-26T17:14:00+01:00"
,
"expectedDepartureTime"
:
"2021-02-26T17:13:30+01:00"
,
"from"
:
{
"latitude"
:
50.94300079345703
,
"longitude"
:
6.9585700035095215
...
...
@@ -30,6 +28,8 @@
}
]
},
"scheduledArrivalTime"
:
"2021-02-26T17:14:00+01:00"
,
"scheduledDepartureTime"
:
"2021-02-26T17:13:30+01:00"
,
"to"
:
{
"identifier"
:
{
"ifopt"
:
"de:05315:11201:7:76"
...
...
@@ -103,13 +103,13 @@
},
{
"disruptionEffect"
:
"NormalService"
,
"expectedArrivalTime"
:
"2021-02-26T17:25:00+01:00"
,
"expectedDepartureTime"
:
"2021-02-26T17:26:00+01:00"
,
"load"
:
[
{
"load"
:
"Medium"
}
],
"scheduledArrivalTime"
:
"2021-02-26T17:25:00+01:00"
,
"scheduledDepartureTime"
:
"2021-02-26T17:20:00+01:00"
,
"stopPoint"
:
{
"identifier"
:
{
...
...
@@ -195,7 +195,9 @@
}
],
"mode"
:
"PublicTransport"
,
"notes"
:
[
"Fahrradmitnahme begrenzt möglich"
],
"notes"
:
[
"Fahrradmitnahme begrenzt möglich"
],
"path"
:
{
"sections"
:
[
{
...
...
@@ -250,8 +252,6 @@
{
"disruptionEffect"
:
"NormalService"
,
"distance"
:
16
,
"expectedArrivalTime"
:
"2021-02-26T17:50:30+01:00"
,
"expectedDepartureTime"
:
"2021-02-26T17:50:00+01:00"
,
"from"
:
{
"identifier"
:
{
"ifopt"
:
"de:05314:61101:7:74"
...
...
@@ -282,6 +282,8 @@
}
]
},
"scheduledArrivalTime"
:
"2021-02-26T17:50:30+01:00"
,
"scheduledDepartureTime"
:
"2021-02-26T17:50:00+01:00"
,
"to"
:
{
"latitude"
:
50.731998443603516
,
"longitude"
:
7.096920013427734
...
...
autotests/ivvassparsertest.cpp
View file @
d8e4678c
...
...
@@ -100,6 +100,9 @@ private Q_SLOTS:
QTest
::
newRow
(
"journey-vrs"
)
<<
s
(
SOURCE_DIR
"/data/ivvass/journey-vrs-input.json"
)
<<
s
(
SOURCE_DIR
"/data/ivvass/journey-vrs-output.json"
);
QTest
::
newRow
(
"journey-long-distance-vrs"
)
<<
s
(
SOURCE_DIR
"/data/ivvass/journey-long-distance-vrs-input.json"
)
<<
s
(
SOURCE_DIR
"/data/ivvass/journey-long-distance-vrs-output.json"
);
}
void
testParseJourneys
()
...
...
src/lib/backends/ivvassparser.cpp
View file @
d8e4678c
...
...
@@ -147,6 +147,22 @@ static Route parseRoute(const QJsonObject &lineObj)
return
route
;
}
struct
EventTime
{
QDateTime
scheduled
;
QDateTime
expected
;
};
static
EventTime
parseTime
(
const
QJsonObject
&
obj
,
const
char
*
baseKey
,
const
char
*
scheduledKey
)
{
EventTime
t
;
t
.
scheduled
=
QDateTime
::
fromString
(
obj
.
value
(
QLatin1String
(
scheduledKey
)).
toString
(),
Qt
::
ISODate
);
t
.
expected
=
QDateTime
::
fromString
(
obj
.
value
(
QLatin1String
(
baseKey
)).
toString
(),
Qt
::
ISODate
);
if
(
!
t
.
scheduled
.
isValid
()
&&
t
.
expected
.
isValid
())
{
std
::
swap
(
t
.
scheduled
,
t
.
expected
);
}
return
t
;
}
std
::
vector
<
Stopover
>
IvvAssParser
::
parseStopovers
(
const
QByteArray
&
data
)
{
const
auto
top
=
QJsonDocument
::
fromJson
(
data
).
object
();
...
...
@@ -168,8 +184,9 @@ std::vector<Stopover> IvvAssParser::parseStopovers(const QByteArray &data)
Stopover
s
;
s
.
setStopPoint
(
stop
);
s
.
setScheduledDepartureTime
(
QDateTime
::
fromString
(
eventObj
.
value
(
QLatin1String
(
"departureScheduled"
)).
toString
(),
Qt
::
ISODate
));
s
.
setExpectedDepartureTime
(
QDateTime
::
fromString
(
eventObj
.
value
(
QLatin1String
(
"departure"
)).
toString
(),
Qt
::
ISODate
));
const
auto
t
=
parseTime
(
eventObj
,
"departure"
,
"departureScheduled"
);
s
.
setScheduledDepartureTime
(
t
.
scheduled
);
s
.
setExpectedDepartureTime
(
t
.
expected
);
const
auto
lineObj
=
eventObj
.
value
(
QLatin1String
(
"line"
)).
toObject
();
s
.
setRoute
(
parseRoute
(
lineObj
));
...
...
@@ -225,10 +242,12 @@ std::vector<Journey> IvvAssParser::parseJourneys(const QByteArray &data)
s
.
setFrom
(
parseLocation
(
segmentObj
.
value
(
QLatin1String
(
"origin"
)).
toObject
()));
s
.
setTo
(
parseLocation
(
segmentObj
.
value
(
QLatin1String
(
"destination"
)).
toObject
()));
s
.
setScheduledDepartureTime
(
QDateTime
::
fromString
(
segmentObj
.
value
(
QLatin1String
(
"departureScheduled"
)).
toString
(),
Qt
::
ISODate
));
s
.
setExpectedDepartureTime
(
QDateTime
::
fromString
(
segmentObj
.
value
(
QLatin1String
(
"departure"
)).
toString
(),
Qt
::
ISODate
));
s
.
setScheduledArrivalTime
(
QDateTime
::
fromString
(
segmentObj
.
value
(
QLatin1String
(
"arrivalScheduled"
)).
toString
(),
Qt
::
ISODate
));
s
.
setExpectedArrivalTime
(
QDateTime
::
fromString
(
segmentObj
.
value
(
QLatin1String
(
"arrival"
)).
toString
(),
Qt
::
ISODate
));
const
auto
dt
=
parseTime
(
segmentObj
,
"departure"
,
"departureScheduled"
);
s
.
setScheduledDepartureTime
(
dt
.
scheduled
);
s
.
setExpectedDepartureTime
(
dt
.
expected
);
const
auto
at
=
parseTime
(
segmentObj
,
"arrival"
,
"arrivalScheduled"
);
s
.
setScheduledArrivalTime
(
at
.
scheduled
);
s
.
setExpectedArrivalTime
(
at
.
expected
);
const
auto
type
=
segmentObj
.
value
(
QLatin1String
(
"type"
)).
toString
();
// TODO "publicTransport"
...
...
@@ -246,10 +265,13 @@ std::vector<Journey> IvvAssParser::parseJourneys(const QByteArray &data)
const
auto
viaObj
=
viaV
.
toObject
();
Stopover
stop
;
stop
.
setStopPoint
(
parseLocation
(
viaObj
));
stop
.
setScheduledDepartureTime
(
QDateTime
::
fromString
(
viaObj
.
value
(
QLatin1String
(
"departureScheduled"
)).
toString
(),
Qt
::
ISODate
));
stop
.
setExpectedDepartureTime
(
QDateTime
::
fromString
(
viaObj
.
value
(
QLatin1String
(
"departure"
)).
toString
(),
Qt
::
ISODate
));
stop
.
setScheduledArrivalTime
(
QDateTime
::
fromString
(
viaObj
.
value
(
QLatin1String
(
"arrivalScheduled"
)).
toString
(),
Qt
::
ISODate
));
stop
.
setExpectedArrivalTime
(
QDateTime
::
fromString
(
viaObj
.
value
(
QLatin1String
(
"arrival"
)).
toString
(),
Qt
::
ISODate
));
const
auto
dt
=
parseTime
(
viaObj
,
"departure"
,
"departureScheduled"
);
stop
.
setScheduledDepartureTime
(
dt
.
scheduled
);
stop
.
setExpectedDepartureTime
(
dt
.
expected
);
const
auto
at
=
parseTime
(
viaObj
,
"arrival"
,
"arrivalScheduled"
);
stop
.
setScheduledArrivalTime
(
at
.
scheduled
);
stop
.
setExpectedArrivalTime
(
at
.
expected
);
const
auto
demand
=
viaObj
.
value
(
QLatin1String
(
"demandEstimated"
));
stop
.
setLoadInformation
(
parseDemand
(
demand
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment