Exemplo n.º 1
0
def get_options(args=None):
    argParser = ArgumentParser()
    argParser.add_argument("-t",
                           "--tripinfo-file",
                           dest="tripinfoFile",
                           help="tripinfo file written by the simulation")
    argParser.add_argument("-a",
                           "--attribute",
                           default="duration",
                           help="attribute to use for statistics")
    argParser.add_argument("-o", "--output", help="the output file")
    options = argParser.parse_args(args=args)
    if not options.tripinfoFile:
        sys.exit("Required argument --tripinfo-file is missing")
    return options
Exemplo n.º 2
0
def get_conn(options_or_config_file):
    if isinstance(options_or_config_file, str):
        argParser = ArgumentParser()
        add_db_arguments(argParser)
        print("parsing", options_or_config_file)
        options = argParser.parse_args(["-c", options_or_config_file])
    else:
        options = options_or_config_file
    if options.host is None:
        return None
    if options.host == "sqlite3":
        conn = sqlite3.connect(":memory:",
                               detect_types=sqlite3.PARSE_DECLTYPES)
        sqlite3.register_adapter(bool, int)
        sqlite3.register_converter("boolean", lambda v: bool(int(
            v)))  # sqlite has no native boolean type and would return ints
        try:
            conn.enable_load_extension(True)
            conn.execute("SELECT load_extension('mod_spatialite%s')" %
                         ('.so' if os.name == "posix" else ''))
        except Exception as e:
            print(
                "Warning! Could not load mod_spatialite, geometry related database operations won't work.",
                e,
                file=sys.stderr)
        database = options.database % os.environ
        core = os.path.join(os.path.dirname(database), 'core.db')
        conn.execute("ATTACH ? AS core", (core, ))
        conn.execute(
            "ATTACH ? AS public", (database, )
        )  # attaching 'public' last makes it the default if name clashes should occur
        return conn
    try:
        return psycopg2.connect(host=options.host,
                                port=options.port,
                                user=options.user,
                                password=options.password,
                                database=options.database)
    except psycopg2.OperationalError as e:
        print(e, file=sys.stderr)
        return None
Exemplo n.º 3
0
def main(args):
    # get the options
    argParser = ArgumentParser()
    options = getOptions(args, argParser)

    if options.clean:
        shutil.rmtree(options.workdir_folder, True)
        conn = db_manipulator.get_conn(options)
        if conn is None:
            print(
                "Warning! No database connection given, deleting files only.")
        else:
            cursor = conn.cursor()
            cursor.execute("DELETE FROM public.%s;" % (SP.OPTIONAL[SP.status]))
            conn.commit()
            conn.close()
        return

    processes = {}
    now = datetime.datetime.now()
    if options.daemon_run_time > 0:
        daemon_end_time = now + datetime.timedelta(
            seconds=options.daemon_run_time)
    else:
        daemon_end_time = datetime.datetime.max
    while now < daemon_end_time:
        # clean up finished processes
        for key in list(processes.keys()):
            if not processes[key].is_alive():
                del processes[key]
        # check for a new simulation request
        for request in get_simulation_requests(options):
            if request[0] in processes:  # this should happen in tests only
                processes[request[0]].join()
                del processes[request[0]]
            if len(processes) >= options.parallel:
                break
            processes[request[0]] = multiprocessing.Process(
                target=simulation_request, args=(options, request))
            processes[request[0]].start()
        if not options.daemon:
            break
        time.sleep(2)
        prev = now
        now = datetime.datetime.now()
        if prev.hour != now.hour:
            print("still listening", now)

    for p in processes.values():
        p.join()
Exemplo n.º 4
0
def parse_args():
    argParser = ArgumentParser()
    db_manipulator.add_db_arguments(argParser)
    argParser.add_argument(
        "-a",
        "--all-pairs",
        dest="all_pairs",
        default=False,
        action="store_true",
        help="Generate trips for all pairs of traffic zones")
    argParser.add_argument(
        "-d",
        "--departure",
        type=int,
        default=3600 * 16,
        help="When used with --all-pairs, set departure second to <INT>")
    argParser.add_argument("-k", "--simkey", help="simulation key to retrieve")
    argParser.add_argument("-l",
                           "--limit",
                           type=int,
                           help="maximum number of trips to retrieve")
    argParser.add_argument("--seed",
                           type=int,
                           default=23432,
                           help="random seed")
    argParser.add_argument("--representatives",
                           default='berlin_location_representatives',
                           help="set the table to read representatives from")
    argParser.add_argument("--triptable",
                           default='berlin_trips',
                           help="set the table to receive trips from")
    argParser.add_argument("--taztable",
                           default='berlin_taz',
                           help="set the table to read districts from")
    argParser.add_argument(
        "-m",
        "--modes",
        default=','.join(CAR_MODES),
        help=
        "the traffic modes to retrieve as a list of integers (default '%default')"
    )
    options = argParser.parse_args()
    options.limit_sql = "" if options.limit is None else "LIMIT %s" % options.limit
    return options
