Skip to content

Commit 2bf2b0d

Browse files
committed
Added control validation for pillars and notions before saving scenarios
1 parent 46ef833 commit 2bf2b0d

File tree

1 file changed

+118
-82
lines changed

1 file changed

+118
-82
lines changed

nebula/frontend/templates/deployment.html

+118-82
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ <h5 class="step-number">Trustworthiness <i class="fa fa-handshake-o"></i>
710710
'robustness-pillar', 'privacy-pillar', 'fairness-pillar', 'explainability-pillar',
711711
'accountability-pillar', 'architectural-soundness-pillar', 'sustainability-pillar', 'robustness-notion-1', 'robustness-notion-2',
712712
'robustness-notion-3', 'privacy-notion-1', 'privacy-notion-2', 'privacy-notion-3', 'fairness-notion-1', 'fairness-notion-2', 'fairness-notion-3',
713-
'explainability-notion-1', 'explainability-notion-2', 'accountability-notion-1', 'architectural_soundness-notion-1', 'architectural_soundness-notion-2',
713+
'explainability-notion-1', 'explainability-notion-2', 'architectural-soundness-notion-1', 'architectural-soundness-notion-2',
714714
'sustainability-notion-1', 'sustainability-notion-2', 'sustainability-notion-3',
715715
checked)" style="display: none;">
716716
<label for="trustworthiness-lock" class="icon-container" style="float: right;">
@@ -860,7 +860,7 @@ <h5 class="step-title">Accountability pillar</h5>
860860
<h5 class="step-title">Factsheet completeness notion</h5>
861861
<input type="number" class="form-control" id="accountability-notion-1"
862862
placeholder="Factsheet completeness notion" min="100" value="100"
863-
style="display: inline; width: 70%;">
863+
style="display: inline; width: 70%;" disabled="true">
864864
<small class="form-text text-muted">%</small>
865865
</div>
866866
</div>
@@ -876,14 +876,14 @@ <h5 class="step-title">Architectural soundness pillar</h5>
876876
<div class="notion-container">
877877
<div class="notion">
878878
<h5 class="step-title">Client management notion</h5>
879-
<input type="number" class="form-control" id="architectural_soundness-notion-1"
879+
<input type="number" class="form-control" id="architectural-soundness-notion-1"
880880
placeholder="Client management notion" min="20" value="50"
881881
style="display: inline; width: 70%;">
882882
<small class="form-text text-muted">%</small>
883883
</div>
884884
<div class="notion">
885885
<h5 class="step-title">Optimization notion</h5>
886-
<input type="number" class="form-control" id="architectural_soundness-notion-2"
886+
<input type="number" class="form-control" id="architectural-soundness-notion-2"
887887
placeholder="Optimization notion" min="20" value="50"
888888
style="display: inline; width: 70%;">
889889
<small class="form-text text-muted">%</small>
@@ -1320,8 +1320,8 @@ <h5 class="step-title">Federation complexity notion</h5>
13201320
data["accountability_pillar"] = document.getElementById("accountability-pillar").value
13211321
data["factsheet_completeness"] = document.getElementById("accountability-notion-1").value
13221322
data["architectural_soundness_pillar"] = document.getElementById("architectural-soundness-pillar").value
1323-
data["client_management"] = document.getElementById("architectural_soundness-notion-1").value
1324-
data["optimization"] = document.getElementById("architectural_soundness-notion-2").value
1323+
data["client_management"] = document.getElementById("architectural-soundness-notion-1").value
1324+
data["optimization"] = document.getElementById("architectural-soundness-notion-2").value
13251325
data["sustainability_pillar"] = document.getElementById("sustainability-pillar").value
13261326
data["energy_source"] = document.getElementById("sustainability-notion-1").value
13271327
data["hardware_efficiency"] = document.getElementById("sustainability-notion-2").value
@@ -1448,9 +1448,9 @@ <h5 class="step-title">Federation complexity notion</h5>
14481448
document.getElementById("explainability-notion-2").value = data["post_hoc_methods"]
14491449
document.getElementById("accountability-pillar").value = data["accountability_pillar"]
14501450
document.getElementById("accountability-notion-1").value = data["factsheet_completeness"]
1451-
document.getElementById("architectural_soundness-pillar").value = data["architectural_soundness_pillar"]
1452-
document.getElementById("architectural_soundness-notion-1").value = data["client_management"]
1453-
document.getElementById("architectural_soundness-notion-2").value = data["optimization"]
1451+
document.getElementById("architectural-soundness-pillar").value = data["architectural_soundness_pillar"]
1452+
document.getElementById("architectural-soundness-notion-1").value = data["client_management"]
1453+
document.getElementById("architectural-soundness-notion-2").value = data["optimization"]
14541454
document.getElementById("sustainability-pillar").value = data["sustainability_pillar"]
14551455
document.getElementById("sustainability-notion-1").value = data["energy_source"]
14561456
document.getElementById("sustainability-notion-2").value = data["hardware_efficiency"]
@@ -2032,30 +2032,42 @@ <h5 class="step-title">Federation complexity notion</h5>
20322032

20332033
//When click "add-btn" button, save actual scenario in the list of scenarios
20342034
document.getElementById("add-btn").addEventListener("click", function(){
2035-
scenarioStorage.saveScenario();
2036-
scenarioStorage.actual_scenario = scenarioStorage.scenariosList.length - 1;
2037-
2038-
sessionStorage.setItem("ScenarioList", JSON.stringify(scenarioStorage.scenariosList));
2035+
trust = document.getElementById("with-trustworthiness-btn").checked ? true : false
20392036

2040-
updateScenariosPosition();
2041-
2042-
var actual_scenario = scenarioStorage.scenariosList[scenarioStorage.actual_scenario];
2043-
setScenarioData(actual_scenario);
2037+
var message= null;
2038+
if (trust === true){
2039+
message = checkWeights()
2040+
}
20442041

2045-
document.getElementById("add-btn").style.display = "none";
2046-
if(scenarioStorage.scenariosList.length == 1){
2047-
document.getElementById("prev-btn").style.display = "none";
2048-
document.getElementById("next-btn").style.display = "none";
2042+
if (message!=null){
2043+
showAlert('info', message);
20492044
}
20502045
else{
2051-
document.getElementById("prev-btn").style.display = "inline-block";
2052-
}
2053-
document.getElementById("new-btn").style.display = "inline-block";
2054-
document.getElementById("del-btn").style.display = "inline-block";
2046+
scenarioStorage.saveScenario();
2047+
scenarioStorage.actual_scenario = scenarioStorage.scenariosList.length - 1;
2048+
2049+
sessionStorage.setItem("ScenarioList", JSON.stringify(scenarioStorage.scenariosList));
2050+
2051+
updateScenariosPosition();
2052+
2053+
var actual_scenario = scenarioStorage.scenariosList[scenarioStorage.actual_scenario];
2054+
setScenarioData(actual_scenario);
2055+
2056+
document.getElementById("add-btn").style.display = "none";
2057+
if(scenarioStorage.scenariosList.length == 1){
2058+
document.getElementById("prev-btn").style.display = "none";
2059+
document.getElementById("next-btn").style.display = "none";
2060+
}
2061+
else{
2062+
document.getElementById("prev-btn").style.display = "inline-block";
2063+
}
2064+
document.getElementById("new-btn").style.display = "inline-block";
2065+
document.getElementById("del-btn").style.display = "inline-block";
20552066

2056-
//Enable run
2057-
if(document.getElementById("run-btn").disabled){
2058-
document.getElementById("run-btn").disabled = false;
2067+
//Enable run
2068+
if(document.getElementById("run-btn").disabled){
2069+
document.getElementById("run-btn").disabled = false;
2070+
}
20592071
}
20602072
});
20612073

@@ -2338,58 +2350,42 @@ <h5 class="step-title">Federation complexity notion</h5>
23382350
'<br><p class="badge text-bg-danger">Warning: you will stop the running scenario and start a new one</p>');
23392351
document.getElementById("yes-button").disabled = false;
23402352

2341-
trust = document.getElementById("with-trustworthiness-btn").checked ? true : false
2353+
document.getElementById("yes-button").addEventListener("click", function () {
23422354

2343-
var check_weights = true;
2355+
scenarioStorage.replaceScenario();
2356+
var data = scenarioStorage.scenariosList;
23442357

2345-
if (trust === true){
2346-
check_weights = checkWights()
2347-
}
2358+
// Hide the modal
2359+
$('#confirm-modal').modal('hide');
2360+
document.querySelector(".overlay").style.display = "block";
2361+
document.getElementById("spinner").style.display = "block";
23482362

2349-
if (checkWights){
2350-
2351-
document.getElementById("yes-button").addEventListener("click", function () {
2352-
2353-
scenarioStorage.replaceScenario();
2354-
var data = scenarioStorage.scenariosList;
2355-
2356-
// Hide the modal
2357-
$('#confirm-modal').modal('hide');
2358-
document.querySelector(".overlay").style.display = "block";
2359-
document.getElementById("spinner").style.display = "block";
2360-
2361-
fetch("/nebula/dashboard/deployment/run", {
2362-
method: "POST",
2363-
headers: {
2364-
'Content-Type': 'application/json'
2365-
},
2366-
body: JSON.stringify(data)
2367-
})
2368-
.then(response => {
2369-
if (response.redirected) {
2370-
window.location.href = response.url;
2371-
} else {
2372-
document.querySelector(".overlay").style.display = "none";
2373-
document.getElementById("spinner").style.display = "none";
2374-
// If the user is a demo, show a modal with a message
2375-
$('#confirm-modal').on('hidden.bs.modal', function () {
2376-
$('#info-modal-body').html('You are not allowed to run a scenario. You have a limited functionality or a scenario is already running');
2377-
$('#info-modal').modal('show');
2378-
});
2379-
}
2380-
})
2381-
.catch(error => {
2382-
console.error('Error:', error);
2363+
fetch("/nebula/dashboard/deployment/run", {
2364+
method: "POST",
2365+
headers: {
2366+
'Content-Type': 'application/json'
2367+
},
2368+
body: JSON.stringify(data)
2369+
})
2370+
.then(response => {
2371+
if (response.redirected) {
2372+
window.location.href = response.url;
2373+
} else {
23832374
document.querySelector(".overlay").style.display = "none";
23842375
document.getElementById("spinner").style.display = "none";
2385-
});
2386-
2376+
// If the user is a demo, show a modal with a message
2377+
$('#confirm-modal').on('hidden.bs.modal', function () {
2378+
$('#info-modal-body').html('You are not allowed to run a scenario. You have a limited functionality or a scenario is already running');
2379+
$('#info-modal').modal('show');
2380+
});
2381+
}
2382+
})
2383+
.catch(error => {
2384+
console.error('Error:', error);
2385+
document.querySelector(".overlay").style.display = "none";
2386+
document.getElementById("spinner").style.display = "none";
23872387
});
2388-
} else {
2389-
$('#confirm-modal-body').html('The sum of all pillar importances is not equal to 100.\n' +
2390-
'<br><br><p style="color: #772953; font-weight: bold">To calculate the trustworthiness of the scenario, the importance of all the pillas must be equal to 100.</p>');
2391-
document.getElementById("yes-button").disabled = false;
2392-
}
2388+
});
23932389
}
23942390
});
23952391

@@ -2622,22 +2618,62 @@ <h5 class="step-title">Federation complexity notion</h5>
26222618
document.getElementById("federationArchitecture").disabled = true;
26232619
});
26242620

