Promene u dizajnu dokumenata, controla, residual graph, residual tabele...
This commit is contained in:
@@ -3,14 +3,6 @@ from backend.core.utils import calculate_aggregate_likelihood, calculate_aggrega
|
||||
|
||||
|
||||
def risk_matrix_table():
|
||||
likelihood_labels = [
|
||||
"Almost Certain (90-100%) (5)",
|
||||
"Probable (51-89%) (4)",
|
||||
"Possible (25-50%) (3)",
|
||||
"Unlikely (11-24%) (2)",
|
||||
"Rare (0-10%) (1)"
|
||||
]
|
||||
|
||||
impact_labels = [
|
||||
"Insignificant (1)",
|
||||
"Significant (2)",
|
||||
@@ -18,39 +10,28 @@ def risk_matrix_table():
|
||||
"Material (4)",
|
||||
"Major (5)"
|
||||
]
|
||||
header = ["Likelihood ↓ / Impact →"] + impact_labels
|
||||
|
||||
color_mapping = {
|
||||
"Very Low": "lightgreen",
|
||||
"Low": "green",
|
||||
"Medium": "yellow",
|
||||
"High": "orange",
|
||||
"Critical": "red"
|
||||
}
|
||||
matrix = [
|
||||
["Almost Certain (5)",
|
||||
(5, "bg-medium"), (10, "bg-high"), (15, "bg-critical"), (20, "bg-critical"), (25, "bg-critical")
|
||||
],
|
||||
["Likely (4)",
|
||||
(4, "bg-low"), (8, "bg-medium"), (12, "bg-high"), (16, "bg-high"), (20, "bg-critical")
|
||||
],
|
||||
["Probable (3)",
|
||||
(3, "bg-low"), (6, "bg-low"), (9, "bg-medium"), (12, "bg-high"), (15, "bg-high")
|
||||
],
|
||||
["Unlikely (2)",
|
||||
(2, "bg-very-low"), (4, "bg-low"), (6, "bg-medium"), (8, "bg-medium"), (10, "bg-medium")
|
||||
],
|
||||
["Rare (1)",
|
||||
(1, "bg-very-low"), (2, "bg-very-low"), (3, "bg-low"), (4, "bg-low"), (5, "bg-medium")
|
||||
],
|
||||
]
|
||||
|
||||
def get_label(score):
|
||||
if score <= 2:
|
||||
return "Very Low"
|
||||
elif score <= 4:
|
||||
return "Low"
|
||||
elif score <= 10:
|
||||
return "Medium"
|
||||
elif score <= 16:
|
||||
return "High"
|
||||
else:
|
||||
return "Critical"
|
||||
|
||||
table_matrix_risk = [["Likelihood ↓ / Impact →"] + impact_labels]
|
||||
|
||||
for likelihood in range(5, 0, -1):
|
||||
row = [likelihood_labels[5 - likelihood]]
|
||||
for impact in range(1, 6):
|
||||
score = likelihood * impact
|
||||
label = get_label(score)
|
||||
color_class = color_mapping[label]
|
||||
row.append((score, label, color_class))
|
||||
table_matrix_risk.append(row)
|
||||
|
||||
return table_matrix_risk
|
||||
table = [header] + matrix
|
||||
return table
|
||||
|
||||
def get_risk_table(document):
|
||||
risks = (
|
||||
@@ -98,3 +79,34 @@ def get_risk_table(document):
|
||||
risks_with_controls.sort(key=lambda x: x['risk_score'], reverse=True)
|
||||
|
||||
return risks_with_controls
|
||||
|
||||
def get_safeguard_summary_table(risks_with_controls):
|
||||
from collections import Counter
|
||||
from backend.core.models import Control
|
||||
|
||||
safeguard_counter = Counter()
|
||||
safeguard_names = {}
|
||||
|
||||
for risk in risks_with_controls:
|
||||
for control in risk.get('controls', []):
|
||||
control_id = control.get('control')
|
||||
control_name = control.get('control__name')
|
||||
if control_id:
|
||||
safeguard_counter[control_id] += 1
|
||||
safeguard_names[control_id] = control_name
|
||||
|
||||
summary = []
|
||||
controls = Control.objects.filter(id__in=safeguard_counter.keys())
|
||||
controls_map = {c.id: c for c in controls}
|
||||
|
||||
for control_id, count in safeguard_counter.items():
|
||||
control = controls_map.get(control_id)
|
||||
summary.append({
|
||||
'id': control_id,
|
||||
'safeguard_id': control.safeguard_id if control else '',
|
||||
'name': safeguard_names.get(control_id, ''),
|
||||
'description': control.description if control else '',
|
||||
'count': count,
|
||||
})
|
||||
summary.sort(key=lambda x: x['count'], reverse=True)
|
||||
return summary
|
||||
Reference in New Issue
Block a user