Ejemplo n.º 1
0
  /** Creates a dataset of type XYSeries */
  public XYDataset convertDataSet() {
    int size = 0; // Initialises a value for size
    int sum = 0; // initialises a value for sum
    int pos = 0; // initialises a value for position
    int j = 0; // initialises a increment for the for loop

    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series = new XYSeries(super.GetTitle());

    DataCell preVal = super.GetDataSet().GetCell(0, 0);
    // Creates a new list for the found elements
    super.m_foundElements = new ArrayList<String>();

    for (int i = 0; i < super.GetDataSet().GetNumOfRows() - 1; i++) {

      if (!super.isUnique(super.GetDataSet().GetCell(super.GetXColumnPosition(), i).toString())) {
        for (j = pos; j < super.GetDataSet().GetNumOfRows() - 1; j++) {
          if (preVal
              .toString()
              .equals(super.GetDataSet().GetCell(super.GetXColumnPosition(), j).toString())) {

            // Check if datatype is a number
            if (super.GetDataSet().GetCell(super.GetXColumnPosition(), j).GetDataType()
                == DataType.INTEGER) {
              sum += super.GetDataSet().GetCell(super.GetYColumnPosition(), j).GetInteger();
            } else if (super.GetDataSet().GetCell(super.GetXColumnPosition(), j).GetDataType()
                == DataType.DOUBLE) {
              sum += super.GetDataSet().GetCell(super.GetYColumnPosition(), j).GetDouble();
            }
          }
        }
        super.m_foundElements.add(
            super.GetDataSet().GetCell(super.GetXColumnPosition(), i).toString());

        // Add to chart dataSet
        series.add(sum, preVal.GetInteger());

        preVal = super.GetDataSet().GetCell(super.GetXColumnPosition(), i++);
        sum = 0; //
        pos++;
      }
    }

    for (j = pos; j < super.GetDataSet().GetNumOfRows() - 1; j++) {
      if (super.m_foundElements
          .get(super.m_foundElements.size() - 1)
          .equals(super.GetDataSet().GetCell(super.GetXColumnPosition(), j).toString())) {
        if (super.GetDataSet().GetCell(super.GetXColumnPosition(), j).GetDataType()
            == DataType.INTEGER) {
          sum += super.GetDataSet().GetCell(super.GetYColumnPosition(), j).GetInteger();
        } else if (super.GetDataSet().GetCell(super.GetXColumnPosition(), j).GetDataType()
            == DataType.DOUBLE) {
          sum += super.GetDataSet().GetCell(super.GetYColumnPosition(), j).GetDouble();
        }
      }
    }
    series.add(sum, preVal.GetInteger());
    dataset.addSeries(series);
    return dataset;
  }
  /**
   * precondition : 'attribute' MUST contain number values only
   *
   * @param cases
   * @param attribute
   * @return DefaultXYDataset with all values of 'attribute' against event numbers or timestamps.
   */
  private XYSeriesCollection getDataAttributes(
      String[] attributes, boolean byTime, double timesize) {
    XYSeriesCollection result = new XYSeriesCollection();
    for (int index = 0; index < attributes.length; index++) {
      String attribute = attributes[index];
      Integer i = 0;
      XYSeries row = new XYSeries(attribute);
      for (ProcessInstance pi : mylog.getInstances()) {
        Integer x = 0; // count event number
        Date begin = pi.getAuditTrailEntries().first().getTimestamp(); // starting
        // time
        // of
        // process
        // instance

        for (AuditTrailEntry ate : pi.getListOfATEs()) {
          if (ate.getAttributes().containsKey(attribute)) {
            Double val;
            val = Double.valueOf(ate.getAttributes().get(attribute));
            if (byTime) {
              row.add(timediff(begin, ate.getTimestamp()) / timesize, val.doubleValue());
            } else {
              row.add(x.doubleValue(), val.doubleValue());
            }
          }
          x++; // event number in case
        }
        i++; // case number
      }
      result.addSeries(row);
    }
    return result;
  }
  /**
   * @return a {@link org.jfree.data.xy.XYSeries} representing the distribution of traveled
   *     distances for the mode (histogramm), or null if the mode is unknown (only modes that
   *     generated events in the previous mobsim run are "known").
   * @param step the width of the bins, in meters
   * @param mode the mode to get the data for
   */
  public XYSeries getTraveledXYsHistogram(final String mode, final double step) {
    boolean autoSort = false;
    boolean allowDuplicateXValues = true;
    XYSeries output = new XYSeries(mode, autoSort, allowDuplicateXValues);
    double[] modeRawData;
    try {
      modeRawData = this.rawData.get(mode).getElements();
    } catch (NullPointerException e) {
      return null;
    }
    Arrays.sort(modeRawData);
    double currentUpperBound = step;
    int count = 0;

    for (double xyValue : modeRawData) {
      if (xyValue < currentUpperBound) {
        count++;
      } else {
        // add the previous bin to the plot
        output.add(currentUpperBound - step, count);
        // output.add(currentUpperBound, count);

        currentUpperBound += step;
        while (xyValue > currentUpperBound) {
          output.add(currentUpperBound, 0d);
          currentUpperBound += step;
        }
        count = 1;
      }
    }
    // add the last count
    output.add(currentUpperBound - step, count);
    output.add(currentUpperBound, 0);
    return output;
  }
