/* * TimeStep.java * * Created on May 14, 2007, 2:59 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ import java.util.Vector; /** * * Encapsulates all data corresponding to a single timestep of a given * experimental condition. * * @author Matt DesVoigne */ public class TimeStep { protected int timeStepID; protected Vector trials; /** Creates a new instance of TimeStep */ public TimeStep(int timestep) { timeStepID = timestep; trials = new Vector(); } /** * This method is used to return the max number of hits that fall in a given * bin at a specified time index for a specified propertyIndex in order to * scale the width of the bars. * * @param timeStepIndex * @param binSize * @param propertyIndex * @return maxHits */ public int getMaxHits(int timeStepIndex, double binSize, int propertyIndex) { double maxProp = -1E20; double minProp = 1E20; Vector trials = getTrials(); for (int j = 0; j < trials.size(); j++) { double property = ((Trial) trials.elementAt(j)) .getProperty(propertyIndex); if (Trial.isNumber(property)) { maxProp = Math.max(maxProp, property); minProp = Math.min(minProp, property); } } int maxHits = 0; double currentProp = maxProp; while (currentProp > minProp) { int numHits = 0; for (int i = 0; i < trials.size(); i++) { double aProperty = ((Trial) trials.elementAt(i)) .getProperty(propertyIndex); if (Trial.isNumber(aProperty) && aProperty < currentProp && aProperty > (currentProp - binSize)) { numHits++; } } maxHits = Math.max(numHits, maxHits); currentProp -= binSize; } return maxHits; } public Vector getTrials() { return trials; } public double getMean(int propertyIndex) { int numTrials = getNumTrials(propertyIndex); if (numTrials == 0) { System.out.println("Warning: No trials for timestep " + timeStepID); return 0.0; } double total = 0.0; for (int i = 0; i < trials.size(); i++) { double property = ((Trial) trials.elementAt(i)) .getProperty(propertyIndex); if (Trial.isNumber(property)) { total += property; } } return (total / numTrials); } /** * Returns the number of non-blank (i.e. data entered trials) for this * timestep given the user selected property index. * * @param propertyIndex * @return */ public int getNumTrials(int propertyIndex) { int retValue = 0; for (int i = 0; i < trials.size(); i++) { double property = ((Trial) trials.elementAt(i)) .getProperty(propertyIndex); if (Trial.isNumber(property)) { retValue++; } } return retValue; } public void addTrial(Trial datapoint) { trials.addElement(datapoint); } public int getTimeStep() { return timeStepID; } }