2625-
function checkWights() {
2621+
function checkWeights() {
2622+
var message = null
2623+
26262624
var robustness_percent = parseFloat(document.getElementById("robustness-pillar").value);
26272625
var privacy_percent = parseFloat(document.getElementById("privacy-pillar").value);
26282626
var fairness_percent = parseFloat(document.getElementById("fairness-pillar").value);
26292627
var explainability_percent = parseFloat(document.getElementById("explainability-pillar").value);
26302628
var accountability_percent = parseFloat(document.getElementById("accountability-pillar").value);
26312629
var architectural_soundness_percent = parseFloat(document.getElementById("architectural-soundness-pillar").value);
26322630
var sustainability_percent = parseFloat(document.getElementById("sustainability-pillar").value);
2633-
2634-
var total_percent = robustness_percent + privacy_percent + fairness_percent + explainability_percent + accountability_percent + architectural_soundness_percent + sustainability_percent;
2635-
2636-
if (total_percent === 100) {
2637-
return true;
2631+
var robustness_notion_1 = parseFloat(document.getElementById("robustness-notion-1").value);
2632+
var robustness_notion_2 = parseFloat(document.getElementById("robustness-notion-2").value);
2633+
var robustness_notion_3 = parseFloat(document.getElementById("robustness-notion-3").value);
2634+
var privacy_notion_1 = parseFloat(document.getElementById("privacy-notion-1").value);
2635+
var privacy_notion_2 = parseFloat(document.getElementById("privacy-notion-2").value);
2636+
var privacy_notion_3 = parseFloat(document.getElementById("privacy-notion-3").value);
2637+
var fairness_notion_1 = parseFloat(document.getElementById("fairness-notion-1").value);
2638+
var fairness_notion_2 = parseFloat(document.getElementById("fairness-notion-2").value);
2639+
var fairness_notion_3 = parseFloat(document.getElementById("fairness-notion-3").value);
2640+
var explainability_notion_1 = parseFloat(document.getElementById("explainability-notion-1").value);
2641+
var explainability_notion_2 = parseFloat(document.getElementById("explainability-notion-2").value);
2642+
var architectural_soundness_notion_1 = parseFloat(document.getElementById("architectural-soundness-notion-1").value);
2643+
var architectural_soundness_notion_2 = parseFloat(document.getElementById("architectural-soundness-notion-2").value);
2644+
var sustainability_notion_1 = parseFloat(document.getElementById("sustainability-notion-1").value);
2645+
var sustainability_notion_2 = parseFloat(document.getElementById("sustainability-notion-2").value);
2646+
var sustainability_notion_3 = parseFloat(document.getElementById("sustainability-notion-3").value);
2647+
2648+
var total_pillar = robustness_percent + privacy_percent + fairness_percent + explainability_percent + accountability_percent + architectural_soundness_percent + sustainability_percent;
2649+
var total_robustness_notion = robustness_notion_1 + robustness_notion_2 + robustness_notion_3;
2650+
var total_privacy_notion = privacy_notion_1 + privacy_notion_2 + privacy_notion_3;
2651+
var total_fairness_notion = fairness_notion_1 + fairness_notion_2 + fairness_notion_3;
2652+
var total_explainability_notion = explainability_notion_1 + explainability_notion_2;
2653+
var total_architectural_soundness_notion = architectural_soundness_notion_1 + architectural_soundness_notion_2;
2654+
var total_sustainability_notion = sustainability_notion_1 + sustainability_notion_2 + sustainability_notion_3;
2655+
2656+
if (total_pillar != 100) {
2657+
return '[Trustworthiness] Check pillars weights';
2658+
}
2659+
if(total_robustness_notion != 100){
2660+
return '[Trustworthiness] Check robustness notions weights';
2661+
}
2662+
if(total_privacy_notion != 100){
2663+
return '[Trustworthiness] Check privacy notions weights';
2664+
}
2665+
if(total_fairness_notion != 100){
2666+
return '[Trustworthiness] Check fairness notions weights';
2667+
}
2668+
if(total_explainability_notion != 100){
2669+
return '[Trustworthiness] Check explainability notions weights';
2670+
}
2671+
if(total_architectural_soundness_notion != 100){
2672+
return '[Trustworthiness] Check architectural soundness notions weights';
2673+
}
2674+
if(total_sustainability_notion != 100){
2675+
return '[Trustworthiness] Check sustainability notions weights';
26382676
}
2639-
2640-
return false;
26412677
}
26422678
</script>
26432679

0 commit comments

Comments
 (0)