Skip to content

Commit

Permalink
quality labels (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesstoetzner authored Nov 20, 2024
1 parent 8a0bb79 commit b24fbc1
Show file tree
Hide file tree
Showing 10 changed files with 725 additions and 157 deletions.
268 changes: 134 additions & 134 deletions docs/docs/variability4tosca/quality/index.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/docs/variability4tosca/quality/qualities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@
hosting:
- '*'
- local.machine
weight: 0.5
weight: 1
reason: While this is a primary use case due to the specialization of Ansible, we must rely on scripts. More specialized types should be used, e.g., service.application.
- technology: terraform
component: software.application
Expand All @@ -675,7 +675,7 @@
hosting:
- '*'
- remote.machine
weight: 0.5
weight: 1
reason: While this is a primary use case due to the specialization of Ansible, we must rely on scripts. More specialized types should be used, e.g., "service.application".
- technology: terraform
component: software.application
Expand All @@ -691,7 +691,7 @@
hosting:
- '*'
- local.machine
weight: 0.5
weight: 1
reason: While this is a primary use case due to the specialization of Ansible, we must rely on scripts. More specialized types should be used, e.g., service.application.
- technology: terraform
component: software.application
Expand All @@ -707,7 +707,7 @@
hosting:
- '*'
- remote.machine
weight: 0.5
weight: 1
reason: While this is a primary use case due to the specialization of Ansible, we must rely on scripts. More specialized types should be used, e.g., service.application.
- technology: terraform
component: software.application
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

30 changes: 16 additions & 14 deletions src/controller/study/technology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Controller from '#controller'
import * as files from '#files'
import Graph from '#graph/graph'
import Loader from '#graph/loader'
import {toString} from '#technologies/utils'
import * as utils from '#utils'
import * as console from 'node:console'
import path from 'path'
Expand Down Expand Up @@ -230,6 +231,7 @@ export default async function (options: StudyTechnologyOptions) {
******************************************************************************************************************/

const qualityData: QualityData[] = []

for (const original of config.originals) {
const inputs = path.join(testsDir, original, 'inputs.yaml')

Expand All @@ -240,21 +242,21 @@ export default async function (options: StudyTechnologyOptions) {

qualityData.push({
scenario: original,
expert: utils.roundNumber(quality.max_weight.weight_average),
expert: toString(utils.roundNumber(quality.max_weight.weight_average)),
non_expert: [
utils.roundNumber(quality.min_weight.weight_average),
utils.roundNumber(quality.max_weight.weight_average),
toString(utils.roundNumber(quality.min_weight.weight_average)),
toString(utils.roundNumber(quality.max_weight.weight_average)),
],
random: [
utils.roundNumber(quality.min_weight.weight_average),
utils.roundNumber(quality.max_weight.weight_average),
toString(utils.roundNumber(quality.min_weight.weight_average)),
toString(utils.roundNumber(quality.max_weight.weight_average)),
],
counting: [
utils.roundNumber(quality.min_count.min_quality.weight_average),
utils.roundNumber(quality.min_count.max_quality.weight_average),
toString(utils.roundNumber(quality.min_count.min_quality.weight_average)),
toString(utils.roundNumber(quality.min_count.max_quality.weight_average)),
],
quality: utils.roundNumber(quality.max_weight.weight_average),
quality_counting: utils.roundNumber(quality.max_weight_min_count.weight_average),
quality: toString(utils.roundNumber(quality.max_weight.weight_average)),
quality_counting: toString(utils.roundNumber(quality.max_weight_min_count.weight_average)),
})
}

Expand Down Expand Up @@ -372,12 +374,12 @@ type RuleData = {

type QualityData = {
scenario: string
expert: number
expert: string
non_expert: any
random: number[]
counting: number[]
quality: number
quality_counting: number
random: string[]
counting: string[]
quality: string
quality_counting: string
}

type MetricsData = {
Expand Down
2 changes: 1 addition & 1 deletion src/resolver/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class Result {
}, {})

/**
* Weight Average (average weight per technology
* Weight Average (average weight per technology)
*/
const weight_average = weight_total / count_total

Expand Down
34 changes: 34 additions & 0 deletions src/technologies/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,37 @@ export function isIgnore(type: NodeType) {
if (check.isUndefined(type.metadata)) return false
return type.metadata[METADATA.VINTNER_IGNORE] === 'true'
}

export enum QUALITY_LABEL {
GOOD = 'good',
MODERATE = 'moderate',
CAUTIOUS = 'cautious',
POOR = 'poor',
BAD = 'bad',
}

export function toLabel(weight: number): QUALITY_LABEL {
if (weight < 0) throw new Error(`Unknown quality weight "${weight}"`)

if (weight <= 0.125) return QUALITY_LABEL.BAD
if (weight <= 0.375) return QUALITY_LABEL.POOR
if (weight <= 0.625) return QUALITY_LABEL.CAUTIOUS
if (weight <= 0.875) return QUALITY_LABEL.MODERATE
if (weight <= 1) return QUALITY_LABEL.GOOD

throw new Error(`Unknown quality weight "${weight}"`)
}

export function toString(weight: number): string {
return `${toLabel(weight)} (${weight})`
}

export function toWeight(label: QUALITY_LABEL) {
if (label === QUALITY_LABEL.GOOD) return 1
if (label === QUALITY_LABEL.MODERATE) return 0.75
if (label === QUALITY_LABEL.CAUTIOUS) return 0.5
if (label === QUALITY_LABEL.POOR) return 0.25
if (label === QUALITY_LABEL.BAD) return 0

throw new Error(`Unknown quality label "${label}"`)
}
3 changes: 2 additions & 1 deletion tasks/docs/generate/quality/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {ServiceTemplate, TOSCA_DEFINITIONS_VERSION} from '#spec/service-template
import {TechnologyRule} from '#spec/technology-template'
import Registry from '#technologies/plugins/rules/registry'
import {METADATA} from '#technologies/plugins/rules/types'
import {QUALITIES_FILENAME, constructRuleName} from '#technologies/utils'
import {QUALITIES_FILENAME, constructRuleName, toLabel} from '#technologies/utils'
import * as utils from '#utils'
import path from 'path'
import process from 'process'
Expand Down Expand Up @@ -97,6 +97,7 @@ async function main() {
svgs,
groups,
utils,
toLabel: toLabel,
link: (type: string) => {
if (type === '*') return type
return `[${type}](${generateLink(type)}){target=_blank}`
Expand Down
4 changes: 2 additions & 2 deletions tasks/docs/generate/quality/template.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The scenario does not require a specific hosting.
<figure markdown><%- scenario.svg %></figure>
<% scenario.technologies.forEach(technology => { %>
!!! <% if (technology.quality > 0.75) { -%>success<% } else if (technology.quality > 0.5) { -%>question<% } else if (technology.quality > 0.25) { -%>warning<% } else { -%>failure<% } -%> "<%= technology.name %> (Quality: <%= technology.quality %>)"
!!! <% if (technology.quality > 0.875) { -%>success<% } else if (technology.quality > 625) { -%>question<% } else if (technology.quality > 0.375) { -%>warning<% } else if (technology.quality > 0.125) { -%>failure<% }else { -%>danger<% } -%> "<%= technology.name %> has <%= toLabel(technology.quality) %> quality for this scenario!"
<%= technology.reason %>
<% }) %>
Expand All @@ -85,7 +85,7 @@ This appendix contains the deployment quality cards.
| Hosting | <%= rule.hosting.map(link).join(" -> ") %> |
<% } -%>
| Quality | <%= rule.weight %> |
| Label | <% if (rule.weight > 0.75) { -%>good<% } else if (rule.weight > 0.5) { -%>caution<% } else if (rule.weight > 0.25) { -%>poor<% } else { -%>bad<% } -%> |
| Label | <%= toLabel(rule.weight) -%> |
| Reason | <%= rule.reason %> |
| Graph |<figure markdown><%- svgs["rule." + rule.technology + "." + (index + 1)]%></figure>|
Expand Down

0 comments on commit b24fbc1

Please sign in to comment.