From 6e7290a03f649531c6e9172221bb0b44348a0a37 Mon Sep 17 00:00:00 2001 From: Sam Lucidi Date: Wed, 20 Sep 2023 13:28:53 -0400 Subject: [PATCH] Add roles for questionnaire/assessment/archetype Signed-off-by: Sam Lucidi --- api/archetype.go | 1 - api/assessment.go | 10 ++++--- assessment/pkg.go | 70 +++++++++++++++++++++++++++++++++++++++++++ assessment/section.go | 6 ---- auth/roles.yaml | 61 +++++++++++++++++++++++++++++++++++-- 5 files changed, 134 insertions(+), 14 deletions(-) diff --git a/api/archetype.go b/api/archetype.go index f27bf718c..221f4cff5 100644 --- a/api/archetype.go +++ b/api/archetype.go @@ -14,7 +14,6 @@ const ( ArchetypesRoot = "/archetypes" ArchetypeRoot = ArchetypesRoot + "/:" + ID ArchetypeAssessmentsRoot = ArchetypeRoot + "/assessments" - ArchetypeAssessmentRoot = ArchetypeAssessmentsRoot + ":/" + ID2 ) // diff --git a/api/assessment.go b/api/assessment.go index be5fbe234..5eb56f92f 100644 --- a/api/assessment.go +++ b/api/assessment.go @@ -170,15 +170,16 @@ type Assessment struct { Resource Application *Ref `json:"application,omitempty" yaml:",omitempty" binding:"excluded_with=Archetype"` Archetype *Ref `json:"archetype,omitempty" yaml:",omitempty" binding:"excluded_with=Application"` - Questionnaire Ref `json:"questionnaire" yaml:"questionnaire" binding:"required"` - Sections []assessment.Section `json:"sections" yaml:"sections"` + Questionnaire Ref `json:"questionnaire" binding:"required"` + Sections []assessment.Section `json:"sections"` Stakeholders []Ref `json:"stakeholders"` StakeholderGroups []Ref `json:"stakeholderGroups"` // read only Risk string `json:"risk"` + Confidence int `json:"confidence"` Status string `json:"status"` - Thresholds assessment.Thresholds `json:"thresholds" yaml:"thresholds"` - RiskMessages assessment.RiskMessages `json:"riskMessages" yaml:"riskMessages"` + Thresholds assessment.Thresholds `json:"thresholds"` + RiskMessages assessment.RiskMessages `json:"riskMessages"` } // @@ -211,6 +212,7 @@ func (r *Assessment) With(m *model.Assessment) { r.Status = AssessmentEmpty } r.Risk = r.RiskLevel() + r.Confidence = assessment.Confidence(r.Sections) } // diff --git a/assessment/pkg.go b/assessment/pkg.go index 90dc65245..dadb144bc 100644 --- a/assessment/pkg.go +++ b/assessment/pkg.go @@ -3,8 +3,78 @@ package assessment import ( "encoding/json" "github.com/konveyor/tackle2-hub/model" + "math" ) +// +// Assessment risk +const ( + RiskUnknown = "unknown" + RiskRed = "red" + RiskYellow = "yellow" + RiskGreen = "green" +) + +// +// Confidence adjustment +const ( + AdjusterRed = 0.5 + AdjusterYellow = 0.98 +) + +// +// Confidence multiplier. +const ( + MultiplierRed = 0.6 + MultiplierYellow = 0.95 +) + +// +// Risk weights +const ( + WeightRed = 1 + WeightYellow = 80 + WeightGreen = 100 + WeightUnknown = 70 +) + +// +// Confidence calculates a confidence score based on the answers to an assessment's questions. +// The algorithm is a reimplementation of the calculation done by Pathfinder. +func Confidence(sections []Section) (score int) { + totalQuestions := 0 + riskCounts := make(map[string]int) + for _, s := range sections { + for _, r := range s.Risks() { + riskCounts[r]++ + totalQuestions++ + } + } + adjuster := 1.0 + if riskCounts[RiskRed] > 0 { + adjuster = adjuster * math.Pow(AdjusterRed, float64(riskCounts[RiskRed])) + } + if riskCounts[RiskYellow] > 0 { + adjuster = adjuster * math.Pow(AdjusterYellow, float64(riskCounts[RiskYellow])) + } + confidence := 0.0 + for i := 0; i < riskCounts[RiskRed]; i++ { + confidence *= MultiplierRed + confidence += WeightRed * adjuster + } + for i := 0; i < riskCounts[RiskYellow]; i++ { + confidence *= MultiplierYellow + confidence += WeightYellow * adjuster + } + confidence += float64(riskCounts[RiskGreen]) * WeightGreen * adjuster + confidence += float64(riskCounts[RiskUnknown]) * WeightUnknown * adjuster + + maxConfidence := WeightGreen * totalQuestions + score = int(confidence / float64(maxConfidence) * 100) + + return +} + // // PrepareForApplication prepares the sections of an assessment by including, excluding, // or auto-answering questions based on a set of tags. diff --git a/assessment/section.go b/assessment/section.go index 9be77e535..18bd22c5e 100644 --- a/assessment/section.go +++ b/assessment/section.go @@ -1,11 +1,5 @@ package assessment -// -// Assessment risk -const ( - RiskUnknown = "unknown" -) - // // Section represents a group of questions in a questionnaire. type Section struct { diff --git a/auth/roles.yaml b/auth/roles.yaml index 6fd0f95d3..774979b51 100644 --- a/auth/roles.yaml +++ b/auth/roles.yaml @@ -42,11 +42,14 @@ - name: applications.stakeholders verbs: - put + - name: applications.assessments + verbs: + - get + - post - name: assessments verbs: - delete - get - - patch - post - put - name: businessservices @@ -185,6 +188,22 @@ - get - post - put + - name: archetypes + verbs: + - delete + - get + - post + - put + - name: archetypes.assessments + verbs: + - get + - post + - name: questionnaires + verbs: + - delete + - get + - post + - put - role: tackle-architect resources: - name: addons @@ -229,11 +248,14 @@ - name: applications.stakeholders verbs: - put + - name: applications.assessments + verbs: + - get + - post - name: assessments verbs: - delete - get - - patch - post - put - name: businessservices @@ -359,6 +381,16 @@ - get - post - put + - name: archetypes + verbs: + - get + - name: archetypes.assessments + verbs: + - get + - post + - name: questionnaires + verbs: + - get - role: tackle-migrator resources: - name: addons @@ -382,10 +414,12 @@ - name: applications.analyses verbs: - get + - name: applications.assessments + verbs: + - get - name: assessments verbs: - get - - post - name: businessservices verbs: - get @@ -466,6 +500,15 @@ - name: analyses verbs: - get + - name: archetypes + verbs: + - get + - name: archetypes.assessments + verbs: + - get + - name: questionnaires + verbs: + - get - role: tackle-project-manager resources: - name: addons @@ -492,6 +535,9 @@ - name: applications.stakeholders verbs: - put + - name: applications.assessments + verbs: + - get - name: assessments verbs: - get @@ -567,3 +613,12 @@ - name: analyses verbs: - get + - name: archetypes + verbs: + - get + - name: archetypes.assessments + verbs: + - get + - name: questionnaires + verbs: + - get \ No newline at end of file