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
c74145c0
Verified
Commit
c74145c0
authored
1 year ago
by
Marco Aceti
Browse files
Options
Downloads
Patches
Plain Diff
Add --railway-lines filter
parent
d37a67ed
Branches
develop
No related tags found
No related merge requests found
Pipeline
#2896
passed
1 year ago
Stage: test
Stage: lint
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/analysis/filter.py
+19
-0
19 additions, 0 deletions
src/analysis/filter.py
src/analysis/main.py
+15
-4
15 additions, 4 deletions
src/analysis/main.py
with
34 additions
and
4 deletions
src/analysis/filter.py
+
19
−
0
View file @
c74145c0
...
...
@@ -61,3 +61,22 @@ def railway_company_filter(
s
.
strip
().
lower
()
for
s
in
railway_companies
.
strip
().
split
(
"
,
"
)
if
len
(
s
)
>
0
]
return
df
.
loc
[
df
.
client_code
.
str
.
lower
().
isin
(
code_list
)]
def
railway_lines_filter
(
df
:
pd
.
DataFrame
,
lines
:
str
|
None
):
"""
Filter dataframe by the railway line.
Args:
df (pd.DataFrame): the considered dataframe
line (str | None): a comma-separated list of railway lines
Returns:
pd.DataFrame: the filtered dataframe
"""
if
not
lines
or
len
(
lines
)
<
1
:
return
df
line_list
:
list
[
str
]
=
[
l
.
strip
().
upper
()
for
l
in
lines
.
strip
().
split
(
"
,
"
)
if
len
(
l
)
>
0
]
return
df
.
loc
[
df
.
line
.
isin
(
line_list
)]
This diff is collapsed.
Click to expand it.
src/analysis/main.py
+
15
−
4
View file @
c74145c0
...
...
@@ -27,7 +27,7 @@ from joblib import Parallel, delayed
from
pandas.core.groupby.generic
import
DataFrameGroupBy
from
src.analysis
import
groupby
,
stat
,
trajectories_map
from
src.analysis.filter
import
date_filter
,
railway_company_filter
from
src.analysis.filter
import
*
from
src.analysis.load_data
import
read_station_csv
,
read_train_csv
,
tag_lines
...
...
@@ -45,6 +45,15 @@ def register_args(parser: argparse.ArgumentParser):
help
=
"
comma-separated list of railway companies to include. If not set, all companies will be included.
"
,
dest
=
"
client_codes
"
,
)
parser
.
add_argument
(
"
--railway-lines
"
,
help
=
(
"
comma-separated list of railway lines to include.
"
"
If not set, all lines will be include.
"
"
Use --stat detect_lines to see available lines.
"
),
dest
=
"
railway_lines
"
,
)
parser
.
add_argument
(
"
--group-by
"
,
help
=
"
group by stops by a value
"
,
...
...
@@ -110,6 +119,7 @@ def main(args: argparse.Namespace):
raise
argparse
.
ArgumentTypeError
(
"
invalid end_date
"
)
railway_companies
:
str
|
None
=
args
.
client_codes
railway_lines
:
str
|
None
=
args
.
railway_lines
# Load dataset
df
:
pd
.
DataFrame
|
DataFrameGroupBy
=
pd
.
DataFrame
()
...
...
@@ -125,14 +135,15 @@ def main(args: argparse.Namespace):
stations
:
pd
.
DataFrame
=
read_station_csv
(
args
.
station_csv
)
original_length
:
int
=
len
(
df
)
# Tag lines
df
=
tag_lines
(
df
,
stations
)
# Apply filters
df
=
date_filter
(
df
,
start_date
,
end_date
)
df
=
railway_company_filter
(
df
,
railway_companies
)
df
=
railway_lines_filter
(
df
,
railway_lines
)
logging
.
info
(
f
"
Loaded
{
len
(
df
)
}
data points (
{
original_length
}
before filtering)
"
)
# Tag lines
df
=
tag_lines
(
df
,
stations
)
# Prepare graphics
stat
.
prepare_mpl
(
df
,
args
)
...
...
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