Example usage for org.jfree.data.time RegularTimePeriod next

List of usage examples for org.jfree.data.time RegularTimePeriod next

Introduction

In this page you can find the example usage for org.jfree.data.time RegularTimePeriod next.

Prototype

public abstract RegularTimePeriod next();

Source Link

Document

Returns the time period following this one, or null if some limit has been reached.

Usage

From source file:info.financialecology.finance.utilities.datastruct.VersatileTimeSeriesCollection.java

/**
 * Add a new time series to the collection.
 * <p>/*from   w ww. j  a  v a  2  s  . co m*/
 * Creates a new {@link VersatileTimeSeries}, populates it with the values from the 
 * {@link DoubleTimeSeries} {@code dts}, and insert it into the collection.
 * <p>
 * Uses the parameter {@code startTime} to set the time at which the time series starts.
 * Use {@code setStartTime()} and {@code overrideStartTime()} to change the start time.  
 * <p>  
 * 
 * @param dts the {@link DoubleTimeSeries} from which we obtain the values to populate the
 * new time series  
 * @param name the name of the time series variable
 */
public void add(DoubleTimeSeries dts) {

    String newKey = dts.getId();

    Assertion.assertOrKill(getSeries(newKey) == null,
            "A time series with the key '" + newKey + "' already exists in the collection");

    VersatileTimeSeries vts = new VersatileTimeSeries(newKey);

    RegularTimePeriod time = internalParams.getStartTime();

    for (int t = 0; t < dts.size(); t++) {
        vts.add(time, dts.getValue(t));
        time = time.next();
    }

    addSeries(vts);

    Assertion.assertOrKill(checkConsistency(), "The time series '" + dts.getId() + "' added to "
            + "the collection is not consistent with the already existing time series");
}

From source file:info.financialecology.finance.utilities.datastruct.VersatileTimeSeriesCollection.java

/**
 * Create a new {@link VersatileTimeSeries}, populate it with values of a 
 * {@link DoubleTimeSeries}, and insert into the collection. The run index 
 * has to be provided while the dimension indices are optional. The key of 
 * the new time series is constructed using the <code>name</code> and the 
 * run and dimension indices provided as parameters.
 * <p>//from   w w  w  .  ja  v a  2  s . co m
 * The sequence of the method arguments is a bit of a hack, to facilitate 
 * passing an arbitrary list of dimension indices.
 * <p>
 * Uses the internal parameters <code>startTime</code> and <code>indexSeparator</code>.
 * <p>  
 * @param dts the {@link DoubleTimeSeries} from which we obtain the values to populate the
 * new time series  
 * @param run the run index
 * @param name the name of the time series variable
 * @param indices the dimension indices (may be empty)
 */
public void populateSeries(int run, String name, DoubleTimeSeries dts, int... indices) {
    String newKey = name + internalParams.getIndexSeparator();

    Assertion.assertStrict(run >= 0, Assertion.Level.ERR, "Run index has to be positive");

    for (int i : indices) {
        Assertion.assertStrict(i >= 0, Assertion.Level.ERR, "Dimension indices have to be positive");
        newKey += Integer.toString(i) + internalParams.getIndexSeparator();
    }

    newKey += "r" + Integer.toString(run);

    VersatileTimeSeries ats = new VersatileTimeSeries(newKey);
    addSeries(ats);

    RegularTimePeriod time = internalParams.getStartTime();

    for (int i = 0; i < dts.size(); i++) {
        ats.add(time, dts.getValue(i));
        time = time.next();
    }

}

From source file:info.financialecology.finance.utilities.datastruct.VersatileTimeSeriesCollection.java

/**
 * Create a new {@link VersatileTimeSeries}, populate it with values of a {@link DoubleTimeSeries}, 
 * and insert into the collection. Experiment and run indices have to be provided while 
 * the dimension indices are optional. The key of the new time series is constructed using
 * the <code>name</code> and the experiment, run, and dimension indices provided as parameters.
 * <p>//from   w w  w. j a v  a2s. c om
 * The sequence of the method arguments is a bit of a hack, to facilitate passing an arbitrary list of
 * dimension indices.
 * <p>
 * Uses the internal parameters <code>startTime</code> and <code>indexSeparator</code>.
 * <p>  
 * @param dts the {@link DoubleTimeSeries} from which we obtain the values to populate the
 * new time series  
 * @param exp the experiment index
 * @param run the run index
 * @param name the name of the time series variable
 * @param indices the dimension indices (may be empty)
 */
public void populateSeries(int exp, int run, String name, DoubleTimeSeries dts, int... indices) {
    String newKey = name + internalParams.getIndexSeparator();

    Assertion.assertStrict((exp >= 0) && (run >= 0), Assertion.Level.ERR,
            "Run and experiment index have to be positive");

    for (int i : indices) {
        Assertion.assertStrict(i >= 0, Assertion.Level.ERR, "Dimension indices have to be positive");
        newKey += Integer.toString(i) + internalParams.getIndexSeparator();
    }

    newKey += "r" + Integer.toString(run) + internalParams.getIndexSeparator() + "e" + Integer.toString(exp);

    VersatileTimeSeries ats = new VersatileTimeSeries(newKey);
    addSeries(ats);

    RegularTimePeriod time = internalParams.getStartTime();

    for (int i = 0; i < dts.size(); i++) {
        ats.add(time, dts.getValue(i));
        time = time.next();
    }

}

From source file:info.financialecology.finance.utilities.datastruct.VersatileTimeSeriesCollection.java

/**
 * Create a new {@link VersatileTimeSeries}, populate it with values of a {@link DoubleTimeSeries}, 
 * and insert into the collection. Experiment, run, and asset indices have to be provided while 
 * the dimension indices are optional. The key of the new time series is constructed using
 * the <code>name</code> and the experiment, run, asset, and dimension indices provided as parameters.
 * <p>//from   www  . j a  va 2  s.  c o m
 * The sequence of the method arguments is a bit of a hack, to facilitate passing an arbitrary list of
 * dimension indices.
 * <p>
 * Uses the internal parameters <code>startTime</code> and <code>indexSeparator</code>.
 * <p>  
 * @param dts the {@link DoubleTimeSeries} from which we obtain the values to populate the
 * new time series  
 * @param exp the experiment index
 * @param run the run index
 * @param assset the asset index
 * @param name the name of the time series variable
 * @param indices the dimension indices (may be empty)
 */
public void populateSeries(int exp, int run, String secId, String name, DoubleTimeSeries dts, int... indices) {
    String newKey = name + internalParams.getIndexSeparator();

    Assertion.assertStrict((exp >= 0) && (run >= 0), Assertion.Level.ERR,
            "Run and experiment index have to be positive");

    for (int i : indices) {
        Assertion.assertStrict(i >= 0, Assertion.Level.ERR, "Dimension indices have to be positive");
        newKey += Integer.toString(i) + internalParams.getIndexSeparator();
    }

    newKey += secId + internalParams.getIndexSeparator() + "r" + Integer.toString(run)
            + internalParams.getIndexSeparator() + "e" + Integer.toString(exp);

    VersatileTimeSeries ats = new VersatileTimeSeries(newKey);
    addSeries(ats);

    RegularTimePeriod time = internalParams.getStartTime();

    for (int i = 0; i < dts.size(); i++) {
        ats.add(time, dts.getValue(i));
        time = time.next();
    }

}

From source file:info.financialecology.finance.utilities.datastruct.VersatileTimeSeriesCollection.java

