Calculate quickest distance interval with (time, distance) data with SQLite? -
i have table of data taken gps device column 1 time, , column 2 distance. time elapsed time starting activity , distance total distance traveled start point.
i'm new sql , having trouble formatting command allows me find out quickest time traveled set distance, e.g. quickest km (or 5km, 10km etc)?
for instance if have table this
+----------+--------------+ | time (s) | distance (m) | +----------+--------------+ | 0 | 0 | | 15 | 10 | | 32 | 22 | | 40 | 34 | | 52 | 40 | +----------+--------------+
is there way output quickest time on distance of interest covered, e.g. quickest 20m? time , distance intervals aren't spaced, there have degree of interpolation.
so in summary,the inputs table of data , distance, , output time in distance covered.
here python gets result want data above.
#data in format [[time,distance],[time, distance]...] data = [[0,0],[15,10],[32,22],[40,34],[52,40]] #calculate distance , time interval between each data point start=0 result_array = [] while start < len(data): end= start+1 while end<len(data): distance_interval = data[end][1]-data[start][1] time_interval = data[end][0]-data[start][0] result_array.append([time_interval,distance_interval]) end+=1 start += 1 #this distance we're interested in distance_in_question = 20 gap = 9999 quickest_time = 9999 #find distance_interval closest distance in question , report associated time point in result_array: distance_interval = point[1] gap_test = distance_interval - distance_in_question if (gap_test>0) , (gap_test<gap): gap = gap_test quickest_time = point[0] #the result print quickest_time
we want compare each record each other (later) record, have join table itself:
select b.time - a.time mytable join mytable b on a.time < b.time b.distance - a.distance >= 20 order b.distance - a.distance limit 1
Comments
Post a Comment