Example usage for org.jfree.data.time TimeSeries getItemCount

List of usage examples for org.jfree.data.time TimeSeries getItemCount

Introduction

In this page you can find the example usage for org.jfree.data.time TimeSeries getItemCount.

Prototype

@Override
public int getItemCount() 

Source Link

Document

Returns the number of items in the series.

Usage

From source file:edu.dlnu.liuwenpeng.Time.TimeSeriesCollection.java

/**    
* Returns the indices of the two data items surrounding a particular     
* millisecond value.      // www. j  a  v a 2s  .c om
*     
* @param series  the series index.    
* @param milliseconds  the time.    
*     
* @return An array containing the (two) indices of the items surrounding     
*         the time.    
*/
public int[] getSurroundingItems(int series, long milliseconds) {
    int[] result = new int[] { -1, -1 };
    TimeSeries timeSeries = getSeries(series);
    for (int i = 0; i < timeSeries.getItemCount(); i++) {
        Number x = getX(series, i);
        long m = x.longValue();
        if (m <= milliseconds) {
            result[0] = i;
        }
        if (m >= milliseconds) {
            result[1] = i;
            break;
        }
    }
    return result;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java

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++;//from  w w  w .j av  a 2s. c o  m
            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");

}

From source file:edu.dlnu.liuwenpeng.Time.TimeSeriesCollection.java

/**    
* Returns the range of the values in this dataset's domain.    
*    /* w w w . j  a v  a  2  s  . co  m*/
* @param includeInterval  a flag that determines whether or not the    
*                         x-interval is taken into account.    
*     
* @return The range.    
*/
public Range getDomainBounds(boolean includeInterval) {
    Range result = null;
    Iterator iterator = this.data.iterator();
    while (iterator.hasNext()) {
        TimeSeries series = (TimeSeries) iterator.next();
        int count = series.getItemCount();
        if (count > 0) {
            RegularTimePeriod start = series.getTimePeriod(0);
            RegularTimePeriod end = series.getTimePeriod(count - 1);
            Range temp;
            //if (!includeInterval) {    
            temp = new Range(getX(start), getX(end));
            //System.out.println("here");
            // }    
            /*  else {    
               temp = new Range(    
                       start.getFirstMillisecond(this.workingCalendar),    
                       end.getLastMillisecond(this.workingCalendar));    
              }    
            */
            result = Range.combine(result, temp);
        }
    }
    return result;
}

From source file:org.jmxtrans.samples.graphite.GraphiteDataInjector.java

public void generateLoad() throws Exception {
    System.out.println("Inject data on Graphite server " + this.graphiteHost);

    TimeSeries timeSeries = new TimeSeries("shopping-cart.raw");

    DateTime now = new DateTime();
    DateTime end = now.plusDays(1);//from w ww .  j  a v a2s.com

    DateTime date = now.minusDays(15);
    DateTime twoDaysAfterBegin = date.plusDays(2);

    int integratedValue = 0;

    MathContext mathContext = new MathContext(1, RoundingMode.CEILING);

    int randomFactor = 0;

    while (date.isBefore(end)) {
        if (timeSeries.getItemCount() % 120 == 0) {
            randomFactor = 10 + random.nextInt(2);
        }
        int weekGrowthFactor = 6 - (now.getWeekOfWeekyear() - date.getWeekOfWeekyear());
        int value = new BigDecimal(randomFactor) // random factor
                .multiply(new BigDecimal(10)) // go to cents of USD
                .multiply(new BigDecimal(weekGrowthFactor))
                .multiply(new BigDecimal(hourlyDistribution[date.getHourOfDay()]))
                .multiply(new BigDecimal(weeklyDistribution[date.getDayOfWeek()]))
                .divide(new BigDecimal(20), mathContext).intValue(); // split hourly value in minutes

        integratedValue += value;
        for (int i1 = 0; i1 < 3; i1++) {
            timeSeries.add(new Minute(date.toDate()), integratedValue);
            date = date.plusMinutes(1);
        }
    }

    TimeSeries ordersPriceInCentsTimeSeries = MovingAverage.createMovingAverage(timeSeries,
            "shopping-cart.OrdersPriceInCents", 60 * 7, 0);

    TimeSeries ordersPriceInCentsSrv1TimeSeries = new TimeSeries("srv1.shopping-cart.OrdersPriceInCents");
    TimeSeries ordersPriceInCentsSrv2TimeSeries = new TimeSeries("srv2.shopping-cart.OrdersPriceInCents");
    int resetValue2ToZeroOffset = 0; // reset value 2 after 3 days of metrics
    for (int i = 0; i < ordersPriceInCentsTimeSeries.getItemCount(); i++) {
        TimeSeriesDataItem dataItem = ordersPriceInCentsTimeSeries.getDataItem(i);
        int value = dataItem.getValue().intValue();
        // value1 is 5% higher to value2 due to a 'weirdness' in the load balancing
        int value1 = Math.min((int) (value * 1.05 / 2), value);

        {
            // simulate srv2 restart
            DateTime currentDate = new DateTime(dataItem.getPeriod().getStart());
            boolean shouldResetValue2 = resetValue2ToZeroOffset == 0
                    && currentDate.getDayOfYear() == twoDaysAfterBegin.getDayOfYear();
            if (shouldResetValue2) {
                resetValue2ToZeroOffset = value - value1;
                System.out.println("reset value2 of " + resetValue2ToZeroOffset + " at " + currentDate);
            }
        }

        int value2 = value - value1 - resetValue2ToZeroOffset;
        // System.out.println("value=" + value + ", value1=" + value1 + ", value2=" + value2);
        ordersPriceInCentsSrv1TimeSeries.add(dataItem.getPeriod(), value1);
        ordersPriceInCentsSrv2TimeSeries.add(dataItem.getPeriod(), value2);
    }

    TimeSeries orderItemsCountTimeSeries = new TimeSeries("shopping-cart.OrderItemsCount");
    TimeSeries orderItemsCountSrv1TimeSeries = new TimeSeries("srv1.shopping-cart.OrderItemsCount");
    TimeSeries orderItemsCountSrv2TimeSeries = new TimeSeries("srv2.shopping-cart.OrderItemsCount");

    for (int i = 0; i < ordersPriceInCentsTimeSeries.getItemCount(); i++) {
        RegularTimePeriod period = ordersPriceInCentsTimeSeries.getDataItem(i).getPeriod();
        int ordersPriceInCents1 = ordersPriceInCentsSrv1TimeSeries.getDataItem(i).getValue().intValue();
        int ordersPriceInCents2 = ordersPriceInCentsSrv2TimeSeries.getDataItem(i).getValue().intValue();

        int value1 = ordersPriceInCents1 / 600;
        int value2 = ordersPriceInCents2 / 600;

        orderItemsCountTimeSeries.add(period, value1 + value2);
        orderItemsCountSrv1TimeSeries.add(period, value1);
        orderItemsCountSrv2TimeSeries.add(period, value2);

    }

    exportMetrics(ordersPriceInCentsTimeSeries, ordersPriceInCentsSrv1TimeSeries,
            ordersPriceInCentsSrv2TimeSeries, ordersPriceInCentsTimeSeries, orderItemsCountTimeSeries,
            orderItemsCountSrv1TimeSeries, orderItemsCountSrv2TimeSeries);

    TimeSeries activeSrv1Visitors = new TimeSeries("srv1.visitors.currentActive");
    TimeSeries activeSrv2Visitors = new TimeSeries("srv1.visitors.currentActive");

}

From source file:utilesChart.util.TimeSeriesCollection.java

/**
 * Returns the bounds of the domain values for the specified series.
 *
 * @param visibleSeriesKeys  a list of keys for the visible series.
 * @param includeInterval  include the x-interval?
 *
 * @return A range./*from w  w  w.  j  a  v a2 s.com*/
 *
 * @since 1.0.13
 */
public Range getDomainBounds(List visibleSeriesKeys, boolean includeInterval) {
    Range result = null;
    Iterator iterator = visibleSeriesKeys.iterator();
    while (iterator.hasNext()) {
        Comparable seriesKey = (Comparable) iterator.next();
        TimeSeries series = getSeries(seriesKey);
        int count = series.getItemCount();
        if (count > 0) {
            RegularTimePeriod start = series.getTimePeriod(0);
            RegularTimePeriod end = series.getTimePeriod(count - 1);
            Range temp;
            if (!includeInterval) {
                temp = new Range(getX(start), getX(end));
            } else {
                temp = new Range(start.getFirstMillisecond(this.workingCalendar),
                        end.getLastMillisecond(this.workingCalendar));
            }
            result = Range.combine(result, temp);
        }
    }
    return result;
}

