Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #162 from azavea/feature/refactor-aggregations
Browse files Browse the repository at this point in the history
Refactor Time Aggregation
  • Loading branch information
rmartz authored Dec 21, 2016
2 parents d0abf6c + 61a2a0d commit 245c780
Show file tree
Hide file tree
Showing 8 changed files with 398 additions and 530 deletions.
24 changes: 17 additions & 7 deletions django/climate_change_api/climate_data/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ def climate_indicator(request, *args, **kwargs):
required: false
type: string
paramType: query
- name: time_aggregation
description: Time granularity to group data by for result structure. Valid aggregations
depend on indicator. Can be 'yearly', 'monthly' or 'daily'
required: false
type: string
paramType: query
- name: units
description: Units in which to return the data. Defaults to Imperial units (Fahrenheit for
temperature indicators and inches per day for precipitation).
Expand Down Expand Up @@ -298,18 +304,21 @@ def climate_indicator(request, *args, **kwargs):
aggregations = agg_param.split(',') if agg_param else None
years_param = request.query_params.get('years', None)
units_param = request.query_params.get('units', None)
time_aggregation = request.query_params.get('time_aggregation', None)

indicator_key = kwargs['indicator']
IndicatorClass = indicator_factory(indicator_key)
if not IndicatorClass:
raise ParseError(detail='Must provide a valid indicator')
data = IndicatorClass(city,
scenario,
models=models_param,
years=years_param,
serializer_aggregations=aggregations,
parameters=request.query_params,
units=units_param).calculate()
indicator = IndicatorClass(city,
scenario,
models=models_param,
years=years_param,
time_aggregation=time_aggregation,
serializer_aggregations=aggregations,
parameters=request.query_params,
units=units_param)
data = indicator.calculate()

if units_param and units_param not in IndicatorClass.available_units:
raise NotFound(detail='Cannot convert indicator {} to units {}.'.format(indicator_key,
Expand All @@ -323,6 +332,7 @@ def climate_indicator(request, *args, **kwargs):
('scenario', scenario.name),
('indicator', IndicatorClass.to_dict()),
('climate_models', [m.name for m in model_list]),
('time_aggregation', indicator.time_aggregation),
('units', units_param),
('data', data),
]))
Expand Down
Loading

0 comments on commit 245c780

Please sign in to comment.