Skip to content

Commit

Permalink
Update docstring and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ptormene committed Mar 10, 2025
1 parent c359e07 commit 206d4ef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
27 changes: 15 additions & 12 deletions doc/api-reference/rest-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ Response:

A list of error lines extracted from the log. If the calculation was successfull, the list is empty.

**********************************
GET /v1/calc/:calc_id/aggrisk_tags
**********************************
********************************
GET /v1/calc/:calc_id/get_impact
********************************

Get risk results aggregated by tag, together with the corresponding exposure values.
Get impact results aggregated by tag, together with the corresponding exposure values.

NB: this URL is valid only for risk calculations with an aggregate_by parameter.
Otherwise it returns a BadRequest error with HTTP code 400.
Expand All @@ -127,29 +127,32 @@ Parameters: None

Response:

A JSON object corresponding to a pandas DataFrame. The names of the
columns are "ID_1", "loss_type", "value", "lossmea", "lossq05",
"lossq95".
A JSON object containing:
- an 'impact' key containing a pandas DataFrame; the names of the columns are "ID_1", "loss_type",
"value", "lossmea", "lossq05", "lossq95".
- a 'loss_type_description' dictionary containing a description for each loss type.

**********************************
GET /v1/calc/:calc_id/mmi_tags
**********************************
*****************************************
GET /v1/calc/:calc_id/get_exposure_by_mmi
*****************************************

Get exposure aggregated by MMI regions and tags.

NB: this URL is valid only for ShakeMap based calculations downloading
the MMI regions from the USGS service/
the MMI regions from the USGS service.

Otherwise it returns a BadRequest error with HTTP code 400.

Parameters: None

Response:

A JSON object corresponding to a pandas DataFrame. The names of the
A JSON object containing:
- an 'exposure_by_mmi' key corresponding to a pandas DataFrame; the names of the
columns are "ID_1", "number", "contents", "nonstructural", "structural",
"residents", "area", "occupants_day", "occupants_night", "occupants_transit",
"occupants_avg", "mmi".
- an exposure_type_description' dictionary containing a description for each exposure type.

***********************************
GET /v1/calc/:calc_id/extract/:spec
Expand Down
7 changes: 4 additions & 3 deletions openquake/server/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ def calc_result(request, result_id):
@require_http_methods(['GET', 'HEAD'])
def get_impact(request, calc_id):
"""
Return aggrisk_tags, by ``calc_id``, as JSON.
Return impact results (aggrisk_tags), by ``calc_id``, as JSON.
:param request:
`django.http.HttpRequest` object.
Expand All @@ -1199,15 +1199,16 @@ def get_impact(request, calc_id):
(exc.__class__.__name__, exc, 'aggrisk_tags', tb),
content_type='text/plain', status=400)
response_data = {'loss_type_description': LOSS_FIELD_DESCRIPTION,
'losses': json.loads(df.to_json())}
'impact': json.loads(df.to_json())}
return JsonResponse(response_data)


@cross_domain_ajax
@require_http_methods(['GET', 'HEAD'])
def get_exposure_by_mmi(request, calc_id):
"""
Return mmi_tags, by ``calc_id``, as JSON.
Return exposure aggregated by MMI regions and tags (mmi_tags),
by ``calc_id``, as JSON.
:param request:
`django.http.HttpRequest` object.
Expand Down

0 comments on commit 206d4ef

Please sign in to comment.