Skip to content

Commit

Permalink
Add documentation score
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurswag committed Jan 8, 2025
1 parent 1d69b53 commit 8efbb7b
Show file tree
Hide file tree
Showing 29 changed files with 262 additions and 101 deletions.
4 changes: 4 additions & 0 deletions backend/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ def get_sorted_requirement_nodes_rec(start: list) -> dict:
"result": req_as.result if req_as else None,
"is_scored": req_as.is_scored if req_as else None,
"score": req_as.score if req_as else None,
"documentation_score": req_as.documentation_score if req_as else None,
"max_score": max_score if req_as else None,
"question": req_as.answer if req_as else node.question,
"mapping_inference": req_as.mapping_inference if req_as else None,
Expand Down Expand Up @@ -324,6 +325,9 @@ def get_sorted_requirement_nodes_rec(start: list) -> dict:
"status": child_req_as.status if child_req_as else None,
"is_scored": child_req_as.is_scored if child_req_as else None,
"score": child_req_as.score if child_req_as else None,
"documentation_score": child_req_as.documentation_score
if child_req_as
else None,
"max_score": max_score if child_req_as else None,
"question": child_req_as.answer if child_req_as else child.question,
"mapping_inference": child_req_as.mapping_inference
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.1.4 on 2025-01-08 10:50

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0046_riskassessment_ebios_rm_study"),
]

operations = [
migrations.AddField(
model_name="complianceassessment",
name="show_documentation_score",
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name="requirementassessment",
name="documentation_score",
field=models.IntegerField(
blank=True, null=True, verbose_name="Documentation Score"
),
),
]
23 changes: 17 additions & 6 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2728,6 +2728,7 @@ class ComplianceAssessment(Assessment):
scores_definition = models.JSONField(
blank=True, null=True, verbose_name=_("Score definition")
)
show_documentation_score = models.BooleanField(default=False)

class Meta:
verbose_name = _("Compliance assessment")
Expand Down Expand Up @@ -2801,7 +2802,8 @@ def create_requirement_assessments(
def get_global_score(self):
requirement_assessments_scored = (
RequirementAssessment.objects.filter(compliance_assessment=self)
.exclude(score=None)
# ----- REMOVE THIS COMMENT AFTER REVIEW ----- #
# .exclude(score=None) # If is_scored is True we must consider the score in the global score right ?
.exclude(status=RequirementAssessment.Result.NOT_APPLICABLE)
.exclude(is_scored=False)
.exclude(requirement__assessable=False)
Expand All @@ -2813,12 +2815,18 @@ def get_global_score(self):
)
score = 0
n = 0

for ras in requirement_assessments_scored:
if not (ig) or (ig & set(ras.requirement.implementation_groups)):
score += ras.score
score += ras.score or 0
n += 1
if self.show_documentation_score:
score += ras.documentation_score or 0
n += 1
if n > 0:
return round(score / n, 1)
global_score = score / n
# We use this instead of using the python round function so that the python backend outputs the same result as the javascript frontend.
return int(global_score * 10) / 10
else:
return -1

Expand Down Expand Up @@ -3241,14 +3249,17 @@ class Result(models.TextChoices):
verbose_name=_("Result"),
default=Result.NOT_ASSESSED,
)
is_scored = models.BooleanField(
default=False,
verbose_name=_("Is scored"),
)
score = models.IntegerField(
blank=True,
null=True,
verbose_name=_("Score"),
)
is_scored = models.BooleanField(
default=False,
verbose_name=_("Is scored"),
documentation_score = models.IntegerField(
blank=True, null=True, verbose_name=_("Documentation Score")
)
evidences = models.ManyToManyField(
Evidence,
Expand Down
8 changes: 6 additions & 2 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2547,8 +2547,11 @@ def quality_check(self, request):
]
return Response({"results": res})

@method_decorator(cache_page(60 * SHORT_CACHE_TTL))
@method_decorator(vary_on_cookie)
# ----- REMOVE THESE COMMENTS AFTER REVIEW ----- #
# I disabled cache because i must wait before the documentation_score being hidden/displayed in the requirement-assessment edit view after changing the show_documentation_score value of the ComplianceAssessment
# @method_decorator(cache_page(60 * SHORT_CACHE_TTL))
# The vary_on_cookie is also disabled because it seem to only be here to support the cache_page disabled cache_page decorator
# @method_decorator(vary_on_cookie)
@action(detail=True, methods=["get"])
def global_score(self, request, pk):
"""Returns the global score of the compliance assessment"""
Expand All @@ -2561,6 +2564,7 @@ def global_score(self, request, pk):
"scores_definition": get_referential_translation(
compliance_assessment.framework, "scores_definition", get_language()
),
"show_documentation_score": compliance_assessment.show_documentation_score,
}
)