Exemplo n.º 5
0
                last_depart = max(last_depart, float(trip.depart))
            print(
                "using previous version of %s, vehicles starting between %s and %s"
                % (options.trips_for_dua, first_depart, last_depart))

        else:
            print("Cannot continue with assignment because %s is missing" %
                  options.trips_for_dua)
            return

    if options.iteration_dir is None:
        print("No iteration dir given, skipping assignment")
        return options.trips_for_dua, None
    if options.assignment == "bulk":
        return assign.run_bulk(options, first_depart, last_depart,
                               options.trips_for_dua, options.weights)
    if options.script_module is None:
        return assign.run_default(options, first_depart, last_depart,
                                  options.trips_for_dua, options.weights)
    return options.script_module.assign_trips(options, first_depart,
                                              last_depart,
                                              options.trips_for_dua,
                                              options.weights)


if __name__ == "__main__":
    argParser = ArgumentParser()
    fillOptions(argParser)
    options = argParser.parse_args(args=sys.argv[1:])
    main(options)
Exemplo n.º 6
0
def parse_args():
    argParser = ArgumentParser()
    db_manipulator.add_db_arguments(argParser)
    argParser.add_argument("-o", "--output", default="osm_scenario_pre/mitte_net/location_priorities.xml", help="output file")
    options = argParser.parse_args()
    return options
Exemplo n.º 7
0
def initOptions():
    ap = ArgumentParser()
    ap.add_argument("-n", "--network", required=True, help="SUMO network file")
    ap.add_argument("--osm-routes", required=True, help="osm routes file")
    ap.add_argument("--gtfs",
                    required=True,
                    help="define gtfs zip file to load (mandatory)")
    ap.add_argument(
        "--bbox",
        required=True,
        help="define the bounding box to filter the gtfs data, format: W,S,E,N"
    )  # noqa
    ap.add_argument("--date",
                    help="define the day to import, format: 'YYYYMMDD'")
    ap.add_argument(
        "--pt-types",
        default="bus,tram,train,subway,ferry",
        help=
        "filter pt-types to import (bus, tram, train, subway and/or ferry). format: 'bus,tram'"
    )  # noqa
    ap.add_argument("--repair", help="repair osm routes", action='store_true')
    ap.add_argument("--debug", action='store_true')
    ap.add_argument("--bus-stop-length",
                    default=13,
                    type=float,
                    help="length for a bus stop")
    ap.add_argument("--train-stop-length",
                    default=110,
                    type=float,
                    help="length for a train stop")
    ap.add_argument("--tram-stop-length",
                    default=60,
                    type=float,
                    help="length for a tram stop")
    ap.add_argument("--duration",
                    default=10,
                    type=int,
                    help="minimum time to wait on a stop")
    ap.add_argument(
        "--min-stops",
        default=3,
        type=int,
        help=
        "minimum number of stops a public transport line must have to be imported"
    )  # noqa

    options = ap.parse_args()
    options.pt_types = options.pt_types.split(",")
    options.region = [float(boundary) for boundary in options.bbox.split(",")]

    return options
