Пример #1
0
def check_shapes(pfeed, *, as_df=False, include_warnings=False):
    """
    Analog of :func:`check_frequencies` for ``pfeed.shapes``
    """
    table = "shapes"
    problems = []

    # Preliminary checks
    if pfeed.shapes is None:
        return problems

    f = pfeed.shapes.copy()
    problems = check_for_required_columns(problems, table, f)
    if problems:
        return gk.format_problems(problems, as_df=as_df)

    if include_warnings:
        problems = check_for_invalid_columns(problems, table, f)

    # Check shape_id
    problems = gk.check_column(problems, table, f, "shape_id", gk.valid_str)

    # Check geometry
    v = lambda x: isinstance(x, sg.LineString) and not x.is_empty
    problems = gk.check_column(problems, table, f, "geometry", v)

    return gk.format_problems(problems, as_df=as_df)
Пример #2
0
def check_meta(pfeed, *, as_df=False, include_warnings=False):
    """
    Analog of :func:`check_frequencies` for ``pfeed.meta``
    """
    table = "meta"
    problems = []

    # Preliminary checks
    if pfeed.meta is None:
        problems.append(["error", "Missing table", table, []])
    else:
        f = pfeed.meta.copy()
        problems = check_for_required_columns(problems, table, f)
    if problems:
        return gk.format_problems(problems, as_df=as_df)

    if include_warnings:
        problems = check_for_invalid_columns(problems, table, f)

    if f.shape[0] > 1:
        problems.append([
            "error", "Meta must have only one row", table,
            list(range(1, f.shape[0]))
        ])

    # Check agency_name
    problems = gk.check_column(problems, table, f, "agency_name", gk.valid_str)

    # Check agency_url
    problems = gk.check_column(problems, table, f, "agency_url", gk.valid_url)

    # Check agency_timezone
    problems = gk.check_column(problems, table, f, "agency_timezone",
                               gk.valid_timezone)

    # Check start_date and end_date
    for col in ["start_date", "end_date"]:
        problems = gk.check_column(problems, table, f, col, gk.valid_date)

    # Check default_route_speed
    problems = gk.check_column(problems, table, f, "default_route_speed",
                               valid_speed)

    return gk.format_problems(problems, as_df=as_df)
Пример #3
0
def check_service_windows(pfeed, *, as_df=False, include_warnings=False):
    """
    Analog of :func:`check_frequencies` for ``pfeed.service_windows``
    """
    table = "service_windows"
    problems = []

    # Preliminary checks
    if pfeed.service_windows is None:
        problems.append(["error", "Missing table", table, []])
    else:
        f = pfeed.service_windows.copy()
        problems = check_for_required_columns(problems, table, f)
    if problems:
        return gk.format_problems(problems, as_df=as_df)

    if include_warnings:
        problems = check_for_invalid_columns(problems, table, f)

    # Check service window ID
    problems = gk.check_column_id(problems, table, f, "service_window_id")

    # Check start_time and end_time
    for column in ["start_time", "end_time"]:
        problems = gk.check_column(problems, table, f, column, gk.valid_time)

    # Check weekday columns
    v = lambda x: x in range(2)
    for col in [
            "monday",
            "tuesday",
            "wednesday",
            "thursday",
            "friday",
            "saturday",
            "sunday",
    ]:
        #
        problems = gk.check_column(problems, table, f, col, v)

    return gk.format_problems(problems, as_df=as_df)
Пример #4
0
def check_frequencies(pfeed, *, as_df=False, include_warnings=False):
    """
    Check that ``pfeed.frequency`` follows the ProtoFeed spec.
    Return a list of problems of the form described in
    :func:`gk.check_table`;
    the list will be empty if no problems are found.
    """
    table = "frequencies"
    problems = []

    # Preliminary checks
    if pfeed.frequencies is None:
        problems.append(["error", "Missing table", table, []])
    else:
        f = pfeed.frequencies.copy()
        problems = check_for_required_columns(problems, table, f)
    if problems:
        return gk.format_problems(problems, as_df=as_df)

    if include_warnings:
        problems = check_for_invalid_columns(problems, table, f)

    # Check route_short_name and route_long_name
    for column in ["route_short_name", "route_long_name"]:
        problems = gk.check_column(problems,
                                   table,
                                   f,
                                   column,
                                   gk.valid_str,
                                   column_required=False)

    cond = ~(f["route_short_name"].notnull() | f["route_long_name"].notnull())
    problems = gk.check_table(
        problems, table, f, cond,
        "route_short_name and route_long_name both empty")

    # Check route_type
    v = lambda x: x in range(8)
    problems = gk.check_column(problems, table, f, "route_type", v)

    # Check service window ID
    problems = gk.check_column_linked_id(problems, table, f,
                                         "service_window_id",
                                         pfeed.service_windows)

    # Check direction
    v = lambda x: x in range(3)
    problems = gk.check_column(problems, table, f, "direction", v)

    # Check frequency
    v = lambda x: isinstance(x, int)
    problems = gk.check_column(problems, table, f, "frequency", v)

    # Check speed
    problems = gk.check_column(problems,
                               table,
                               f,
                               "speed",
                               valid_speed,
                               column_required=False)

    # Check shape ID
    problems = gk.check_column_linked_id(problems, table, f, "shape_id",
                                         pfeed.shapes)

    return gk.format_problems(problems, as_df=as_df)