Exemple #1
0
def analysis(request):
	if request.method == 'POST':
		num_centroids = int(request.POST.get('num_centroids'))
		num_points = int(request.POST.get('num_points'))

		pc = MongoDB.list_all_postal_codes()

		list_analysis = []
		i = 0
		while i < num_points:
			r = random.randint(0, (len(pc)-1))
			list_analysis.append(pc.pop(r))
			i += 1

		points, centroids = k_means.k_means_lists(num_centroids, 20, list_analysis)
		dic = k_means.sse(points, centroids)
		regions, table = viewLists.listTableMoreInputs()

		t = get_template('analysis.html')
		html = t.render(
			Context(
				{
				'regions' : regions,
				'table': table,
				'center' : "-23.2062436,-45.900007" ,
				'localizations' : points,
				'colors' : ColorsRandom.generate_colors(num_centroids),
				'centroids' : centroids,
				'sse' : dic,
				'hospitals' : MongoDB.list_all_healths(),
				'csrf_token' : csrf(request)['csrf_token']
				}
			)
		)
		html = html.replace("&#39;", "'")
		return HttpResponse(html)

	# return render_to_response(
	# 	'index.html',
	# 	context_instance=RequestContext(request))
	regions, table = viewLists.listTableMoreInputs()
	t = get_template('index.html')
	html = t.render(
		Context(
			{
			'regions' : regions,
			'table': table,
			'csrf_token' : csrf(request)['csrf_token']
			}
		)
	)
	html = html.replace("&#39;", "'")
	return HttpResponse(html)
Exemple #2
0
def randomCIDs(quantity=0):
	"""
	Cria uma quantidade aleatória de CIDs para utilizar e	
	Retorna um dictionary com todas os CIDs gerados, 
	uma lista com cada CIDs, com suas cores devidas, e 
	um dictionary com as cores para cada CID
	function(number) -> dictionary, list, dictionary
	"""
	from collections import Counter
	lista = MongoDB.list_all_cids()
	colors = ColorsRandom.parallel_gen_colors(quantity)
	randomList = []
	while len(randomList) < quantity:
		item = random.choice(lista)
		randomList.append(item['code'])

	dic = dict(Counter(randomList))

	colors = ColorsRandom.parallel_gen_colors(len(dic))

	dicColors = {}
	count = 0
	for i in dic:
		dicColors[i] = colors[count]
		count+=1

	latLng = []
	lista = MongoDB.list_all_postal_codes()
	while len(latLng) < quantity:
		cid = randomList.pop()
		item = random.choice(lista)
		latLng.append(
			[cid, item['lat'], item['lng'], dicColors[cid] ]
		)

	return dic, latLng, dicColors
Exemple #3
0
def locations(request):
	regions, table = viewLists.listTableMoreInputs()

	if request.method == 'POST':
		# center's maps
		num_clusters = int(request.POST.get('num_clusters'))

		colors = ColorsRandom.generate_colors(num_clusters)

		country = request.POST.get('country')
		state = request.POST.get('state')
		city = request.POST.get('city')
		center = Geocode.geocode([country + ' ' + state + ' ' + city, city], isCenter=True)
		center = str(center['lat']) + "," + str(center['lng'])
		
		# ceps's locations
		ceps_list = [ 
			[country + ' ' + 
			state + ' ' +
			city + ' ' +  
			i, i] for i in request.POST.get('ceps').split(';')]

		# items = Geocode.parallelGeocode(ceps_list)
		items = []
		for i in ceps_list:
			items.append(Geocode.geocode(i))

		points, centroids = k_means.k_means_lists(num_clusters, 20, items)

		dic = k_means.sse(points, centroids)

		t = get_template('maps.html')
		html = t.render(
			Context(
				{
				'regions' : regions,
				'table': table,
				'center' : center ,
				'localizations' : points,
				'colors' : colors,
				'centroids' : centroids,
				'sse' : dic,
				'hospitals' : MongoDB.list_all_healths(),
				'csrf_token' : csrf(request)['csrf_token']
				}
			)
		)
		html = html.replace("&#39;", "'")

		return HttpResponse(html)

	# return render_to_response(
	# 	'index.html',
	# 	context_instance=RequestContext(request))

	t = get_template('index.html')
	html = t.render(
		Context(
			{
			'regions' : regions,
			'table': table,
			'csrf_token' : csrf(request)['csrf_token']
			}
		)
	)
	html = html.replace("&#39;", "'")
	return HttpResponse(html)