Exemplo n.º 8
0
def getOptions(args=None):
    optParser = ArgumentParser(
        description='Plot arbitrary attributes from xml files',
        epilog=
        'Individual trajectories can be clicked in interactive mode to print the data Id on the console\n'
        'selects two attributs for x and y axis and optionally a third (id-attribute)\n'
        'for grouping of data points into lines\n\n'
        'Example\n'
        '  plotXMLAttributes.py -x started -y initialPersons -s stopout.xml\n'
        '    plots passengers over time for vehicles from SUMO stop output',
        formatter_class=RawDescriptionHelpFormatter)

    optParser.add_option("-x", "--xattr", help="attribute for x-axis")
    optParser.add_option("-y", "--yattr", help="attribute for y-axis")
    optParser.add_option("-i",
                         "--idattr",
                         default="id",
                         help="attribute for grouping data points into lines")
    optParser.add_option("--xelem", help="element for x-axis")
    optParser.add_option("--yelem", help="element for y-axis")
    optParser.add_option("--idelem",
                         help="element for grouping data points into lines")
    optParser.add_option("-s",
                         "--show",
                         action="store_true",
                         default=False,
                         help="show plot directly")
    optParser.add_option("-o",
                         "--output",
                         help="outputfile for saving plots",
                         default="plot.png")
    optParser.add_option("--csv-output",
                         dest="csv_output",
                         help="write plot as csv",
                         metavar="FILE")
    optParser.add_option(
        "--filter-ids",
        dest="filterIDs",
        help="only plot data points from the given list of ids")
    optParser.add_option(
        "-p",
        "--pick-distance",
        dest="pickDist",
        type=float,
        default=1,
        help="pick lines within the given distance in interactive plot mode")
    optParser.add_option("--label", help="plot label (default input file name")
    optParser.add_option("--xlabel", help="plot label (default xattr)")
    optParser.add_option("--ylabel", help="plot label (default yattr)")
    optParser.add_option("--xfactor",
                         help="multiplier for x-data",
                         type=float,
                         default=1)
    optParser.add_option("--yfactor",
                         help="multiplier for y-data",
                         type=float,
                         default=1)
    optParser.add_option("--invert-yaxis",
                         dest="invertYAxis",
                         action="store_true",
                         default=False,
                         help="Invert the Y-Axis")
    optParser.add_option("--scatterplot",
                         action="store_true",
                         default=False,
                         help="Draw a scatterplot instead of lines")
    optParser.add_option("--legend",
                         action="store_true",
                         default=False,
                         help="Add legend")
    optParser.add_option("-v",
                         "--verbose",
                         action="store_true",
                         default=False,
                         help="tell me what you are doing")
    optParser.add_argument("files",
                           nargs='+',
                           help="List of XML files to plot")

    options = optParser.parse_args(args=args)

    options.attrOptions = ['idattr', 'xattr', 'yattr']
    options.attrElems = [options.idelem, options.xelem, options.yelem]

    if options.filterIDs is not None:
        options.filterIDs = set(options.filterIDs.split(','))

    for a in options.attrOptions:
        if getattr(options, a) is None:
            sys.exit("mandatory argument --%s is missing" % a)

    if options.xlabel is None:
        options.xlabel = options.xattr
    if options.ylabel is None:
        options.ylabel = options.yattr

    return options
Exemplo n.º 9
0
def parse_args():
    USAGE = "Usage: " + sys.argv[0] + " <source> <dest> <output-prefix>"
    optParser = ArgumentParser()
    optParser.add_option("-v",
                         "--verbose",
                         action="store_true",
                         default=False,
                         help="Give more output")
    optParser.add_option(
        "-p",
        "--use-prefix",
        action="store_true",
        default=False,
        help=
        "interpret source and dest as plain-xml prefix instead of network names"
    )
    optParser.add_option("-d",
                         "--direct",
                         action="store_true",
                         default=False,
                         help="compare source and dest files directly")
    optParser.add_option(
        "-i",
        "--patch-on-import",
        action="store_true",
        dest="patchImport",
        default=False,
        help="generate patch that can be applied during initial network import"
        + " (exports additional connection elements)")
    optParser.add_option(
        "--copy",
        help=
        "comma-separated list of element names to copy (if they are unchanged)"
    )
    optParser.add_option("--path", dest="path", help="Path to binaries")
    optParser.add_option(
        "--remove-plain",
        action="store_true",
        help="avoid saving plain xml files of source and destination networks")
    optParser.add_option(
        "-l",
        "--write-selections",
        action="store_true",
        dest="writeSelections",
        default=False,
        help="Write selection files for created,deleted and changed elements")
    optParser.add_option(
        "-s",
        "--write-shapes",
        action="store_true",
        dest="writeShapes",
        default=False,
        help="Write shape files for created,deleted and changed elements")
    options, args = optParser.parse_known_args()
    if len(args) != 3:
        sys.exit(USAGE)
    if options.use_prefix and options.direct:
        optParser.error(
            "Options --use-prefix and --direct are mutually exclusive")

    if options.writeShapes:
        if options.direct:
            optParser.error(
                "Options --write-shapes and --direct are mutually exclusive")
        if options.use_prefix:
            optParser.error(
                "Options --write-shapes and --use-prefix are mutually exclusive"
            )

    options.source, options.dest, options.outprefix = args
    return options
