Ejemplo n.º 1
0
def test_after_midnight():
    sample_date = pendulum.datetime(2019, 1, 29, 1, tz="America/Los_Angeles")
    schedule_path = "../sample_data/schedule/804_lametro-rail/2019-01-28.csv"

    assert (
        get_appropriate_timetable(
            sample_date, f"../sample_data/schedule/{line}_{agency}"
        )["path"]
        == schedule_path
    )
Ejemplo n.º 2
0
def test_arbitrary_schedule():
    sample_date = pendulum.datetime(2019, 1, 31, 12, tz="America/Los_Angeles")
    schedule_path = "../sample_data/schedule/804_lametro-rail/2019-01-31.csv"

    assert (
        get_appropriate_timetable(
            sample_date, f"../sample_data/schedule/{line}_{agency}"
        )["path"]
        == schedule_path
    )

    assert (
        get_date_if_exists_otherwise_previous(
            sample_date, f"../sample_data/schedule/{line}_{agency}"
        )
        == sample_date
    )
)
from helpers.timing import get_appropriate_timetable
from analyzer.summary import statistic_summary

agency = "lametro-rail"
datetime = pendulum.now("America/Los_Angeles")

master_summary = {}
count = 0
for line in range(801, 807):

    count = count + 1
    print("loop: {}".format(count))

    schedule_base_path = f"data/schedule/{line}_{agency}"
    schedule_meta = get_appropriate_timetable(datetime, schedule_base_path)
    #    print("\nschedule_meta path: \n" + schedule_meta["path"])
    #    for i in schedule_meta:
    #        print(schedule_meta[i])
    vehicles_base_path = f"data/vehicle_tracking/processed/{line}_{agency}"
    vehicles_meta = get_appropriate_timetable(datetime, vehicles_base_path)
    #    print("\nvehicles_meta path: \n" + vehicles_meta["path"])
    #    for i in vehicles_meta:
    #        print(vehicles_meta[i])

    # if the schdeule data and vehicle dates don't match, run "query_vehicles.sh" or
    # process_vehicles.sh to update files before proceeding
    if schedule_meta["date"] == vehicles_meta["date"]:
        continue

    vehicles = pd.read_csv(vehicles_meta["path"],
from helpers.upload import upload
import pendulum
from helpers.timing import get_appropriate_timetable


now = pendulum.now("America/Los_Angeles")
agency = "lametro-rail"

for line in range(801, 807):
    vehicles_base_path = f"data/vehicle_tracking/processed/{line}_{agency}"
    vehicles_meta = get_appropriate_timetable(now, vehicles_base_path)
    date = vehicles_meta["date"]
    positions_path = vehicles_meta["path"]
    upload(positions_path, positions_path)

summary_path = f"data/summaries/{date}.json"
upload(summary_path, summary_path)
import pendulum
import pandas as pd
from analyzer.process_vehicles import (
    preprocess,
    determine_vehicle_paths,
    get_track,
    process_raw_vehicles,
)
from helpers.timing import get_appropriate_timetable

agency = "lametro-rail"
datetime = pendulum.now("America/Los_Angeles")
print(f"The current time is {datetime.to_iso8601_string()}")

for line in range(801, 807):
    schedule = get_appropriate_timetable(datetime,
                                         f"data/schedule/{line}_{agency}")
    print(schedule["path"])
    print("start: ", schedule["start"])
    print("end: ", schedule["end"])
    raw_vehicle_files = determine_vehicle_paths(
        f"data/vehicle_tracking/raw/{line}_{agency}", schedule["start"],
        schedule["end"])
    array = [preprocess(path) for path in raw_vehicle_files]
    print("Preprocessing complete")
    cleaned = [row for row in array if row is not None]
    print("Cleaning complete")
    df = pd.concat(cleaned)
    track = get_track(line, f"data/line_info/{line}")
    print("got track")
    processed = process_raw_vehicles(df, track)
    print("Processing complete (big job)")