Ejemplo n.º 4
0
  public void execute() {
    // TODO Auto-generated method stub

    // simply get the environment datamodel
    dmodel = (StaticEnvDataModel) sim.getEnvDataModel();

    double infected = getPercentInfected(dmodel);

    synchronized (this) {
      XYSeries series;
      try {
        series = data.getSeries("infected");
        series.add(dmodel.time, infected);
      } catch (org.jfree.data.UnknownKeyException e) {
        series = new XYSeries("infected");
        data.addSeries(series);
        series.add(dmodel.time, infected);
      }

      if (dmodel.time % 100 == 0) {
        // this will cause the gui to update?
        updateChart();
      }
    }
  }
Ejemplo n.º 5
0
 /**
  * Adds any unique x-values from 'series' to the dataset, and also adds any x-values that are in
  * the dataset but not in 'series' to the series.
  *
  * @param series the series (<code>null</code> not permitted).
  */
 private void updateXPoints(XYSeries series) {
   if (series == null) {
     throw new IllegalArgumentException("Null 'series' not permitted.");
   }
   HashSet seriesXPoints = new HashSet();
   boolean savedState = this.propagateEvents;
   this.propagateEvents = false;
   for (int itemNo = 0; itemNo < series.getItemCount(); itemNo++) {
     Number xValue = series.getX(itemNo);
     seriesXPoints.add(xValue);
     if (!this.xPoints.contains(xValue)) {
       this.xPoints.add(xValue);
       int seriesCount = this.data.size();
       for (int seriesNo = 0; seriesNo < seriesCount; seriesNo++) {
         XYSeries dataSeries = (XYSeries) this.data.get(seriesNo);
         if (!dataSeries.equals(series)) {
           dataSeries.add(xValue, null);
         }
       }
     }
   }
   Iterator iterator = this.xPoints.iterator();
   while (iterator.hasNext()) {
     Number xPoint = (Number) iterator.next();
     if (!seriesXPoints.contains(xPoint)) {
       series.add(xPoint, null);
     }
   }
   this.propagateEvents = savedState;
 }
Ejemplo n.º 6
0
 /**
  * Creates and returns a sample dataset. The data was randomly generated.
  *
  * @return a sample dataset.
  */
 private XYDataset createSampleData() {
   XYSeries series = new XYSeries("Series 1");
   series.add(2.0, 56.27);
   series.add(3.0, 41.32);
   series.add(4.0, 31.45);
   series.add(5.0, 30.05);
   series.add(6.0, 24.69);
   series.add(7.0, 19.78);
   series.add(8.0, 20.94);
   series.add(9.0, 16.73);
   series.add(10.0, 14.21);
   series.add(11.0, 12.44);
   XYSeriesCollection result = new XYSeriesCollection(series);
   XYSeries series2 = new XYSeries("Series 2");
   series2.add(11.0, 56.27);
   series2.add(10.0, 41.32);
   series2.add(9.0, 31.45);
   series2.add(8.0, 30.05);
   series2.add(7.0, 24.69);
   series2.add(6.0, 19.78);
   series2.add(5.0, 20.94);
   series2.add(4.0, 16.73);
   series2.add(3.0, 14.21);
   series2.add(2.0, 12.44);
   result.addSeries(series2);
   return result;
 }