Exemplo n.º 10
0
def get_options():
    USAGE = "Usage " + sys.argv[0] + " [options] <net.xml> <rou.xml>"
    optParser = ArgumentParser(usage=USAGE)
    optParser.add_option("-v", "--verbose", action="store_true",
                         default=False, help="Give more output")
    optParser.add_option("--threshold", type=float, default=2.5,
                         help="Routes with an implausibility-score above treshold are reported")
    optParser.add_option("--airdist-ratio-factor", type=float, default=1, dest="airdist_ratio_factor",
                         help="Implausibility factor for the ratio of routeDist/airDist ")
    optParser.add_option("--detour-ratio-factor", type=float, default=1, dest="detour_ratio_factor",
                         help="Implausibility factor for the ratio of routeDuration/shortestDuration ")
    optParser.add_option("--detour-factor", type=float, default=0.01, dest="detour_factor",
                         help="Implausibility factor for the absolute detour time in (routeDuration-shortestDuration)" +
                              " in seconds")
    optParser.add_option("--min-dist", type=float, default=0, dest="min_dist",
                         help="Minimum shortest-path distance below which routes are implausible")
    optParser.add_option("--min-air-dist", type=float, default=0, dest="min_air_dist",
                         help="Minimum air distance below which routes are implausible")
    optParser.add_option("--standalone", action="store_true",
                         default=False, help="Parse stand-alone routes that are not define as child-element of " +
                                             "a vehicle")
    optParser.add_option("--blur", type=float, default=0,
                         help="maximum random disturbance to output polygon geometry")
    optParser.add_option("--ignore-routes", dest="ignore_routes",
                         help="List of route IDs (one per line) that are filtered when generating polygons and " +
                              "command line output (they will still be added to restrictions-output)")
    optParser.add_option("-o", "--xml-output", dest="xmlOutput",
                         help="Write implausibility scores and routes to xml FILE")
    optParser.add_option("--restriction-output", dest="restrictions_output",
                         help="Write flow-restriction output suitable for passing to flowrouter.py to FILE")
    optParser.add_option("--od-restrictions", action="store_true", dest="odrestrictions",
                         default=False, help="Write restrictions for origin-destination relations rather than " +
                                             "whole routes")
    optParser.add_option("--edge-loops", action="store_true",
                         default=False, help="report routes which use edges twice")
    optParser.add_option("--node-loops", action="store_true",
                         default=False, help="report routes which use junctions twice")
    optParser.add_option("--threads", default=1, type=int,
                         help="number of threads to use for duarouter")
    optParser.add_option("--min-edges", default=2, type=int,
                         help="number of edges a route needs to have to be analyzed")
    optParser.add_option("--heterogeneous", action="store_true",
                         default=False, help="Use slow parsing for route files with different formats in one file")
    optParser.add_option("--reuse-routing", action="store_true",
                         default=False, help="do not run duarouter again if output file exists")
    optParser.add_option("network", help="network file to use")
    optParser.add_option("routeFiles", nargs='+', help="route files to use")
    options, args = optParser.parse_known_args()

    # options for generate_poly
    options.layer = 100
    options.geo = False
    options.internal = False
    options.spread = None

    return options
