-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
451 lines (380 loc) · 16.7 KB
/
Copy pathapp.js
File metadata and controls
451 lines (380 loc) · 16.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
// EU Cloud Sovereignty Assessment Tool - Main Application
// Version: 3.0 - aligned with the official Implementation Guidance &
// Sovereignty Assessment Calculator (European Commission, 1 June 2026).
//
// Two independent outputs, exactly as in the official calculator:
// 1. Sovereignty Score = weighted average of the 8 objective scores, /1000.
// 2. SEAL level = the MINIMUM (weakest-link) SEAL across every answered
// criterion, on the official 0-4 scale.
// Application State
let currentObjectiveIndex = 0;
let currentQuestionIndex = 0;
let answers = {}; // globalIndex -> selected answer index
let objectiveResults = {};
// Flatten questions for easier navigation
let flatQuestions = [];
// Initialize the application
function initializeApp() {
flatQuestions = [];
assessmentData.objectives.forEach((objective, objIndex) => {
objective.questions.forEach((question, qIndex) => {
flatQuestions.push({
objectiveIndex: objIndex,
questionIndex: qIndex,
objective: objective,
question: question,
globalIndex: flatQuestions.length
});
});
});
}
// Start the assessment
function startAssessment() {
initializeApp();
currentObjectiveIndex = 0;
currentQuestionIndex = 0;
answers = {};
objectiveResults = {};
showScreen('assessment-screen');
displayQuestion();
}
// Show a specific screen
function showScreen(screenId) {
document.querySelectorAll('.screen').forEach(screen => {
screen.classList.remove('active');
});
document.getElementById(screenId).classList.add('active');
window.scrollTo(0, 0);
}
// Display the current question
function displayQuestion() {
const current = flatQuestions[getCurrentGlobalIndex()];
const { objective, question, globalIndex } = current;
const progress = ((globalIndex + 1) / flatQuestions.length) * 100;
document.getElementById('progress-fill').style.width = `${progress}%`;
document.getElementById('progress-text').textContent = `Question ${globalIndex + 1} of ${flatQuestions.length}`;
document.getElementById('current-objective-code').textContent = objective.code;
document.getElementById('current-objective-name').textContent = objective.name;
document.getElementById('current-objective-weight').textContent = `${Math.round(objective.weight * 100)}%`;
document.getElementById('question-number').textContent = `${objective.code} · Criterion ${question.number}`;
document.getElementById('question-text').textContent = question.text;
// Contextual help (collapsed by default on every question)
const helpEl = document.getElementById('question-help');
const helpToggle = document.getElementById('help-toggle');
helpEl.hidden = true;
helpToggle.classList.remove('active');
if (question.help) {
helpEl.textContent = question.help;
helpToggle.style.display = '';
} else {
helpEl.textContent = '';
helpToggle.style.display = 'none';
}
renderQuestionOptions(question, globalIndex);
updateNavigationButtons();
}
// Toggle the contextual help panel for the current question
function toggleHelp() {
const helpEl = document.getElementById('question-help');
const helpToggle = document.getElementById('help-toggle');
helpEl.hidden = !helpEl.hidden;
helpToggle.classList.toggle('active', !helpEl.hidden);
}
// Render the ordinal answer options for a question
function renderQuestionOptions(question, globalIndex) {
const optionsContainer = document.getElementById('question-options');
optionsContainer.innerHTML = '';
question.answers.forEach((answer, index) => {
const button = createOptionButton(answer.label, index, globalIndex);
optionsContainer.appendChild(button);
});
}
// Create an option button
function createOptionButton(label, value, globalIndex) {
const button = document.createElement('button');
button.className = 'option-btn';
button.onclick = (e) => selectOption(globalIndex, value, e);
const radio = document.createElement('div');
radio.className = 'option-radio';
const labelSpan = document.createElement('span');
labelSpan.textContent = label;
button.appendChild(radio);
button.appendChild(labelSpan);
if (answers[globalIndex] === value) {
button.classList.add('selected');
}
return button;
}
// Select an option
function selectOption(globalIndex, value, e) {
answers[globalIndex] = value;
const buttons = document.querySelectorAll('.option-btn');
buttons.forEach(btn => btn.classList.remove('selected'));
(e || window.event).currentTarget.classList.add('selected');
document.getElementById('next-btn').disabled = false;
}
// Get current global question index
function getCurrentGlobalIndex() {
let index = 0;
for (let i = 0; i < currentObjectiveIndex; i++) {
index += assessmentData.objectives[i].questions.length;
}
index += currentQuestionIndex;
return index;
}
// Navigate to next question
function nextQuestion() {
const globalIndex = getCurrentGlobalIndex();
if (globalIndex < flatQuestions.length - 1) {
const next = flatQuestions[globalIndex + 1];
currentObjectiveIndex = next.objectiveIndex;
currentQuestionIndex = next.questionIndex;
displayQuestion();
} else {
calculateResults();
showScreen('results-screen');
}
}
// Navigate to previous question
function previousQuestion() {
const globalIndex = getCurrentGlobalIndex();
if (globalIndex > 0) {
const prev = flatQuestions[globalIndex - 1];
currentObjectiveIndex = prev.objectiveIndex;
currentQuestionIndex = prev.questionIndex;
displayQuestion();
}
}
// Update navigation buttons state
function updateNavigationButtons() {
const globalIndex = getCurrentGlobalIndex();
document.getElementById('prev-btn').disabled = globalIndex === 0;
document.getElementById('next-btn').disabled = answers[globalIndex] === undefined;
const nextBtn = document.getElementById('next-btn');
nextBtn.textContent = (globalIndex === flatQuestions.length - 1) ? 'View Results' : 'Next';
}
// Look up a SEAL level descriptor
function getSealDescriptor(level) {
return assessmentData.sealLevels.find(s => s.level === level) || assessmentData.sealLevels[0];
}
// Calculate results following the official calculator methodology
function calculateResults() {
objectiveResults = {};
const divisor = assessmentData.framework.scoreDivisor || 1000;
let weightedScore = 0; // Σ (weight × objectiveScore)
let overallSeal = null; // weakest-link minimum across all criteria
assessmentData.objectives.forEach((objective, objIndex) => {
let objectiveScore = 0;
let objectiveMax = 0;
let objectiveSeal = null; // min SEAL within this objective
const limitingCriteria = []; // criteria selected at the lowest SEAL
objective.questions.forEach((question, qIndex) => {
const globalIndex = getGlobalIndexForQuestion(objIndex, qIndex);
const answerIndex = answers[globalIndex];
// Per-question maximum value (top answer on the ordinal ladder).
objectiveMax += Math.max(...question.answers.map(a => a.value));
if (answerIndex !== undefined) {
const answer = question.answers[answerIndex];
objectiveScore += answer.value;
if (overallSeal === null || answer.seal < overallSeal) overallSeal = answer.seal;
if (objectiveSeal === null || answer.seal < objectiveSeal) objectiveSeal = answer.seal;
}
});
// Record which criteria sit at this objective's minimum SEAL (the binding constraints).
objective.questions.forEach((question, qIndex) => {
const globalIndex = getGlobalIndexForQuestion(objIndex, qIndex);
const answerIndex = answers[globalIndex];
if (answerIndex !== undefined && question.answers[answerIndex].seal === objectiveSeal) {
limitingCriteria.push({
number: question.number,
text: question.text,
selected: question.answers[answerIndex].label,
seal: objectiveSeal
});
}
});
objectiveResults[objective.id] = {
code: objective.code,
name: objective.name,
weight: objective.weight,
score: objectiveScore,
maxScore: objectiveMax,
percentage: objectiveMax ? Math.round((objectiveScore / objectiveMax) * 100) : 0,
seal: objectiveSeal,
limitingCriteria
};
weightedScore += objective.weight * objectiveScore;
});
// Sovereignty Score: weighted average of objective scores, normalised by the divisor.
const sovScoreFraction = Math.min(weightedScore / divisor, 1);
displayResults(sovScoreFraction, weightedScore / divisor, overallSeal ?? 0);
}
// Get global index for a specific objective/question combination
function getGlobalIndexForQuestion(objIndex, qIndex) {
let index = 0;
for (let i = 0; i < objIndex; i++) {
index += assessmentData.objectives[i].questions.length;
}
index += qIndex;
return index;
}
// Display results
function displayResults(sovScoreFraction, rawWeighted, overallSeal) {
const percentage = Math.round(sovScoreFraction * 100);
const seal = getSealDescriptor(overallSeal);
// Sovereignty Score
document.getElementById('sov-score-value').textContent = `${percentage}%`;
document.getElementById('sov-score-detail').textContent =
`Weighted sovereignty score · ${Math.round(rawWeighted * 1000)} / 1000`;
// SEAL badge (weakest link)
const sealBadge = document.getElementById('seal-badge');
sealBadge.className = `seal-badge seal-${seal.level}`;
sealBadge.innerHTML = `
<div class="seal-code">${seal.code}</div>
<div class="seal-name">${seal.name}</div>
<div class="seal-desc">${seal.description}</div>
`;
displayObjectivesBreakdown();
displayRecommendations(overallSeal);
}
// Display objectives breakdown
function displayObjectivesBreakdown() {
const container = document.getElementById('objectives-breakdown');
container.innerHTML = '<h3>Breakdown by Objective</h3>';
Object.values(objectiveResults).forEach(obj => {
const seal = getSealDescriptor(obj.seal);
const item = document.createElement('div');
item.className = 'breakdown-item';
item.innerHTML = `
<div class="breakdown-label">
<strong>${obj.code}</strong> ${obj.name}
<span class="breakdown-weight">weight ${Math.round(obj.weight * 100)}%</span>
</div>
<div class="breakdown-right">
<span class="breakdown-seal seal-pill seal-${obj.seal}">${seal.code}</span>
<span class="breakdown-score">${obj.percentage}%</span>
</div>
<div class="breakdown-bar">
<div class="breakdown-bar-fill" style="width: ${obj.percentage}%"></div>
</div>
`;
container.appendChild(item);
});
}
// Display recommendations — focus on the weakest-link criteria that cap the SEAL
function displayRecommendations(overallSeal) {
const container = document.getElementById('recommendations');
container.innerHTML = '<h3>Priorities for Improvement</h3>';
const maxLevel = Math.max(...assessmentData.sealLevels.map(s => s.level));
const sealName = getSealDescriptor(overallSeal).code;
if (overallSeal >= maxLevel) {
const top = getSealDescriptor(maxLevel);
const p = document.createElement('p');
p.className = 'rec-intro';
p.innerHTML = `Outstanding — every criterion already reaches <strong>${top.code} (${top.name})</strong>, ` +
`the highest SEAL. The only remaining work is lifting any objective below 100% to raise the Sovereignty Score.`;
container.appendChild(p);
} else {
const intro = document.createElement('p');
intro.className = 'rec-intro';
intro.innerHTML = `Your overall SEAL is <strong>${sealName}</strong>, set by the lowest-scoring criteria below. ` +
`Because SEAL is a weakest-link measure, raising it requires improving <em>every</em> criterion currently at ${sealName}.`;
container.appendChild(intro);
// Criteria across all objectives that sit at the overall (binding) SEAL.
const binding = [];
Object.values(objectiveResults).forEach(obj => {
obj.limitingCriteria.forEach(c => {
if (c.seal === overallSeal) binding.push({ code: obj.code, ...c });
});
});
binding.forEach(c => {
const div = document.createElement('div');
div.className = 'recommendation-item';
div.innerHTML = `<strong>${c.code} · Criterion ${c.number}</strong> (currently ${getSealDescriptor(c.seal).code}): ` +
`${c.text} <em>— your answer: "${c.selected}".</em>`;
container.appendChild(div);
});
}
// Also surface the lowest-scoring objectives for the Sovereignty Score.
const weak = Object.values(objectiveResults)
.filter(o => o.percentage < 75)
.sort((a, b) => a.percentage - b.percentage);
if (weak.length) {
const h = document.createElement('p');
h.className = 'rec-intro';
h.textContent = 'Objectives dragging down the Sovereignty Score (below 75%):';
container.appendChild(h);
weak.forEach(o => {
const div = document.createElement('div');
div.className = 'recommendation-item';
div.textContent = `${o.code} ${o.name}: ${o.percentage}% (weight ${Math.round(o.weight * 100)}%)`;
container.appendChild(div);
});
}
}
// Download report
function downloadReport() {
const sovScore = document.getElementById('sov-score-value').textContent;
const sealCode = document.querySelector('#seal-badge .seal-code')?.textContent || '';
const sealName = document.querySelector('#seal-badge .seal-name')?.textContent || '';
const timestamp = new Date().toISOString().replace(/:/g, '-').split('.')[0];
let report = `EU CLOUD SOVEREIGNTY FRAMEWORK ASSESSMENT
==========================================
Assessment Date: ${new Date().toLocaleString()}
Assessment ID: cloud-sovereignty-assessment-${timestamp}
Methodology: ${assessmentData.framework.name} ${assessmentData.framework.version}
${assessmentData.framework.methodology}
RESULTS
-------
Sovereignty Score : ${sovScore}
SEAL (weakest link): ${sealCode} - ${sealName}
The SEAL level is the LOWEST SEAL achieved on any single criterion. The
Sovereignty Score is the weighted average of the eight objective scores.
SCORE BREAKDOWN BY OBJECTIVE
----------------------------
`;
Object.values(objectiveResults).forEach(obj => {
report += `${obj.code} ${obj.name} (weight ${Math.round(obj.weight * 100)}%): ` +
`${obj.percentage}% | objective SEAL: ${getSealDescriptor(obj.seal).code}\n`;
});
report += `
BINDING CRITERIA (currently capping the overall SEAL)
-----------------------------------------------------
`;
const overallSeal = Math.min(...Object.values(objectiveResults).map(o => o.seal));
Object.values(objectiveResults).forEach(obj => {
obj.limitingCriteria.forEach(c => {
if (c.seal === overallSeal) {
report += `• ${obj.code} · Criterion ${c.number} (${getSealDescriptor(c.seal).code}): ${c.text}\n Your answer: "${c.selected}"\n`;
}
});
});
report += `
Reference: ${assessmentData.framework.name} ${assessmentData.framework.version};
Implementation Guidance and Sovereignty Assessment Calculator (1 June 2026).
This tool is provided for informational and self-assessment purposes only.
It does not constitute legal advice or official EU certification. Point values
are reference figures that contracting authorities may adapt.
`;
const blob = new Blob([report], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `cloud-sovereignty-assessment-${timestamp}.txt`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
// Restart assessment
function restartAssessment() {
currentObjectiveIndex = 0;
currentQuestionIndex = 0;
answers = {};
objectiveResults = {};
showScreen('welcome-screen');
}
// Initialize on page load
document.addEventListener('DOMContentLoaded', () => {
initializeApp();
});