def getBasicStats(verbose, method, vehicles, assignments): totalVeh = 0. totalTravelTime = 0. totalTravelLength = 0. totalTravelSpeed = 0. totalWaitTime = 0. totalDiffTime = 0. totalDiffSpeed = 0. totalDiffLength = 0. totalDiffWaitTime = 0. totalDiffTravelTime = 0. totalDepartDelay = 0. for veh in vehicles: totalVeh += 1 veh.method = method # unit: speed - m/s; traveltime - s; travel length - m veh.speed = veh.travellength / veh.traveltime totalTravelTime += veh.traveltime totalTravelLength += veh.travellength totalWaitTime += veh.waittime totalTravelSpeed += veh.speed totalDepartDelay += veh.departdelay if verbose: print 'totalVeh:', totalVeh totalVehDivisor = max(1, totalVeh) # avoid division by 0 avgTravelTime = totalTravelTime / totalVehDivisor avgTravelLength = totalTravelLength / totalVehDivisor avgTravelSpeed = totalTravelSpeed / totalVehDivisor avgWaitTime = totalWaitTime / totalVehDivisor avgDepartDelay = totalDepartDelay / totalVehDivisor for veh in vehicles: totalDiffTravelTime += (veh.traveltime - avgTravelTime)**2 totalDiffSpeed += (veh.speed - avgTravelSpeed)**2 totalDiffLength += (veh.travellength - avgTravelLength)**2 totalDiffWaitTime += (veh.waittime - avgWaitTime)**2 #SD: standard deviation SDTravelTime = (totalDiffTravelTime / totalVehDivisor)**(0.5) SDLength = (totalDiffLength / totalVehDivisor)**(0.5) SDSpeed = (totalDiffSpeed / totalVehDivisor)**(0.5) SDWaitTime = (totalDiffWaitTime / totalVehDivisor)**(0.5) assignments[method] = Assign(method, totalVeh, totalTravelTime, totalTravelLength, totalDepartDelay, totalWaitTime, avgTravelTime, avgTravelLength, avgTravelSpeed, avgDepartDelay, avgWaitTime, SDTravelTime, SDLength, SDSpeed, SDWaitTime)
def getBasicStats(verbose, method, vehicles, assignments): totalVeh = 0. totalTravelTime = 0. totalTravelLength = 0. totalTravelSpeed = 0. totalWaitTime = 0. totalDiffSpeed = 0. totalDiffLength = 0. totalDiffWaitTime = 0. totalDiffTravelTime = 0. totalDepartDelay = 0. for veh in vehicles: totalVeh += 1 veh.method = method # unit: speed - m/s; traveltime - s; travel length - m veh.speed = veh.travellength / veh.traveltime totalTravelTime += veh.traveltime totalTravelLength += veh.travellength totalWaitTime += veh.waittime totalTravelSpeed += veh.speed totalDepartDelay += veh.departdelay if verbose: print('totalVeh:', totalVeh) totalVehDivisor = max(1, totalVeh) # avoid division by 0 avgTravelTime = totalTravelTime / totalVehDivisor avgTravelLength = totalTravelLength / totalVehDivisor avgTravelSpeed = totalTravelSpeed / totalVehDivisor avgWaitTime = totalWaitTime / totalVehDivisor avgDepartDelay = totalDepartDelay / totalVehDivisor for veh in vehicles: totalDiffTravelTime += (veh.traveltime - avgTravelTime)**2 totalDiffSpeed += (veh.speed - avgTravelSpeed)**2 totalDiffLength += (veh.travellength - avgTravelLength)**2 totalDiffWaitTime += (veh.waittime - avgWaitTime)**2 # SD: standard deviation SDTravelTime = (totalDiffTravelTime / totalVehDivisor)**(0.5) SDLength = (totalDiffLength / totalVehDivisor)**(0.5) SDSpeed = (totalDiffSpeed / totalVehDivisor)**(0.5) SDWaitTime = (totalDiffWaitTime / totalVehDivisor)**(0.5) assignments[method] = Assign(method, totalVeh, totalTravelTime, totalTravelLength, totalDepartDelay, totalWaitTime, avgTravelTime, avgTravelLength, avgTravelSpeed, avgDepartDelay, avgWaitTime, SDTravelTime, SDLength, SDSpeed, SDWaitTime) data = [[ "totalVeh", "totalTravelTime", "totalTravelLength", "totalDepartDelay", "totalWaitTime", "avgTravelTime", "avgTravelLength", "avgTravelSpeed", "avgDepartDelay" ], [ totalVeh, totalTravelTime, totalTravelLength, totalDepartDelay, totalWaitTime, avgTravelTime, avgTravelLength, avgTravelSpeed, avgDepartDelay ]] csvfile = options.outputfile f = open(str(csvfile) + '.csv', 'w') with f: writer = csv.writer(f) writer.writerows(data)
def getBasicStats(verbose, method, vehicles, assignments): totalVeh = 0. totalTravelTime = 0. totalTravelLength = 0. totalTravelSpeed = 0. totalWaitTime = 0. totalDiffSpeed = 0. totalDiffLength = 0. totalDiffWaitTime = 0. totalDiffTravelTime = 0. totalDepartDelay = 0. priorityTotalVeh = dict() priorityTotalTravelTime = dict() priorityTotalTravelLength = dict() priorityTotalTravelSpeed = dict() priorityTotalWaitTime = dict() priorityTotalDiffTime = dict() priorityTotalDiffSpeed = dict() priorityTotalDiffLength = dict() priorityTotalDiffWaitTime = dict() priorityTotalDiffTravelTime = dict() priorityTotalDepartDelay = dict() priorityAvgTravelTime = dict() priorityAvgTravelLength = dict() priorityAvgTravelSpeed = dict() priorityAvgWaitTime = dict() priorityAvgDepartDelay = dict() for veh in vehicles: t = veh.vType totalVeh += 1 veh.method = method # unit: speed - m/s; traveltime - s; travel length - m veh.speed = veh.travellength / veh.traveltime totalTravelTime += veh.traveltime totalTravelLength += veh.travellength totalWaitTime += veh.waittime totalTravelSpeed += veh.speed totalDepartDelay += veh.departdelay if (not priorityTotalVeh.has_key(t)): priorityTotalVeh[t] = 0 priorityTotalTravelTime[t] = 0 priorityTotalTravelLength[t] = 0 priorityTotalWaitTime[t] = 0 priorityTotalTravelSpeed[t] = 0 priorityTotalDepartDelay[t] = 0 priorityTotalVeh[t] += 1 priorityTotalTravelTime[t] += veh.traveltime priorityTotalTravelLength[t] += veh.travellength priorityTotalWaitTime[t] += veh.waittime priorityTotalTravelSpeed[t] += veh.speed priorityTotalDepartDelay[t] += veh.departdelay if verbose: print('totalVeh:', totalVeh) for key in priorityTotalVeh: totalVehDivisor = max(1, priorityTotalVeh[key]) # avoid division by 0 priorityAvgTravelTime[ key] = priorityTotalTravelTime[key] / totalVehDivisor priorityAvgTravelLength[ key] = priorityTotalTravelLength[key] / totalVehDivisor priorityAvgTravelSpeed[ key] = priorityTotalTravelSpeed[key] / totalVehDivisor priorityAvgWaitTime[key] = priorityTotalWaitTime[key] / totalVehDivisor priorityAvgDepartDelay[ key] = priorityTotalDepartDelay[key] / totalVehDivisor totalVehDivisor = max(1, totalVeh) # avoid division by 0 avgTravelTime = totalTravelTime / totalVehDivisor avgTravelLength = totalTravelLength / totalVehDivisor avgTravelSpeed = totalTravelSpeed / totalVehDivisor avgWaitTime = totalWaitTime / totalVehDivisor avgDepartDelay = totalDepartDelay / totalVehDivisor for veh in vehicles: t = veh.vType if not priorityTotalDiffTravelTime.has_key(t): priorityTotalDiffSpeed[t] = 0 priorityTotalDiffLength[t] = 0 priorityTotalDiffWaitTime[t] = 0 priorityTotalDiffTravelTime[t] = 0 priorityTotalDiffTravelTime[t] += (veh.traveltime - priorityAvgTravelTime[t])**2 priorityTotalDiffSpeed[t] += (veh.speed - priorityAvgTravelSpeed[t])**2 priorityTotalDiffLength[t] += (veh.travellength - priorityAvgTravelLength[t])**2 priorityTotalDiffWaitTime[t] += (veh.waittime - priorityAvgWaitTime[t])**2 totalDiffTravelTime += (veh.traveltime - avgTravelTime)**2 totalDiffSpeed += (veh.speed - avgTravelSpeed)**2 totalDiffLength += (veh.travellength - avgTravelLength)**2 totalDiffWaitTime += (veh.waittime - avgWaitTime)**2 # SD: standard deviation SDTravelTime = (totalDiffTravelTime / totalVehDivisor)**(0.5) SDLength = (totalDiffLength / totalVehDivisor)**(0.5) SDSpeed = (totalDiffSpeed / totalVehDivisor)**(0.5) SDWaitTime = (totalDiffWaitTime / totalVehDivisor)**(0.5) for key in priorityTotalVeh: prioritySDTravelTime = (priorityTotalDiffTravelTime[key] / totalVehDivisor)**(0.5) prioritySDLength = (priorityTotalDiffLength[key] / totalVehDivisor)**(0.5) prioritySDSpeed = (priorityTotalDiffSpeed[key] / totalVehDivisor)**(0.5) prioritySDWaitTime = (priorityTotalDiffWaitTime[key] / totalVehDivisor)**(0.5) assignments[method + key] = Assign( method + key, priorityTotalVeh[key], priorityTotalTravelTime[key], priorityTotalTravelLength[key], priorityTotalDepartDelay[key], priorityTotalWaitTime[key], priorityAvgTravelTime[key], priorityAvgTravelLength[key], priorityAvgTravelSpeed[key], priorityAvgDepartDelay[key], priorityAvgWaitTime[key], prioritySDTravelTime, prioritySDLength, prioritySDSpeed, prioritySDWaitTime) assignments[method] = Assign(method, totalVeh, totalTravelTime, totalTravelLength, totalDepartDelay, totalWaitTime, avgTravelTime, avgTravelLength, avgTravelSpeed, avgDepartDelay, avgWaitTime, SDTravelTime, SDLength, SDSpeed, SDWaitTime)