예제 #1
0
파일: stats.py 프로젝트: flaxter/CityRank
def stats_detail(request, id):
	datasource = DataSource.objects.get(id=id)
	schemes = DataScheme.objects.filter(source=datasource)
	
	datasource.aggregate = datasource in request.session.get('sources_to_aggregate', DefaultSources)

	itemdata = [Data.objects.filter(source=datasource, scheme=scheme).order_by('item') for scheme in schemes]

	schema = [('Item', 'string')]
	order = ['Item']

	i = 0
	for scheme in schemes:
                schema.append((scheme.type + str(i), 'number', scheme.description))
		order.append(scheme.type + str(i))
		i += 1

	def get_values(v):
		return [x.value for x in v]

	items = [v.item for v in itemdata[0]]
	values = [v.value for v in itemdata[0]]
	decimals = schemes[0].decimals

	formatted_names = ["<a href=\"/items/%s\">%s</a>" % (v.item.name, v.item.name) for v in itemdata[0]]
	names = [v.item.name for v in itemdata[0]]

	itemdata = [get_values(v) for v in itemdata]	

	graph = zip(names, values)
	graph.sort(key=lambda x: x[1], reverse=(not schemes[0].sort_ascending))
		#graph.sort(lambda x, y: y[1] - x[1])
	order_string = "asc" if schemes[0].sort_ascending else "desc"

	table = DataTableYUI(schema, zip(formatted_names, *itemdata))

	graph_table = gviz_api.DataTable(schema, graph[:25])

	json_graph_table = graph_table.ToJSon(columns_order=order, order_by=(order[1], order_string))
	json_table = table.ToJSonYUI(columns_order=order, order_by=(order[1], order_string))
	json_map = utils.items_to_json(items, values, True)

	return render_response(request, 'items/stats_detail.html', {'datasource': datasource, 'titles': schemes, 'json_table': json_table, 'json_map': json_map, 'title': datasource.name, 'item_data': zip(items, values), 'json_graph_table': json_graph_table, 'decimals': decimals })
예제 #2
0
파일: views.py 프로젝트: flaxter/CityRank
def datasource_detail(request, id):
	datasource = DataSource.objects.get(id=id, active=True)
	schemes = DataScheme.objects.filter(source=datasource)
	
	datasource.aggregate = datasource in request.session.get('sources_to_aggregate', DefaultSources)

	itemdata = [Data.objects.filter(source=datasource, scheme=scheme).order_by('item') for scheme in schemes]

	schema = [('Item', 'string')]
	order = ['Item']

	i = 0
	for scheme in schemes:
		schema.append((scheme.type + str(i), 'number', scheme.description))
		order.append(scheme.type + str(i))
		i += 1

	def get_values(v):
		return [x.value for x in v]

	items = [v.item for v in itemdata[0]]
	ranks = [int(v.value) for v in itemdata[0]]
	values = [v.value for v in itemdata[1]]
	rankMax = [min(v,26) for v in ranks]

	formatted_names = ["<a href=\"/items/%s\">%s</a>" % (v.item.name, v.item.name) for v in itemdata[0]]
	names = [v.item.name for v in itemdata[0]]
	#print names
	itemdata = [get_values(v) for v in itemdata]	

	graph = zip(names, values)
	graph.sort(lambda x, y: int(y[1] - x[1]))

	table = DataTableYUI(schema, zip(formatted_names, *itemdata))
	graph_table = gviz_api.DataTable(schema, graph[:25])

	json_table = table.ToJSonYUI(columns_order=order, order_by=order[1])
	json_graph_table = graph_table.ToJSon(columns_order=order, order_by=order[1])
	json_map = utils.items_to_json(items, ranks, True)

	return render_response(request, 'items/ranking_detail.html', {'datasource': datasource, 'titles': schemes, 'json_table': json_table, 'json_graph_table': json_graph_table, 'json_map': json_map, 'title': datasource.name, 'item_data': zip(items, ranks, rankMax, values), 'ranking_id': request.session.get('ranking_id', 100) + 1})
예제 #3
0
파일: views.py 프로젝트: flaxter/CityRank
def item_list(request):
	items = Item.objects.all()

	class ItemsForm(forms.Form): 
		item = forms.ModelChoiceField(queryset=items)

	if request.method == 'POST':
		form = ItemsForm(request.POST)
		if form.is_valid():
			item = form.cleaned_data['item']
			#country = form.cleaned_data['country']
			return HttpResponseRedirect("/items/" + item.name)
	else:
		form = ItemsForm()

	countries = [c.tld.country_set.all()[0] for c in items]
	counts = [utils.sources_for_item(c).count() for c in items]

	json_map = utils.items_to_json(items, counts)

	return render_response(request, 'items/item_list.html', {'items': zip(items, countries),  'json_map': json_map, 'form': form })