timeBench.action.analytical.GranularityAggregationAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of timebench Show documentation
Show all versions of timebench Show documentation
TimeBench, a flexible, easy-to-use, and reusable software library written in Java that provides foundational data structures and algorithms for time- oriented data in Visual Analytics.
The newest version!
package timeBench.action.analytical;
import ieg.prefuse.data.ParentChildNode;
import java.util.ArrayList;
import org.apache.log4j.Logger;
import timeBench.calendar.Calendar;
import timeBench.calendar.CalendarFactory;
import timeBench.calendar.Granularity;
import timeBench.calendar.Granule;
import timeBench.data.GranularityAggregationTree;
import timeBench.data.GranularityAggregationTreeProvider;
import timeBench.data.Instant;
import timeBench.data.TemporalDataException;
import timeBench.data.TemporalDataset;
import timeBench.data.TemporalDatasetProvider;
import timeBench.data.TemporalObject;
/**
*
*
*
* Added: / TL
* Modifications:
*
*
* @author Tim Lammarsch
*
*/
public class GranularityAggregationAction extends prefuse.action.Action implements GranularityAggregationTreeProvider,TemporalDatasetProvider {
private final Logger logger = Logger.getLogger(this.getClass());
TemporalDataset sourceDataset;
GranularityAggregationTree workingDataset;
Calendar calendar;
Granularity[] granularities;
double missingValueIdentifier;
GranularityAggregationFunction[] aggFct;
public GranularityAggregationAction(TemporalDataset sourceDataset,Granularity[] granularities,
Double missingValueIdentifier) {
this(sourceDataset,granularities,null,missingValueIdentifier);
}
/**
* @param data
* @param temporalDataset
* @param columnsUsed
*/
public GranularityAggregationAction(TemporalDataset sourceDataset,Granularity[] granularities,
GranularityAggregationFunction[] aggFct,
Double missingValueIdentifier) {
this.sourceDataset = sourceDataset;
this.granularities = new Granularity[granularities.length];
this.aggFct = aggFct;
if(granularities.length > 0)
this.calendar = CalendarFactory.getSingleton().getCalendar(
CalendarFactory.getSingleton().getCalendarIdentifierFromGranularityIdentifier(
granularities[0].getIdentifier()));
this.granularities = granularities;
if (aggFct == null) {
this.aggFct = new GranularityAggregationFunction[granularities.length];
for (int i=0; i begin of method");
try {
workingDataset = new GranularityAggregationTree(sourceDataset.getDataColumnSchema(),granularities.length+1);
ArrayList currentBranches = new ArrayList();
ArrayList> currentLeaves = new ArrayList>();
for(TemporalObject iO : sourceDataset.temporalObjects()) {
long inf = iO.getTemporalElement().asGeneric().getGranule().getInf();
int i = 0;
for(TemporalObject iB : currentBranches) {
if (iB.getTemporalElement().asGeneric().getGranule().contains(inf)) {
currentLeaves.get(i).add(iO);
break;
}
i++;
}
if(i >= currentBranches.size()) {
Granule newGranule = new Granule(inf,inf,granularities[0]);
Instant newTe = workingDataset.addInstant(newGranule);
currentBranches.add(workingDataset.addTemporalObject(newTe));
ArrayList leaves = new ArrayList();
leaves.add(iO);
currentLeaves.add(leaves);
}
}
long[] roots = new long[currentBranches.size()];
for(int i=0; i 1) {
for(int i=1; i> futureLeaves = new ArrayList>();
ArrayList futureBranches = new ArrayList();
int whichChild = 0;
for(int k=0; k iCurrentLeaves = currentLeaves.get(k);
while(iCurrentLeaves.size() > 0) {
TemporalObject currentLeave = iCurrentLeaves.get(0);
iCurrentLeaves.remove(0);
TemporalObject targetBranch = null;
long inf = currentLeave.getTemporalElement().asGeneric().getInf();
long sup = currentLeave.getTemporalElement().asGeneric().getSup();
whichChild = 0;
for(int l=0; l());
whichChild = futureLeaves.size() - 1;
currentBranches.get(k).linkWithChild(targetBranch);
}
futureLeaves.get(whichChild).add(currentLeave);
}
}
if(i==granularities.length-1) {
for(int j=0; j 0.0)
change = true;
}
if (change)
aggregate(aRoot, 0);
}
}
private void aggregate(TemporalObject parent,int level) {
if (parent.getChildCount() > 0) {
for (TemporalObject child : parent.childObjects()) {
aggregate(child,level+1);
}
aggregate(parent,parent.childObjects(),level);
}
}
private void aggregate(TemporalObject parent,Iterable childs,int level) {
int[] dataColumnIndices = sourceDataset.getDataColumnIndices();
// Vector aggregateColumn = new Vector();
/*
* Aggregate Only the data Columns, do not aggregate the Metadata
* To have the Metadata in the leafes, we keep the Metadata Columns in th lowest level
*/
// if (level < (granularities.length - 1)) {
// for (int i = 0 ; i < dataColumnIndices.length; i++) {
// if (!(parent.getColumnName(dataColumnIndices[i]).endsWith(".kind") ||
// parent.getColumnName(dataColumnIndices[i]).endsWith(".minValue") ||
// parent.getColumnName(dataColumnIndices[i]).endsWith(".maxValue"))) {
// aggregateColumn.add(Integer.valueOf(dataColumnIndices[i]));
// }
// }
//
// dataColumnIndices = new int[aggregateColumn.size()];
// for (int i =0; i < dataColumnIndices.length; i++) {
// dataColumnIndices[i] = aggregateColumn.get(i).intValue();
// }
// }
// TODO skip columns where NOT canSetDouble() e.g. boolean, Object
// already done: .kind
double[] totalValue = aggFct[(aggFct.length-1)-level].aggregate(childs, dataColumnIndices, missingValueIdentifier);
for(int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy