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
bdbdc128
Verified
Commit
bdbdc128
authored
Mar 26, 2023
by
Marco Aceti
Browse files
Options
Downloads
Patches
Plain Diff
Add train loading and basic day filtering
parent
ba05e019
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/analysis/filter.py
+23
-0
23 additions, 0 deletions
src/analysis/filter.py
src/analysis/load_data.py
+1
-0
1 addition, 0 deletions
src/analysis/load_data.py
src/analysis/main.py
+28
-1
28 additions, 1 deletion
src/analysis/main.py
with
52 additions
and
1 deletion
src/analysis/filter.py
0 → 100644
+
23
−
0
View file @
bdbdc128
from
datetime
import
datetime
import
pandas
as
pd
def
date_filter
(
df
:
pd
.
DataFrame
,
start_date
:
datetime
|
None
,
end_date
:
datetime
|
None
)
->
pd
.
DataFrame
:
"""
Filter dataframe by date (day).
Args:
df (pd.DataFrame): the considered dataframe
start_date (datetime | None): the start date
end_date (datetime | None): the end date
Returns:
pd.DataFrame: the filtered dataframe
"""
if
isinstance
(
start_date
,
datetime
):
df
=
df
.
loc
[
df
.
day
>=
start_date
.
date
()]
if
isinstance
(
end_date
,
datetime
):
df
=
df
.
loc
[
df
.
day
<=
end_date
.
date
()]
return
df
This diff is collapsed.
Click to expand it.
src/analysis/load_data.py
+
1
−
0
View file @
bdbdc128
...
...
@@ -27,6 +27,7 @@ def read_train_csv(file: Path) -> pd.DataFrame:
infer_datetime_format
=
True
,
)
df
.
client_code
=
df
.
client_code
.
apply
(
RailwayCompany
.
from_code
)
# type: ignore
df
.
day
=
df
.
day
.
apply
(
lambda
dt
:
dt
.
date
())
return
df
.
loc
[(
df
.
phantom
==
False
)
&
(
df
.
trenord_phantom
==
False
)].
drop
(
[
"
phantom
"
,
"
trenord_phantom
"
],
axis
=
1
)
...
...
This diff is collapsed.
Click to expand it.
src/analysis/main.py
+
28
−
1
View file @
bdbdc128
import
argparse
import
logging
import
pathlib
from
datetime
import
datetime
import
pandas
as
pd
from
dateparser
import
parse
from
tqdm
import
tqdm
from
src.analysis.filter
import
date_filter
from
src.analysis.load_data
import
read_station_csv
,
read_train_csv
def
register_args
(
parser
:
argparse
.
ArgumentParser
):
...
...
@@ -37,4 +44,24 @@ def main(args: argparse.Namespace):
if
args
.
end_date
and
not
end_date
:
raise
argparse
.
ArgumentTypeError
(
"
invalid end_date
"
)
raise
NotImplementedError
()
# Load dataset
df
=
pd
.
DataFrame
()
logging
.
info
(
"
Loading datasets...
"
)
for
train_csv
in
(
tqdm
(
args
.
trains_csv
)
if
logging
.
root
.
getEffectiveLevel
()
>
logging
.
DEBUG
else
args
.
trains_csv
):
path
=
pathlib
.
Path
(
train_csv
)
train_df
:
pd
.
DataFrame
=
read_train_csv
(
pathlib
.
Path
(
train_csv
))
df
=
pd
.
concat
([
df
,
train_df
],
axis
=
0
)
logging
.
debug
(
f
"
Loaded
{
len
(
train_df
)
}
data points @
{
path
}
"
)
stations
:
pd
.
DataFrame
=
read_station_csv
(
args
.
station_csv
)
original_length
:
int
=
len
(
df
)
# Apply filters
df
=
date_filter
(
df
,
start_date
,
end_date
)
logging
.
info
(
f
"
Loaded
{
len
(
df
)
}
data points (
{
original_length
}
before filtering)
"
)
print
(
df
)
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