Exemplo n.º 1
0
#!/usr/bin/env python3
import attr, collections, datetime
from common import file_in_this_dir
NYU_PICKLE = file_in_this_dir("NYU.pickle")
DAYS_OF_WEEK = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
                "Saturday", "Sunday")


def _deques_increasing_first(list_of_deques, greater_than=None):
    '''
    Yields tuples. In each tuple, a) each item is a value from a deque and
    b) each item is greater than the previous. The first item is greater than
    greater_than. This generator yields all combinations that satisfy these
    conditions. It is assumed that the deques are sorted in ascending order.
    '''
    if list_of_deques:
        # Get the first deque in the list of deques.
        q = list_of_deques[0]
        # Get the first value in the deque that is greater than greater_than.
        # Discard all values before it.
        if greater_than is not None:
            try:
                while q[0] <= greater_than:
                    q.popleft()
            except IndexError:
                # This deque is empty. The generator must terminate.
                return
        # At this point, the first value in the deque is greater than
        # greater_than.
        for value in q:
            # Construct the tuple, starting with the value from the deque.
#!/usr/bin/env python3
'''
This module is responsible for telling pickle_nyu how long it takes the bus to
get from one place to another. Normally, the schedule has this information.
However, for some reason, NYU decided not to include the information for some
stops. That's why it has to be provided by this module.

The information is stored in "Driving Time Overrides.csv". When this module
does not know the driving time from one stop to another, those two stops are
written to this file with a question mark for the time. It is up to you to put
the correct time in.
'''
import atexit, csv, multiprocessing, os.path, sys
from common import file_in_this_dir
UNWRITTEN_TIMES_CSV = file_in_this_dir("Driving Time Overrides.csv")
linit = multiprocessing.Lock()
unwritten_times = None

def save():
    '''
    This function saves the driving times back to UNWRITTEN_TIMES_CSV. There is
    no need to call this function from outside the module; it is automatically
    called when the module is exited.
    
    This function is not thread-safe.
    '''
    global unwritten_times
    if unwritten_times is not None:
        unwritten_times.pop(("", ""), 0)
        with open(UNWRITTEN_TIMES_CSV, "w", newline="", encoding="UTF-8") as f:
            writer = csv.writer(f)
Exemplo n.º 3
0
#!/usr/bin/env python3
# QA checklist:
# - No times in titles
# - No missing letters in titles
# - Blank cells in PDFs are still blank in the output
# - No words like "Arrival," "Arrive," "Depart," or "Departure" in titles
# - Randomly select some schedules, compare output to original PDF
import cgi, collections, copy, csv, datetime, dateutil.parser, io, itertools, \
    multiprocessing.pool, os, pickle, re, requests, subprocess, sys, \
    urllib.parse
from common import NODE_LIST_TXT, file_in_this_dir
from common_nyu import DAYS_OF_WEEK, NYU_PICKLE, NYUSchedule, NYUTime
import pickle_nyu_unwritten_times
NYU_HTML = file_in_this_dir("NYU.html")
SCHEDULES = file_in_this_dir("NYU Bus Schedules.csv")
REPLACEMENTS = file_in_this_dir("NYU Bus Stop Replacements.csv")
IGNORED_TIMES = {
    # Cells with these exact times will be treated as blank.
    datetime.time(0, 0),
    datetime.time(0, 4),
    datetime.time(0, 7),
}
ABBREVIATION_EXPANSION = {
    "&": "At",
    "at": "At",
    "N": "North",
    "E": "East",
    "S": "South",
    "W": "West",
    "NB": "Northbound",
    "EB": "Eastbound",
#!/usr/bin/env python3
from common import file_in_this_dir
WALKING_TIMES_PICKLE = file_in_this_dir("WalkingStatic.pickle")
#!/usr/bin/env python3
'''
Use this script to prepare the pickle that agency_walking_static needs.

Before running this script, make sure that all stops are in the node list
and run match_stops_locations.
'''
import errno, itertools, json, os, pickle, sys
from common import file_in_this_dir, LineSegment
from common_walking_static import WALKING_TIMES_PICKLE
import bing_maps, stops
WALKING_DIRECTORY = file_in_this_dir("Walking")


def walking_directions_filename(line):
    # Round to the nearest 0.00001, which is a
    # little more than a meter at the equator.
    return os.path.join(
        WALKING_DIRECTORY, "Walking_Directions_" +
        line.to_filename_friendly(precision=5) + ".json")


def all_lines():
    '''
    Takes stops.name_to_point and yields a (name, name, LineSegment, filename)
    tuple from every location to every other location. The filename refers to
    the name of the file in which the API response should be cached.
    '''
    for (from_name, from_node), (to_name, to_node) in itertools.permutations(
            stops.name_to_point.items(), 2):
        line = LineSegment(from_node, to_node)