/**
 * Create a new set of {@link VersatileTimeSeries}, populate them with 
 * values of {@link DoubleTimeSeries} from a {@link DoubleTimeSeriesList},
 * and insert them into this collection. The run index has to be provided 
 * together with the index at which the dimension index starts. The keys 
 * of the new time series are constructed using the <code>name</code> and 
 * the run index provided as parameters.
 * <p>//from   w  ww .  j a  va  2s .  c o m
 * <b>Note:</b> This currently works only for series with a single dimension 
 * index.
 * <p>
 * Uses the internal parameters <code>startTime</code> and <code>indexSeparator</code>.
 * <p>  
 * @param dtl the {@link DoubleTimeSeriesList} from which we obtain the values to 
 * populate the new time series  
 * @param run the run index
 * @param name the name of the time series variable
 * @param startIndex the value at which the dimension index starts 
 */
public void populateSeries(int run, String name, DoubleTimeSeriesList dtl, int startIndex) {

    Assertion.assertStrict((run >= 0) && (startIndex >= 0), Assertion.Level.ERR,
            "Start index and experiment index have to be positive");

    for (int i = 0; i < dtl.size(); i++) {
        String newKey = name + internalParams.getIndexSeparator() + Integer.toString(i + startIndex)
                + internalParams.getIndexSeparator() + "r" + Integer.toString(run);
        VersatileTimeSeries ats = new VersatileTimeSeries(newKey);
        addSeries(ats);

        RegularTimePeriod time = internalParams.getStartTime();

        for (int j = 0; j < dtl.get(i).size(); j++) {
            ats.add(time, dtl.get(i).getValue(j));
            time = time.next();
        }
    }
}

From source file:info.financialecology.finance.utilities.datastruct.VersatileTimeSeriesCollection.java

/**
 * Create a new set of {@link VersatileTimeSeries}, populate them with 
 * values of {@link DoubleTimeSeries} from a {@link DoubleTimeSeriesList},
 * and insert them into this collection. The experiment and run indices 
 * have to be provided together with the index at which the dimension index
 * starts. The keys of the new time series are constructed using the 
 * <code>name</code> and the experiment and run indices provided as parameters.
 * <p>/*from w  ww .  j  a  v  a  2  s  . co  m*/
 * <b>Note:</b> This currently works only for series with a single dimension 
 * index.
 * <p>
 * Uses the internal parameters <code>startTime</code> and <code>indexSeparator</code>.
 * <p>  
 * @param dtl the {@link DoubleTimeSeriesList} from which we obtain the values to 
 * populate the new time series  
 * @param exp the experiment index
 * @param run the run index
 * @param name the name of the time series variable
 * @param startIndex the value at which the dimension index starts 
 */
public void populateSeries(int exp, int run, String name, DoubleTimeSeriesList dtl, int startIndex) {

    Assertion.assertStrict((exp >= 0) && (run >= 0) && (startIndex >= 0), Assertion.Level.ERR,
            "Start index and run and experiment indices have to be positive");

    for (int i = 0; i < dtl.size(); i++) {
        String newKey = name + internalParams.getIndexSeparator() + Integer.toString(i + startIndex)
                + internalParams.getIndexSeparator() + "r" + Integer.toString(run)
                + internalParams.getIndexSeparator() + "e" + Integer.toString(exp);
        VersatileTimeSeries ats = new VersatileTimeSeries(newKey);
        addSeries(ats);

        RegularTimePeriod time = internalParams.getStartTime();

        for (int j = 0; j < dtl.get(i).size(); j++) {
            ats.add(time, dtl.get(i).getValue(j));
            time = time.next();
        }
    }
}

From source file:fmiquerytest.Coordinates.java

static String drawTempRainChart(List<stepWeather> stepDataBase, Map routeWeather) {
    //First, fetch the real data
    List<Double> times = new ArrayList<>();
    List<Double> temps = new ArrayList<>();
    List<Double> rains = new ArrayList<>();
    List<Double> lights = new ArrayList<>();
    for (int i = 0; i < stepDataBase.size(); ++i) {
        stepWeather step = stepDataBase.get(i);
        stepWeather nextstep = step;/*from   www .  jav a2 s .  c  o m*/
        if (i < stepDataBase.size() - 1) {
            nextstep = stepDataBase.get(i + 1);
        }
        times.add(step.timeAsDouble);
        temps.add(getParameterAverage(routeWeather, step, nextstep, "Temperature"));
        rains.add(getParameterAverage(routeWeather, step, nextstep, "Precipitation1h"));
        lights.add(Math.pow(Math.abs(step.timeAsDouble % 24 - ((step.sunRise + step.sunSet) / 2))
                / ((step.sunSet - step.sunRise) / 2), 5));
    }

    double zeroPoint = times.get(0);
    // Make first dataset
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    final TimeSeries s1 = new TimeSeries("Temperature C", Minute.class);
    // Make second dataset
    final TimeSeriesCollection dataset2 = new TimeSeriesCollection();
    final TimeSeries s2 = new TimeSeries("Rain (mm)", Minute.class);
    // Make third dataset
    //final TimeSeriesCollection dataset3 = new TimeSeriesCollection();
    final TimeSeries s3 = new TimeSeries("Darkness", Minute.class);
    // Show data per minute
    RegularTimePeriod start = new Minute(new Date(FmiQueryTest.startTimeMillis));
    for (int i = 0; i < times.size() - 1; ++i) {
        double time = times.get(i);
        double nexttime = times.get(i + 1);
        int firstMinute = intValue((time - zeroPoint) * 60);
        int currentMinute = firstMinute;
        int lastMinute = intValue((nexttime - zeroPoint) * 60);
        while (currentMinute < lastMinute) {
            s1.add(start, temps.get(i) + ((double) currentMinute - firstMinute) / (lastMinute - firstMinute)
                    * (temps.get(i + 1) - temps.get(i)));
            s2.add(start, (rains.get(i) + rains.get(i + 1)) / 2);
            //+((double)currentMinute-firstMinute)/(lastMinute-firstMinute)*(rains.get(i+1)-rains.get(i)));
            s3.add(start, lights.get(i) + ((double) currentMinute - firstMinute) / (lastMinute - firstMinute)
                    * (lights.get(i + 1) - lights.get(i)));
            ++currentMinute;
            start = start.next();
        }
    }
    dataset.addSeries(s1);
    dataset2.addSeries(s3);
    dataset2.addSeries(s2);

    // Initialize chart
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Temperature and rain", "Time",
            "Temperature C", dataset, true, // legend? 
            true, // tooltips? 
            false // URLs? 
    );
    final XYPlot plot = chart.getXYPlot();
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setUpperMargin(0.0);

    // configure the range axis to display first dataset...
    final ValueAxis rangeAxis = (ValueAxis) plot.getRangeAxis();
    rangeAxis.setRange(-30, 30);
    final TickUnits units = new TickUnits();
    units.add(new NumberTickUnit(10.0));
    units.add(new NumberTickUnit(1.0));
    units.add(new NumberTickUnit(0.1));
    rangeAxis.setStandardTickUnits(units);
    //rangeAxis.setTickLabelFont(new Font("SansSerif", Font.BOLD, 16));

    // add the secondary dataset/renderer/axis
    plot.setRangeAxis(rangeAxis);
    final XYItemRenderer renderer2 = new XYAreaRenderer();
    final ValueAxis axis2 = new NumberAxis("Rain (mm) ");
    axis2.setRange(0, 2);
    axis2.setStandardTickUnits(units);
    //axis2.setTickLabelFont(new Font("SansSerif", Font.BOLD, 16));
    renderer2.setSeriesPaint(0, new Color(0, 0, 255, 128));
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);
    plot.setRangeAxis(1, axis2);
    plot.mapDatasetToRangeAxis(1, 1);
    final XYItemRenderer renderer3 = new XYAreaRenderer();
    renderer3.setSeriesPaint(0, new Color(0, 0, 0, 64));
    //plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer3);
    plot.setRangeAxis(1, axis2);
    plot.mapDatasetToRangeAxis(1, 1);

    chart.setBackgroundPaint(Color.white);
    //plot.setBackgroundPaint(Color.lightGray);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    //        final TextTitle subtitle = new TextTitle("An area chart demonstration.  We use this "
    //            + "subtitle as an example of what happens when you get a really long title or "
    //            + "subtitle.");
    //        subtitle.setFont(new Font("SansSerif", Font.PLAIN, 12));
    //        subtitle.setPosition(RectangleEdge.TOP);
    ////        subtitle.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.05));
    //        subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
    //        chart.addSubtitle(subtitle);

    // Produce chart
    //        ChartFrame frame = new ChartFrame("Tamperature and rain", chart);
    //        frame.pack();
    //        RefineryUtilities.centerFrameOnScreen(frame);
    //        frame.setVisible(true);
    ByteArrayOutputStream bas = new ByteArrayOutputStream();
    try {
        ChartUtilities.writeChartAsPNG(bas, chart, 600, 400);
    } catch (IOException ex) {
        Logger.getLogger(WeatherTools.class.getName()).log(Level.SEVERE, null, ex);
    }
    byte[] byteArray = bas.toByteArray();
    String baseCode = Base64.encode(byteArray);
    return "<img width=\"480\" alt=\"Temperature and rain\" src=\"data:image/png;base64," + baseCode.trim()
            + "\" />";
}