Ejemplo n.º 7
0
  protected void updateXYSerieses() throws MicroarrayException {

    Iterable<Float> xValues = data.queryFeatures(xVar.getExpression()).asFloats();
    Iterable<Float> yValues = data.queryFeatures(yVar.getExpression()).asFloats();

    XYSeries series = new XYSeries("");
    XYSeries selectionSeries = new XYSeries("");

    Iterator<Float> xIterator = xValues != null ? xValues.iterator() : null;
    int i = 0;

    for (Float y : yValues) {
      if (selectedIndexes.contains(i)) {
        if (xIterator != null) {
          selectionSeries.add(xIterator.next(), y);
        } else {
          selectionSeries.add(i, y);
        }
      } else {

        if (xIterator != null) {
          series.add(xIterator.next(), y);
        } else {
          series.add(i, y);
        }
      }
      i++;
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);
    dataset.addSeries(selectionSeries);

    plot.setDataset(dataset);
  }
Ejemplo n.º 8
0
  /**
   * A check for the datasetIndex and seriesIndex fields in the LegendItem returned by the
   * getLegendItem() method.
   */
  public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYDotRenderer r = new XYDotRenderer();
    XYPlot plot = new XYPlot(d1, new NumberAxis("x"), new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
  }
  private void scatterPlot(
      Map<Double, Map<String, Tuple<Double, Double>>> inputData, String outFile) {

    String mode1 = travelModes[0];
    String mode2 = travelModes[1];

    XYSeries carFlow = new XYSeries(mode1 + " flow");
    XYSeries bikeFlow = new XYSeries(mode2 + " flow");
    XYSeries carSpeed = new XYSeries(mode1 + " speed");
    XYSeries bikeSpeed = new XYSeries(mode2 + " speed");

    for (double d : inputData.keySet()) {
      carFlow.add(d, inputData.get(d).get(mode1).getFirst());
      carSpeed.add(d, inputData.get(d).get(mode1).getSecond());

      bikeFlow.add(d, inputData.get(d).get(mode2).getFirst());
      bikeSpeed.add(d, inputData.get(d).get(mode2).getSecond());
    }

    // flow vs density
    XYSeriesCollection flowDataset = new XYSeriesCollection();
    flowDataset.addSeries(carFlow);
    flowDataset.addSeries(bikeFlow);

    NumberAxis flowAxis = new NumberAxis("Flow (PCU/h)");
    flowAxis.setRange(0.0, 2100.0);

    XYPlot plot1 = new XYPlot(flowDataset, null, flowAxis, new XYLineAndShapeRenderer(false, true));
    plot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // speed vs density
    XYSeriesCollection speedDataset = new XYSeriesCollection();
    speedDataset.addSeries(carSpeed);
    speedDataset.addSeries(bikeSpeed);

    NumberAxis speedAxis = new NumberAxis("Speed (m/s)");
    speedAxis.setRange(0.0, 17.0);

    XYPlot plot2 =
        new XYPlot(speedDataset, null, speedAxis, new XYLineAndShapeRenderer(false, true));
    plot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    NumberAxis densityAxis = new NumberAxis("Overall density (PCU/km)");
    densityAxis.setRange(0.0, 150.00);

    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(densityAxis);
    plot.setGap(10.);
    plot.add(plot1);
    plot.add(plot2);
    plot.setOrientation(PlotOrientation.VERTICAL);

    JFreeChart chart =
        new JFreeChart("Fundamental diagrams", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    try {
      ChartUtilities.saveChartAsPNG(new File(outFile), chart, 800, 600);
    } catch (IOException e) {
      throw new RuntimeException("Data is not plotted. Reason " + e);
    }
  }
 /**
  * Creates a series for testing.
  *
  * @return A series.
  */
 private XYSeries createSeries1() {
   XYSeries series1 = new XYSeries("Series 1", true, false);
   series1.add(1.0, 1.0);
   series1.add(2.0, 1.0);
   series1.add(4.0, 1.0);
   series1.add(5.0, 1.0);
   return series1;
 }
 /**
  * Creates a sample dataset.
  *
  * @param index the dataset index.
  * @return A dataset.
  */
 private XYDataset createDataset(int index) {
   XYSeries series1 = new XYSeries("Series " + (index + 1));
   series1.add(-10.0, -5.0);
   series1.add(10.0, 5.0);
   XYSeriesCollection dataset = new XYSeriesCollection();
   dataset.addSeries(series1);
   return dataset;
 }
 /**
  * Creates a series for testing.
  *
  * @return A series.
  */
 private XYSeries createSeries2() {
   XYSeries series2 = new XYSeries("Series 2", true, false);
   series2.add(2.0, 2.0);
   series2.add(3.0, 2.0);
   series2.add(4.0, 2.0);
   series2.add(5.0, 2.0);
   series2.add(6.0, 2.0);
   return series2;
 }
Ejemplo n.º 13
0
 /** Checks that the auto-range for the range axis on an XYPlot is working as expected. */
 @Test
 public void testXYAutoRange2() {
   XYSeries series = new XYSeries("Series 1");
   series.add(1.0, 1.0);
   series.add(2.0, 2.0);
   series.add(3.0, 3.0);
   XYSeriesCollection dataset = new XYSeriesCollection();
   dataset.addSeries(series);
   JFreeChart chart = ChartFactory.createScatterPlot("Test", "X", "Y", dataset);
   XYPlot plot = (XYPlot) chart.getPlot();
   NumberAxis axis = (NumberAxis) plot.getRangeAxis();
   axis.setAutoRangeIncludesZero(false);
   assertEquals(0.9, axis.getLowerBound(), EPSILON);
   assertEquals(3.1, axis.getUpperBound(), EPSILON);
 }
Ejemplo n.º 14
0
  /**
   * A demonstration application showing a scatter plot.
   *
   * @param title the frame title.
   */
  public ScatterPlotDemo4(String title) {

    super(title);
    XYSeries series = new XYSeries("Average Weight");
    series.add(-20.0, 20.0);
    series.add(40.0, 25.0);
    series.add(55.0, 50.0);
    series.add(70.0, 65.0);
    series.add(270.0, 65.0);
    series.add(570.0, 55.0);
    XYDataset data = new XYSeriesCollection(series);
    JFreeChart chart =
        ChartFactory.createScatterPlot(
            "Scatter Plot Demo", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = chart.getXYPlot();
    LogElemRenderer render = new LogElemRenderer();
    render.setDotWidth(25);
    render.setDotHeight(25);
    plot.setRenderer(render);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(800, 470));

    Border border =
        BorderFactory.createCompoundBorder(
            BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createEtchedBorder());
    chartPanel.setBorder(border);
    add(chartPanel);

    JPanel dashboard = new JPanel(new BorderLayout());
    dashboard.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4));
    // make the slider units "minutes"
    slider = new JSlider(-200, 200, 0);
    slider.setPaintLabels(true);
    slider.setMajorTickSpacing(50);
    slider.setPaintTicks(true);
    slider.addChangeListener(this);
    dashboard.add(slider);
    add(dashboard, BorderLayout.SOUTH);

    // setContentPane(chartPanel);

  }
Ejemplo n.º 15
0
  private XYDataset createDataset(String metricName) {

    series = new XYSeriesCollection();

    // For each collection of evaluations
    for (int i = 0; i < evaluationsCollection.size(); i++) {

      if (!set.contains(i)) {

        List<AbstractEvaluation> evaluations = evaluationsCollection.get(i);
        XYSeries newXYSerie = new XYSeries(queryNames.get(i));

        int evalIndex = 0;

        for (AbstractEvaluation eval : evaluations) {
          if (evalIndex % reportFrecuency == 0) {
            newXYSerie.add(eval.getLabeledSetSize(), eval.getMetricValue(metricName));
          }
          ++evalIndex;
        }
        series.addSeries(newXYSerie);
      }
    }
    // The series that belongs to passive learning is the last
    if (passiveEvaluation != null) {

      series.addSeries(createPassiveLearningSerie(metricName, evaluationsCollection.get(0)));
    }
    return series;
  }
Ejemplo n.º 16
0
  private static XYDataset createDataset(
      String expName, String hostName, String metric, String category) throws Exception {

    DBManager dba = new DBManager();
    XYSeries series = new XYSeries(category);

    String sql =
        "SELECT time_s*100000+time_us as time, data from "
            + expName
            + "_proc WHERE instance = '"
            + category
            + "' and metric = '"
            + metric
            + "' and hostname = '"
            + hostName
            + "' ORDER BY time_s,time_us;";
    //  System.out.println(sql);
    ArrayList resultList = dba.executeSql(sql);

    for (int i = 0; i < resultList.size(); i++) {
      HashMap hash = (HashMap) resultList.get(i);
      double time = Double.parseDouble(hash.get("TIME").toString());
      double data = Double.parseDouble(hash.get("DATA").toString());
      System.out.println(time + " and " + data);
      series.add(time, data);
    }

    XYSeriesCollection result = new XYSeriesCollection(series);
    return result;
  }
