Skip to content

Commit

Permalink
Adding docx export, closes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
davetaz committed May 28, 2024
1 parent d870765 commit 32679dc
Show file tree
Hide file tree
Showing 6 changed files with 478 additions and 6 deletions.
19 changes: 15 additions & 4 deletions controllers/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ async function getUserProjectMetrics(userProjects) {
topRisks.push({
projectId: project._id,
consequence: unintendedConsequence.consequence,
score: unintendedConsequence.riskScore
score: unintendedConsequence.riskScore,
level: getScoreText(unintendedConsequence.riskScore/3)
});
}
}
Expand All @@ -124,9 +125,9 @@ async function getUserProjectMetrics(userProjects) {
const top5Risks = topRisks.slice(0, 5);

// Calculate averages
const averageLikelihood = totalLikelihood / totalUnintendedConsequences;
const averageImpact = totalImpact / totalUnintendedConsequences;
const averageRiskScore = totalRiskScore / totalUnintendedConsequences;
const averageLikelihood = (totalLikelihood / totalUnintendedConsequences).toFixed(2);
const averageImpact = (totalImpact / totalUnintendedConsequences).toFixed(2);
const averageRiskScore = (totalRiskScore / totalUnintendedConsequences).toFixed(2);

// Return risk counts, averages, and top 5 risks as a data object
return {
Expand All @@ -153,6 +154,16 @@ function getRiskValue(textValue) {
}
}

function getScoreText(score) {
if (score < 1) {
return 'Low';
} else if (score < 2) {
return 'Medium';
} else {
return 'High';
}
}

async function addRiskScoreToProject(project) {
for (const unintendedConsequence of project.unintendedConsequences) {
// Check if both impact and likelihood are defined
Expand Down
Loading

0 comments on commit 32679dc

Please sign in to comment.