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;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.ISelectionListener;
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.style.FillStyle;
import org.fortiss.tooling.common.ui.javafx.style.FontStyle;
......@@ -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
* Object is selected
*/
private IHierarchicElement lastSelectedElement;
private EObject lastSelectedElement;
/** {@inheritDoc} */
@Override
......@@ -141,23 +140,14 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
return;
}
if(!(currentRootElement instanceof IHierarchicElement)) {
// topLabel.setText("Root is not an IHierarchicElement");
var root_provider = manager.getRootNodes().get(currentRootElement);
if(root_provider == null) {
// topLabel.setText("No Metric found for this project, did you export metrics?");
return;
}
if(selected instanceof IHierarchicElement) {
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");
}
lastSelectedElement = selected;
updateCharts();
}
......@@ -175,7 +165,7 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
if(lastSelectedElement != null) {
MetricDataManager manager = ModelQualityService.metricDataManagerInstance;
MetricTreeNode node = manager.getHierarchicLookupTable().get(lastSelectedElement);
MetricTreeNode node = manager.getTreeNodeLookupTable().get(lastSelectedElement);
if(node != null) {
......@@ -251,14 +241,18 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
return null;
}
double maxval =
children.stream().mapToDouble(p -> p.getValueAsDouble(key)).max().getAsDouble();
double maxval = children.stream().map(p -> p.getValueAsDouble(key)).filter(p -> p != null)
.mapToDouble(p -> p).max().getAsDouble();
chartStyle.setUseIndividualAxisSegments(false);
chartStyle.setTitleStyle(new FontStyle("Verdana", 14, BLUE.brighter()));
DataSeries elementData = new DataSeries("Data");
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);
AxisStyle aStyle3Segs = new AxisStyle(SOLID_BLACK_1PT, BLACK_VERDANA_14PT, 3,
......@@ -266,7 +260,7 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
chartStyle.setAxisStyle(testing, aStyle3Segs);
spiderChart.addAxis(testing);
elementData.setPoint(testing, child.getValueAsDouble(key));
elementData.setPoint(testing, value);
}
spiderChart.addData(elementData);
......
......@@ -18,7 +18,7 @@ package org.fortiss.tooling.ext.quality.data;
import java.util.HashMap;
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;
/**
......@@ -28,7 +28,7 @@ import org.fortiss.tooling.kernel.model.IProjectRootElement;
public class MetricDataManager {
/** a map to lookup the corresponding tree node */
private Map<IHierarchicElement, MetricTreeNode> hierarchicLookupTable;
private Map<EObject, MetricTreeNode> treeNodeLookupTable;
/** the root tree node */
private Map<IProjectRootElement, MetricTreeNode> root_nodes;
......@@ -38,14 +38,14 @@ public class MetricDataManager {
*/
public MetricDataManager() {
root_nodes = new HashMap<>();
hierarchicLookupTable = new HashMap<>();
treeNodeLookupTable = new HashMap<>();
}
/**
* @return the lookup map
*/
public Map<IHierarchicElement, MetricTreeNode> getHierarchicLookupTable() {
return hierarchicLookupTable;
public Map<EObject, MetricTreeNode> getTreeNodeLookupTable() {
return treeNodeLookupTable;
}
/**
......
......@@ -52,6 +52,11 @@ public enum MetricKey {
*/
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
//
......
......@@ -126,6 +126,16 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider
MetricTreeNode root_node = new MetricTreeNode();
recursivlyCollectMetrics(root_node, firstElement, 0);
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
......@@ -161,14 +171,14 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider
specificationElement.getContainedElements();
if(containedElements.size() == 1) {
// 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
recursivlyCollectMetrics(node, containedElements.get(0), recursionLevel);
} else {
recursivlyCollectMetrics(node, specificationElement, recursionLevel);
}
// Add reference from the element to this, so the lookups works as expected
manager.getHierarchicLookupTable().put(currentElement, node);
manager.getTreeNodeLookupTable().put(currentElement, node);
} else {
// Iterate over all children and merge values
......@@ -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, true);
......@@ -472,7 +482,7 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider
MetricKey key = recursively ? MetricKey.BETWEENESS_CENTRALITY_RECURSIVELY
: MetricKey.BETWEENESS_CENTRALITY;
for(IHierarchicElement child : scopeElement.getContainedElements()) {
manager.getHierarchicLookupTable().get(child).getStoredDoubles().put(key,
manager.getTreeNodeLookupTable().get(child).getStoredDoubles().put(key,
betweenness.get(child));
}
}
......@@ -485,17 +495,17 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider
* element to collect the data from
*/
@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()) {
// it should not happen that no provider is found
throw new IllegalStateException();
// throw new IllegalStateException();
}
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