Ejemplo n.º 17
0
 private XYDataset filterData(List<double[]> ds) {
   this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
   double[] correlation = null;
   double[] dblData1 = applyWindow(ds.get(0), (String) getTaperCB().getSelectedItem());
   try {
     if (ds.size() == 1) {
       correlation = IstiUtilsMath.correlate(dblData1, dblData1);
     } else {
       double[] dblData2 = applyWindow(ds.get(1), (String) taperCB.getSelectedItem());
       correlation = IstiUtilsMath.correlate(dblData1, dblData2);
     }
   } catch (IllegalArgumentException e) {
     logger.error("IllegalArgumentException:", e);
   }
   logger.debug("correlation computed, size = " + correlation.length);
   XYSeriesCollection dataset = new XYSeriesCollection();
   XYSeries series = new XYSeries(seriesName);
   double ampMax = 0;
   int ampMaxPoint = -1;
   for (int i = 0; i < correlation.length; i++) {
     series.add(sampleRate * (i - correlation.length / 2) / 1000, correlation[i]);
     if (Math.abs(correlation[i]) > ampMax) {
       ampMax = Math.abs(correlation[i]);
       ampMaxPoint = i;
     }
   }
   dataset.addSeries(series);
   getAmpMaxL().setText("Max Amplitude: " + dFormat.format(ampMax));
   getLagTimeL()
       .setText("Lag time: " + sampleRate * (ampMaxPoint - correlation.length / 2) / 1000 + " s");
   this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
   return dataset;
 }
