Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Infoscreen
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Evy Storozhenko
Infoscreen
Commits
e4562acd
Commit
e4562acd
authored
1 year ago
by
Niklas Schrötler
Browse files
Options
Downloads
Patches
Plain Diff
FahrplanPanel: Implemented grouping stops of the same tour
Also cleaned up superfluous code
parent
821183f4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/panels/Fahrplan/FahrplanPanel.tsx
+21
-38
21 additions, 38 deletions
src/panels/Fahrplan/FahrplanPanel.tsx
with
21 additions
and
38 deletions
src/panels/Fahrplan/FahrplanPanel.tsx
+
21
−
38
View file @
e4562acd
...
@@ -21,8 +21,10 @@ type Route = {
...
@@ -21,8 +21,10 @@ type Route = {
stops
:
{
stops
:
{
name
:
string
,
name
:
string
,
arrival
:
Date
,
arrival
:
Date
,
delay
?:
number
delay
?:
number
,
}[]
countdown
:
number
}[],
countdown
:
number
}
}
const
FahrplanPanel
=
(
props
:
{
definition
:
FahrplanPanelDefinition
})
=>
{
const
FahrplanPanel
=
(
props
:
{
definition
:
FahrplanPanelDefinition
})
=>
{
...
@@ -44,12 +46,11 @@ const FahrplanPanel = (props: {definition: FahrplanPanelDefinition}) => {
...
@@ -44,12 +46,11 @@ const FahrplanPanel = (props: {definition: FahrplanPanelDefinition}) => {
}
}
// Find existing route with same uid
// Find existing route with same uid
const
existing_ind
=
newRoutes
.
findIndex
(
r
=>
r
.
uid
===
departure
.
lineref
.
identifier
)
const
existing_ind
=
newRoutes
.
findIndex
(
r
=>
r
.
uid
===
departure
.
key
)
// Pre-compute values that will be needed regardless
// Pre-compute values that will be needed regardless
const
delay
=
stringToDelay
(
departure
.
delay
);
const
delay
=
stringToDelay
(
departure
.
delay
);
const
arrival
=
processArrival
(
departure
.
sched_date
,
departure
.
time
);
const
arrival
=
processArrival
(
departure
.
sched_date
,
departure
.
time
);
console
.
log
(
arrival
)
if
(
existing_ind
===
-
1
)
{
if
(
existing_ind
===
-
1
)
{
// If it does not exist, create a new route
// If it does not exist, create a new route
...
@@ -61,21 +62,27 @@ const FahrplanPanel = (props: {definition: FahrplanPanelDefinition}) => {
...
@@ -61,21 +62,27 @@ const FahrplanPanel = (props: {definition: FahrplanPanelDefinition}) => {
{
{
name
:
departure
.
internal
.
stop
,
name
:
departure
.
internal
.
stop
,
arrival
,
arrival
,
delay
delay
,
countdown
:
parseInt
(
departure
.
countdown
)
}
}
]
],
countdown
:
parseInt
(
departure
.
countdown
)
})
})
}
else
{
}
else
{
// If it doesn't, just add a stop to the existing route
// If it doesn't, just add a stop to the existing route
newRoutes
[
existing_ind
].
stops
.
push
({
newRoutes
[
existing_ind
].
stops
.
push
({
name
:
departure
.
internal
.
stop
,
name
:
departure
.
internal
.
stop
,
arrival
,
arrival
,
delay
:
stringToDelay
(
departure
.
delay
)
delay
:
stringToDelay
(
departure
.
delay
),
countdown
:
parseInt
(
departure
.
countdown
)
})
})
newRoutes
[
existing_ind
].
stops
=
newRoutes
[
existing_ind
].
stops
.
sort
((
a
,
b
)
=>
a
.
countdown
-
b
.
countdown
)
}
}
}
}
// Sort the output
// Sort the output
newRoutes
=
newRoutes
.
sort
((
a
,
b
)
=>
a
.
countdown
-
b
.
countdown
)
// Write to the display
// Write to the display
setRoutes
(
newRoutes
);
setRoutes
(
newRoutes
);
...
@@ -150,42 +157,18 @@ async function getStopData(stop: string): Promise<StationResponse> {
...
@@ -150,42 +157,18 @@ async function getStopData(stop: string): Promise<StationResponse> {
}
}
function
stringToDelay
(
input
:
string
):
number
|
undefined
{
function
stringToDelay
(
input
:
string
):
number
|
undefined
{
try
{
const
delay
=
parseInt
(
input
);
const
delay
=
parseInt
(
input
);
if
(
delay
===
0
)
{
if
(
delay
===
0
)
{
return
undefined
;
return
undefined
;
}
}
if
(
delay
===
Number
.
NaN
)
{
return
delay
;
console
.
warn
(
"
While parsing delay, the string was not interpretable as number
"
,
input
);
}
catch
(
e
)
{
console
.
warn
(
"
While parsing delay, the string was not interpretable
"
,
input
);
return
undefined
;
return
undefined
;
}
}
return
delay
;
}
}
function
processArrival
(
date
:
string
,
time
:
string
):
Date
{
function
processArrival
(
date
:
string
,
time
:
string
):
Date
{
const
d_parts
=
date
.
split
(
"
.
"
);
const
d_parts
=
date
.
split
(
"
.
"
);
console
.
log
(
date
,
time
,
"
to
"
,
`
${
d_parts
[
2
]}
-
${
d_parts
[
1
]}
-
${
d_parts
[
0
]}
${
time
}
`
);
return
new
Date
(
`
${
d_parts
[
2
]}
-
${
d_parts
[
1
]}
-
${
d_parts
[
0
]}
${
time
}
`
);
return
new
Date
(
`
${
d_parts
[
2
]}
-
${
d_parts
[
1
]}
-
${
d_parts
[
0
]}
${
time
}
`
);
}
}
// function sortData(data: any) {
// for (var i = 0; i < data.length; ++i) {
// data[i]['stops'] = data[i]['stops'].sort(sortFn);
// data[i]['timeValue'] = data[i]['stops'][0]['timeValue'];
// }
// return data.sort(sortFn);
// }
//
// function sortFn(a: any, b: any) {
// return a['timeValue'] - b['timeValue'];
// }
//
// function calcDateValue(_year: string, _month: string, _day: string, _hour: string, _minute: string): number {
// const year = parseInt(_year) * 12 * 31 * 24 * 60;
// const month = parseInt(_month) * 31 * 24 * 60;
// const day = parseInt(_day) * 24 * 60;
// const hour = parseInt(_hour) * 60;
// const minute = parseInt(_minute);
// return year+month+day+hour+minute;
// }
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment