def stoptime( request, id ): stoptime = StopTime.objects.get(pk=id) runs = VehicleUpdate.runs( stoptime.trip_id ) events = [] for run in runs: for vu1, vu2 in cons( run.vps ): if vu1.percent_along_trip <= stoptime.percent_along_trip and \ vu2.percent_along_trip >= stoptime.percent_along_trip: dt = vu2.data_timestamp - vu1.data_timestamp ds = vu2.percent_along_trip - vu1.percent_along_trip ds_prime = stoptime.percent_along_trip - vu1.percent_along_trip if ds == 0: percent_of_interval = 1 else: percent_of_interval = ds_prime/ds interpolated_time = percent_of_interval*dt + vu1.data_timestamp events.append( {'vu1':vu1, 'vu2':vu2, 'time':datetime.fromtimestamp(interpolated_time),'timestamp':interpolated_time} ) #meantime = sum([x['timestamp'] for x in events])/len(events) #stddev = find_stddev( [x['timestamp'] for x in events] ) return HttpResponse( render_to_response( "stoptime.html", {'stoptime':stoptime, 'events':events} ) )
def run(request, trip_id, start_date): run = VehicleUpdate.runs( trip_id, start_date )[0] trip = run.trip stoptimes = trip.stoptime_set.all().order_by('departure_time').select_related( 'stop' ) shape = trip.shape run.set_vehicle_position_deviation_metadata( shape, stoptimes ) return render_to_response( 'run.html', {'vps':run.vps} )
def run(request, trip_id, start_date): run = VehicleUpdate.runs(trip_id, start_date)[0] trip = run.trip stoptimes = trip.stoptime_set.all().order_by( 'departure_time').select_related('stop') shape = trip.shape run.set_vehicle_position_deviation_metadata(shape, stoptimes) return render_to_response('run.html', {'vps': run.vps})
def stoptime(request, id): stoptime = StopTime.objects.get(pk=id) runs = VehicleUpdate.runs(stoptime.trip_id) events = [] for run in runs: for vu1, vu2 in cons(run.vps): if vu1.percent_along_trip <= stoptime.percent_along_trip and \ vu2.percent_along_trip >= stoptime.percent_along_trip: dt = vu2.data_timestamp - vu1.data_timestamp ds = vu2.percent_along_trip - vu1.percent_along_trip ds_prime = stoptime.percent_along_trip - vu1.percent_along_trip if ds == 0: percent_of_interval = 1 else: percent_of_interval = ds_prime / ds interpolated_time = percent_of_interval * dt + vu1.data_timestamp events.append({ 'vu1': vu1, 'vu2': vu2, 'time': datetime.fromtimestamp(interpolated_time), 'timestamp': interpolated_time }) #meantime = sum([x['timestamp'] for x in events])/len(events) #stddev = find_stddev( [x['timestamp'] for x in events] ) return HttpResponse( render_to_response("stoptime.html", { 'stoptime': stoptime, 'events': events }))