From b577ec61eddbb233f802e09710e9f4fef2f9231e Mon Sep 17 00:00:00 2001
From: Ludovic Apvrille <ludovic.apvrille@telecom-paris.fr>
Date: Tue, 21 May 2024 18:09:27 +0200
Subject: [PATCH] Adding CSV line

---
 src/main/java/ui/MainGUI.java                 |  3 +-
 src/main/java/ui/TDiagramPanel.java           |  1 +
 .../java/ui/atd/AttackTreeDiagramPanel.java   | 30 +++++++++++++++++--
 3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/src/main/java/ui/MainGUI.java b/src/main/java/ui/MainGUI.java
index 8f4181f9ee..1a2e69cff2 100644
--- a/src/main/java/ui/MainGUI.java
+++ b/src/main/java/ui/MainGUI.java
@@ -3553,6 +3553,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Per
             JFrameBasicText fbt = new JFrameBasicText("SysML V2 - " + getCurrentTDiagramPanel().getName(), data);
             fbt.setSize(800, 800);
             fbt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+            GraphicLib.centerFrame(fbt, frame);
             fbt.setVisible(true);
             TraceManager.addDev("Frame shown");
         }
@@ -3588,7 +3589,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Per
             JFrameBasicText fbt = new JFrameBasicText("Textual format - " + getCurrentTDiagramPanel().getName(), data);
             fbt.setSize(800, 800);
             fbt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
+            GraphicLib.centerFrame(fbt, frame);
             fbt.setVisible(true);
             TraceManager.addDev("Frame shown");
         }
diff --git a/src/main/java/ui/TDiagramPanel.java b/src/main/java/ui/TDiagramPanel.java
index 831dd8a59a..6f405c9878 100644
--- a/src/main/java/ui/TDiagramPanel.java
+++ b/src/main/java/ui/TDiagramPanel.java
@@ -108,6 +108,7 @@ import java.util.*;
 public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
     protected final static String CR = "\n";
+    protected final static String CSV_SEP = ",";
 
     protected TDiagramMouseManager tdmm;
     protected PanelKeyListener pkl;
diff --git a/src/main/java/ui/atd/AttackTreeDiagramPanel.java b/src/main/java/ui/atd/AttackTreeDiagramPanel.java
index 8e94a37823..323bf128b2 100644
--- a/src/main/java/ui/atd/AttackTreeDiagramPanel.java
+++ b/src/main/java/ui/atd/AttackTreeDiagramPanel.java
@@ -618,6 +618,8 @@ public class AttackTreeDiagramPanel extends TDiagramPanel implements TDPWithAttr
 
 
     public String getStats() {
+        double synCorrect = 0.0;
+
         StringBuffer sb = new StringBuffer();
 
         sb.append(CR + "# General stats" + CR);
@@ -634,15 +636,18 @@ public class AttackTreeDiagramPanel extends TDiagramPanel implements TDPWithAttr
             sb.append("- Tree has " + getNbOfRootAttacks() + " root attacks -> ERROR " + CR + CR);
         }
 
+        double tva = 0.0;
         HashMap<ATDAttack, ArrayList<Boolean>> mapOfSyntaxForAttacks = computeSyntaxRulesForAttacks();
         for(ATDAttack attack: mapOfSyntaxForAttacks.keySet()) {
             sb.append("- Attack " + attack.getAttackName());
             int nbOfTrue = 0;
             ArrayList<Boolean> list = mapOfSyntaxForAttacks.get(attack);
             String notRespected = "";
+            double not = list.size();
             for(int i=0; i<list.size(); i++) {
                 if (list.get(i)) { nbOfTrue++; } else {
                     notRespected += " " + (i+1);
+                    not --;
                 }
             }
             if (nbOfTrue == syntaxRulesOfAttacks.length) {
@@ -650,9 +655,11 @@ public class AttackTreeDiagramPanel extends TDiagramPanel implements TDPWithAttr
             } else {
                 sb.append(" does NOT respect rules: " + notRespected.trim() +  ". ERROR" + CR);
             }
+            tva += not / list.size();
         }
 
         sb.append(CR);
+        double tvo = 0.0;
         HashMap<ATDConstraint, ArrayList<Boolean>> mapOfSyntaxForConstraints = computeSyntaxRulesForOperators();
         for(ATDConstraint constraint: mapOfSyntaxForConstraints.keySet()) {
             String name = constraint.getValue();
@@ -664,9 +671,11 @@ public class AttackTreeDiagramPanel extends TDiagramPanel implements TDPWithAttr
             int nbOfTrue = 0;
             ArrayList<Boolean> list = mapOfSyntaxForConstraints.get(constraint);
             String notRespected = "";
+            double not = list.size();
             for(int i=0; i<list.size(); i++) {
                 if (list.get(i)) { nbOfTrue++; } else {
                     notRespected += " " + (i+1);
+                    not --;
                 }
             }
             if (nbOfTrue == syntaxRulesOfOperators.length) {
@@ -674,8 +683,21 @@ public class AttackTreeDiagramPanel extends TDiagramPanel implements TDPWithAttr
             } else {
                 sb.append(" does NOT respect rules: " + notRespected.trim() +  ". ERROR" + CR);
             }
+            tvo += not / list.size();
+
         }
 
+        sb.append(CR + "# Summary of syntaxic correctness: " + CR);
+        sb.append("- tva =  " + tva + CR);
+        sb.append("- tvo =  " + tvo + CR);
+        synCorrect = ((tva + tvo)/getComplexity());
+        sb.append("- syntaxic correctness =  " + synCorrect + CR);
+
+
+        sb.append(CR + "# CSV line" + CR + getName() + CSV_SEP + getComplexity() + CSV_SEP + "?" + CSV_SEP + "?" + CSV_SEP +
+
+                "?" + CSV_SEP + "?"  + CSV_SEP + "?" + CSV_SEP + "?" + CSV_SEP + synCorrect + CR);
+
 
         sb.append(CR + CR + CR + "# Definition of Metrics" + CR + CR);
         sb.append(CR + "## Semantic correctness: (ra + ro) / complexity" + CR);
@@ -686,9 +708,11 @@ public class AttackTreeDiagramPanel extends TDiagramPanel implements TDPWithAttr
         sb.append("- ma: number of attack nodes that should have been in the attack tree but were absent" + CR);
         sb.append("- mo: number of operator nodes that should have been in the attack tree but were absent" + CR);
 
-        sb.append(CR + "## Syntaxic correctness = (Tva + Tvo) / complexity " + CR);
-        sb.append("- Tva: the sum of for each attack node, the number of respected syntax rules divided by the total number of attack node syntax rules" + CR);
-        sb.append("- Tvo: the sum of for each operator node, the number of respected syntax rules divided by the total number of operator node syntax rules" + CR);
+        sb.append(CR + "## Syntaxic correctness = (tva + tvo) / complexity " + CR);
+        sb.append("- tva: the sum of for each attack node, the number of respected syntax rules divided by the total number of attack node syntax " +
+                "rules" + CR);
+        sb.append("- tvo: the sum of for each operator node, the number of respected syntax rules divided by the total number of operator node " +
+                "syntax rules" + CR);
 
         sb.append(CR + "## Syntax rules of attack trees" + CR);
         for(int i=0; i<syntaxRulesOfAttackTree.length; i++) {
-- 
GitLab