Skip to content
Snippets Groups Projects
Commit d4b5501e authored by Eddie Groh's avatar Eddie Groh
Browse files

Refactor for compatibility with DataDictonaryProvider

Issue-Ref: 4310
Issue-Url: af3#4310



Signed-off-by: default avatarEddie Groh <groh@fortiss.org>
parent 1879e1b2
No related branches found
No related tags found
1 merge request!210Setting up Metric extraction plugin for AF3 : Issue 4310
...@@ -34,7 +34,6 @@ import org.eclipse.emf.ecore.EObject; ...@@ -34,7 +34,6 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.ISelectionListener; import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPart;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.common.ui.javafx.layout.CompositeFXControllerBase; import org.fortiss.tooling.common.ui.javafx.layout.CompositeFXControllerBase;
import org.fortiss.tooling.common.ui.javafx.style.FillStyle; import org.fortiss.tooling.common.ui.javafx.style.FillStyle;
import org.fortiss.tooling.common.ui.javafx.style.FontStyle; import org.fortiss.tooling.common.ui.javafx.style.FontStyle;
...@@ -107,7 +106,7 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan ...@@ -107,7 +106,7 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
* The last IHierachicElement which the user has clicked. Might be null when no or invalid * The last IHierachicElement which the user has clicked. Might be null when no or invalid
* Object is selected * Object is selected
*/ */
private IHierarchicElement lastSelectedElement; private EObject lastSelectedElement;
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
...@@ -141,23 +140,14 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan ...@@ -141,23 +140,14 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
return; return;
} }
if(!(currentRootElement instanceof IHierarchicElement)) { var root_provider = manager.getRootNodes().get(currentRootElement);
// topLabel.setText("Root is not an IHierarchicElement");
if(root_provider == null) {
// topLabel.setText("No Metric found for this project, did you export metrics?");
return; return;
} }
if(selected instanceof IHierarchicElement) { lastSelectedElement = selected;
var root_provider = manager.getRootNodes().get(currentRootElement);
if(root_provider == null) {
// topLabel.setText("No Metric found for this project, did you export metrics?");
return;
}
lastSelectedElement = (IHierarchicElement)selected;
} else {
// topLabel.setText("Selected is not an IHierarchicElement");
}
updateCharts(); updateCharts();
} }
...@@ -175,7 +165,7 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan ...@@ -175,7 +165,7 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
if(lastSelectedElement != null) { if(lastSelectedElement != null) {
MetricDataManager manager = ModelQualityService.metricDataManagerInstance; MetricDataManager manager = ModelQualityService.metricDataManagerInstance;
MetricTreeNode node = manager.getHierarchicLookupTable().get(lastSelectedElement); MetricTreeNode node = manager.getTreeNodeLookupTable().get(lastSelectedElement);
if(node != null) { if(node != null) {
...@@ -251,14 +241,18 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan ...@@ -251,14 +241,18 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
return null; return null;
} }
double maxval = double maxval = children.stream().map(p -> p.getValueAsDouble(key)).filter(p -> p != null)
children.stream().mapToDouble(p -> p.getValueAsDouble(key)).max().getAsDouble(); .mapToDouble(p -> p).max().getAsDouble();
chartStyle.setUseIndividualAxisSegments(false); chartStyle.setUseIndividualAxisSegments(false);
chartStyle.setTitleStyle(new FontStyle("Verdana", 14, BLUE.brighter())); chartStyle.setTitleStyle(new FontStyle("Verdana", 14, BLUE.brighter()));
DataSeries elementData = new DataSeries("Data"); DataSeries elementData = new DataSeries("Data");
for(var child : node.getChildren()) { for(var child : node.getChildren()) {
Double value = child.getValueAsDouble(key);
if(value == null) {
value = 0.0;
}
DoubleAxis testing = new DoubleAxis(child.getName(), 0.0, maxval); DoubleAxis testing = new DoubleAxis(child.getName(), 0.0, maxval);
AxisStyle aStyle3Segs = new AxisStyle(SOLID_BLACK_1PT, BLACK_VERDANA_14PT, 3, AxisStyle aStyle3Segs = new AxisStyle(SOLID_BLACK_1PT, BLACK_VERDANA_14PT, 3,
...@@ -266,7 +260,7 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan ...@@ -266,7 +260,7 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
chartStyle.setAxisStyle(testing, aStyle3Segs); chartStyle.setAxisStyle(testing, aStyle3Segs);
spiderChart.addAxis(testing); spiderChart.addAxis(testing);
elementData.setPoint(testing, child.getValueAsDouble(key)); elementData.setPoint(testing, value);
} }
spiderChart.addData(elementData); spiderChart.addData(elementData);
......
...@@ -18,7 +18,7 @@ package org.fortiss.tooling.ext.quality.data; ...@@ -18,7 +18,7 @@ package org.fortiss.tooling.ext.quality.data;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.fortiss.tooling.base.model.element.IHierarchicElement; import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.model.IProjectRootElement; import org.fortiss.tooling.kernel.model.IProjectRootElement;
/** /**
...@@ -28,7 +28,7 @@ import org.fortiss.tooling.kernel.model.IProjectRootElement; ...@@ -28,7 +28,7 @@ import org.fortiss.tooling.kernel.model.IProjectRootElement;
public class MetricDataManager { public class MetricDataManager {
/** a map to lookup the corresponding tree node */ /** a map to lookup the corresponding tree node */
private Map<IHierarchicElement, MetricTreeNode> hierarchicLookupTable; private Map<EObject, MetricTreeNode> treeNodeLookupTable;
/** the root tree node */ /** the root tree node */
private Map<IProjectRootElement, MetricTreeNode> root_nodes; private Map<IProjectRootElement, MetricTreeNode> root_nodes;
...@@ -38,14 +38,14 @@ public class MetricDataManager { ...@@ -38,14 +38,14 @@ public class MetricDataManager {
*/ */
public MetricDataManager() { public MetricDataManager() {
root_nodes = new HashMap<>(); root_nodes = new HashMap<>();
hierarchicLookupTable = new HashMap<>(); treeNodeLookupTable = new HashMap<>();
} }
/** /**
* @return the lookup map * @return the lookup map
*/ */
public Map<IHierarchicElement, MetricTreeNode> getHierarchicLookupTable() { public Map<EObject, MetricTreeNode> getTreeNodeLookupTable() {
return hierarchicLookupTable; return treeNodeLookupTable;
} }
/** /**
......
...@@ -52,6 +52,11 @@ public enum MetricKey { ...@@ -52,6 +52,11 @@ public enum MetricKey {
*/ */
CLUSTERING_COEFFICIENT(false, 0.0), CLUSTERING_COEFFICIENT(false, 0.0),
/** How many constraints this element violates with severity error */
CONSTRAINT_VIOLATIONS_ERROR(false),
/** How many constraints this element violates with severity warning */
CONSTRAINT_VIOLATIONS_WARNING(false),
// //
// Metrics which are collected over all children nodes // Metrics which are collected over all children nodes
// //
......
...@@ -126,6 +126,16 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider ...@@ -126,6 +126,16 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider
MetricTreeNode root_node = new MetricTreeNode(); MetricTreeNode root_node = new MetricTreeNode();
recursivlyCollectMetrics(root_node, firstElement, 0); recursivlyCollectMetrics(root_node, firstElement, 0);
root_nodes.put(rootElement, root_node); root_nodes.put(rootElement, root_node);
} else {
var root_nodes = metricDataManagerInstance.getRootNodes();
MetricTreeNode rootNode = new MetricTreeNode();
// Search for provider on ProjectRootElement
collectMetrics(rootNode, rootElement);
root_nodes.put(rootElement, rootNode);
metricDataManagerInstance.getTreeNodeLookupTable().put(rootElement, rootNode);
} }
} }
// Store all currently saved metrics to the csv // Store all currently saved metrics to the csv
...@@ -161,14 +171,14 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider ...@@ -161,14 +171,14 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider
specificationElement.getContainedElements(); specificationElement.getContainedElements();
if(containedElements.size() == 1) { if(containedElements.size() == 1) {
// Add reference from the element to this, so the lookups works as expected // Add reference from the element to this, so the lookups works as expected
manager.getHierarchicLookupTable().put(specificationElement, node); manager.getTreeNodeLookupTable().put(specificationElement, node);
// Skip the specification element to get a more useful tree structure // Skip the specification element to get a more useful tree structure
recursivlyCollectMetrics(node, containedElements.get(0), recursionLevel); recursivlyCollectMetrics(node, containedElements.get(0), recursionLevel);
} else { } else {
recursivlyCollectMetrics(node, specificationElement, recursionLevel); recursivlyCollectMetrics(node, specificationElement, recursionLevel);
} }
// Add reference from the element to this, so the lookups works as expected // Add reference from the element to this, so the lookups works as expected
manager.getHierarchicLookupTable().put(currentElement, node); manager.getTreeNodeLookupTable().put(currentElement, node);
} else { } else {
// Iterate over all children and merge values // Iterate over all children and merge values
...@@ -191,7 +201,7 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider ...@@ -191,7 +201,7 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider
} }
} }
manager.getHierarchicLookupTable().put(currentElement, node); manager.getTreeNodeLookupTable().put(currentElement, node);
calculateBetweennessCentrality(currentElement, manager, false); calculateBetweennessCentrality(currentElement, manager, false);
calculateBetweennessCentrality(currentElement, manager, true); calculateBetweennessCentrality(currentElement, manager, true);
...@@ -472,7 +482,7 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider ...@@ -472,7 +482,7 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider
MetricKey key = recursively ? MetricKey.BETWEENESS_CENTRALITY_RECURSIVELY MetricKey key = recursively ? MetricKey.BETWEENESS_CENTRALITY_RECURSIVELY
: MetricKey.BETWEENESS_CENTRALITY; : MetricKey.BETWEENESS_CENTRALITY;
for(IHierarchicElement child : scopeElement.getContainedElements()) { for(IHierarchicElement child : scopeElement.getContainedElements()) {
manager.getHierarchicLookupTable().get(child).getStoredDoubles().put(key, manager.getTreeNodeLookupTable().get(child).getStoredDoubles().put(key,
betweenness.get(child)); betweenness.get(child));
} }
} }
...@@ -485,17 +495,17 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider ...@@ -485,17 +495,17 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider
* element to collect the data from * element to collect the data from
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void collectMetrics(MetricTreeNode node, IHierarchicElement element) { private void collectMetrics(MetricTreeNode node, EObject object) {
List<IMetricProvider<?>> providers = getAllMetricProviders(element); List<IMetricProvider<?>> providers = getAllMetricProviders(object);
if(providers.isEmpty()) { if(providers.isEmpty()) {
// it should not happen that no provider is found // it should not happen that no provider is found
throw new IllegalStateException(); // throw new IllegalStateException();
} }
for(IMetricProvider<?> provider : providers) { for(IMetricProvider<?> provider : providers) {
((IMetricProvider<EObject>)provider).collectMetrics(node, element); ((IMetricProvider<EObject>)provider).collectMetrics(node, object);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment