/******************************************************************************* * Copyright (c) 2012-2015 INRIA. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Damien Dosimont <damien.dosimont@imag.fr> * Youenn Corre <youenn.corret@inria.fr> ******************************************************************************/ package fr.inria.soctrace.tools.ocelotl.statistics.operators; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Set; import fr.inria.soctrace.framesoc.ui.colors.FramesocColorManager; import fr.inria.soctrace.framesoc.ui.model.ITableRow; import fr.inria.soctrace.lib.model.EventProducer; import fr.inria.soctrace.tools.ocelotl.core.dataaggregmanager.spacetime.EventProducerHierarchy; import fr.inria.soctrace.tools.ocelotl.core.dataaggregmanager.spacetime.EventProducerHierarchy.EventProducerNode; import fr.inria.soctrace.tools.ocelotl.core.ivisuop.VisuSTOperator; import fr.inria.soctrace.tools.ocelotl.ui.views.OcelotlView; public class StateLeaveSummaryStatST extends StateLeaveSummaryStat { public StateLeaveSummaryStatST(OcelotlView aView) { super(aView); } EventProducerHierarchy hierarchy; @Override public void computeData() { int i; data = new HashMap<String, Double>(); double total = 0.0; VisuSTOperator propOperator = (VisuSTOperator) ocelotlview.getCore().getVisuOperator(); hierarchy = propOperator.getHierarchy(); setupTimeRegion(); // Get the corresponding time slices // add +1 to avoid falling on the ending timestamp of the previous // timeslice (which overlaps with starting timestamp of the next one) int startingSlice = (int) microModel.getTimeSliceManager() .getTimeSlice(timeRegion.getTimeStampStart() + 2); int endingSlice = (int) microModel.getTimeSliceManager().getTimeSlice( timeRegion.getTimeStampEnd()); // Get data from the microscopic model for (i = startingSlice; i <= endingSlice; i++) { for (EventProducer ep : microModel.getMatrix().get(i).keySet()) { if (!isInSpatialSelection(ep) || !isLeaf(ep)) continue; for (String et : microModel.getMatrix().get(i).get(ep).keySet()) { // If first time we meet the event type if (!data.containsKey(et)) { // Initialize to 0 data.put(et, 0.0); } data.put(et, microModel.getMatrix().get(i).get(ep).get(et) + data.get(et)); } } } int nbProducers = numberOfSelectedLeaves(); total = timeRegion.getTimeDuration() * nbProducers; statData = new ArrayList<ITableRow>(); // Create the data objects for the table for (String ep : data.keySet()) { double proportion = 0.0; // If there was no value in the selected zone, let proportion at 0 if (total != 0) proportion = (data.get(ep) / total) * 100.0; statData.add(new SummaryStatModel(ep, data.get(ep), proportion, FramesocColorManager .getInstance().getEventTypeColor(ep).getSwtColor())); } } /** * Check whether or not an event producer is a leaf in the EP hierarchy * * @param ep * @return */ protected boolean isLeaf(EventProducer ep) { return hierarchy.getLeaves().containsKey(ep.getId()) || ocelotlview.getOcelotlParameters() .getAggregatedLeavesIndex().keySet().contains(ep); } @Override protected boolean isInSpatialSelection(EventProducer ep) { if (ocelotlview.getOcelotlParameters().isSpatialSelection()) { if (ocelotlview.getOcelotlParameters().isDisplayedSubselection()) { for (EventProducerNode epn : ocelotlview.getOcelotlParameters() .getSelectedEventProducerNodes()) { if (epn.getMe().getId() == ep.getId()) { return true; } } return false; } else { for (EventProducerNode epn : hierarchy.getLeaves().values()) { if (epn.getMe().getId() == ep.getId()) { return true; } } return false; } } return true; } /** * Select the leaf producers among the current selected producer * * @return the current number of selected leaves producers */ public Integer numberOfSelectedLeaves() { int numberOfLeaves = 0; Set<EventProducer> aggregatedProd = new HashSet<EventProducer>(); // If there is a spatial selection if (ocelotlview.getOcelotlParameters().isSpatialSelection()) { // Check for all leave producers (non-aggregated) for (EventProducerNode anSepn : hierarchy.getLeaves().values()) { // That it is part of the selection and active if (ocelotlview.getOcelotlParameters() .isDisplayedSubselection()) { if (ocelotlview.getOcelotlParameters() .getSelectedEventProducerNodes().contains(anSepn) && microModel.getActiveProducers().contains( anSepn.getMe())) numberOfLeaves++; } else { numberOfLeaves++; } } // Search for selected producer that are aggregation of EP leaves if (ocelotlview.getOcelotlParameters().isHasLeaveAggregated()) for (EventProducer anEP : ocelotlview.getOcelotlParameters() .getSpatiallySelectedProducers()) if ((microModel.getAggregatedProducers() .containsValue(anEP) && microModel .getActiveProducers().contains(anEP))) aggregatedProd.add(anEP); } else { // Same thing as above without caring about spatial selection for (EventProducerNode anSepn : hierarchy .getLeaves().values()) { if (microModel.getActiveProducers().contains(anSepn.getMe())) numberOfLeaves++; if (ocelotlview.getOcelotlParameters().isHasLeaveAggregated()) if (microModel.getActiveProducers().contains( anSepn.getParentNode().getMe())) aggregatedProd.add(anSepn.getParentNode().getMe()); } if (ocelotlview.getOcelotlParameters().isHasLeaveAggregated()) for (EventProducer anEP : microModel.getAggregatedProducers() .values()) if (microModel.getActiveProducers().contains(anEP)) aggregatedProd.add(anEP); } // For all prod that are aggregation of leaves, add the // corresponding number of aggregated leaves for (EventProducer anEp : aggregatedProd) numberOfLeaves = numberOfLeaves + microModel .removeFilteredEP( ocelotlview .getOcelotlParameters() .getEventProducerHierarchy() .getLeaves( ocelotlview .getOcelotlParameters() .getEventProducerHierarchy() .getEventProducerNodes() .get(anEp.getId()))) .size(); return numberOfLeaves; } }