From source file:utilesChart.util.TimeSeriesCollection.java

/**
 * Returns the range of the values in this dataset's domain.
 *
 * @param includeInterval  a flag that determines whether or not the
 *                         x-interval is taken into account.
 *
 * @return The range./*from  ww w.  j  a v  a 2s .  c om*/
 */
public Range getDomainBounds(boolean includeInterval) {
    Range result = null;
    Iterator iterator = this.data.iterator();
    while (iterator.hasNext()) {
        TimeSeries series = (TimeSeries) iterator.next();
        int count = series.getItemCount();
        if (count > 0) {
            RegularTimePeriod start = series.getTimePeriod(0);
            RegularTimePeriod end = series.getTimePeriod(count - 1);
            Range temp;
            if (!includeInterval) {
                temp = new Range(getX(start), getX(end));
            } else {
                temp = new Range(start.getFirstMillisecond(this.workingCalendar),
                        end.getLastMillisecond(this.workingCalendar));
            }
            result = Range.combine(result, temp);
        }
    }
    return result;
}

From source file:org.jfree.data.time.TimeSeriesCollection.java

/**
 * Returns the bounds of the domain values for the specified series.
 *
 * @param visibleSeriesKeys  a list of keys for the visible series.
 * @param includeInterval  include the x-interval?
 *
 * @return A range.//from  w w  w. java 2s  .  c  o m
 *
 * @since 1.0.13
 */
@Override
public Range getDomainBounds(List visibleSeriesKeys, boolean includeInterval) {
    Range result = null;
    Iterator iterator = visibleSeriesKeys.iterator();
    while (iterator.hasNext()) {
        Comparable seriesKey = (Comparable) iterator.next();
        TimeSeries series = getSeries(seriesKey);
        int count = series.getItemCount();
        if (count > 0) {
            RegularTimePeriod start = series.getTimePeriod(0);
            RegularTimePeriod end = series.getTimePeriod(count - 1);
            Range temp;
            if (!includeInterval) {
                temp = new Range(getX(start), getX(end));
            } else {
                temp = new Range(start.getFirstMillisecond(this.workingCalendar),
                        end.getLastMillisecond(this.workingCalendar));
            }
            result = Range.combine(result, temp);
        }
    }
    return result;
}

From source file:org.jfree.data.time.TimeSeriesCollection.java

/**
 * Returns the range of the values in this dataset's domain.
 *
 * @param includeInterval  a flag that determines whether or not the
 *                         x-interval is taken into account.
 *
 * @return The range./* w ww . ja  v a 2 s. c  o  m*/
 */
@Override
public Range getDomainBounds(boolean includeInterval) {
    Range result = null;
    Iterator iterator = this.data.iterator();
    while (iterator.hasNext()) {
        TimeSeries series = (TimeSeries) iterator.next();
        int count = series.getItemCount();
        if (count > 0) {
            RegularTimePeriod start = series.getTimePeriod(0);
            RegularTimePeriod end = series.getTimePeriod(count - 1);
            Range temp;
            if (!includeInterval) {
                temp = new Range(getX(start), getX(end));
            } else {
                temp = new Range(start.getFirstMillisecond(this.workingCalendar),
                        end.getLastMillisecond(this.workingCalendar));
            }
            result = Range.combine(result, temp);
        }
    }
    return result;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.XYChartExpression.java

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);
        }//from w  w w  .j ava  2 s .  co  m
    }
    return tableXYDataset;
}

From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java

private int getDataIndex(TimeSeries timeSeries, Day targetDay) {
    int low = 0;//from   w w w  .  j a  v  a2s.  c o m
    int high = timeSeries.getItemCount() - 1;

    while (low <= high) {
        int mid = (low + high) >>> 1;

        final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(mid);
        final Day searchDay = (Day) timeSeriesDataItem.getPeriod();
        final long cmp = searchDay.compareTo(targetDay);

        if (cmp < 0) {
            low = mid + 1;
        } else if (cmp > 0) {
            high = mid - 1;
        } else {
            return mid;
        }
    }
    return -1;
}