Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(risk-matrix): use plotly #2

Merged
merged 5 commits into from
Jun 11, 2024
Merged

Conversation

somehowchris
Copy link
Contributor

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Jan 23, 2024

Codecov Report

Attention: Patch coverage is 44.68085% with 26 lines in your changes are missing coverage. Please review.

Project coverage is 71.05%. Comparing base (efc2f99) to head (76629a0).
Report is 2 commits behind head on main.

Files Patch % Lines
src/riskmatrix/views/risk_assessment.py 39.53% 26 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main       #2      +/-   ##
==========================================
+ Coverage   70.92%   71.05%   +0.12%     
==========================================
  Files          61       61              
  Lines        2573     2591      +18     
==========================================
+ Hits         1825     1841      +16     
- Misses        748      750       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Daverball Daverball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A proper review will have to wait until the black auto formatting of views/risk_assessment.py has been reverted.

Copy link
Member

@Daverball Daverball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for the most part, there's still some style nits that are probably leftovers from black auto formatting and an architectural change on how to get a numbered column inside a DataTable (especially one that remains stable once sorting and/or AJAX are involved, although the latter case you can probably forget about for now, since we'll likely never deal with thousands of rows, so loading them in separated requests isn't really worth it at that point).

Comment on lines 175 to 176
for idx, item in enumerate(query):
item.nr = idx + 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for idx, item in enumerate(query):
item.nr = idx + 1
for idx, item in enumerate(query, start=1):
item.nr = idx

Alright now I see what you use this nr for. This probably shouldn't really be stored on the model at all (definitely not inside the database through a mapped_column, a regular attribute should be fine). I would probably implement this using a subclass of DataColumn. It will be a little bit more tricky to get right though from that end, so maybe this should just be an option on the DataTable to prepend a numeric column, just like you can optionally add buttons, although I'm not sure how this will interact with custom sorting.

You could also potentially do it entirely through the frontend: https://datatables.net/examples/api/counter_columns.html

Comment on lines 430 to 432
"title": _("Risk Matrix"),
"plot": Markup(plot_risk_matrix(table.query())), # noqa: MS001
"table": table,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"title": _("Risk Matrix"),
"plot": Markup(plot_risk_matrix(table.query())), # noqa: MS001
"table": table,
'title': _('Risk Matrix'),
'plot': plot_risk_matrix(table.query()),
'table': table,

style nit, also I would return Markup from plot_risk_matrix, don't wrap it here.

Copy link
Member

@Daverball Daverball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still needs a small change to make the tests pass.
Otherwise just a couple of nits, suggestions and comments.

@@ -1,6 +1,6 @@
from pyramid.events import NewRequest
from pyramid.events import NewResponse

import secrets
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to keep imports sorted alphabetically and by type, if that's too tedious you can consider adding isort as precommit hook, so it does it for you. Although isort will not separate out typing imports into its own block at the bottom, like I usually do, I can live with those being mixed in with the other imports.

@@ -51,6 +51,12 @@ def sentry_context(event: NewRequest) -> None:
scope.user = {'id': request.user.id}


def request_none_generator(event: 'NewRequest') -> None:
request = event.request
request.set_property(lambda r: secrets.token_urlsafe(), 'csp_nonce', reify=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to also add a csp_nonce attribute to testing.DummyRequest, this can just be a static string for testing. Some tests currently fail because the attribute doesn't exist.

@@ -22,7 +24,7 @@
if TYPE_CHECKING:
from pyramid.interfaces import IRequest
from sqlalchemy.orm.query import Query
from typing import TypeVar
from typing import TypeVar, Iterator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from typing import TypeVar, Iterator
from collections.abc import Iterator
from typing import TypeVar

Always use the collections.abc imports for these protocols, the typing aliases have been deprecated since 3.9. You could use pyupgrade to auto-correct imports. Although if you're also going to include isort it might be easier to just switch most of the linting over to ruff and only keep flake8 for some of the plugins that aren't included in ruff or not as up-to-date like flake8-type-checking.

ruff also includes auto fixes for a lot of the errors, if you're into that sort of thing.



class RiskMatrixAssessment(RiskAssessment):
nr: ClassVar[int]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nr: ClassVar[int]
nr: int

Based on how this is used, this shouldn't be a ClassVar.

Comment on lines 371 to 372
hovertemplate=f'{risk.nr} {risk.name} \
(Impact: {risk.impact} Likelihood: {risk.likelihood})',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hovertemplate=f'{risk.nr} {risk.name} \
(Impact: {risk.impact} Likelihood: {risk.likelihood})',
hovertemplate=f'{risk.nr} {risk.name} '
'(Impact: {risk.impact} Likelihood: {risk.likelihood})',

Please avoid using broken lines, especially inside string literals. Python has implicit string concatenation. There's flake8-broken-lines in case this is something copilot tries to make you do, rather than a conscious decision.

@somehowchris somehowchris merged commit 3dd2cb1 into main Jun 11, 2024
2 of 3 checks passed
@somehowchris somehowchris deleted the feature/generate-riskmatrix branch June 11, 2024 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants