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

808 score breakdown #896

Merged
merged 9 commits into from
Jan 24, 2022
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
6 changes: 6 additions & 0 deletions src/interfaces/RiskArea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default interface RiskArea {
risk_area: string;
no_of_questions: number;
project_score: number;
maximum_score: number;
}
5 changes: 5 additions & 0 deletions src/plugins/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"riskArea": "Risk Area",
"noOfQuestions": "No. of Questions",
"projectScore": "Project Score",
"maximumScore": "Maximum Score",
"mitigationArea": "Mitigation Area",
"showHelp": "Show help",
"startAgain": "Start Again",
"version": "Version: 0.9.1",
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/fr.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"riskArea": "Secteur de risque",
"noOfQuestions": "Nombre de questions",
"projectScore": "Cote du projet",
"maximumScore": "Cote maximale",
"mitigationArea": "Secteur d'atténuation",
"showHelp": "Afficher l'aide",
"startAgain": "Recommencer",
"version": "Version: 0.9.1",
Expand Down
29 changes: 29 additions & 0 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,29 @@ function calculateFinalScore(
return [rawRiskScore, mitigationScore, total, level];
}

function calculateSectionScore(
survey: SurveyModel,
questionNames: string[],
section: string
): number[] {
let projectScore = 0;
let maximumScore = 0;
let noOfQuesions = 0;

let questionNamesBySection = questionNames.filter(name =>
name.includes(section)
);
noOfQuesions = questionNamesBySection.length;
questionNamesBySection.forEach(name => {
var currentQuestion = survey.getQuestionByName(name);
// eslint-disable-next-line security/detect-object-injection
projectScore += getValue(survey.data[name]);
maximumScore += getMaxScoreForQuestion(<QuestionSelectBase>currentQuestion);
});

return [noOfQuesions, projectScore, maximumScore];
}

//Toggles wheather the next button appears based on if it is located on the last page
function toggleButton(state: RootState): void {
//When I do not include the btn class it prevents from the next button same for prev button from showing
Expand Down Expand Up @@ -319,6 +342,12 @@ const store: StoreOptions<RootState> = {
if (state.result === undefined) return [0, 0, 0];
return calculateFinalScore(state.result, state.questionNames);
},
getScoreBySection: state => (section: string) => {
if (state.result === undefined) {
return [0, 0, 0];
}
return calculateSectionScore(state.result, state.questionNames, section);
},
getTranslationsOnResult: state => {
return state.translationsOnResult;
},
Expand Down
107 changes: 106 additions & 1 deletion src/views/Results.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,23 @@
{{ $t("currentScore") }} {{ ": " + score[2] }}
</h3>
<h3>{{ $t("rawRiskScore") }}{{ ": " + score[0] }}</h3>

<b-table
striped
hover
:items="riskAreaItems()"
:fields="riskAreaFields"
></b-table>

<h3>{{ $t("mitigationScore") }}{{ ": " + score[1] }}</h3>

<b-table
striped
hover
:items="mitigationItems()"
:fields="mitigationFields"
></b-table>

<Obligations />
<div class="row">
<h2 id="qA">{{ "Section 3: " + $t("resultSectionQA") }}</h2>
Expand Down Expand Up @@ -108,7 +124,7 @@
</div>
</div>

<div style="margin-bottom:15px;">
<div style="margin-bottom: 15px">
<h1>{{ $t("export") }}</h1>
<button
type="button"
Expand Down Expand Up @@ -267,6 +283,7 @@ import Obligations from "@/components/Obligations.vue";
import SurveyFile from "@/interfaces/SurveyFile";
import i18n from "@/plugins/i18n";
import surveyJSON from "@/survey-enfr.json";
import RiskArea from "@/interfaces/RiskArea";

@Component({
components: {
Expand All @@ -284,6 +301,94 @@ import surveyJSON from "@/survey-enfr.json";
export default class Results extends Vue {
myResults = this.$store.getters.resultDataSections;

riskAreaFields = [
{ key: "risk_area", label: this.$t("riskArea").toString() },
{ key: "no_of_questions", label: this.$t("noOfQuestions").toString() },
{ key: "project_score", label: this.$t("projectScore").toString() },
{ key: "maximum_score", label: this.$t("maximumScore").toString() }
];

mitigationFields = [
{ key: "risk_area", label: this.$t("mitigationArea").toString() },
{ key: "no_of_questions", label: this.$t("noOfQuestions").toString() },
{ key: "project_score", label: this.$t("projectScore").toString() },
{ key: "maximum_score", label: this.$t("maximumScore").toString() }
];

riskAreaItems() {
let items: RiskArea[] = [];
let totalNoQuestions = 0;
let totalProjectScore = 0;
let totalMaxScore = 0;
if (this.myResults[1]?.length > 0) {
this.myResults[1].forEach((myResult: any) => {
if (myResult.questionHeader !== undefined) {
let riskAreaTitle = myResult.questionHeader;
let riskAreaName = myResult.name.replace(/\d/, "");
let sectionScore = this.$store.getters.getScoreBySection(
riskAreaName
);
items.push({
risk_area: riskAreaTitle[this.$i18n.locale],
no_of_questions: sectionScore[0],
project_score: sectionScore[1],
maximum_score: sectionScore[2]
});
totalNoQuestions += sectionScore[0];
totalProjectScore += sectionScore[1];
totalMaxScore += sectionScore[2];
}
});
}
items.push({
risk_area: this.$t("rawRiskScore")
.toString()
.toUpperCase(),
no_of_questions: totalNoQuestions,
project_score: totalProjectScore,
maximum_score: totalMaxScore
});
return items;
}

mitigationItems() {
let items: RiskArea[] = [];
let totalNoQuestions = 0;
let totalProjectScore = 0;
let totalMaxScore = 0;
if (this.myResults[2]?.length > 0) {
this.myResults[2].forEach((myResult: any) => {
if (myResult.questionHeader !== undefined) {
let riskAreaTitle = myResult.questionHeader;
let riskAreaName = myResult.name.replace(/\d/, "");
let sectionScore = this.$store.getters.getScoreBySection(
riskAreaName
);
items.push({
risk_area: riskAreaTitle[this.$i18n.locale]
? riskAreaTitle[this.$i18n.locale]
: riskAreaTitle["en"],
no_of_questions: sectionScore[0],
project_score: sectionScore[1],
maximum_score: sectionScore[2]
});
totalNoQuestions += sectionScore[0];
totalProjectScore += sectionScore[1];
totalMaxScore += sectionScore[2];
}
});
}
items.push({
risk_area: this.$t("mitigationScore")
.toString()
.toUpperCase(),
no_of_questions: totalNoQuestions,
project_score: totalProjectScore,
maximum_score: totalMaxScore
});
return items;
}

Survey: Model = new Model(surveyJSON);

startAgain() {
Expand Down