Expand Down
7 changes: 5 additions & 2 deletions frontend/messages/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,11 @@
"addTag": "إضافة علامة",
"tagsHelpText": "تُستخدم العلامات لتصنيف العناصر وتصفيتها. يمكنك إضافة علامات في قسم \"إضافي\"",
"forgotPassword": "هل نسيت كلمة السر",
"scoreSemiColon": "نتيجة:",
"score": "نتيجة",
"mappingInferenceHelpText": "هذه المتغيرات ثابتة ولن تتغير اعتمادًا على المصدر.",
"bringTheEvidences": "أحضر الأدلة",
"bringTheEvidencesHelpText": "في حالة التعطيل، سيتم تكرار الكائن بدون أدلته"
"bringTheEvidencesHelpText": "في حالة التعطيل، سيتم تكرار الكائن بدون أدلته",
"documentationScore": "درجة التوثيق",
"useDocumentationScore": "استخدام درجة التوثيق",
"useDocumentationScoreHelpText": "ستتوفر درجة ثانية (درجة التوثيق) لتقييم المتطلبات."
}
6 changes: 5 additions & 1 deletion frontend/messages/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@
"youCanSetNewPassword": "Zde si můžete nastavit nové heslo",
"userWillBeDisconnected": "Uživatel bude odpojen a bude se muset znovu přihlásit",
"scoresDefinition": "Definice skóre",
"score": "Skóre",
"selectedImplementationGroups": "Vybrané implementační skupiny",
"implementationGroupsDefinition": "Definice implementačních skupin",
"threatRadarChart": "Radarový graf hrozeb",
Expand Down Expand Up @@ -854,5 +855,8 @@
"addTag": "Přidat štítek",
"tagsHelpText": "Štítky pomáhají kategorizovat a filtrovat více objektů. Můžete je spravovat v menu Extra.",
"bringTheEvidences": "Přineste důkazy",
"bringTheEvidencesHelpText": "Pokud je zakázáno, objekt bude duplikován bez jeho důkazů"
"bringTheEvidencesHelpText": "Pokud je zakázáno, objekt bude duplikován bez jeho důkazů",
"documentationScore": "Skóre dokumentace",
"useDocumentationScore": "Použití skóre dokumentace",
"useDocumentationScoreHelpText": "Pro posouzení požadavků bude k dispozici druhé bodové skóre (skóre dokumentace)."
}
7 changes: 5 additions & 2 deletions frontend/messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,11 @@
"addTag": "Tag hinzufügen",
"tagsHelpText": "Tags werden zum Kategorisieren und Filtern der Elemente verwendet. Sie können Tags im Abschnitt Extra hinzufügen",
"forgotPassword": "Passwort vergessen",
"scoreSemiColon": "Punktzahl:",
"score": "Punktzahl",
"mappingInferenceHelpText": "Diese Variablen sind fest und ändern sich je nach Quelle nicht.",
"bringTheEvidences": "Bringen Sie die Beweise",
"bringTheEvidencesHelpText": "Wenn deaktiviert, wird das Objekt ohne seine Beweise dupliziert"
"bringTheEvidencesHelpText": "Wenn deaktiviert, wird das Objekt ohne seine Beweise dupliziert",
"documentationScore": "Bewertung der Dokumentation",
"useDocumentationScore": "Dokumentationsnote verwenden",
"useDocumentationScoreHelpText": "Eine zweite Punktzahl (Dokumentationspunktzahl) wird verfügbar sein, um die Anforderungen zu bewerten."
}
7 changes: 5 additions & 2 deletions frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@
"youCanSetPasswordHere": "You can set your password here",
"forgotPassword": "Forgot password",
"ssoSettingsUpdated": "SSO settings updated",
"scoreSemiColon": "Score:",
"score": "Score",
"mappingInferenceHelpText": "These variables are fixed and will not change depending on the source.",
"priority": "Priority",
"p1": "P1",
Expand Down Expand Up @@ -1082,5 +1082,8 @@
"missionsAndOrganizationalServices": "Missions and organizational services",
"human": "Human",
"material": "Material",
"environmental": "Environmental"
"environmental": "Environmental",
"documentationScore": "Documentation score",
"useDocumentationScore": "Use documentation score",
"useDocumentationScoreHelpText": "A second score (the documentation score) will be available for scoring the requirements."
}
7 changes: 5 additions & 2 deletions frontend/messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,11 @@
"addTag": "Agregar etiqueta",
"tagsHelpText": "Las etiquetas se utilizan para categorizar y filtrar los elementos. Puedes agregar etiquetas en la sección Extra",
"forgotPassword": "Has olvidado tu contraseña",
"scoreSemiColon": "Puntaje:",
"score": "Puntaje",
"mappingInferenceHelpText": "Estas variables son fijas y no cambiarán dependiendo de la fuente.",
"bringTheEvidences": "Traer las evidencias",
"bringTheEvidencesHelpText": "Si está deshabilitado, el objeto se duplicará sin sus evidencias."
"bringTheEvidencesHelpText": "Si está deshabilitado, el objeto se duplicará sin sus evidencias.",
"documentationScore": "Puntuación de la documentación",
"useDocumentationScore": "Utilizar la puntuación de la documentación",
"useDocumentationScoreHelpText": "Se dispondrá de una segunda puntuación (puntuación de la documentación) para evaluar los requisitos."
}
7 changes: 5 additions & 2 deletions frontend/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@
"youCanSetPasswordHere": "Vous pouvez définir votre mot de passe ici",
"forgotPassword": "Mot de passe oublié",
"ssoSettingsUpdated": "Paramètres SSO mis à jour",
"scoreSemiColon": "Score:",
"score": "Score",
"mappingInferenceHelpText": "Ces variables sont fixes et ne changeront pas en fonction de la source.",
"priority": "Priorité",
"p1": "P1",
Expand Down Expand Up @@ -1082,5 +1082,8 @@
"missionsAndOrganizationalServices": "Missions et service de l'organisation",
"human": "Humain",
"material": "Matériel",
"environmental": "Environnemental"
"environmental": "Environnemental",
"documentationScore": "Score de documentation",
"useDocumentationScore": "Utiliser le score de documentation",
"useDocumentationScoreHelpText": "Un deuxième score (le score de documentation) sera disponible pour évaluer les exigences."
}
7 changes: 5 additions & 2 deletions frontend/messages/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,11 @@
"addTag": "टैग जोड़ें",
"tagsHelpText": "टैग का उपयोग आइटम को वर्गीकृत और फ़िल्टर करने के लिए किया जाता है। आप अतिरिक्त अनुभाग में टैग जोड़ सकते हैं",
"forgotPassword": "पासवर्ड भूल गए",
"scoreSemiColon": "अंक:",
"score": "अंक",
"mappingInferenceHelpText": "ये चर निश्चित हैं और स्रोत के आधार पर परिवर्तित नहीं होंगे।",
"bringTheEvidences": "सबूत लाओ",
"bringTheEvidencesHelpText": "यदि अक्षम किया गया है, तो ऑब्जेक्ट को उसके साक्ष्य के बिना डुप्लिकेट किया जाएगा"
"bringTheEvidencesHelpText": "यदि अक्षम किया गया है, तो ऑब्जेक्ट को उसके साक्ष्य के बिना डुप्लिकेट किया जाएगा",
"documentationScore": "दस्तावेज़ीकरण स्कोर",
"useDocumentationScore": "दस्तावेज़ स्कोर का उपयोग करें",
"useDocumentationScoreHelpText": "आवश्यकताओं का आकलन करने के लिए दूसरी रेटिंग (दस्तावेज़ीकरण स्कोर) उपलब्ध होगी।"
}
7 changes: 5 additions & 2 deletions frontend/messages/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@
"youCanSetPasswordHere": "Anda dapat mengatur kata sandi Anda di sini",
"forgotPassword": "Lupa kata sandi",
"ssoSettingsUpdated": "Pengaturan SSO diperbarui",
"scoreSemiColon": "Skor:",
"score": "Skor",
"mappingInferenceHelpText": "Variabel-variabel ini tetap dan tidak akan berubah tergantung pada sumber.",
"priority": "Prioritas",
"p1": "P1",
Expand Down Expand Up @@ -1083,5 +1083,8 @@
"missionsAndOrganizationalServices": "Misi dan layanan organisasi",
"human": "Manusia",
"material": "Materi",
"environmental": "Lingkungan"
"environmental": "Lingkungan",
"documentationScore": "Skor dokumentasi",
"useDocumentationScore": "Gunakan skor dokumentasi",
"useDocumentationScoreHelpText": "Skor kedua (skor dokumentasi) akan tersedia untuk menilai persyaratan."
}
7 changes: 5 additions & 2 deletions frontend/messages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,11 @@
"addTag": "Aggiungi tag",
"tagsHelpText": "I tag vengono utilizzati per categorizzare e filtrare gli elementi. Puoi aggiungere tag nella sezione Extra",
"forgotPassword": "Ha dimenticato la password",
"scoreSemiColon": "Punto:",
"score": "Punto",
"mappingInferenceHelpText": "Queste variabili sono fisse e non cambiano a seconda della fonte.",
"bringTheEvidences": "Portare le prove",
"bringTheEvidencesHelpText": "Se disabilitato, l'oggetto verrà duplicato senza le sue prove"
"bringTheEvidencesHelpText": "Se disabilitato, l'oggetto verrà duplicato senza le sue prove",
"documentationScore": "Punteggio della documentazione",
"useDocumentationScore": "Utilizzare il punteggio della documentazione",
"useDocumentationScoreHelpText": "Un secondo punteggio (punteggio di documentazione) sarà disponibile per valutare i requisiti."
}
7 changes: 5 additions & 2 deletions frontend/messages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,11 @@
"addTag": "Tag toevoegen",
"tagsHelpText": "Tags worden gebruikt om de items te categoriseren en te filteren. U kunt tags toevoegen in de sectie Extra",
"forgotPassword": "Wachtwoord vergeten",
"scoreSemiColon": "Punt:",
"score": "Punt",
"mappingInferenceHelpText": "Deze variabelen zijn vast en veranderen niet, afhankelijk van de bron.",
"bringTheEvidences": "Breng de bewijzen",
"bringTheEvidencesHelpText": "Als dit is uitgeschakeld, wordt het object gedupliceerd zonder de bijbehorende bewijzen"
"bringTheEvidencesHelpText": "Als dit is uitgeschakeld, wordt het object gedupliceerd zonder de bijbehorende bewijzen",
"documentationScore": "Documentatie score",
"useDocumentationScore": "Documentatiescore gebruiken",
"useDocumentationScoreHelpText": "Een tweede score (documentatiescore) zal beschikbaar zijn om de vereisten te beoordelen."
}
7 changes: 5 additions & 2 deletions frontend/messages/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,11 @@
"addTag": "Dodaj tag",
"tagsHelpText": "Tagi służą do kategoryzowania i filtrowania elementów. Możesz dodać tagi w sekcji Extra",
"forgotPassword": "Zapomniałem hasła",
"scoreSemiColon": "Wynik:",
"score": "Wynik",
"mappingInferenceHelpText": "Te zmienne są stałe i nie zmieniają się w zależności od źródła.",
"bringTheEvidences": "Przynieś dowody",
"bringTheEvidencesHelpText": "Jeśli wyłączone, obiekt zostanie zduplikowany bez dowodów"
"bringTheEvidencesHelpText": "Jeśli wyłączone, obiekt zostanie zduplikowany bez dowodów",
"documentationScore": "Wynik dokumentacji",
"useDocumentationScore": "Korzystanie z punktacji dokumentacji",
"useDocumentationScoreHelpText": "Drugi wynik (wynik dokumentacji) będzie dostępny do oceny wymagań."
}
7 changes: 5 additions & 2 deletions frontend/messages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,11 @@
"addTag": "Adicionar etiqueta",
"tagsHelpText": "As tags são usadas para categorizar e filtrar os itens. Você pode adicionar tags na seção Extra",
"forgotPassword": "Esqueceu sua senha",
"scoreSemiColon": "Pontuação:",
"score": "Pontuação",
"mappingInferenceHelpText": "Essas variáveis são fixas e não mudarão dependendo da fonte.",
"bringTheEvidences": "Traga as evidências",
"bringTheEvidencesHelpText": "Se desabilitado, o objeto será duplicado sem suas evidências"
"bringTheEvidencesHelpText": "Se desabilitado, o objeto será duplicado sem suas evidências",
"documentationScore": "Pontuação da documentação",
"useDocumentationScore": "Utilizar a pontuação da documentação",
"useDocumentationScoreHelpText": "Uma segunda pontuação (a pontuação da documentação) estará disponível para avaliar os requisitos."
}
7 changes: 5 additions & 2 deletions frontend/messages/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,11 @@
"addTag": "Adăugați etichetă",
"tagsHelpText": "Etichetele sunt folosite pentru a clasifica și filtra articolele. Puteți adăuga etichete în secțiunea Extra",
"forgotPassword": "Aţi uitat parola",
"scoreSemiColon": "Scor:",
"score": "Scor",
"mappingInferenceHelpText": "Aceste variabile sunt fixe și nu se vor modifica în funcție de sursă.",
"bringTheEvidences": "Aduceți dovezile",
"bringTheEvidencesHelpText": "Dacă este dezactivat, obiectul va fi duplicat fără dovezile sale"
"bringTheEvidencesHelpText": "Dacă este dezactivat, obiectul va fi duplicat fără dovezile sale",
"documentationScore": "Punctajul documentației",
"useDocumentationScore": "Utilizați punctajul documentației",
"useDocumentationScoreHelpText": "Un al doilea punctaj (punctajul pentru documentație) va fi disponibil pentru evaluarea cerințelor."
}
7 changes: 5 additions & 2 deletions frontend/messages/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,11 @@
"youCanSetPasswordHere": "Du kan ställa in ditt lösenord här.",
"forgotPassword": "Glömt lösenord",
"ssoSettingsUpdated": "SSO-inställningar uppdaterade",
"scoreSemiColon": "Göra:",
"score": "Göra",
"mappingInferenceHelpText": "Dessa variabler är fasta och kommer inte att ändras beroende på källan.",
"bringTheEvidences": "Kom med bevisen",
"bringTheEvidencesHelpText": "Om det är inaktiverat kommer objektet att dupliceras utan dess bevis"
"bringTheEvidencesHelpText": "Om det är inaktiverat kommer objektet att dupliceras utan dess bevis",
"documentationScore": "Poäng för dokumentation",
"useDocumentationScore": "Använd poängsättning av dokumentation",
"useDocumentationScoreHelpText": "En andra poäng (dokumentationspoängen) kommer att finnas tillgänglig för att bedöma kraven."
}
7 changes: 5 additions & 2 deletions frontend/messages/ur.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,11 @@
"addTag": "ٹیگ شامل کریں۔",
"tagsHelpText": "ٹیگز اشیاء کی درجہ بندی اور فلٹر کرنے کے لیے استعمال ہوتے ہیں۔ آپ اضافی سیکشن میں ٹیگ شامل کر سکتے ہیں۔",
"forgotPassword": "پاس ورڈ بھول گئے۔",
"scoreSemiColon": "سکور:",
"score": "سکور",
"mappingInferenceHelpText": "یہ متغیرات طے شدہ ہیں اور ماخذ کے لحاظ سے تبدیل نہیں ہوں گے۔",
"bringTheEvidences": "ثبوت لے کر آئیں",
"bringTheEvidencesHelpText": "اگر غیر فعال ہو تو، اعتراض کو اس کے ثبوت کے بغیر نقل کر دیا جائے گا۔"
"bringTheEvidencesHelpText": "اگر غیر فعال ہو تو، اعتراض کو اس کے ثبوت کے بغیر نقل کر دیا جائے گا۔",
"documentationScore": "دستاویزی سکور",
"useDocumentationScore": "دستاویزی سکور استعمال کریں۔",
"useDocumentationScoreHelpText": "ضروریات کو پورا کرنے کے لیے دوسرا سکور (دستاویزی سکور) دستیاب ہوگا۔"
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@
}
}}
/>
<Checkbox
{form}
field="show_documentation_score"
label={m.useDocumentationScore()}
helpText={m.useDocumentationScoreHelpText()}
cacheLock={cacheLocks['show_documentation_score']}
bind:cachedValue={formDataCache['show_documentation_score']}
/>
{#if model.selectOptions['selected_implementation_groups'] && model.selectOptions['selected_implementation_groups'].length}
<AutocompleteSelect
multiple
Expand Down
Loading

0 comments on commit 8efbb7b

Please sign in to comment.