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

[PRO] priority review matrix #1255

Merged
merged 4 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,19 @@ def get_linked_requirements_count(self):
requirementassessment__applied_controls=self
).count()

@property
def links_count(self):
reqs = 0 # compliance requirements
scenarios = 0 # risk scenarios
sh_actions = 0 # stakeholder tprm actions

reqs = RequirementNode.objects.filter(
requirementassessment__applied_controls=self
).count()
scenarios = RiskScenario.objects.filter(applied_controls=self).count()

return reqs + scenarios + sh_actions

def has_evidences(self):
return self.evidences.count() > 0

Expand All @@ -1859,6 +1872,14 @@ def eta_missed(self):
self.eta < date.today() and self.status != "active" if self.eta else False
)

@property
def days_until_eta(self):
if not self.eta:
return None
days_remaining = (self.eta - date.today()).days

return max(-1, days_remaining)


class PolicyManager(models.Manager):
def get_queryset(self):
Expand Down
68 changes: 68 additions & 0 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import io

import random

from docxtpl import DocxTemplate
from .generators import gen_audit_context

Expand Down Expand Up @@ -1169,6 +1171,72 @@ def get_controls_info(self, request):
}
)

@action(detail=False, name="Get priority chart data")
def priority_chart_data(self, request):
qs = AppliedControl.objects.exclude(status="active")

data = {
"--": [],
"to_do": [],
"in_progress": [],
"on_hold": [],
"deprecated": [],
}
angle_offsets = {"4": 0, "3": 90, "1": 180, "2": 270}
status_offset = {
"--": 4,
"to_do": 12,
"in_progress": 20,
"on_hold": 28,
"deprecated": 36,
}

not_displayed_cnt = 0

p_dict = qs.aggregate(
p1=Count("priority", filter=Q(priority=1)),
p2=Count("priority", filter=Q(priority=2)),
p3=Count("priority", filter=Q(priority=3)),
p4=Count("priority", filter=Q(priority=4)),
)
for ac in qs:
if ac.priority:
if ac.eta:
days_countdown = min(100, ac.days_until_eta)
# how many days until the ETA
else:
days_countdown = 100
impact_factor = 5 + ac.links_count

# angle = angle_offsets[str(ac.priority)]+ (next(offsets) % 80) + random.randint(1,4)
angle = (
angle_offsets[str(ac.priority)]
+ status_offset[ac.status]
+ random.randint(1, 40)
)
# angle = angle_offsets[str(ac.priority)] + next(offsets)

vector = [
days_countdown,
angle,
impact_factor,
f"[{ac.priority}] {str(ac)}",
ac.status,
ac.id,
]
if ac.status:
data[ac.status].append(vector)
else:
data["unclassified"].append(vector)
else:
print("priority unset - add it to triage lot")
not_displayed_cnt += 1

data["not_displayed"] = not_displayed_cnt
data["priority_cnt"] = p_dict

return Response(data)

@action(detail=False, methods=["get"])
def get_timeline_info(self, request):
entries = []
Expand Down
Loading
Loading