From source file:info.financialecology.finance.utilities.datastruct.VersatileTimeSeries.java

/**
 * Creates a new time series by applying the integral operator to this time series. 
 * The value of a data point in the new time series is equal to the sum of the values
 * up to that point in time. This can be used for instance to compute the current asset 
 * position as the sum of all prior orders.
 * /*w  ww  .  j  a  v  a  2  s . c  o m*/
 * @param name the label of the new time series
 * @return a new time series with the difference values
 */
public VersatileTimeSeries operatorCumulative(String name) {
    VersatileTimeSeries ats = new VersatileTimeSeries(name);
    RegularTimePeriod currentTime = getTimePeriod(0);

    ats.add(new TimeSeriesDataItem(currentTime, this.getValue(0)));

    for (int i = 1; i < this.getItemCount(); i++) {
        currentTime = currentTime.next();
        ats.add(currentTime, ats.getValue(i - 1).doubleValue() + this.getValue(i).doubleValue());
    }

    return ats;
}

From source file:info.financialecology.finance.utilities.datastruct.VersatileTimeSeries.java

/**
 * Creates a new time series with the absolute values of each data point of this time
 * series. This can be used for instance to calculate trading volume from total 
 * orders. // w w w .  java2s. c  om
 * 
 * @param name the label of the new time series
 * @return a new time series with the absolute values
 */
public VersatileTimeSeries operatorAbs(String name) {
    VersatileTimeSeries ats = new VersatileTimeSeries(name);
    RegularTimePeriod currentTime = getTimePeriod(0);

    for (int i = 0; i < this.getItemCount(); i++) {
        ats.add(currentTime, Math.abs(this.getValue(i).doubleValue()));
        currentTime = currentTime.next();
    }

    return ats;
}

From source file:info.financialecology.finance.utilities.datastruct.VersatileTimeSeries.java

/**
 * Creates a new time series with the exponential values of each data point of this time
 * series. Since many models work with log prices, this method can be used to calculate 
 * the corresponding prices, which are easier to interpret when inspecting the results.  
 * /*from   w w w.  ja va2  s . c o m*/
 * @param name the label of the new time series
 * @return a new time series with the exponential values
 */
public VersatileTimeSeries operatorExp(String name) {
    VersatileTimeSeries ats = new VersatileTimeSeries(name);
    RegularTimePeriod currentTime = getTimePeriod(0);

    for (int i = 0; i < this.getItemCount(); i++) {
        ats.add(currentTime, Math.exp(this.getValue(i).doubleValue()));
        currentTime = currentTime.next();
    }

    return ats;
}