Exemplo n.º 11
0
def getOptions(args=None):
    optParser = ArgumentParser()
    optParser.add_option(
        "-t",
        "--trajectory-type",
        dest="ttype",
        default="ds",
        help="select two letters from [t, s, d, a, i, x, y, k] to plot" +
        " Time, Speed, Distance, Acceleration, Angle, x-Position, y-Position, Kilometrage."
        + " Default 'ds' plots Distance vs. Speed")
    optParser.add_option("--persons",
                         action="store_true",
                         default=False,
                         help="plot person trajectories")
    optParser.add_option("-s",
                         "--show",
                         action="store_true",
                         default=False,
                         help="show plot directly")
    optParser.add_option("-o",
                         "--output",
                         help="outputfile for saving plots",
                         default="plot.png")
    optParser.add_option("--csv-output",
                         dest="csv_output",
                         help="write plot as csv",
                         metavar="FILE")
    optParser.add_option("-b",
                         "--ballistic",
                         action="store_true",
                         default=False,
                         help="perform ballistic integration of distance")
    optParser.add_option(
        "--filter-route",
        dest="filterRoute",
        help=
        "only export trajectories that pass the given list of edges (regardless of gaps)"
    )
    optParser.add_option("--filter-edges",
                         dest="filterEdges",
                         help="only consider data for the given list of edges")
    optParser.add_option(
        "--filter-ids",
        dest="filterIDs",
        help="only consider data for the given list of vehicle (or person) ids"
    )
    optParser.add_option(
        "-p",
        "--pick-distance",
        dest="pickDist",
        type=float,
        default=1,
        help="pick lines within the given distance in interactive plot mode")
    optParser.add_option(
        "-i",
        "--invert-distance-angle",
        dest="invertDistanceAngle",
        type=float,
        help="invert distance for trajectories with a average angle near FLOAT"
    )
    optParser.add_option("--label", help="plot label (default input file name")
    optParser.add_option("--invert-yaxis",
                         dest="invertYAxis",
                         action="store_true",
                         default=False,
                         help="Invert the Y-Axis")
    optParser.add_option("--legend",
                         action="store_true",
                         default=False,
                         help="Add legend")
    optParser.add_option("-v",
                         "--verbose",
                         action="store_true",
                         default=False,
                         help="tell me what you are doing")

    options, args = optParser.parse_known_args(args=args)
    if len(args) < 1:
        sys.exit("mandatory argument FCD_FILE missing")
    options.fcdfiles = args

    if options.filterRoute is not None:
        options.filterRoute = options.filterRoute.split(',')
    if options.filterEdges is not None:
        options.filterEdges = set(options.filterEdges.split(','))
    if options.filterIDs is not None:
        options.filterIDs = set(options.filterIDs.split(','))
    return options
Exemplo n.º 12
0
def get_options(args=None):
    op = ArgumentParser()
    op.add_option("-n",
                  "--net-file",
                  dest="netfile",
                  help="define the net filename (mandatory)")
    op.add_option("-r",
                  "--route-files",
                  dest="routefiles",
                  help="define the route file seperated by comma (mandatory)")
    op.add_option("-o",
                  "--output-file",
                  dest="outfile",
                  help="define the output filename")
    op.add_option("-t",
                  "--typesfile",
                  dest="typesfile",
                  help="Give a typesfile")
    op.add_option(
        "-d",
        "--duration",
        help=
        "Define duration of vehicle stop (setting 'X-Y' picks randomly from [X,Y[)"
    )
    op.add_option("-u", "--until", help="Define end time of vehicle stop")
    op.add_option("-p",
                  "--parking",
                  dest="parking",
                  action="store_true",
                  default=False,
                  help="where is the vehicle parking")
    op.add_option(
        "--relpos",
        help="relative stopping position along the edge [0,1] or 'random'")
    op.add_option(
        "--lane",
        default="0",
        help=
        "set index of stop lane or 'random' (unusable lanes are not counted)")
    op.add_option(
        "--reledge",
        default="1",
        help=
        "relative stopping position along the route [0,1] or 'random' (1 indicates the last edge)"
    )
    op.add_option("--probability",
                  type=float,
                  default=1,
                  help="app stop with the given probability ]0, 1]")
    op.add_option(
        "--parking-areas",
        dest="parkingareas",
        default=False,
        help=
        "load parkingarea definitions and stop at parkingarea on the arrival edge if possible"
    )
    op.add_option("--start-at-stop",
                  dest="startAtStop",
                  action="store_true",
                  default=False,
                  help="shorten route so it starts at stop")
    op.add_option("--rel-occupancy",
                  dest="relOccupancy",
                  type=float,
                  help="fill all parkingAreas to relative occupancy")
    op.add_option("--abs-occupancy",
                  dest="absOccupancy",
                  type=int,
                  default=1,
                  help="fill all parkingAreas to absolute occupancy")
    op.add_option("--abs-free",
                  dest="absFree",
                  type=int,
                  help="fill all parkingAreas to absolute remaining capacity")
    op.add_option(
        "-D",
        "--person-duration",
        dest="pDuration",
        help=
        "Define duration of person stop (setting 'X-Y' picks randomly from [X,Y[)"
    )
    op.add_option("-U",
                  "--person-until",
                  dest="pUntil",
                  help="Define end time of person stop")
    op.add_option("-s", "--seed", type=int, default=42, help="random seed")
    op.add_option("-v",
                  "--verbose",
                  dest="verbose",
                  action="store_true",
                  default=False,
                  help="tell me what you are doing")

    (options, args) = op.parse_known_args(args=args)

    if options.parkingareas:
        options.parkingareas = options.parkingareas.split(",")

    if not options.routefiles:
        if not options.startAtStop:
            op.print_help()
            sys.exit("--route-files missing")
        elif not options.parkingareas:
            sys.exit(
                "--parking-areas needed to generation stationary traffic without route-files"
            )
        else:
            options.routefiles = []
            if not options.outfile:
                options.outfile = options.parkingareas[0][:-4] + ".stops.xml"
    else:
        options.routefiles = options.routefiles.split(',')
        if not options.outfile:
            options.outfile = options.routefiles[0][:-4] + ".stops.xml"

    if not options.netfile:
        op.print_help()
        sys.exit("--net-file missing")

    if not options.typesfile:
        options.typesfile = options.routefiles
    else:
        options.typesfile = options.typesfile.split(",")

    if not options.duration and not options.until:
        op.print_help()
        sys.exit("stop duration or until missing")

    if options.relpos is not None:
        try:
            options.relpos = max(0, min(1, float(options.relpos)))
        except ValueError:
            if options.relpos != 'random':
                sys.exit(
                    "option --relpos must be set to 'random' or to a float value from [0,1]"
                )
            pass

    if options.lane is not None:
        try:
            options.lane = int(options.lane)
            if options.lane < 0:
                sys.exit(
                    "option --lane must be set to 'random' or to a non-negative integer value"
                )
        except ValueError:
            if options.lane != 'random':
                sys.exit(
                    "option --lane must be set to 'random' or to an integer value"
                )
            pass

    if options.reledge is not None:
        try:
            options.reledge = max(0, min(1, float(options.reledge)))
        except ValueError:
            if options.reledge != 'random':
                sys.exit(
                    "option --reledge must be set to 'random' or to a float value from [0,1]"
                )
            pass

    return options
