Java Code Examples for org.jfree.data.time.TimeSeries#getItemCount()

The following examples show how to use org.jfree.data.time.TimeSeries#getItemCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeSeriesStatistics.java    From incubator-iotdb with Apache License 2.0 6 votes vote down vote up
TimeSeriesStatistics(TimeSeries timeSeries) {
  Date lastDate = null;
  name = (String) timeSeries.getKey();
  for (int i = 0; i < timeSeries.getItemCount(); i++) {
    TimeSeriesDataItem dataItem = timeSeries.getDataItem(i);
    Date currDate = dataItem.getPeriod().getStart();
    double value = dataItem.getValue().doubleValue();
    if (lastDate == null) {
      lastDate = currDate;
    } else {
      long interval = currDate.getTime() - lastDate.getTime();
      lastDate = currDate;
      meanInterval = (meanInterval * size + interval) / (size + 1);
      maxInterval = maxInterval < interval ? interval : maxInterval;
      minInterval = minInterval < interval ? minInterval : interval;
    }
    meanVal = (meanVal * size + value) / (size + 1);
    maxVal = maxVal < value ? value : maxVal;
    minVal = minVal < value ? minVal : value;
    valSum += value;
    size ++;
  }
}
 
Example 2
Source File: ExponentialSmoothingChartDemo.java    From OpenForecast with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * A helper function to convert data points (from startIndex to
 * endIndex) of a (JFreeChart) TimeSeries object into an
 * OpenForecast DataSet.
 * @param series the series of data points stored as a JFreeChart
 * TimeSeries object.
 * @param startIndex the index of the first data point required from the
 * series.
 * @param endIndex the index of the last data point required from the
 * series.
 * @return an OpenForecast DataSet representing the data points extracted
 * from the TimeSeries.
 */
private DataSet getDataSet( TimeSeries series,
                            int startIndex, int endIndex )
{
    DataSet dataSet = new DataSet();
    if ( endIndex > series.getItemCount() )
        endIndex = series.getItemCount();
    
    for ( int i=startIndex; i<endIndex; i++ )
        {
            TimeSeriesDataItem dataPair = series.getDataItem(i);
            DataPoint dp = new Observation( dataPair.getValue().doubleValue() );
            dp.setIndependentValue( "t", i );
            dataSet.add( dp );
        }
    
    return dataSet;
}
 
Example 3
Source File: ForecastingChartDemo.java    From OpenForecast with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * A helper function to convert data points (from startIndex to
 * endIndex) of a (JFreeChart) TimeSeries object into an
 * OpenForecast DataSet.
 * @param series the series of data points stored as a JFreeChart
 * TimeSeries object.
 * @param startIndex the index of the first data point required from the
 * series.
 * @param endIndex the index of the last data point required from the
 * series.
 * @return an OpenForecast DataSet representing the data points extracted
 * from the TimeSeries.
 */
private DataSet getDataSet( TimeSeries series,
                            int startIndex, int endIndex )
{
    DataSet dataSet = new DataSet();
    if ( endIndex > series.getItemCount() )
        endIndex = series.getItemCount();
    
    for ( int i=startIndex; i<endIndex; i++ )
        {
            TimeSeriesDataItem dataPair = series.getDataItem(i);
            DataPoint dp = new Observation( dataPair.getValue().doubleValue() );
            dp.setIndependentValue( "t", i );
            dataSet.add( dp );
        }
    
    return dataSet;
}
 
Example 4
Source File: SparkLine.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addAvaregeSeries(TimeSeries series, XYPlot plot) {
	logger.debug("IN");
	boolean isFirst = true;
	double avg = 0, min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY;
	int count = 0;
	for(int i = 0; i < series.getItemCount(); i++) {
		if( series.getValue(i) != null ) {
			count++;
			if(isFirst) {
				min = series.getValue(i).doubleValue();
				max = series.getValue(i).doubleValue();
				isFirst = false;
			}
			double n = series.getValue(i).doubleValue();
			avg += n;
			if(n < min) min = n;
			if(n > max) max = n;
			logger.debug(n);
		}

	}
	avg = avg/(double)count;


	//plot.getRangeAxis().setRange(new Range(min-2, max+2));

	addMarker(1, avg, colorAverage, 0.8f, plot);
	logger.debug("OUT");

}
 
Example 5
Source File: SparkLine.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addPointSeries(TimeSeries series, XYPlot plot) {
	logger.debug("IN");
	TimeSeries pointSerie = new TimeSeries("Point", Month.class);
	for(int i = 0; i < series.getItemCount(); i++) {
		pointSerie.add(series.getTimePeriod(i), series.getValue(i));
	}
	final TimeSeriesCollection avgDs = new TimeSeriesCollection(pointSerie); 



	XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) { 
		public boolean getItemShapeVisible(int _series, int item) { 
			return (true); 
		} 
	}; 
	renderer.setSeriesPaint(2, Color.LIGHT_GRAY);
	renderer.setBaseShapesVisible(true); 
	renderer.setBaseShapesFilled(true); 
	renderer.setDrawOutlines(true); 
	renderer.setUseFillPaint(true); 
	renderer.setBaseFillPaint(Color.BLACK); 
	renderer.setBaseOutlinePaint(Color.BLACK); 
	renderer.setUseOutlinePaint(true); 
	renderer.setSeriesShape(0, new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0));

	plot.setDataset(2, avgDs);
	plot.setRenderer(2, renderer);
	logger.debug("OUT");

}
 
Example 6
Source File: TimeSeriesBuilder.java    From OpenForecast with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Constructs a new TimeSeriesBuilder that reads its input from the given
 * TimeSeries object. This builder defaults the of the independent, time
 * variable to be the class name of the RegularTimePeriod used in the
 * TimeSeries. For example, if a series of org.jfree.data.time.Day objects
 * are used, then the name of the independent variable will default to
 * "Day" (without the quotes).
 *
 * See the class description for more information.
 * @param timeSeries the TimeSeries object containing data to be used to
 * build the DataSet.
 * @throws IllegalArgumentException if the TimeSeries is empty.
 */
public TimeSeriesBuilder( TimeSeries timeSeries )
{
    if ( timeSeries.getItemCount() <= 0 )
        throw new IllegalArgumentException("TimeSeries cannot be empty.");
    
    this.timeSeries = timeSeries;
    
    // Use base name of TimePeriod class, as name of time variable
    RegularTimePeriod timePeriod = timeSeries.getTimePeriod(0);
    String name = timePeriod.getClass().getName();
    name = name.substring( name.lastIndexOf(".")+1 );
    addVariable( name );
}
 
Example 7
Source File: TimeSeriesValidator.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public TimeSeries validate(TimeSeries timeSeries, String sourceName, TimeSeriesType type) throws ParseException {
    String qualifiedSourceName = createQualifiedSourcename(sourceName, type);
    final Symbol symbol = namespace.resolveSymbol(qualifiedSourceName);
    if (symbol == null) {
        throw new ParseException("No variable for identifier '" + qualifiedSourceName + "' registered.");
    }
    final String expression = getExpressionFor(qualifiedSourceName);
    if (expression == null || expression.trim().isEmpty()) {
        return timeSeries;
    }
    final Variable variable = (Variable) symbol;
    final Term term = parser.parse(expression, namespace);

    final int seriesCount = timeSeries.getItemCount();
    final TimeSeries validatedSeries = new TimeSeries(timeSeries.getKey());
    for (int i = 0; i < seriesCount; i++) {
        final TimeSeriesDataItem dataItem = timeSeries.getDataItem(i);
        final Number value = dataItem.getValue();
        variable.assignD(null, value.doubleValue());
        if (term.evalB(null)) {
            validatedSeries.add(dataItem);
        }
    }

    return validatedSeries;
}
 
Example 8
Source File: XYChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected ExtTimeTableXYDataset convertToTable( final XYDataset xyDataset ) {
  final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) xyDataset;
  final ExtTimeTableXYDataset tableXYDataset = new ExtTimeTableXYDataset();
  final int count = timeSeriesCollection.getSeriesCount();
  for ( int i = 0; i < count; i++ ) {
    final Comparable key = timeSeriesCollection.getSeriesKey( i );
    final TimeSeries timeSeries = timeSeriesCollection.getSeries( i );
    final int itemCount = timeSeries.getItemCount();
    for ( int ic = 0; ic < itemCount; ic++ ) {
      final TimeSeriesDataItem seriesDataItem = timeSeries.getDataItem( ic );
      tableXYDataset.add( seriesDataItem.getPeriod(), seriesDataItem.getValue(), key, false );
    }
  }
  return tableXYDataset;
}
 
Example 9
Source File: TimeSeriesBuilder.java    From OpenForecast with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Constructs a new TimeSeriesBuilder that reads its input from the given
 * TimeSeries object. This builder uses the given name for the independent,
 * time variable in the DataPoints that are created.
 * @param timeSeries the TimeSeries object containing data to be used to
 * build the DataSet.
 * @param timeVariableName the name to use for the time variable.
 * @throws IllegalArgumentException if the TimeSeries is empty.
 */
public TimeSeriesBuilder( TimeSeries timeSeries, String timeVariableName )
{
    if ( timeSeries.getItemCount() <= 0 )
        throw new IllegalArgumentException("TimeSeries cannot be empty.");
    
    this.timeSeries = timeSeries;
    setTimeVariable( timeVariableName );
}