def cool_form(): if request.method == 'POST': # do stuff when the form is submitted # redirect to end the POST handling # the redirect can be to the same route or somewhere else return redirect(geojsonio.make_url(contents)) # show the form, it wasn't submitted return render_template('cool_form.html')
def test_factory_gist(features): contents = json.dumps(features) size = len(contents) with mock.patch.object(github3.GitHub, 'create_gist') as MockInstance: class Dummy(object): id = 'abc123' MockInstance.return_value = Dummy() url = geojsonio.make_url(contents, size_for_gist=size-1) assert url == geojsonio.gist_url(Dummy.id)
def generate_map_urls(location, km, monumentbool, nr_of_mutations): routeGen = route.Route(pool_size=10, nr_mutants=10, nr_of_attempts=100, max_length_path=100, pref_dist=km) routeGen.import_file('../../maps/waterloo_small.osm') print 'file imported' # get the first node start_node = self.get_initial_node(location) print('initial start node: ' + str(start_node)) routeGen.setup_initial_pool(start_node) for i in range(0, nr_of_mutations): routeGen.mutation() routeGen.mutation() # routeGen.add_random_cycles(start_node) if i % 2 == 0: routeGen.cut_pool_size2() # final cut routeGen.final_cut() fitness = [0] * len(list(routeGen.pool)) # for i in range(0,len(list(routeGen.pool))): # route = routeGen.pool[i] # # find fitness # for node in list(route): # print node # fitness[i] += routeGen.nature_or_monuments(monumentbool, node) ind = fitness.index(max(fitness)) coords = osmgraph.tools.coordinates(routeGen.map, routeGen.pool[ind]) url = geojsonio.make_url( json.dumps({ 'type': 'LineString', 'coordinates': coords })) return url
def test_factory_data(features): contents = json.dumps(features) size = len(contents) url = geojsonio.make_url(contents, size_for_gist=size+1) assert url == geojsonio.data_url(contents)
# -*- coding: utf-8 -*- """ Created on Wed May 2 15:28:30 2018 @author: daniel """ import geojsonio from geojsonio import display with open('/home/daniel/workspaces/serrazul/geo/version_2/stations6.geojson' ) as f: contents = f.read() #print geojsonio.make_url(contents) #print contents display(contents) print geojsonio.make_url(contents)
def test_factory_data(features): contents = json.dumps(features) size = len(contents) url = geojsonio.make_url(contents, size_for_gist=size + 1) assert url == geojsonio.data_url(contents)
def generate_map_urls(location, km, monumentbool, nr_of_mutations): routeGen = Route(pool_size=10, nr_mutants=nr_of_mutations, nr_of_attempts=100, max_length_path=1000, pref_dist=km) routeGen.import_file('maps/maps_osm/waterloo_small.osm') print 'file imported' # get the first node start_node = routeGen.get_initial_node(location) print('initial start node: ' + str(start_node)) routeGen.setup_initial_pool(start_node) margin = 500 pool = [] while pool == []: routeGen.mutation() routeGen.mutation() # routeGen.add_random_cycles(start_node) routeGen.cut_pool_size2() pool = [ routeGen.total_distance(x) for x in routeGen.pool if ((km - margin) < routeGen.total_distance(x) < (km + margin)) ] print pool # final cut routeGen.final_cut(km) fitness = [0] * len(list(routeGen.pool)) if len(list(routeGen.pool)) > 0: for i in range(0, len(list(routeGen.pool))): route = routeGen.pool[i] route = np.random.choice(route, 5) # find fitness for node in list(route): fitness[i] += routeGen.nature_or_monuments(monumentbool, node) if np.any(fitness): # if not all zero print fitness print 'not all zero' ind = fitness.index(max(list(fitness))) else: print 'all zero' ind = random.choice(range(0, len(list(routeGen.pool)))) else: print 'only one' ind = random.choice(range(0, len(list(routeGen.pool)))) print ind coords = osmgraph.tools.coordinates(routeGen.map, routeGen.pool[ind]) url = geojsonio.make_url( json.dumps({ 'type': 'LineString', 'coordinates': coords })) return url
def index(): #return render_template('index.html') return redirect(geojsonio.make_url(contents))