Skip to content

Commit 388c1a5

Browse files
authored
Merge pull request #60 from OpenTransitTools/replace_joinload_all
Replace joinload all
2 parents 8638a9d + 2382d10 commit 388c1a5

File tree

8 files changed

+85
-62
lines changed

8 files changed

+85
-62
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ COMMIT_EDITMSG
1212
#*
1313
.idea
1414
*.iml
15+
gtfs.zip
1516
.DS_Store
1617
**/tests/*feed
1718

README.rst

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,92 @@
1-
======
1+
===========
22
GTFSDB
3-
======
3+
===========
4+
45

56
.. image:: https://badges.gitter.im/Join%20Chat.svg
67
:alt: Join the chat at https://gitter.im/OpenTransitTools/gtfsdb
78
:target: https://gitter.im/OpenTransitTools/gtfsdb?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
89

910

1011
Supported Databases
11-
===================
12+
*******************
1213

13-
- PostgreSQL (PostGIS for Geo tables) - preferred
14-
- Oracle - tested
15-
- MySQL - tested
16-
- SQLite - tested
14+
* PostgreSQL (PostGIS for Geo tables) - preferred
15+
* Oracle - tested
16+
* MySQL - tested
17+
* SQLite - tested
1718

1819

1920
GTFS (General Transit Feed Specification) Database
20-
==================================================
21+
**************************************************
2122

22-
Python code that will load GTFS data into a relational database, and SQLAlchemy ORM bindings to the GTFS tables in the gtfsdb.
23-
The gtfsdb project's focus is on making GTFS data available in a programmatic context for software developers. The need for the
24-
gtfsdb project comes from the fact that a lot of developers start out a GTFS-related effort by first building some amount of code
25-
to read GTFS data (whether that's an in-memory loader, a database loader, etc...); GTFSDB can hopefully reduce the need for such
26-
drudgery, and give developers a starting point beyond the first step of dealing with GTFS in .csv file format.
23+
Python code that will load GTFS data into a relational database, and SQLAlchemy ORM bindings to the GTFS tables in the gtfsdb. The gtfsdb project's focus is on making GTFS data available in a programmatic context for software developers. The need for the gtfsdb project comes from the fact that a lot of developers start out a GTFS-related effort by first building some amount of code to read GTFS data (whether that's an in-memory loader, a database loader, etc...); GTFSDB can hopefully reduce the need for such drudgery, and give developers a starting point beyond the first step of dealing with GTFS in .csv file format.
2724

28-
(Slightly out-of-date version) available on pypi: https://pypi.python.org/pypi/gtfsdb
25+
Available on pypi: https://pypi.python.org/pypi/gtfsdb
2926

3027

3128
Install from source via github (if you want the latest code) :
32-
==========================================
29+
**************************************************************
30+
31+
#. Install Python 3.x https://www.python.org/downloads/ (code also runs on 2.7 if you are stuck on that version)
32+
#. `pip install zc.buildout` - https://pypi.org/project/zc.buildout
33+
#. (optinal step for **postgres users**: 'pip install psycopg2-binary')
34+
#. git clone https://github.com/OpenTransitTools/gtfsdb.git
35+
#. cd gtfsdb
36+
#. buildout install prod -- NOTE: if you're using postgres, do a 'buildout install prod postgresql'
37+
#. bin/gtfsdb-load --database_url <db url> <gtfs file | url>
38+
#. examples:
3339

34-
1. Install Python 3.x https://www.python.org/downloads/ (code also runs on 2.7 if you are stuck on that version)
40+
* bin/gtfsdb-load --database_url sqlite:///gtfs.db gtfsdb/tests/large-sample-feed.zip
3541

36-
2. `pip install zc.buildout` - https://pypi.org/project/zc.buildout
42+
* bin/gtfsdb-load --database_url sqlite:///gtfs.db http://developer.trimet.org/schedule/gtfs.zip
3743

38-
3. (optinal step for **postgres users**: 'pip install psycopg2-binary')
44+
* bin/gtfsdb-load --database_url postgresql://postgres@localhost:5432 --is_geospatial http://developer.trimet.org/schedule/gtfs.zip
3945

40-
4. git clone https://github.com/OpenTransitTools/gtfsdb.git
46+
.. note:: adding the `is_geospatial` cmdline flag, when paired with a spatial-database ala PostGIS (e.g., is_spatial is meaningless with sqllite), will take longer to load...but will create geometry columns for both rendering and calculating nearest distances, etc...
4147

42-
5. cd gtfsdb
48+
#. view db ( example: https://sqliteonline.com )
4349

44-
6. buildout install prod -- NOTE: if you're using postgres, do a 'buildout install prod postgresql'
50+
The best way to get gtfsbd up and running is via the 'zc.buildout' tool. Highly recommended to first install
51+
buildout (e.g., pip install zc.buildout) before doing much of anything else.
4552

46-
7. bin/gtfsdb-load --database_url <db url> <gtfs file | url>
53+
Postgres users, gtfsdb requires the psycopg2-binary database driver. Installing that via `pip install psychopg2-binary` will relieve gtfsdb from re-installing locally as part of the build. And if after the fact, you see *exceptions* mentioning
4754

48-
examples:
55+
.. note:: if you get the message "ImportError: No module named psycopg2", then 'pip install psychopg2-binary' should fix things. (Assumes you have postgres also installed on the machine you're trying to use the pg driver).
4956

50-
- bin/gtfsdb-load --database_url sqlite:///gtfs.db gtfsdb/tests/large-sample-feed.zip
51-
- bin/gtfsdb-load --database_url sqlite:///gtfs.db http://developer.trimet.org/schedule/gtfs.zip
52-
- bin/gtfsdb-load --database_url postgresql://postgres@localhost:5432 --is_geospatial http://developer.trimet.org/schedule/gtfs.zip
5357

54-
NOTE: adding the `is_geospatial` cmdline flag, when paired with a spatial-database ala PostGIS (e.g., is_spatial is meaningless with sqllite), will take longer to load...but will create geometry columns for both rendering and calculating nearest distances, etc...
58+
Usage with Docker:
59+
******************
5560

56-
8. view db ( example: https://sqliteonline.com )
61+
#. Build the image with `docker build -t gtfsdb .`
62+
#. Run it with:
5763

58-
The best way to get gtfsbd up and running is via the 'zc.buildout' tool. Highly recommended to first install
59-
buildout (e.g., pip install zc.buildout) before doing much of anything else.
64+
.. code-block:: bash
6065
61-
Postgres users, gtfsdb requires the psycopg2-binary database driver. Installing that via `pip install psychopg2-binary`
62-
will relieve gtfsdb from re-installing locally as part of the build. And if after the fact, you see *exceptions* mentioning
63-
**"ImportError: No module named psycopg2"**, then 'pip install psychopg2-binary' should fix that up quick...
66+
docker run gtfsdb --database_url <db url> <gtfs file | url>
6467
68+
.. note:: The entrypoint command is `bin/gtfsdb-load` so the arguments will be passed to it.
6569

66-
Usage with Docker
67-
=================
6870

69-
1. Build the image with :code:`docker build -t gtfsdb .`.
70-
2. Run it with
71-
:code:`docker run gtfsdb --database_url <db url> <gtfs file | url>`.
72-
The entrypoint command is :code:`bin/gtfsdb-load`
73-
so the arguments will be passed to it.
71+
Example Queries:
72+
****************
7473

74+
* get first stop time of each trip for route_id 1
7575

76-
Example Query:
77-
==============
76+
.. code-block:: sql
7877
79-
-- get first stop time of each trip for route_id 1
78+
select *
79+
from trips t, stop_times st
80+
where t.route_id = '1'
81+
and t.trip_id = st.trip_id
82+
and st.stop_sequence = 1
8083
81-
select *
82-
from trips t, stop_times st
83-
where t.route_id = '1'
84-
and t.trip_id = st.trip_id
85-
and st.stop_sequence = 1
84+
* get agency name and number of routes
8685

87-
-- get agency name and number of routes
86+
.. code-block:: sql
8887
89-
select a.agency_name, a.agency_id, count(r.route_id)
90-
from routes r, agency a
91-
where r.agency_id = a.agency_id
92-
group by a.agency_id, a.agency_name
93-
order by 3 desc
88+
select a.agency_name, a.agency_id, count(r.route_id)
89+
from routes r, agency a
90+
where r.agency_id = a.agency_id
91+
group by a.agency_id, a.agency_name
92+
order by 3 desc

gtfsdb/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from gtfsdb.model.stop_feature import * # noqa
1616
from gtfsdb.model.stop_time import StopTime # noqa
1717
from gtfsdb.model.transfer import Transfer # noqa
18+
from gtfsdb.model.translation import Translation # noqa
1819
from gtfsdb.model.trip import Trip # noqa
1920
from gtfsdb.model.block import Block # noqa
2021

@@ -42,6 +43,7 @@
4243
FareAttribute.__name__,
4344
FareRule.__name__,
4445
UniversalCalendar.__name__,
46+
Translation.__name__,
4547
]
4648

4749

gtfsdb/model/stop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections import defaultdict
22

33
from sqlalchemy import Column, Integer, Numeric, String
4-
from sqlalchemy.orm import joinedload, joinedload_all, object_session, relationship
4+
from sqlalchemy.orm import joinedload, object_session, relationship
55

66
from gtfsdb import config, util
77
from gtfsdb.model.base import Base
@@ -82,7 +82,7 @@ def headsigns(self):
8282
session = object_session(self)
8383
log.info("QUERY StopTime")
8484
q = session.query(StopTime)
85-
q = q.options(joinedload_all('trip.route'))
85+
q = q.options(joinedload('trip').joinedload('route'))
8686
q = q.filter_by(stop_id=self.stop_id)
8787
for r in q:
8888
headsign = r.stop_headsign or r.trip.trip_headsign

gtfsdb/model/stop_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from sqlalchemy import Column, Integer, Numeric, String
2-
from sqlalchemy.orm import joinedload, joinedload_all, object_session, relationship
2+
from sqlalchemy.orm import joinedload, object_session
33

44
from gtfsdb import config
55
from gtfsdb.util import BBox, Point

gtfsdb/model/stop_time.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from gtfsdb import config, util
55
from gtfsdb.model.base import Base
66
from sqlalchemy import Column
7-
from sqlalchemy.orm import joinedload_all, relationship
7+
from sqlalchemy.orm import joinedload, relationship
88
from sqlalchemy.sql.expression import func
99
from sqlalchemy.types import SmallInteger, Integer, Numeric, String
1010

@@ -237,7 +237,7 @@ def get_departure_schedule(cls, session, stop_id, date=None, route_id=None, limi
237237
q = q.filter(StopTime.trip.has(Trip.route_id == route_id))
238238

239239
# step 3: options to speed up /q
240-
q = q.options(joinedload_all('trip'))
240+
q = q.options(joinedload('trip'))
241241

242242
# step 4: order the stop times
243243
if limit is None or limit > 1:

gtfsdb/model/translation.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from sqlalchemy import Column, Integer, Sequence
2+
from sqlalchemy.types import String
3+
4+
from gtfsdb import config
5+
from gtfsdb.model.base import Base
6+
7+
8+
class Translation(Base):
9+
datasource = config.DATASOURCE_GTFS
10+
filename = 'translations.txt'
11+
12+
__tablename__ = 'translations'
13+
14+
id = Column(Integer, Sequence(None, optional=True), primary_key=True)
15+
table_name = Column(String(255), nullable=False)
16+
field_name = Column(String(255), nullable=False)
17+
language = Column(String(255), nullable=False)
18+
translation = Column(String(255), nullable=False)
19+
record_id = Column(String(255))
20+
record_sub_id = Column(String(255))
21+
field_value = Column(String(255))

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
setup(
2222
name='gtfsdb',
23-
version='0.5.0',
23+
version='0.6.0',
2424
description='GTFS Database',
2525
long_description=open('README.rst').read(),
2626
keywords='GTFS',
@@ -40,10 +40,10 @@
4040
]
4141
},
4242
classifiers=(
43-
'Development Status :: 4 - Beta',
43+
'Development Status :: 5 - Production/Stable',
4444
'Environment :: Console',
4545
'Intended Audience :: Developers',
46-
'License :: OSI Approved :: Mozilla-derived (MPL)',
46+
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
4747
'Natural Language :: English',
4848
'Programming Language :: Python :: 2.7',
4949
'Programming Language :: Python :: 3.7',

0 commit comments

Comments
 (0)