def main(tripinfos, lengthThreshold=0.1):
    lengthThreshold = float(lengthThreshold)
    stats = Statistics('walkfactor')
    statsZeroDuration = Statistics('length of zero-duration walks')
    statsShort = Statistics('duration of short walks (length <= %s)' % lengthThreshold)
    numUnfinished = 0
    for personinfo in parse(tripinfos, 'personinfo'):
        if personinfo.hasChild('walk'):
            for i, walk in enumerate(personinfo.walk):
                if walk.arrival[0] == '-':
                    numUnfinished += 1
                    continue
                walkID = "%s.%s" % (personinfo.id, i)
                duration = float(walk.duration)
                routeLength = float(walk.routeLength)
                if duration > 0:
                    if routeLength <= lengthThreshold:
                        statsShort.add(duration, walkID)
                    else:
                        avgSpeed = routeLength / duration
                        walkFactor = avgSpeed / float(walk.maxSpeed)
                        stats.add(walkFactor, walkID)
                else:
                    statsZeroDuration.add(routeLength, walkID)

    print(stats)
    if statsZeroDuration.count() > 0:
        print(statsZeroDuration)
    if statsShort.count() > 0:
        print(statsShort)
    if numUnfinished > 0:
        print("unfinished walks: %s" % numUnfinished)
Пример #2
0
def main(tripinfos, lengthThreshold=0.1):
    lengthThreshold = float(lengthThreshold)
    stats = Statistics('walkfactor')
    statsZeroDuration = Statistics('length of zero-duration walks')
    statsShort = Statistics('duration of short walks (length <= %s)' % lengthThreshold)
    numUnfinished = 0
    for personinfo in parse(tripinfos, 'personinfo'):
        if personinfo.hasChild('walk'):
            for i, walk in enumerate(personinfo.walk):
                if walk.arrival[0] == '-':
                    numUnfinished += 1
                    continue
                walkID = "%s.%s" % (personinfo.id, i)
                duration = float(walk.duration)
                routeLength = float(walk.routeLength)
                if duration > 0:
                    if routeLength <= lengthThreshold:
                        statsShort.add(duration, walkID)
                    else:
                        avgSpeed = routeLength / duration
                        walkFactor = avgSpeed / float(walk.maxSpeed)
                        stats.add(walkFactor, walkID)
                else:
                    statsZeroDuration.add(routeLength, walkID)

    print(stats)
    if statsZeroDuration.count() > 0:
        print(statsZeroDuration)
    if statsShort.count() > 0:
        print(statsShort)
    if numUnfinished > 0:
        print("unfinished walks: %s" % numUnfinished)
Пример #3
0
def _get_all_pair_stats(roualt_file, net):
    """Parses a duarouter .rou.alt.xml output for travel times and calculates the route length.
    The file is supposed to contain only vehicles of a single vType"""
    sumoTime = Statistics("SUMO durations")
    sumoDist = Statistics("SUMO distances")
    for vehicle in output.parse(roualt_file, 'vehicle'):
        duration = float(vehicle.routeDistribution[0].route[0].cost)
        edges = vehicle.routeDistribution[0].route[0].edges.split()
        distance = sum(map(lambda e: net.getEdge(e).getLength(), edges))
        sumoTime.add(duration, vehicle.id)
        sumoDist.add(distance, vehicle.id)
        if sumoDist.count() % 10000 == 0:
            print("parsed %s taz representatives" % sumoDist.count())
        fromTaz, toTaz = _parseTaz(vehicle)
        yield fromTaz, toTaz, 1, duration, distance
    print(sumoTime)
    print(sumoDist)
Пример #4
0
def upload_all_pairs(conn, tables, start, end, vType, real_routes, rep_routes, net, taz_list, startIdx=0):
    stats = _parse_vehicle_info_taz(real_routes, start, end, vType)
    stats.extend(_get_all_pair_stats(rep_routes, net))
    stats.sort()
    min_samples = 5
    last = None
    values = []
    sumoTime = Statistics("SUMO durations")
    sumoDist = Statistics("SUMO distances")
    real = 0
    remain = set([(o, d) for o in taz_list for d in taz_list])
    for source, dest, faked, duration, dist in stats:
        if (source, dest) != last:
            if last is not None:
                values.append(_createValueTuple(last, vType, end, real, sumoTime, sumoDist))
                remain.discard(last)
                sumoTime = Statistics("SUMO durations")
                sumoDist = Statistics("SUMO distances")
                real = 0
            last = (source, dest)
        if not faked or sumoTime.count() < min_samples:
            if not faked:
                real += 1
            sumoTime.add(duration)
            sumoDist.add(dist)
    if last is not None:
        values.append(_createValueTuple(last, vType, end, real, sumoTime, sumoDist))
        remain.discard(last)
    if remain:
        print("inserting dummy data for %s unconnected O-D relations" % len(remain))
        for o, d in remain:
            values.append(_createValueTuple((o, d), vType, end))
    cursor = conn.cursor()
    # insert values
    odValues = []
    entryValues = []
    for idx, v in enumerate(values):
        odValues.append(str(v[:4] + (startIdx + idx,)))
        entryValues.append(str(v[4:] + (startIdx + idx, "{car}")))
    odQuery = """INSERT INTO temp.%s (taz_id_start, taz_id_end, sumo_type, interval_end, entry_id)
VALUES %s""" % (tables[0], ','.join(odValues))
    cursor.execute(odQuery)
    insertQuery = """INSERT INTO temp.%s (realtrip_count, representative_count,
 travel_time_sec, travel_time_stddev, distance_real, distance_stddev, entry_id, used_modes)
VALUES %s""" % (tables[1], ','.join(entryValues))
    cursor.execute(insertQuery)
    conn.commit()
    return startIdx + len(values)