Пример #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)
Пример #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