Ejemplo n.º 1
0
def main():
	facet_id = 'habitat_type.substrate.id'
	facet_label = 'Substrates'
	facet_type = 'multiselect'
	id_field = 'habitat_type.substrate.id'
	label_field = 'habitat_type.substrate.name'
	value_field = 'area'
	filters = []
	aggregate_func = 'sum'

	choice_facet = habitat_services.get_choice_facet(
			id_field=id_field, 
			value_field=value_field, 
			label_field=label_field, 
			filters=filters, 
			aggregate_func=aggregate_func
			)
	#print choice_facet

	numeric_facet = habitat_services.get_numeric_facet(
			grouping_field={ 'id':'z', 'transform': '-1 * {field}' },
			value_field={'id': 'area'},
			filters=[
				{'field': 'habitat_type.substrate.id', 'op': 'in', 'value': ['S1']}
				]
			)

	totals = habitat_services.get_totals(value_field='area', filters=[])
	#print totals

	# Test aggregates.
	value_fields = [
			{
				'id': 'area',
				'aggregate_funcs': ['sum']
				}
			]

	grouping_fields = [
			#{'id': "habitat_type.substrate.id", 'label': 'substrate_id', 'label_field': {'id': 'habitat_type.substrate.name'}, 'all_values': True},
			{ 'id':'z', 'transform': '-1 * {field}', 'as_histogram': True, 'all_values': True},
			]
	filters = []
	aggregates = habitat_services.get_aggregates(
			value_fields = value_fields,
			grouping_fields = grouping_fields,
			filters = filters
			)
	#print aggregates

	# Test aggregates w/ unfiltered.
	uf_aggregates = habitat_services.get_aggregates(
			value_fields = value_fields,
			grouping_fields = grouping_fields,
			filters = [ 
				{'field': 'habitat_type.substrate.id', 'op': 'in', 'value': ['S1']}
				],
			with_unfiltered = True
			)
Ejemplo n.º 2
0
def get_aggregates():

	value_fields_json = request.args.get('VALUE_FIELDS', '')
	if value_fields_json: value_fields = json.loads(value_fields_json)
	else: value_fields= []

	grouping_fields_json = request.args.get('GROUPING_FIELDS', '')
	if grouping_fields_json: grouping_fields = json.loads(grouping_fields_json)
	else: grouping_fields = []

	filters_json = request.args.get('FILTERS','[]')
	if filters_json: filters = json.loads(filters_json)
	else: filters = []

	with_unfiltered = request.args.get('WITH_UNFILTERED','FALSE')
	if with_unfiltered == 'TRUE': with_unfiltered = True
	else: with_unfiltered = False

	base_filters_json = request.args.get('BASE_FILTERS','[]')
	if base_filters_json: base_filters = json.loads(base_filters_json)
	else: base_filters = []

	aggregates = habitat_services.get_aggregates(
			value_fields=value_fields,
			grouping_fields=grouping_fields,
			filters=filters,
			with_unfiltered=with_unfiltered,
			base_filters=base_filters
			)

	return Response(json.dumps(aggregates, indent=2), mimetype='application/json')