Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tesi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
Marco Aceti
Tesi
Commits
ee3ee660
Verified
Commit
ee3ee660
authored
2 years ago
by
Marco Aceti
Browse files
Options
Downloads
Patches
Plain Diff
Add delays chart in trajectories map
parent
11eaa446
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#2834
passed
2 years ago
Stage: test
Stage: lint
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/analysis/assets/templates/stats_chart.html
+32
-12
32 additions, 12 deletions
src/analysis/assets/templates/stats_chart.html
src/analysis/trajectories_map.py
+35
-21
35 additions, 21 deletions
src/analysis/trajectories_map.py
with
67 additions
and
33 deletions
src/analysis/assets/templates/
train_coun
t.html
→
src/analysis/assets/templates/
stats_char
t.html
+
32
−
12
View file @
ee3ee660
...
...
@@ -48,9 +48,11 @@
return
currentTime
;
}
const
data
=
{{
this
.
get_data
()
}};
const
startTime
=
moment
(
data
[
0
][
'
x
'
]);
const
endTime
=
moment
(
data
[
data
.
length
-
1
][
'
x
'
]);
const
train_count_data
=
{{
this
.
get_train_count_data
()
}};
const
delays_data
=
{{
this
.
get_delays_data
()
}};
const
startTime
=
moment
(
train_count_data
[
0
][
'
x
'
]);
const
endTime
=
moment
(
train_count_data
[
train_count_data
.
length
-
1
][
'
x
'
]);
const
timeHighlighter
=
{
id
:
'
timeHighlighter
'
,
...
...
@@ -73,10 +75,18 @@
let
chart
=
new
Chart
(
ctx
,
{
type
:
'
line
'
,
data
:
{
datasets
:
[{
data
:
data
,
label
:
"
Circulating train count
"
,
}],
datasets
:
[
{
data
:
train_count_data
,
label
:
"
Circulating train count
"
,
yAxisID
:
'
y
'
,
},
{
data
:
delays_data
,
label
:
"
Mean delay
"
,
yAxisID
:
'
y1
'
,
}
],
},
options
:
{
scales
:
{
...
...
@@ -90,6 +100,20 @@
isoWeekday
:
true
,
}
},
y
:
{
display
:
true
,
type
:
'
linear
'
,
position
:
'
left
'
,
},
y1
:
{
display
:
true
,
type
:
'
linear
'
,
position
:
'
right
'
,
title
:
{
display
:
true
,
text
:
"
Minutes
"
}
}
},
elements
:
{
point
:
{
...
...
@@ -98,12 +122,8 @@
}
},
plugins
:
{
title
:
{
display
:
true
,
text
:
"
Circulating train count
"
,
},
legend
:
{
display
:
fals
e
,
display
:
tru
e
,
}
},
},
...
...
This diff is collapsed.
Click to expand it.
src/analysis/trajectories_map.py
+
35
−
21
View file @
ee3ee660
...
...
@@ -229,7 +229,7 @@ def train_stop_geojson(st: pd.DataFrame, train: pd.DataFrame) -> list[dict]:
return
ret
class
TrainCount
Chart
(
MacroElement
):
class
Stats
Chart
(
MacroElement
):
"""
Helper class to compute and embed the train count chart.
"""
def
__init__
(
self
,
df
:
pd
.
DataFrame
,
*
args
,
**
kwargs
):
...
...
@@ -239,34 +239,48 @@ class TrainCountChart(MacroElement):
df (pd.DataFrame): the train stop data
"""
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
df
=
df
def
get_data
(
self
)
->
list
[
dict
[
str
,
str
|
int
]]:
"""
Utility function used by the template to get the computed data,
in a JS-likable format.
"""
trains
=
self
.
df
.
groupby
(
"
train_hash
"
)
trains_n
=
pd
.
DataFrame
(
index
=
self
.
df
.
train_hash
.
unique
())
trains_n
[
"
departure
"
]
=
trains
.
first
()[
"
departure_actual
"
].
fillna
(
# Prepare dataset
trains
=
df
.
groupby
(
"
train_hash
"
)
self
.
data
=
pd
.
DataFrame
(
index
=
df
.
train_hash
.
unique
())
self
.
data
[
"
departure
"
]
=
trains
.
first
()[
"
departure_actual
"
].
fillna
(
trains
.
first
()[
"
departure_expected
"
]
)
trains_n
[
"
arrival
"
]
=
trains
.
last
()[
"
arrival_actual
"
].
fillna
(
self
.
data
[
"
arrival
"
]
=
trains
.
last
()[
"
arrival_actual
"
].
fillna
(
trains
.
first
()[
"
arrival_expected
"
]
)
self
.
data
[
"
delay
"
]
=
trains
.
mean
(
numeric_only
=
True
)[
"
departure_delay
"
].
fillna
(
trains
.
mean
(
numeric_only
=
True
)[
"
arrival_delay
"
]
)
js_dataset
:
list
[
dict
[
str
,
str
|
int
]]
=
[]
for
time
in
fill_time
(
trains_n
.
departure
.
min
(),
trains_n
.
arrival
.
max
()):
js_dataset
.
append
(
def
get_train_count_data
(
self
)
->
list
[
dict
[
str
,
str
|
int
]]:
"""
Return circulating train count in a JS-likable format.
"""
ret
:
list
[
dict
[
str
,
str
|
int
]]
=
[]
for
time
in
fill_time
(
self
.
data
.
departure
.
min
(),
self
.
data
.
arrival
.
max
()):
subset
:
pd
.
DataFrame
=
self
.
data
.
loc
[
(
time
>=
self
.
data
.
departure
)
&
(
time
<=
self
.
data
.
arrival
)
]
ret
.
append
(
{
"
x
"
:
time
.
isoformat
(),
"
y
"
:
len
(
subset
),
}
)
return
ret
def
get_delays_data
(
self
)
->
list
[
dict
[
str
,
str
|
float
]]:
ret
:
list
[
dict
[
str
,
str
|
float
]]
=
[]
for
time
in
fill_time
(
self
.
data
.
departure
.
min
(),
self
.
data
.
arrival
.
max
()):
subset
:
pd
.
DataFrame
=
self
.
data
.
loc
[
(
time
>=
self
.
data
.
departure
)
&
(
time
<=
self
.
data
.
arrival
)
]
ret
.
append
(
{
"
x
"
:
time
.
isoformat
(),
"
y
"
:
len
(
trains_n
.
loc
[
(
time
>=
trains_n
.
departure
)
&
(
time
<=
trains_n
.
arrival
)
]
),
"
y
"
:
subset
.
delay
.
mean
()
if
len
(
subset
)
>
20
else
"
NaN
"
,
}
)
return
js_datas
et
return
r
et
class
MarkerLegend
(
MacroElement
):
...
...
@@ -325,8 +339,8 @@ def build_map(st: pd.DataFrame, df: pd.DataFrame) -> None:
m
.
get_root
().
add_child
(
legend
)
# Add train count chart
macro
=
TrainCount
Chart
(
df
)
with
open
(
ASSETS_PATH
/
"
templates
"
/
"
train_coun
t.html
"
,
"
r
"
)
as
f
:
macro
=
Stats
Chart
(
df
)
with
open
(
ASSETS_PATH
/
"
templates
"
/
"
stats_char
t.html
"
,
"
r
"
)
as
f
:
macro
.
_template
=
Template
(
"
\n
"
.
join
(
f
.
readlines
()))
m
.
get_root
().
add_child
(
macro
)
...
...
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