/*******************************************************************************
* 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 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.ui.views.OcelotlView;
public class StateActiveProducerSummaryStat extends SummaryStat{
public StateActiveProducerSummaryStat(OcelotlView aView) {
super(aView);
}
@Override
public void computeData() {
int i;
data = new HashMap<String, Double>();
double total = 0.0;
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) || !microModel.getActiveProducers().contains(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 = getNumberOfProducers();
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()));
}
}
/**
* Select the leaf producers among the current selected producer
*
* @return the current number of selected leaves producers
*/
public Integer getNumberOfProducers() {
int nbProducers = 0;
if (ocelotlview.getOcelotlParameters().isSpatialSelection()) {
ArrayList<EventProducer> currentSelection = new ArrayList<EventProducer>();
for (EventProducer anEP : microModel.getActiveProducers())
if (ocelotlview.getOcelotlParameters()
.getSpatiallySelectedProducers().contains(anEP)
&& (!ocelotlview.getOcelotlParameters()
.getOcelotlSettings().isAggregateLeaves() || (ocelotlview
.getOcelotlParameters().getOcelotlSettings()
.isAggregateLeaves() && !ocelotlview
.getOcelotlParameters()
.getAggregatedEventProducers().contains(anEP)))) {
currentSelection.add(anEP);
}
nbProducers = currentSelection.size();
if (nbProducers == 2)
// Since we add the parent producers when only one producer is
// selected, we remove it to have correct data
nbProducers = 1;
// Add the corresponding number of aggregated producers and
// remove the current producer as we cannot know if it is really an
// active producer
// TODO : deactivate this operator ?
for (EventProducer anEP : ocelotlview.getOcelotlParameters()
.getAggregatedLeavesIndex().keySet())
if (ocelotlview.getOcelotlParameters()
.getSpatiallySelectedProducers().contains(anEP))
nbProducers = nbProducers
+ ocelotlview.getOcelotlParameters()
.getAggregatedLeavesIndex().get(anEP) - 1;
}
else {
nbProducers = microModel.getActiveProducers().size();
}
return nbProducers;
}
}