예제 #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
			)
예제 #2
0
def get_numeric_facet():

	value_field_json = request.args.get('VALUE_FIELD', '')
	value_field = json.loads(value_field_json)

	grouping_field_json = request.args.get('GROUPING_FIELD', '')
	grouping_field = json.loads(grouping_field_json)

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

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

	facet = habitat_services.get_numeric_facet(
			value_field=value_field,
			grouping_field=grouping_field,
			base_filters=base_filters,
			filters=filters,
			)

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