Skip to content

Commit

Permalink
Release 0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
stefancoe committed Feb 4, 2023
1 parent 1a758f2 commit 7c02426
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
5 changes: 4 additions & 1 deletion combine_gtfs_feeds/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from .cli import CLI
from . import run
from .gtfs_schema import GTFS_Schema
from . import run



12 changes: 6 additions & 6 deletions combine_gtfs_feeds/cli/gtfs_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ class Stop_Times(pa.SchemaModel):
drop_off_type: Optional[Series[pd.Int64Dtype]] = pa.Field(
coerce=True, nullable=True, isin=[0, 1, 2, 3]
)
continuous_pickup: Optional[Series[pd.Int64Dtype]] = pa.Field(
coerce=True, nullable=True, isin=[0, 1, 2, 3]
)
continuous_drop_off: Optional[Series[pd.Int64Dtype]] = pa.Field(
coerce=True, nullable=True, isin=[0, 1, 2, 3]
)
# continuous_pickup: Optional[Series[pd.Int64Dtype]] = pa.Field(
# coerce=True, nullable=True, isin=[0, 1, 2, 3]
# )
# continuous_drop_off: Optional[Series[pd.Int64Dtype]] = pa.Field(
# coerce=True, nullable=True, isin=[0, 1, 2, 3]
# )
shape_dist_traveled: Optional[Series[float64]] = pa.Field(
coerce=True, nullable=True, ge=0
)
Expand Down
32 changes: 21 additions & 11 deletions combine_gtfs_feeds/cli/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import combine_gtfs_feeds.cli.log_controller as log_controller
from gtfs_schema import GTFS_Schema
try:
from .gtfs_schema import GTFS_Schema
except:
from gtfs_schema import GTFS_Schema

import pandas as pd
import numpy as np
import os as os
Expand All @@ -14,8 +18,9 @@
class Combined_GTFS(object):
file_list = ["agency", "trips", "stop_times", "stops", "routes", "shapes"]

def __init__(self, df_dict):
def __init__(self, df_dict, output_dir):
# self.agency_df = df_dict["agency"]
self.output_dir = output_dir
self.agency_df = GTFS_Schema.Agency.validate(df_dict["agency"])
self.agency_df = self.agency_df[
[col for col in GTFS_Schema.agency_columns if col in self.agency_df.columns]
Expand Down Expand Up @@ -65,8 +70,8 @@ def __init__(self, df_dict):
]
]

def export_feed(self, dir):
dir = Path(dir)
def export_feed(self):
dir = Path(self.output_dir)
self.agency_df.to_csv(dir / "agency.txt", index=None)
self.routes_df.to_csv(dir / "routes.txt", index=None)
self.stops_df.to_csv(dir / "stops.txt", index=None)
Expand Down Expand Up @@ -362,18 +367,21 @@ def run(args):
a single feed.
"""

logger = log_controller.setup_custom_logger("main_logger", args.output_dir)
logger.info("------------------combine_gtfs_feeds Started----------------")
#logger = log_controller.setup_custom_logger("main_logger", args.output_dir)
#logger.info("------------------combine_gtfs_feeds Started----------------")

feeds = combine(args.gtfs_dir, args.output_dir, args.service_date, logger)
feeds = combine(args.gtfs_dir, args.service_date, args.output_dir)

feeds.export_feed(args.output_dir)
feeds.export_feed()

logger.info("Finished running combine_gtfs_feeds")
#logger.info("Finished running combine_gtfs_feeds")
# sys.exit()
print ("Finished running combine_gtfs_feeds")


def combine(gtfs_dir, output_dir, service_date, logger):
def combine(gtfs_dir, service_date, output_dir):
logger = log_controller.setup_custom_logger("main_logger", output_dir)
logger.info("------------------combine_gtfs_feeds Started----------------")
output_loc = output_dir

if not os.path.isdir(output_loc):
Expand Down Expand Up @@ -540,7 +548,9 @@ def combine(gtfs_dir, output_dir, service_date, logger):
df = pd.concat([df, feed_dict[feed][file_name]])
combined_feed_dict[file_name] = df

return Combined_GTFS(combined_feed_dict)
#logger.info("Finished running combine_gtfs_feeds")

return Combined_GTFS(combined_feed_dict, output_dir)


if __name__ == "__main__":
Expand Down
9 changes: 6 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pandas>=1.0.0
numpy>=1.16.1
PyYAML>=5.1
numpy==1.24.1
pandas==1.5.3
pandera==0.13.4
pydantic==1.9.0
PyYAML==6.0
setuptools==65.6.3
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name="combine_gtfs_feeds",
version="0.1.3",
version="0.1.4",
author="psrc staff",
author_email="[email protected]",
url="https://github.com/psrc/combine_gtfs_feeds",
Expand All @@ -20,6 +20,7 @@
long_description_content_type="text/markdown",
license="MIT",
packages=find_packages(),
python_requires='>3.6.1',
entry_points={
"console_scripts": ["combine_gtfs_feeds = combine_gtfs_feeds.cli.main:main"]
},
Expand Down

0 comments on commit 7c02426

Please sign in to comment.