Skip to content

Commit

Permalink
Running pre-commit, reformatting all files
Browse files Browse the repository at this point in the history
  • Loading branch information
kuanb committed Nov 24, 2017
1 parent 312fa4a commit aa66ed7
Show file tree
Hide file tree
Showing 20 changed files with 124 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
*.pyc
__pycache__/
ptenv/
.cache/
.cache/
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Docs @ http://pre-commit.com/

repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
sha: v0.7.1 # Use the ref you want to point at
- repo: https://github.com/kuanb/pre-commit-hooks.git
sha: 61d0735ca8b0ce5ab8df867bc974798ba8316ee5
hooks:
- id: autopep8-wrapper
- id: check-added-large-files
Expand All @@ -24,7 +24,7 @@ repos:
- id: flake8
- id: trailing-whitespace

- repo: https://github.com/CalthorpeAnalytics/pre-commit-python-sorter.git
- repo: https://github.com/kuanb/pre-commit-python-sorter.git
sha: 1.0.8
hooks:
- id: python-import-sorter
- id: python-import-sorter
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ install:
- pip install -r requirements.txt

script:
- PYTHONPATH=. py.test
- PYTHONPATH=. py.test
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
PYTHONPATH=. py.test
PYTHONPATH=. py.test
3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Usage
# use to summarize impedance
start = 7*60*60 # 7:00 AM
end = 10*60*60 # 10:00 AM
# Converts feed subset into a directed
# network multigraph
G = pt.load_feed_as_graph(feed, start, end)
Expand All @@ -42,4 +42,3 @@ Note: Still a WIP. Current version on PyPI not good...
.. code:: console
pip install peartree
2 changes: 1 addition & 1 deletion peartree/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.2'
__version__ = '0.1.2'
14 changes: 4 additions & 10 deletions peartree/graph.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
from typing import Dict

import networkx as nx
import numpy as np
import pandas as pd
import random

from fiona import crs
import networkx as nx
import pandas as pd
import partridge as ptg
from fiona import crs

from .settings import WGS84
from .summarizer import (generate_edge_and_wait_values,
generate_summary_edge_costs,
generate_summary_wait_times)
from .utilities import log


def generate_empty_md_graph(name: str,
Expand All @@ -35,10 +29,10 @@ def generate_summary_graph_elements(feed: ptg.gtfs.feed,
all_wait_times) = generate_edge_and_wait_values(feed,
target_time_start,
target_time_end)

summary_edge_costs = generate_summary_edge_costs(all_edge_costs)
wait_times_by_stop = generate_summary_wait_times(all_wait_times)

return (summary_edge_costs, wait_times_by_stop)


Expand All @@ -53,7 +47,7 @@ def populate_graph(G: nx.MultiDiGraph,

# TODO: Join tables before hand to make
# this part go faster
id_mask = (feed.stops.stop_id==sid)
id_mask = (feed.stops.stop_id == sid)
stop_data = feed.stops[id_mask].head(1).T.squeeze()

G.add_node(full_sid,
Expand Down
41 changes: 24 additions & 17 deletions peartree/paths.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import string
import random
import string

import networkx as nx
import partridge as ptg

from .graph import (generate_empty_md_graph,
generate_summary_graph_elements,
from .graph import (generate_empty_md_graph, generate_summary_graph_elements,
populate_graph)
from .utilities import log

Expand All @@ -26,14 +25,15 @@ def _generate_random_name(N: int=5):

def get_representative_feed(file_loc: str,
day_type: str='busiest'):

service_ids_by_date = ptg.read_service_ids_by_date(file_loc)
trip_counts_by_date = ptg.read_trip_counts_by_date(file_loc)

# Make sure we have some valid values returned in trips
if not len(trip_counts_by_date.items()):
# Otherwise, error out
raise InvalidGTFS('No valid trip counts by date were identified in GTFS.')
raise InvalidGTFS('No valid trip counts by date '
'were identified in GTFS.')

# At this point, different methods can be implemented to help select how
# to pick which date/schedule id to use
Expand All @@ -43,14 +43,14 @@ def get_representative_feed(file_loc: str,
else:
raise NotImplementedError('Unsupported day type string supplied.')

log('Selected_date: {}'.format(selected_date))
log('Number of trips on that date: {}'.format(trip_count))
log(f'Selected_date: {selected_date}')
log(f'Number of trips on that date: {trip_count}')

all_service_ids = '\n\t'.join(service_ids_by_date[selected_date])
log('\nAll related service IDs: \n\t{}'.format(all_service_ids))
log(f'\nAll related service IDs: \n\t{all_service_ids}')

selected_service_ids = service_ids_by_date[selected_date]
feed_query = {'trips.txt': {'service_id': selected_service_ids}}
sub = service_ids_by_date[selected_date]
feed_query = {'trips.txt': {'service_id': sub}}
return ptg.feed(file_loc, view=feed_query)


Expand All @@ -68,10 +68,13 @@ def load_feed_as_graph(feed: ptg.gtfs.feed,
raise InvalidTimeBracket('Invalid start or end target times provided.')

if end_time < start_time:
raise InvalidTimeBracket('Invalid ordering: Start time is greater than end time.')
raise InvalidTimeBracket('Invalid ordering: Start time '
'is greater than end time.')

(summary_edge_costs,
wait_times_by_stop) = generate_summary_graph_elements(feed, start_time, end_time)
wait_times_by_stop) = generate_summary_graph_elements(feed,
start_time,
end_time)

# This is a flag used to check if we need to run any additional steps
# after the feed is returned to ensure that new nodes and edge can connect
Expand All @@ -80,11 +83,15 @@ def load_feed_as_graph(feed: ptg.gtfs.feed,

# G is either a new MultiDiGraph or one pass from before
if existing_graph_supplied:
# TODO: If passed from before we should run some checks to ensure it is valid
# as well as set a flag to create join points with other feeds so that
# they can be linked when the next is added.
# TODO: If passed from before we should run some checks to ensure
# it is valid as well as set a flag to create join points with
# other feeds so that they can be linked when the next is added.
G = existing_graph
else:
G = generate_empty_md_graph(name)

return populate_graph(G, name, feed, wait_times_by_stop, summary_edge_costs)

return populate_graph(G,
name,
feed,
wait_times_by_stop,
summary_edge_costs)
7 changes: 6 additions & 1 deletion peartree/plot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import matplotlib
import networkx as nx
import osmnx as ox

# Force matplotlib to not use any Xwindows backend.
matplotlib.use('Agg')


def generate_plot(G: nx.MultiDiGraph):
# TODO: Build out custom plotting configurations but,
# in the meantime, use OSMnx's plotting configurations
Expand All @@ -16,4 +21,4 @@ def generate_plot(G: nx.MultiDiGraph):
edge_color='#e2dede',
edge_alpha=0.25,
bgcolor='black')
return (fig, ax)
return (fig, ax)
4 changes: 2 additions & 2 deletions peartree/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
log_console = False
log_level = lg.INFO

# Set some globals here that
# Set some globals here that
# are used as reference throughout lib
WGS84 = 4326 # degree measurement
WEB_MERCATOR = 3857 # meter-based
WEB_MERCATOR = 3857 # meter-based
Loading

0 comments on commit aa66ed7

Please sign in to comment.