from __future__ import print_function
import matplotlib.pyplot as plt
import random
import math
import folium
import pandas as pd
import numpy as np


#select a point to generate points around
pt = [46.086262,11.128824]

#load TT stops
stops = pd.read_csv("stops.txt")

#generate N points around pt.
temp = []
def generate_random_data(lon,lat, n_points):
    for _ in xrange(n_points):
            dec_lat = random.random()/10 # <-modify the denominator in order to change the radius
            dec_lon = random.random()/10 # <-
            temp.append((lon+dec_lon, lat+dec_lat))
    return pd.DataFrame(temp)

df = generate_random_data(pt[0],pt[1],20) # <- call the function and generate 20 points

map_1 = folium.Map(location=pt,zoom_start=12) # <- initialize a map

#populate the map with the random points
for i,row in df.iterrows():
    map_1.simple_marker((row[0],row[1]))


#create N tuples of the form (driver,rider,end)    
i = 0
while i<10: # <- create 10 tuples
    #get three point
    point1 = df.ix[i,0],df.ix[i,1]
    point2 = df.ix[i+1,0],df.ix[i+1,1] 
    point3 = stops['stop_lat'][random.randrange(len(stops))],stops['stop_lon'][random.randrange(len(stops))]
    #draw lines from driver->end,rider->end
    map_1.line((point1,point3))
    map_1.line((point2,point3))
    #build vectors and calculate angle in between
    v0 = np.array(point1)-np.array(point3)
    v1 = np.array(point2)-np.array(point3)
    angle = np.math.atan2(np.linalg.det([v0,v1]),np.dot(v0,v1))
    #name the end point. In this case I show the angle
    map_1.simple_marker(point3,popup=str(math.degrees(angle)))
    i += 2

map_1.create_map(path='simulation.html')
