Anonymous Anonymous - 1 month ago
163 0

No description

Python

euclid

index = 0
    busla = bus_stop_coordinates[0]
    buslo = bus_stop_coordinates[1]
    finalT = trip.index[0]

    curr = 0
    euclid = math.sqrt((busla - trip.iloc[0]['lat'])**2 + (buslo - trip.iloc[0]['lon'])**2)
    
    
#     trip = trip.copy()
#     trip['euclid'] = (trip['lat'],trip['lon'])
#     trip['euclid'] = trip.apply(lambda row : math.sqrt((busla - row['lat'])**2 + (buslo - row['lon'])**2), axis=1)

#     finalT = trip.ix[trip['euclid'].idxmin()].tmstmp

#     trip = trip.sort_values(by='tmstmp')
   
    for i in trip.iterrows():

        row = i[1]

            
        currEuc = math.sqrt((busla - row['lat'])**2 + (buslo - row['lon'])**2)

        if currEuc < euclid:
            if currEuc == euclid:

                finalT = min(finalT, i[0])
            else:
                finalT = i[0]
            euclid = currEuc
            index = curr
        curr+=1

#     (finalT, euc) = min(minA, key = lambda t: t[1])
#     trip = trip[(trip.tmstmp <= finalT) | (trip.euclid == euclid)]
    trip = trip.head(index+1)
#     trip = trip.drop(trip[(trip.tmstmp == finalT) and (math.sqrt((busla - trip.lat)**2 + (buslo - trip.lon)**2) != euclid)])
    
    trip = trip.copy()

    
  
    trip['eta'] = trip.index

    trip['eta'] = trip['eta'].apply(lambda x: (finalT-x).total_seconds() / 60)

#     print trip['eta']
#     trip['eta'] = ((finalT-trip.index).total_seconds() / 60)


    return trip