Skip to content

Commit f280cef

Browse files
authored
CDF forecasts spec (#67)
* add CDF forecast schemas * add probabilistic forecasts * fix existing test paths * add descriptions to forecasts links fields * better descriptions, don't repeat axis field * test/ -> tests, value_type -> interval_value_type
1 parent 72252d8 commit f280cef

File tree

10 files changed

+372
-82
lines changed

10 files changed

+372
-82
lines changed

sfa_api/demo/forecasts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"run_length": 1440,
1111
"interval_label": "beginning",
1212
"lead_time_to_start": "60",
13-
"value_type": "mean",
13+
"interval_value_type": "mean",
1414
},
1515
'f8dd49fa-23e2-48a0-862b-ba0af6dec276': {
1616
"forecast_id": "f8dd49fa-23e2-48a0-862b-ba0af6dec276",
@@ -23,6 +23,6 @@
2323
"interval_length": 1,
2424
"interval_label": "beginning",
2525
"lead_time_to_start": 60,
26-
"value_type": "mean",
26+
"interval_value_type": "mean",
2727
}
2828
}

sfa_api/demo/observations.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"provider": "UO SRML",
99
"site_id": "123e4567-e89b-12d3-a456-426655440001",
1010
"variable": "ghi",
11-
"value_type": "interval_mean",
11+
"interval_value_type": "interval_mean",
1212
"interval_label": "beginning",
1313
"interval_length": 5
1414
},
@@ -21,7 +21,7 @@
2121
"provider": "UO SRML",
2222
"site_id": "123e4567-e89b-12d3-a456-426655440001",
2323
"variable": "dhi",
24-
"value_type": "interval_mean",
24+
"interval_value_type": "interval_mean",
2525
"interval_label": "beginning",
2626
"interval_length": 5
2727
},
@@ -34,7 +34,7 @@
3434
"provider": "UO SRML",
3535
"site_id": "123e4567-e89b-12d3-a456-426655440001",
3636
"variable": "dni",
37-
"value_type": "interval_mean",
37+
"interval_value_type": "interval_mean",
3838
"interval_label": "beginning",
3939
"interval_length": 5
4040
},
@@ -47,7 +47,7 @@
4747
"provider": "UO SRML",
4848
"site_id": "d2018f1d-82b1-422a-8ec4-4e8b3fe92a4a",
4949
"variable": "ghi",
50-
"value_type": "interval_mean",
50+
"interval_value_type": "interval_mean",
5151
"interval_label": "beginning",
5252
"interval_length": 5
5353
},
@@ -60,7 +60,7 @@
6060
"provider": "NOAA",
6161
"site_id": "d2018f1d-82b1-422a-8ec4-4e8b3fe92a4a",
6262
"variable": "ghi",
63-
"value_type": "interval_mean",
63+
"interval_value_type": "interval_mean",
6464
"interval_label": "beginning",
6565
"interval_length": 5
6666
}

sfa_api/forecasts.py

Lines changed: 208 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def post(self, *args):
4848
requests to this endpoint without a trailing slash will
4949
result in a redirect response.
5050
requestBody:
51-
desctiption: JSON representation of an observation.
51+
desctiption: JSON representation of a forecast.
5252
required: True
5353
content:
5454
application/json:
@@ -150,9 +150,7 @@ def get(self, forecast_id, *args):
150150
content:
151151
applciation/json:
152152
schema:
153-
type: array
154-
items:
155-
$ref: '#/components/schemas/ForecastValue'
153+
$ref: '#/components/schemas/ForecastValues'
156154
text/csv:
157155
schema:
158156
type: string
@@ -218,7 +216,7 @@ def post(self, forecast_id, *args):
218216
content:
219217
application/json:
220218
schema:
221-
$ref: '#/components/schemas/ForecastValues'
219+
$ref: '#/components/schemas/ForecastValuesPost'
222220
text/csv:
223221
schema:
224222
type: string
@@ -231,9 +229,9 @@ def post(self, forecast_id, *args):
231229
quality_flag may be 0 or 1 (indicating the value is not
232230
to be trusted).
233231
example: |-
234-
timestamp,value,quality_flag
235-
2018-10-29T12:00:00Z,32.93,0
236-
2018-10-29T13:00:00Z,25.17,0
232+
timestamp,value
233+
2018-10-29T12:00:00Z,32.93
234+
2018-10-29T13:00:00Z,25.17
237235
responses:
238236
201:
239237
$ref: '#/components/responses/201-Created'
@@ -328,6 +326,183 @@ def get(self, forecast_id, *args):
328326
return jsonify(ForecastSchema().dump(forecast))
329327