Exemplo n.º 13
0
def get_options(args=None):
    optParser = ArgumentParser()
    optParser.add_option("-n",
                         "--net-file",
                         dest="netfile",
                         help="define the net filename (mandatory)")
    optParser.add_option(
        "-r",
        "--route-files",
        dest="routefiles",
        help="define the route file seperated by comma (mandatory)")
    optParser.add_option("-o",
                         "--output-file",
                         dest="outfile",
                         help="define the output filename")
    optParser.add_option("-t",
                         "--typesfile",
                         dest="typesfile",
                         help="Give a typesfile")
    optParser.add_option("-d",
                         "--duration",
                         help="Define duration of vehicle stop")
    optParser.add_option("-u",
                         "--until",
                         help="Define end time of vehicle stop")
    optParser.add_option("-p",
                         "--parking",
                         dest="parking",
                         action="store_true",
                         default=False,
                         help="where is the vehicle parking")
    optParser.add_option(
        "--parking-areas",
        dest="parkingareas",
        default=False,
        help=
        "load parkingarea definitions and stop at parkingarea on the arrival edge if possible"
    )
    optParser.add_option("--start-at-stop",
                         dest="startAtStop",
                         action="store_true",
                         default=False,
                         help="shorten route so it starts at stop")
    optParser.add_option("--rel-occupancy",
                         dest="relOccupancy",
                         type=float,
                         help="fill all parkingAreas to relative occupancy")
    optParser.add_option("--abs-occupancy",
                         dest="absOccupancy",
                         type=int,
                         default=1,
                         help="fill all parkingAreas to absolute occupancy")
    optParser.add_option(
        "--abs-free",
        dest="absFree",
        type=int,
        help="fill all parkingAreas to absolute remaining capacity")
    optParser.add_option("-D",
                         "--person-duration",
                         dest="pDuration",
                         help="Define duration of person stop")
    optParser.add_option("-U",
                         "--person-until",
                         dest="pUntil",
                         help="Define end time of person stop")
    optParser.add_option("-v",
                         "--verbose",
                         dest="verbose",
                         action="store_true",
                         default=False,
                         help="tell me what you are doing")

    (options, args) = optParser.parse_known_args(args=args)

    if options.parkingareas:
        options.parkingareas = options.parkingareas.split(",")

    if not options.routefiles:
        if not options.startAtStop:
            optParser.print_help()
            sys.exit("--route-files missing")
        elif not options.parkingareas:
            sys.exit(
                "--parking-areas needed to generation stationary traffic without route-files"
            )
        else:
            options.routefiles = []
            if not options.outfile:
                options.outfile = options.parkingareas[0][:-4] + ".stops.xml"
    else:
        options.routefiles = options.routefiles.split(',')
        if not options.outfile:
            options.outfile = options.routefiles[0][:-4] + ".stops.xml"

    if not options.netfile:
        optParser.print_help()
        sys.exit("--net-file missing")

    if not options.typesfile:
        options.typesfiles = options.routefiles

    if not options.duration and not options.until:
        optParser.print_help()
        sys.exit("stop duration or until missing")
    return options
