示例#1
0
def json2wzi(wzi_json):
    """ convert json to `pyticas_tetres.types.WorkZoneInfo` from TICAS client

    :type wzi_json: str
    :rtype: pyticas_tetres.ttypes.WorkZoneInfo
    """
    wzi = json_loads(wzi_json)

    assert isinstance(wzi, WorkZoneInfo)

    if hasattr(wzi, 'route1'):
        route_setup(wzi.route1)
    else:
        wzi.route1 = None

    if hasattr(wzi, 'route2'):
        route_setup(wzi.route2)
    else:
        wzi.route2 = None

    # wzi.years = wzi.years_string(wzi.str2datetime(wzi.start_time).year, wzi.str2datetime(wzi.end_time).year)
    # if wzi.route1 or wzi.route2:
    #     wzi.corridors = wzi.corridor_string([wzi.route1, wzi.route2])
    # else:
    #     wzi.corridors = ''

    return wzi
示例#2
0
def json2ttri(json_str):
    """ convert json to `pyticas_tetres.types.TTRouteInfo` object from TICAS client

    :type json_str: str
    :rtype: TTRouteInfo
    """

    tmp = json.loads(json_str)
    if not hasattr(tmp.route, 'cfg'):
        tmp.route.cfg = None
    route_setup(tmp.route)
    return tmp
示例#3
0
def json2route(json_str):
    """ convert json to `Route` object from TICAS client

    :type json_str: str
    :rtype: Route
    """

    tmp = json.loads(json_str)

    r = Route(tmp.name, tmp.desc)
    if not hasattr(tmp, 'cfg'):
        tmp.cfg = None
    if not hasattr(tmp, 'rnodes'):
        tmp.rnodes = []
    r.cfg = tmp.cfg
    r.rnodes = tmp.rnodes
    route_setup(r)
    return r
示例#4
0
def json2snri(json_str):
    """

    :type json_str: str
    :rtype: pyticas_ncrtes.itypes.SnowRouteInfo
    """
    snri = json_loads(json_str)

    if hasattr(snri, 'route1'):
        route_setup(snri.route1)
    else:
        snri.route1 = None

    if hasattr(snri, 'route2'):
        route_setup(snri.route2)
    else:
        snri.route2 = None

    return snri
示例#5
0
def json2snri(json_str):
    """ convert json to `pyticas_tetres.types.SnowRouteInfo` object from TICAS client

    :type json_str: str
    :rtype: SnowRouteInfo
    """

    info = json.loads(json_str)
    if info.route1 and not hasattr(info.route1, 'cfg'):
        info.route1.cfg = None
    route_setup(info.route1)
    route2 = route.opposite_route(info.route1)
    cfg2 = info.route1.cfg.clone()
    rc.route_config.reverse(cfg2)
    route2.cfg = cfg2
    info.route2 = route2
    info.route1.name = 'route1 - %s' % info.route1.rnodes[0].corridor.name
    info.route1.desc = ''
    info.route2.name = 'route2 - %s' % info.route2.rnodes[0].corridor.name
    info.route2.desc = ''
    return info