330328

329+
class AllCDFForecastGroupsView(MethodView):
330+
def get(self, args):
331+
"""
332+
---
333+
summary: List Probabilistic Forecasts groups.
334+
description: List all probabilistic forecasts a user has access to.
335+
tags:
336+
- Probabilistic Forecasts
337+
responses:
338+
200:
339+
description: A list of probabilistic forecasts
340+
content:
341+
application/json:
342+
schema:
343+
type: array
344+
items:
345+
$ref: '#/components/schemas/CDFForecastGroupMetadata'
346+
401:
347+
$ref: '#/components/responses/401-Unauthorized'
348+
404:
349+
$ref: '#/components/responses/404-NotFound'
350+
"""
351+
return jsonify({'errors': {'error': ['Not Implemented']}})
352+
353+
def post(self, *args):
354+
"""
355+
---
356+
summary: Create Probabilistic Forecast group.
357+
tags:
358+
- Probabilistic Forecasts
359+
description: >-
360+
Create a new Probabilistic Forecast by posting metadata.
361+
Note that POST requests to this endpoint without a trailing
362+
slash will result in a redirect response.
363+
requestBody:
364+
desctiption: JSON representation of a probabilistic forecast.
365+
required: True
366+
content:
367+
application/json:
368+
schema:
369+
$ref: '#/components/schemas/CDFForecastGroupDefinition'
370+
responses:
371+
201:
372+
description: Probabilistic forecast created successfully
373+
content:
374+
application/json:
375+
schema:
376+
$ref: '#/components/schemas/CDFForecastGroupMetadata'
377+
400:
378+
$ref: '#/components/responses/400-BadRequest'
379+
401:
380+
$ref: '#/components/responses/401-Unauthorized'
381+
382+
"""
383+
return jsonify({'errors': {'error': ['Not Implemented']}})
384+
385+
386+
class CDFForecastGroupMetadataView(MethodView):
387+
def get(self, forecast_id, *args):
388+
"""
389+
---
390+
summary: Get Probabilistic Forecast group Metadata.
391+
tags:
392+
- Probabilistic Forecasts
393+
parameters:
394+
- $ref: '#/components/parameters/forecast_id'
395+
responses:
396+
200:
397+
description: Successfully retrieved Forecasts.
398+
content:
399+
application/json:
400+
schema:
401+
type: array
402+
items:
403+
$ref: '#/components/schemas/CDFForecastGroupMetadata'
404+
401:
405+
$ref: '#/components/responses/401-Unauthorized'
406+
404:
407+
$ref: '#/components/responses/404-NotFound'
408+
"""
409+
return jsonify({'errors': {'error': ['Not Implemented']}})
410+
411+
412+
class CDFForecastMetadata(MethodView):
413+
def get(self, forecast_id):
414+
"""
415+
---
416+
summary: Get Metadata for one Probabilistic Forecast constant value.
417+
tags:
418+
- Probabilistic Forecasts
419+
parameters:
420+
- $ref: '#/components/parameters/forecast_id'
421+
responses:
422+
200:
423+
description: Successfully retrieved Forecast CDF metadata.
424+
content:
425+
application/json:
426+
schema:
427+
type: array
428+
items:
429+
$ref: '#/components/schemas/CDFForecastMetadata'
430+
401:
431+
$ref: '#/components/responses/401-Unauthorized'
432+
404:
433+
$ref: '#/components/responses/404-NotFound'
434+
"""
435+
return jsonify({'errors': {'error': ['Not Implemented']}})
436+
437+
438+
class CDFForecastValues(MethodView):
439+
def get(self, forecast_id):
440+
"""
441+
---
442+
summary: Get Probabilistic Forecast data for one constant value.
443+
tags:
444+
- Probabilistic Forecasts
445+
responses:
446+
200:
447+
content:
448+
applciation/json:
449+
schema:
450+
items:
451+
$ref: '#/components/schemas/ForecastValues'
452+
text/csv:
453+
schema:
454+
type: string
455+
example: |-
456+
timestamp,value
457+
2018-10-29T12:00:00Z,32.93
458+
2018-10-29T13:00:00Z,25.17
459+
401:
460+
$ref: '#/components/responses/401-Unauthorized'
461+
404:
462+
$ref: '#/components/responses/404-NotFound'
463+
"""
464+
return jsonify({'errors': {'error': ['Not Implemented']}})
465+
466+
def post(self, forecast_id):
467+
"""
468+
---
469+
summary: Add Probabilistic Forecast data for one constant value.
470+
description: >-
471+
Add timeseries values to a Probabilistic Forecast constant value.
472+
tags:
473+
- Probabilistic Forecasts
474+
parameters:
475+
- $ref: '#/components/parameters/forecast_id'
476+
requestBody:
477+
required: True
478+
content:
479+
application/json:
480+
schema:
481+
$ref: '#/components/schemas/ForecastValuesPost'
482+
text/csv:
483+
schema:
484+
type: string
485+
description: |
486+
Text file with fields separated by ',' and
487+
lines separated by '\\n'. The first line must
488+
be a header with the following fields: timestamp,
489+
value. Timestamp must be an ISO 8601 datetime and
490+
value may be an integer or floatquality_flag.
491+
example: |-
492+
timestamp,value
493+
2018-10-29T12:00:00Z,32.93
494+
2018-10-29T13:00:00Z,25.17
495+
responses:
496+
201:
497+
$ref: '#/components/responses/201-Created'
498+
401:
499+
$ref: '#/components/responses/401-Unauthorized'
500+
404:
501+
$ref: '#/components/responses/404-NotFound'
502+
"""
503+
return jsonify({'errors': {'error': ['Not Implemented']}})
504+
505+
331506
spec.components.parameter(
332507
'forecast_id', 'path',
333508
{
@@ -342,10 +517,28 @@ def get(self, forecast_id, *args):
342517
forecast_blp = Blueprint(
343518
'forecasts', 'forecasts', url_prefix="/forecasts",
344519
)
345-
forecast_blp.add_url_rule('/', view_func=AllForecastsView.as_view('all'))
346-
forecast_blp.add_url_rule('/<forecast_id>',
347-
view_func=ForecastView.as_view('single'))
348-
forecast_blp.add_url_rule('/<forecast_id>/values',
349-
view_func=ForecastValuesView.as_view('values'))
350-
forecast_blp.add_url_rule('/<forecast_id>/metadata',
351-
view_func=ForecastMetadataView.as_view('metadata'))
520+
forecast_blp.add_url_rule(
521+
'/single/',
522+
view_func=AllForecastsView.as_view('all'))
523+
forecast_blp.add_url_rule(
524+
'/single/<forecast_id>',
525+
view_func=ForecastView.as_view('single'))
526+
forecast_blp.add_url_rule(
527+
'/single/<forecast_id>/values',
528+
view_func=ForecastValuesView.as_view('values'))
529+
forecast_blp.add_url_rule(
530+
'/single/<forecast_id>/metadata',
531+
view_func=ForecastMetadataView.as_view('metadata'))
532+
533+
forecast_blp.add_url_rule(
534+
'/cdf/',
535+
view_func=AllCDFForecastGroupsView.as_view('all_cdf_groups'))
536+
forecast_blp.add_url_rule(
537+
'/cdf/<forecast_id>',
538+
view_func=CDFForecastGroupMetadataView.as_view('single_cdf_group'))
539+
forecast_blp.add_url_rule(
540+
'/cdf/single/<forecast_id>',
541+
view_func=CDFForecastMetadata.as_view('single_cdf_metadata'))
542+
forecast_blp.add_url_rule(
543+
'/cdf/single/<forecast_id>/values',
544+
view_func=CDFForecastValues.as_view('single_cdf_value'))

sfa_api/observations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def post(self, obs_id, *args):
219219
content:
220220
application/json:
221221
schema:
222-
$ref: '#/components/schemas/ObservationValues'
222+
$ref: '#/components/schemas/ObservationValuesPost'
223223
text/csv:
224224
schema:
225225
type: string

0 commit comments

Comments
 (0)