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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marco Aceti
Tesi
Commits
d37a67ed
Verified
Commit
d37a67ed
authored
May 23, 2023
by
Marco Aceti
Browse files
Options
Downloads
Patches
Plain Diff
Add detect_lines stat
parent
7181227f
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#2894
passed
May 23, 2023
Stage: test
Stage: lint
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
requirements.txt
+1
-0
1 addition, 0 deletions
requirements.txt
src/analysis/main.py
+6
-2
6 additions, 2 deletions
src/analysis/main.py
src/analysis/stat.py
+43
-0
43 additions, 0 deletions
src/analysis/stat.py
with
50 additions
and
2 deletions
requirements.txt
+
1
−
0
View file @
d37a67ed
...
...
@@ -14,3 +14,4 @@ joblib==1.2.0
timple
==0.1.5
colour
==0.1.5
branca
==0.6.0
itables
==1.5.2
This diff is collapsed.
Click to expand it.
src/analysis/main.py
+
6
−
2
View file @
d37a67ed
...
...
@@ -74,6 +74,7 @@ def register_args(parser: argparse.ArgumentParser):
"
delay_boxplot
"
,
"
day_train_count
"
,
"
trajectories_map
"
,
"
detect_lines
"
,
),
default
=
"
describe
"
,
)
...
...
@@ -130,7 +131,7 @@ def main(args: argparse.Namespace):
logging
.
info
(
f
"
Loaded
{
len
(
df
)
}
data points (
{
original_length
}
before filtering)
"
)
# Tag lines
tag_lines
(
df
,
stations
)
df
=
tag_lines
(
df
,
stations
)
# Prepare graphics
stat
.
prepare_mpl
(
df
,
args
)
...
...
@@ -163,5 +164,8 @@ def main(args: argparse.Namespace):
elif
args
.
stat
==
"
trajectories_map
"
:
if
not
isinstance
(
df
,
pd
.
DataFrame
):
raise
ValueError
(
"
can
'
t use trajectories_map with unaggregated data
"
)
trajectories_map
.
build_map
(
stations
,
df
)
elif
args
.
stat
==
"
detect_lines
"
:
if
not
isinstance
(
df
,
pd
.
DataFrame
):
raise
ValueError
(
"
can
'
t use detect_lines with unaggregated data
"
)
stat
.
detect_lines
(
df
,
stations
)
This diff is collapsed.
Click to expand it.
src/analysis/stat.py
+
43
−
0
View file @
d37a67ed
...
...
@@ -16,11 +16,14 @@
import
argparse
import
webbrowser
from
tempfile
import
NamedTemporaryFile
import
matplotlib
as
mpl
import
matplotlib.pyplot
as
plt
import
pandas
as
pd
import
seaborn
as
sns
from
itables
import
to_html_datatable
from
pandas.core.groupby.generic
import
DataFrameGroupBy
from
src.const
import
RAILWAY_COMPANIES_PALETTE
,
WEEKDAYS
...
...
@@ -145,3 +148,43 @@ def day_train_count(df: pd.DataFrame | DataFrameGroupBy) -> None:
ax
.
set
(
xlabel
=
"
Day
"
,
ylabel
=
"
Train count
"
)
plt
.
show
()
def
detect_lines
(
df
:
pd
.
DataFrame
,
st
:
pd
.
DataFrame
)
->
None
:
"""
Show a interactive table with the detected (by tag_lines) railway lines
"""
st_names
:
pd
.
DataFrame
=
st
.
drop
(
[
"
region
"
,
"
latitude
"
,
"
longitude
"
,
"
short_name
"
],
axis
=
1
,
)
lines
:
pd
.
DataFrame
=
(
(
df
.
join
(
st_names
,
on
=
"
origin
"
)
.
rename
({
"
long_name
"
:
"
station_a
"
},
axis
=
1
)
.
join
(
st_names
,
on
=
"
destination
"
)
.
rename
({
"
long_name
"
:
"
station_b
"
},
axis
=
1
)
)[[
"
line
"
,
"
station_a
"
,
"
station_b
"
,
"
train_hash
"
,
"
stop_number
"
]]
.
groupby
(
"
line
"
)
.
agg
(
{
"
station_a
"
:
"
first
"
,
"
station_b
"
:
"
first
"
,
"
train_hash
"
:
"
nunique
"
,
"
stop_number
"
:
lambda
g
:
max
(
g
)
+
1
,
}
)
.
rename
({
"
train_hash
"
:
"
train_count
"
},
axis
=
1
)
.
sort_values
(
by
=
"
train_count
"
,
ascending
=
False
)
.
reset_index
()
)
html
:
str
=
to_html_datatable
(
lines
,
caption
=
"
Detected railway lines
"
,
lengthMenu
=
[
20
,
50
,
100
],
order
=
[
3
,
"
desc
"
],
maxBytes
=
2
**
17
,
)
outfile
=
NamedTemporaryFile
(
delete
=
False
)
outfile
.
write
(
html
.
encode
(
"
utf-8
"
))
webbrowser
.
open
(
outfile
.
name
)
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