Example #1
0
def predictions(points, hazards = [], hazard_decrease = .5):
    count = 0
    prev_point = None

    speeds = []
    next_locations = []
    for point in points:
        if prev_point != None:
            l1 = (point.latitude, point.longitude)
            l2 = (prev_point.latitude, prev_point.longitude)

            distance = geo.calculate_distance(l1,l2)
            time = point.timestamp - prev_point.timestamp
            speed = geo.speed(distance, time)

            predict = geo.predict_next_location(l2, l1, time, time)
            error = geo.error(l2,predict)

            speeds.append(speed * 1000)
            next_locations.append(predict)
            print(error)
        prev_point = point
        count += 1

    return speeds, next_locations
import geo_utils as geo
import time

if __name__ == '__main__':
    start=time.time()

    point1 = (39.525498,89.534926)
    point2 = (39.498231,89.479093)
    point3 = (39.470964,89.42326) #(39.45178619542422, 89.4516830045628)

    nextPoint = geo.predict_next_location(point1, point2, 300, 300)
    print(nextPoint)
    timeToPoint = geo.calculate_time(point1, point3, .008)/60
    print(timeToPoint, " minutes")

    error = geo.error(nextPoint, point3)
    print("Error: ", error, " km")

    end=time.time()
    cost = end - start
    print("Cost: " , cost , " seconds")