Skip to content

Commit

Permalink
Add gravity choices endpoint for feared events
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche committed Dec 5, 2024
1 parent 6e26974 commit c5360f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backend/ebios_rm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ def save(self, *args, **kwargs):
def risk_matrix(self):
return self.ebios_rm_study.risk_matrix

@property
def parsed_matrix(self):
return self.risk_matrix.parse_json_translated()


class RoTo(AbstractBaseModel, FolderMixin):
class RiskOrigin(models.TextChoices):
Expand Down
14 changes: 14 additions & 0 deletions backend/ebios_rm/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ def risk_matrix(self, request, pk=None):
feared_event = self.get_object()
return Response(RiskMatrixReadSerializer(feared_event.risk_matrix).data)

@method_decorator(cache_page(60 * LONG_CACHE_TTL))
@action(detail=True, name="Get impact choices")
def gravity(self, request, pk):
feared_event: FearedEvent = self.get_object()
undefined = dict([(-1, "--")])
_choices = dict(
zip(
list(range(0, 64)),
[x["name"] for x in feared_event.parsed_matrix["impact"]],
)
)
choices = undefined | _choices
return Response(choices)


class RoToViewSet(BaseModelViewSet):
model = RoTo
Expand Down

0 comments on commit c5360f7

Please sign in to comment.