Exemplo n.º 14
0
def get_options(args=None):
    argParser = ArgumentParser()
    argParser.add_argument("-t", "--tripinfo-file", dest="tripinfoFile",
                           help="tripinfo file written by the simulation")
    argParser.add_argument("-a", "--attribute", default="duration",
                           help="attribute to use for statistics")
    argParser.add_argument("-o", "--output", help="the output file")
    argParser.add_argument("-i", "--interval", help="custom aggregation interval (seconds or H:M:S)")
    argParser.add_argument("--by-arrivals", action="store_true", default=False, dest="byArrivals",
                           help="When using --interval, aggregated by arrival time instead of depart time")
    options = argParser.parse_args(args=args)
    if not options.tripinfoFile:
        sys.exit("Required argument --tripinfo-file is missing")

    if options.interval is not None:
        options.interval = parseTime(options.interval)
    return options
Exemplo n.º 15
0
def main():
    argParser = ArgumentParser()
    db_manipulator.add_db_arguments(argParser)
    argParser.add_argument("-n", "--net-file",
                           help="specifying the net file of the scenario to use")
    argParser.add_argument("-k", "--simkey", default="test",
                           help="simulation key to use")
    argParser.add_argument("-l", "--limit", type=int,
                           help="maximum number of trips to retrieve")
    argParser.add_argument("--representatives", default="",
                           help="set the route alternatives file to read representative travel times from")
    argParser.add_argument("--real-trips", default="",
                           help="set the route file to read travel times for real trips from")
    argParser.add_argument("-a", "--all-pairs",
                           default=False, action="store_true",
                           help="Only write the all pairs table")
    options, args = argParser.parse_known_args()
    if len(args) == 2:
        aggregate_weights(args[0], [float(x) for x in args[1].split(",")])
        return
    conn = db_manipulator.get_conn(options)
    if os.path.isfile(options.real_trips) and not options.all_pairs:
        upload_trip_results(conn, options.simkey, SP.OPTIONAL, options.real_trips, options.limit)
    if os.path.isfile(options.representatives):
        tables = create_all_pairs(conn, options.simkey, SP.OPTIONAL)
        upload_all_pairs(conn, tables, 0, 86400, "passenger", options.real_trips,
                         options.representatives, readNet(options.net_file), [])
    conn.close()
Exemplo n.º 16
0
        print("running pre test instructions")
        run_instructions(options, pre_test)
    process_db_manipulator = None
    if par_test:
        # run as parallel process
        print("starting parallel test instructions")
        process_db_manipulator = multiprocessing.Process(
            target=run_instructions, args=(options, par_test))
        process_db_manipulator.start()
    print("starting main")
    sys.stdout.flush()
    subprocess.call(call)
    sys.stdout.flush()
    sys.stderr.flush()
    if process_db_manipulator:
        print("waiting for parallel test")
        process_db_manipulator.join()
    if post_test:
        print("running post test instructions")
        run_instructions(options, post_test)


if __name__ == "__main__":
    argParser = ArgumentParser()
    add_db_arguments(argParser)
    argParser.add_argument("sqlfile", nargs="*", help="SQL files to process")
    options = argParser.parse_args()
    # get connection to (test) db
    print('using server', options)
    run_instructions(options, [open(o) for o in options.sqlfile])