Ejemplo n.º 18
0
  @Override
  protected void setChart() {
    SeriesManager<Double, Double> sf = new SeriesManager<Double, Double>(intermediateData);
    List<DataSeries<Double, Double>> seriesList = sf.getSeries();

    DataSeries<Double, Double> series = seriesList.get(0);
    List<SeriesPair<Double, Double>> values = series.getSeriesValues(Double.class, Double.class);

    XYSeries deltaMassSeries = new XYSeries(series.getIdentifier());
    for (SeriesPair<Double, Double> value : values) {
      deltaMassSeries.add(value.getX(), value.getY());
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(deltaMassSeries);

    chart =
        ChartFactory.createXYLineChart(
            getChartTitle(), // chart title
            "Experimental m/z - Theoretical m/z", // x axis label
            "Relative Frequency", // y axis label
            dataset, // chartData
            PlotOrientation.VERTICAL,
            false, // include legend
            true, // tooltips
            false // urls
            );
    chart.addSubtitle(new TextTitle(getChartSubTitle()));

    XYPlot plot = chart.getXYPlot();
    plot.setDomainZeroBaselineVisible(true);
    plot.setBackgroundAlpha(0f);
    plot.setDomainGridlinePaint(Color.red);
    plot.setRangeGridlinePaint(Color.blue);
  }
Ejemplo n.º 19
0
 /** Adds a value to the data series */
 public void addValue(double x, double y) {
   if (series != null) {
     synchronized (series) {
       series.add(x, y);
     }
   }
 }
Ejemplo n.º 20
0
 /**
  * Sets the value of the existing point (abscissa, value) at index index to y. If the index is
  * negative, does not do anything. If the index equals the index of the last element of the signal
  * plus one, adds an element (index, y) to the signal at the index index. If the index is greateur
  * than the index of the last element of the signal plus one, does not do anything.
  *
  * @param index index of the exsisting point. If the point does not exists, adds it
  * @param y value to be given to the corresponding point (abscissa, value).
  */
 public void setValueOf(int index, double y) {
   if (index == this.getNbSamples()) {
     data.add(index, y);
   } else if ((index >= 0) && (index < this.getNbSamples())) {
     data.updateByIndex(index, y);
   }
 }
  private void crearImagen() {

    XYSeries serie = new XYSeries("Serie");
    Iterator<Double> iterator = ejercicio.getHistoricoSolucion().iterator();
    for (int i = 0; i < ejercicio.getHistoricoSolucion().size(); i++) {
      serie.add(i, iterator.next());
    }

    XYSeriesCollection coleccionSeries = new XYSeriesCollection();
    coleccionSeries.addSeries(serie);

    JFreeChart chart =
        ChartFactory.createXYLineChart(
            "Comportamiento Simulated Annealing",
            "Ciclo",
            "Solucion",
            coleccionSeries,
            PlotOrientation.VERTICAL,
            false,
            false,
            true);

    ChartPanel panel = new ChartPanel(chart);
    panel.setMouseZoomable(true);
    this.add(panel);
  }
Ejemplo n.º 22
0
 private void writeTimeSpentScalabilitySummaryChart() {
   List<XYSeries> seriesList =
       new ArrayList<XYSeries>(plannerBenchmarkResult.getSolverBenchmarkResultList().size());
   for (SolverBenchmarkResult solverBenchmarkResult :
       plannerBenchmarkResult.getSolverBenchmarkResultList()) {
     String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix();
     XYSeries series = new XYSeries(solverLabel);
     for (SingleBenchmarkResult singleBenchmarkResult :
         solverBenchmarkResult.getSingleBenchmarkResultList()) {
       if (singleBenchmarkResult.hasAllSuccess()) {
         long problemScale = singleBenchmarkResult.getProblemBenchmarkResult().getProblemScale();
         long timeMillisSpent = singleBenchmarkResult.getTimeMillisSpent();
         series.add((Long) problemScale, (Long) timeMillisSpent);
       }
     }
     seriesList.add(series);
   }
   XYPlot plot =
       createScalabilityPlot(
           seriesList,
           "Problem scale",
           NumberFormat.getInstance(locale),
           "Time spent",
           new MillisecondsSpentNumberFormat(locale));
   JFreeChart chart =
       new JFreeChart(
           "Time spent scalability summary (lower is better)",
           JFreeChart.DEFAULT_TITLE_FONT,
           plot,
           true);
   timeSpentScalabilitySummaryChartFile =
       writeChartToImageFile(chart, "timeSpentScalabilitySummary");
 }
Ejemplo n.º 23
0
 private void writeAverageCalculateCountPerSecondSummaryChart() {
   List<XYSeries> seriesList =
       new ArrayList<XYSeries>(plannerBenchmarkResult.getSolverBenchmarkResultList().size());
   for (SolverBenchmarkResult solverBenchmarkResult :
       plannerBenchmarkResult.getSolverBenchmarkResultList()) {
     String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix();
     XYSeries series = new XYSeries(solverLabel);
     for (SingleBenchmarkResult singleBenchmarkResult :
         solverBenchmarkResult.getSingleBenchmarkResultList()) {
       if (singleBenchmarkResult.hasAllSuccess()) {
         long problemScale = singleBenchmarkResult.getProblemBenchmarkResult().getProblemScale();
         long averageCalculateCountPerSecond =
             singleBenchmarkResult.getAverageCalculateCountPerSecond();
         series.add((Long) problemScale, (Long) averageCalculateCountPerSecond);
       }
     }
     seriesList.add(series);
   }
   XYPlot plot =
       createScalabilityPlot(
           seriesList,
           "Problem scale",
           NumberFormat.getInstance(locale),
           "Average calculate count per second",
           NumberFormat.getInstance(locale));
   JFreeChart chart =
       new JFreeChart(
           "Average calculate count summary (higher is better)",
           JFreeChart.DEFAULT_TITLE_FONT,
           plot,
           true);
   averageCalculateCountSummaryChartFile =
       writeChartToImageFile(chart, "averageCalculateCountSummary");
 }
Ejemplo n.º 24
0
  public static XYSeries getXY(String url) {
    XYSeries xyseries = new XYSeries("");

    Path path = new Path(url);
    Configuration conf = HUtils.getConf();
    SequenceFile.Reader reader = null;
    try {
      reader =
          new SequenceFile.Reader(
              conf, Reader.file(path), Reader.bufferSize(4096), Reader.start(0));
      DoubleArrStrWritable dkey =
          (DoubleArrStrWritable) ReflectionUtils.newInstance(reader.getKeyClass(), conf);
      DoublePairWritable dvalue =
          (DoublePairWritable) ReflectionUtils.newInstance(reader.getValueClass(), conf);

      while (reader.next(dkey, dvalue)) { // 循环读取文件
        xyseries.add(dvalue.getFirst(), dvalue.getSecond());
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      IOUtils.closeStream(reader);
    }
    return xyseries;
  }
Ejemplo n.º 25
0
  private boolean plotCorrectionData() {
    plot3d.removeAllPlots();
    XYSeries series;
    XYPlot plot = chartPanel.getChart().getXYPlot();
    XYSeriesCollection lineDataset = (XYSeriesCollection) plot.getDataset(0);
    DecimalFormat df = new DecimalFormat(".00");
    String val;
    int i = 0;
    int j = 0;
    if (!Utils.isTableEmpty(corrTable)) {
      try {
        for (i = 1; i < corrTable.getColumnCount(); ++i) {
          val = corrTable.getValueAt(0, i).toString();
          series = new XYSeries(df.format(Double.valueOf(val)));
          for (j = 1; j < corrTable.getRowCount(); ++j) {
            if (corrTable.getValueAt(j, i) != null) {
              val = corrTable.getValueAt(j, i).toString();
              if (!val.isEmpty())
                series.add(
                    Double.valueOf(corrTable.getValueAt(j, 0).toString()), Double.valueOf(val));
            }
          }
          if (series.getItemCount() > 0) {
            corrData.add(series);
            series.setDescription(series.getKey().toString());
            lineDataset.addSeries(series);
          }
        }
        plot.getDomainAxis(0).setAutoRange(true);
        plot.getRangeAxis(0).setAutoRange(true);
        plot.getDomainAxis(0).setLabel(xAxisName);
        plot.getRangeAxis(0).setLabel(yAxisName);
        plot.getRenderer(0).setSeriesVisible(0, false);

        double[] x = new double[xAxisArray.size()];
        for (i = 0; i < xAxisArray.size(); ++i) x[i] = xAxisArray.get(i);
        double[] y = new double[yAxisArray.size()];
        for (i = 0; i < yAxisArray.size(); ++i) y[i] = yAxisArray.get(i);
        double[][] z = Utils.doubleZArray(corrTable, x, y);
        Color[][] colors = Utils.generateTableColorMatrix(corrTable, 1, 1);
        plot3d.addGridPlot("Average Error % Plot", colors, x, y, z);
      } catch (NumberFormatException e) {
        logger.error(e);
        JOptionPane.showMessageDialog(
            null,
            "Error parsing number from "
                + corrTableName
                + " table, cell("
                + i
                + " : "
                + j
                + "): "
                + e,
            "Error",
            JOptionPane.ERROR_MESSAGE);
        return false;
      }
    }
    return true;
  }
Ejemplo n.º 26
0
 /**
  * Looks for the element of the given abscissa and sets its value to ordiante. If there is no
  * points existing with the given abcisssa, adds a point (abscissa, ordinate) to the signal.
  * (actually, this method does the exact same thing as addElement).
  *
  * @param abscissa abscissa of the considered point
  * @param ordinate value to add or update in the signal
  */
 public void setElement(double abscissa, double ordinate) {
   int index = data.indexOf(abscissa);
   if (index < 0) {
     data.add(abscissa, ordinate);
   } else {
     data.updateByIndex(index, ordinate);
   }
 }
Ejemplo n.º 27
0
  public void setPath(List<XYPoint> xyList) {
    mIdeal.clear();
    clearActuals();

    for (int i = 0; i < xyList.size(); ++i) {
      mIdeal.add(xyList.get(i).mX, xyList.get(i).mY);
    }
  }
Ejemplo n.º 28
0
  private JFreeChart getGraphic(final ModeData modeData, final String modeName) {
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries departuresSerie = new XYSeries("departures", false, true);
    final XYSeries arrivalsSerie = new XYSeries("arrivals", false, true);
    final XYSeries onRouteSerie = new XYSeries("en route", false, true);
    int onRoute = 0;
    for (int i = 0; i < modeData.countsDep.length; i++) {
      onRoute = onRoute + modeData.countsDep[i] - modeData.countsArr[i] - modeData.countsStuck[i];
      double hour = i * this.binSize / 60.0 / 60.0;
      departuresSerie.add(hour, modeData.countsDep[i]);
      arrivalsSerie.add(hour, modeData.countsArr[i]);
      onRouteSerie.add(hour, onRoute);
    }

    xyData.addSeries(departuresSerie);
    xyData.addSeries(arrivalsSerie);
    xyData.addSeries(onRouteSerie);

    final JFreeChart chart =
        ChartFactory.createXYStepChart(
            "Leg Histogram, " + modeName + ", it." + this.iteration,
            "time",
            "# vehicles",
            xyData,
            PlotOrientation.VERTICAL,
            true, // legend
            false, // tooltips
            false // urls
            );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));

    plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setDomainGridlinePaint(Color.gray);

    return chart;
  }
  /**
   * @param valueSource
   * @param plotInstance
   * @param autoWidthFraction If this value is greater than 0, an auto width for the intervals is
   *     calculated such that the intervals nearest to each other touch. This value is then
   *     multiplied with the value of autoWidthFtraction. If unset, the intervals have width 0.
   * @param allowDuplicates
   * @param sortByDomain if true, the data is sorted by domain values (useful for bar and area
   *     charts)
   * @return
   * @throws ChartPlottimeException
   */
  public static XYSeriesCollection createXYSeriesCollection(
      ValueSource valueSource,
      PlotInstance plotInstance,
      double autoWidthFraction,
      boolean allowDuplicates,
      boolean sortByDomain)
      throws ChartPlottimeException {
    XYSeriesCollection xyDataset = new XYSeriesCollection();
    if (autoWidthFraction > 0) {
      xyDataset.setAutoWidth(true);
    } else {
      xyDataset.setAutoWidth(false);
      xyDataset.setIntervalWidth(0);
    }

    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    assertMaxValueCountNotExceededOrThrowException(valueSourceData);
    GroupCellSeriesData dataForAllGroupCells = valueSourceData.getSeriesDataForAllGroupCells();

    // Loop over group cells and add data to dataset
    for (GroupCellKeyAndData groupCellKeyAndData : dataForAllGroupCells) {
      GroupCellKey groupCellKey = groupCellKeyAndData.getKey();
      GroupCellData groupCellData = groupCellKeyAndData.getData();

      String seriesName =
          generateSeriesName(
              valueSource, groupCellKey, plotInstance.getCurrentPlotConfigurationClone());

      XYSeries series = new XYSeries(seriesName, sortByDomain, allowDuplicates);
      Map<PlotDimension, double[]> dataForUsageType =
          groupCellData.getDataForUsageType(SeriesUsageType.MAIN_SERIES);
      int rowCount = dataForUsageType.get(PlotDimension.DOMAIN).length;
      double[] xValues = dataForUsageType.get(PlotDimension.DOMAIN);
      double[] yValues = dataForUsageType.get(PlotDimension.VALUE);

      try {
        // Loop over rows and add data to series
        for (int row = 0; row < rowCount; ++row) {
          double x = xValues[row];
          double y = yValues[row];
          if (!Double.isNaN(x)) {
            series.add(x, y);
          }
        }
      } catch (SeriesException e) {
        throw new ChartPlottimeException(
            "duplicate_value", valueSource.toString(), PlotDimension.DOMAIN.getName());
      }

      xyDataset.addSeries(series);
    }
    // intervals should not touch each other, so decrease auto width.
    if (xyDataset.getIntervalWidth() > 0) {
      xyDataset.setIntervalWidth(xyDataset.getIntervalWidth() * autoWidthFraction);
    }
    return xyDataset;
  }
 /**
  * Add sample to a series
  *
  * @param x Abcissa
  * @param y Ordinate
  * @param seriesName Series name
  */
 @Override
 public void addSample(double x, double y, String seriesName) {
   for (XYSeries serie : seriesList) {
     if (serie.getKey().toString().equals(seriesName)) {
       serie.add(x, y);
       break;
     }
   }
 }