From c4d52e97bfa694782840f42712e2dfc0b1d05aa9 Mon Sep 17 00:00:00 2001 From: Eddie Groh <groh@fortiss.org> Date: Mon, 10 Jul 2023 11:37:26 +0200 Subject: [PATCH] Added metrics for Entry and Exit Connectors Issue-Ref: 4310 Issue-Url: https://git.fortiss.org/af3/af3/-/issues/4310 Signed-off-by: Eddie Groh <groh@fortiss.org> --- .../ui/view/fx/MetricsFXController.java | 12 +++++---- .../quality/HierarchicElementProvider.java | 25 ++++++++++++------- .../tooling/ext/quality/data/MetricKey.java | 8 ++++-- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/MetricsFXController.java b/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/MetricsFXController.java index 5610d6a80..5e5699f3e 100644 --- a/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/MetricsFXController.java +++ b/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/MetricsFXController.java @@ -166,8 +166,9 @@ public class MetricsFXController extends CompositeFXControllerBase<SplitPane, No pieChart.getData().clear(); for(var child : node.getChildren()) { - PieChart.Data slice = new PieChart.Data(child.getName(), - child.getStoredMetrics().get(MetricKey.NUMBER_OF_TOTAL_PORTS)); + PieChart.Data slice = + new PieChart.Data(child.getName(), child.getStoredMetrics() + .get(MetricKey.NUMBER_OF_TOTAL_ENTRY_CONNECTORS)); pieChart.getData().add(slice); pieChart.setLegendVisible(false); pieChart.setTitle(""); @@ -213,8 +214,9 @@ public class MetricsFXController extends CompositeFXControllerBase<SplitPane, No } double maxval = children.stream() - .mapToDouble(p -> p.getStoredMetrics().get(MetricKey.NUMBER_OF_TOTAL_PORTS)).max() - .getAsDouble(); + .mapToDouble( + p -> p.getStoredMetrics().get(MetricKey.NUMBER_OF_TOTAL_EXIT_CONNECTORS)) + .max().getAsDouble(); chartStyle.setUseIndividualAxisSegments(false); chartStyle.setTitleStyle(new FontStyle("Verdana", 14, BLUE.brighter())); @@ -229,7 +231,7 @@ public class MetricsFXController extends CompositeFXControllerBase<SplitPane, No spiderChart.addAxis(testing); elementData.setPoint(testing, - child.getStoredMetrics().get(MetricKey.NUMBER_OF_TOTAL_PORTS)); + child.getStoredMetrics().get(MetricKey.NUMBER_OF_TOTAL_EXIT_CONNECTORS)); } spiderChart.addData(elementData); diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/HierarchicElementProvider.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/HierarchicElementProvider.java index 2889efa8d..7ebd78175 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/HierarchicElementProvider.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/HierarchicElementProvider.java @@ -18,12 +18,15 @@ package org.fortiss.tooling.ext.quality; import java.util.Optional; import org.eclipse.emf.common.util.EList; +import org.fortiss.tooling.base.model.base.EntryConnectorBase; +import org.fortiss.tooling.base.model.base.ExitConnectorBase; import org.fortiss.tooling.base.model.element.IHierarchicElement; import org.fortiss.tooling.ext.quality.data.MetricDataManager; import org.fortiss.tooling.ext.quality.data.MetricKey; import org.fortiss.tooling.ext.quality.data.MetricTreeNode; import org.fortiss.tooling.kernel.model.IIdLabeled; import org.fortiss.tooling.kernel.model.INamedCommentedElement; +import org.fortiss.tooling.kernel.utils.EcoreUtils; /** * {@link IModelQualityProvider} to count the ratio of filled out comments of @@ -107,21 +110,24 @@ public class HierarchicElementProvider implements IModelQualityProvider<IHierarc private void applyMetrics(MetricDataManager manager, MetricTreeNode node, IHierarchicElement currentElement) { - // TODO input ports number - // TODO output ports number - - // EcoreUtils.pickInstanceOf(target, srcList) var metrics = node.getStoredMetrics(); metrics.put(MetricKey.UNQIUE_ID, (currentElement instanceof IIdLabeled) ? ((IIdLabeled)currentElement).getId() : -1.0); - metrics.put(MetricKey.NUMBER_OF_PORTS, (double)currentElement.getConnectors().size()); + + var connectors = currentElement.getConnectors(); + metrics.put(MetricKey.NUMBER_OF_CONNECTORS, (double)connectors.size()); + metrics.put(MetricKey.NUMBER_OF_CONTAINED_ELEMENTS, (double)currentElement.getContainedElements().size()); metrics.put(MetricKey.NUMBER_OF_CHANNELS, (double)currentElement.getConnections().size()); - // depth metrics - metrics.put(MetricKey.NUMBER_OF_TOTAL_PORTS, (double)currentElement.getConnectors().size()); + metrics.put(MetricKey.NUMBER_OF_TOTAL_CONNECTORS, (double)connectors.size()); + var entry_connectors = EcoreUtils.pickInstanceOf(EntryConnectorBase.class, connectors); + var exit_connectors = EcoreUtils.pickInstanceOf(ExitConnectorBase.class, connectors); + metrics.put(MetricKey.NUMBER_OF_TOTAL_ENTRY_CONNECTORS, (double)entry_connectors.size()); + metrics.put(MetricKey.NUMBER_OF_TOTAL_EXIT_CONNECTORS, (double)exit_connectors.size()); + metrics.put(MetricKey.NUMBER_OF_TOTAL_ELEMENTS, 1.0); metrics.put(MetricKey.NUMBER_OF_TOTAL_LEAF_ELEMENTS, @@ -132,8 +138,9 @@ public class HierarchicElementProvider implements IModelQualityProvider<IHierarc node.getChildren().add(child); apply(manager, child, containedElement); - for(MetricKey key : new MetricKey[] {MetricKey.NUMBER_OF_TOTAL_PORTS, - MetricKey.NUMBER_OF_TOTAL_ELEMENTS, + for(MetricKey key : new MetricKey[] {MetricKey.NUMBER_OF_TOTAL_CONNECTORS, + MetricKey.NUMBER_OF_TOTAL_ENTRY_CONNECTORS, + MetricKey.NUMBER_OF_TOTAL_EXIT_CONNECTORS, MetricKey.NUMBER_OF_TOTAL_ELEMENTS, MetricKey.NUMBER_OF_TOTAL_COMMENTABLE_ELEMENTS, MetricKey.NUMBER_OF_TOTAL_COMMENTED_ELEMENTS, MetricKey.NUMBER_OF_TOTAL_LEAF_ELEMENTS}) { diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/data/MetricKey.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/data/MetricKey.java index 2b0e08ff0..d52ffeda1 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/data/MetricKey.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/data/MetricKey.java @@ -28,7 +28,7 @@ public enum MetricKey { UNQIUE_ID, /** Key for the metric counting ports */ - NUMBER_OF_PORTS, + NUMBER_OF_CONNECTORS, /** Key for the metric counting elements */ NUMBER_OF_CONTAINED_ELEMENTS, /** Key for the metric counting channels */ @@ -36,7 +36,11 @@ public enum MetricKey { // Metrics which are collected over all children nodes /** Key for the metric counting the total amount of ports contained */ - NUMBER_OF_TOTAL_PORTS, + NUMBER_OF_TOTAL_CONNECTORS, + /** Key for the metric counting the total amount of input ports contained */ + NUMBER_OF_TOTAL_ENTRY_CONNECTORS, + /** Key for the metric counting the total amount of output ports contained */ + NUMBER_OF_TOTAL_EXIT_CONNECTORS, /** Key for the metric counting the total amount of elements contained */ NUMBER_OF_TOTAL_ELEMENTS, /** Key for the metric counting the total amount of elements which can be commented */ -- GitLab