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

Refactored to accomondate AllocationTableProvider

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



Signed-off-by: default avatarEddie Groh <groh@fortiss.org>
parent d4b5501e
No related branches found
No related tags found
1 merge request!210Setting up Metric extraction plugin for AF3 : Issue 4310
......@@ -28,7 +28,9 @@ import static org.fortiss.tooling.kernel.ui.util.SelectionUtils.checkAndPickFirs
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getFirstParentWithType;
import java.text.DecimalFormat;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ISelection;
......@@ -52,6 +54,7 @@ import org.fortiss.tooling.spiderchart.style.ChartStyle;
import org.fortiss.tooling.spiderchart.style.DataSeriesStyle;
import org.fortiss.tooling.spiderchart.style.LegendStyle;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.chart.PieChart;
......@@ -171,6 +174,17 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
// topLabel.setText("Text");
Set<MetricKey> validKeys = new HashSet<>();
validKeys.addAll(node.getStoredDoubles().keySet());
validKeys.addAll(node.getStoredIntegers().keySet());
ObservableList<MetricKey> choices = choiceBox.getItems();
choices.retainAll(validKeys);
for(MetricKey key : validKeys) {
if(!choices.contains(key)) {
choices.add(key);
}
}
if(!node.getChildren().isEmpty()) {
if(choiceBox.getValue() != null) {
......
......@@ -57,6 +57,11 @@ public enum MetricKey {
/** How many constraints this element violates with severity warning */
CONSTRAINT_VIOLATIONS_WARNING(false),
/** Number of allocated components to this task */
TASK_ALLOCATED_COMPONENTS(false),
/** How many constraints this element violates with severity warning */
HARDWARE_ALLOCATED_TASKS(false),
//
// Metrics which are collected over all children nodes
//
......
......@@ -18,6 +18,7 @@ package org.fortiss.tooling.ext.quality.service;
import static java.util.Collections.emptyList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
......@@ -110,33 +111,42 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider
@Override
public void performMetricAnalysis(ITopLevelElement topLvl) {
for(IProjectRootElement rootElement : EcoreUtils
.getChildrenWithType(topLvl.getRootModelElement(), IProjectRootElement.class)) {
if(rootElement instanceof IHierarchicElement) {
// Sort root elements, as some metrics are saved into trees from other root elements
// To avoid these problems, the elements have to be processed in a certain order
EList<IHierarchicElement> elements =
((IHierarchicElement)rootElement).getContainedElements();
if(elements.isEmpty()) {
continue;
}
var root_nodes = metricDataManagerInstance.getRootNodes();
// Currently the only element affected by this is the allocation table which
List<IProjectRootElement> rootElements = new ArrayList<>();
rootElements.addAll(EcoreUtils.getChildrenWithType(topLvl.getRootModelElement(),
IProjectRootElement.class));
// Get first element, there should not be any other elements
IHierarchicElement firstElement = elements.get(0);
MetricTreeNode root_node = new MetricTreeNode();
recursivlyCollectMetrics(root_node, firstElement, 0);
root_nodes.put(rootElement, root_node);
} else {
String allocationTableClassName =
"org.fortiss.af3.allocation.model.impl.AllocationTableCollectionImpl";
var root_nodes = metricDataManagerInstance.getRootNodes();
MetricTreeNode rootNode = new MetricTreeNode();
Collections.sort(rootElements, (r1, r2) -> {
if(allocationTableClassName.equals(r1.getClass().getName())) {
return 1;
} else if(allocationTableClassName.equals(r2.getClass().getName())) {
return -1;
}
return 0;
});
for(IProjectRootElement rootElement : rootElements) {
var root_nodes = metricDataManagerInstance.getRootNodes();
MetricTreeNode rootNode = new MetricTreeNode();
if(rootElement instanceof IHierarchicElement) {
IHierarchicElement firstElement = (IHierarchicElement)rootElement;
recursivlyCollectMetrics(rootNode, firstElement, 0);
} else {
// Search for provider on ProjectRootElement
collectMetrics(rootNode, rootElement);
root_nodes.put(rootElement, rootNode);
metricDataManagerInstance.getTreeNodeLookupTable().put(rootElement, rootNode);
}
root_nodes.put(rootElement, rootNode);
metricDataManagerInstance.getTreeNodeLookupTable().put(rootElement, rootNode);
}
// Store all currently saved metrics to the csv
CSVFileWriter.metricExtractionToCSV(metricDataManagerInstance.getRootNodes());
......@@ -491,8 +501,8 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider
/**
* @param node
* to which the data is collected
* @param element
* element to collect the data from
* @param object
* object to collect the data from
*/
@SuppressWarnings("unchecked")
private void collectMetrics(MetricTreeNode node, EObject 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