@Test public void calculateAverageIrregularSeries() { Graph.Series average = new Graph.Series("Test Series average 1 and 4"); average.addLine(new Graph.ReportLine(10, 15)); average.addLine(new Graph.ReportLine(40, 75)); average.addLine(new Graph.ReportLine(70, 135)); Graph.Series calculatedAvg = Graph.statSeries("test2", testSeries3).avg; Assert.assertEquals(average.vals.get(0).x, calculatedAvg.vals.get(0).x, 0.00001); Assert.assertEquals(average.vals.get(1).x, calculatedAvg.vals.get(1).x, 0.00001); Assert.assertEquals(average.vals.get(2).x, calculatedAvg.vals.get(2).x, 0.00001); Assert.assertEquals(100, calculatedAvg.vals.get(3).x, 0.00001); Assert.assertEquals(average.vals.get(0).y, calculatedAvg.vals.get(0).y, 0.00001); Assert.assertEquals(average.vals.get(1).y, calculatedAvg.vals.get(1).y, 0.00001); Assert.assertEquals(average.vals.get(2).y, calculatedAvg.vals.get(2).y, 0.00001); Assert.assertEquals(155, calculatedAvg.vals.get(3).y, 0.00001); }
public static StatSeries statSeries(String title, List<Graph.Series> series) { Graph.Series seriesMin = new Graph.Series(title + "(min)"); Graph.Series seriesMax = new Graph.Series(title + "(max)"); Graph.Series seriesAvg = new Graph.Series(title + "(avg)"); Graph.Series largest = null; for (Graph.Series s : series) { if (largest == null || s.vals.size() > largest.vals.size()) { largest = s; } } for (int i = 0; largest != null && i < largest.vals.size(); i++) { double x = largest.vals.get(i).x; double sum = 0; double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; for (Series s : series) { if (i < s.vals.size()) { double lx = s.vals.get(i).x; if (Math.abs(x - lx) > EPS) { throw new IllegalArgumentException( "We need the indexes to be the same, x=" + x + ", lx=" + lx); } min = Math.min(min, s.vals.get(i).y); max = Math.max(max, s.vals.get(i).y); sum += s.vals.get(i).y; } else { sum += s.vals.get(s.vals.size() - 1).y; } } seriesMin.addLine(new Graph.ReportLine(x, min)); seriesMax.addLine(new Graph.ReportLine(x, max)); seriesAvg.addLine(new Graph.ReportLine(x, sum / series.size())); } return new StatSeries(seriesMin, seriesMax, seriesAvg); }
Graph { public static StatSeries statSeries(String title, List<Graph.Series> series) { Graph.Series seriesMin = new Graph.Series(title + "(min)"); Graph.Series seriesMax = new Graph.Series(title + "(max)"); Graph.Series seriesAvg = new Graph.Series(title + "(avg)"); Graph.Series largest = null; for (Graph.Series s : series) { if (largest == null || s.vals.size() > largest.vals.size()) { largest = s; } } for (int i = 0; largest != null && i < largest.vals.size(); i++) { double x = largest.vals.get(i).x; double sum = 0; double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; for (Series s : series) { if (i < s.vals.size()) { double lx = s.vals.get(i).x; if (Math.abs(x - lx) > EPS) { throw new IllegalArgumentException( "We need the indexes to be the same, x=" + x + ", lx=" + lx); } min = Math.min(min, s.vals.get(i).y); max = Math.max(max, s.vals.get(i).y); sum += s.vals.get(i).y; } else { sum += s.vals.get(s.vals.size() - 1).y; } } seriesMin.addLine(new Graph.ReportLine(x, min)); seriesMax.addLine(new Graph.ReportLine(x, max)); seriesAvg.addLine(new Graph.ReportLine(x, sum / series.size())); } return new StatSeries(seriesMin, seriesMax, seriesAvg); } }
Graph { public static StatSeries statSeries(String title, List<Graph.Series> series) { Graph.Series seriesMin = new Graph.Series(title + "(min)"); Graph.Series seriesMax = new Graph.Series(title + "(max)"); Graph.Series seriesAvg = new Graph.Series(title + "(avg)"); Graph.Series largest = null; for (Graph.Series s : series) { if (largest == null || s.vals.size() > largest.vals.size()) { largest = s; } } for (int i = 0; largest != null && i < largest.vals.size(); i++) { double x = largest.vals.get(i).x; double sum = 0; double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; for (Series s : series) { if (i < s.vals.size()) { double lx = s.vals.get(i).x; if (Math.abs(x - lx) > EPS) { throw new IllegalArgumentException( "We need the indexes to be the same, x=" + x + ", lx=" + lx); } min = Math.min(min, s.vals.get(i).y); max = Math.max(max, s.vals.get(i).y); sum += s.vals.get(i).y; } else { sum += s.vals.get(s.vals.size() - 1).y; } } seriesMin.addLine(new Graph.ReportLine(x, min)); seriesMax.addLine(new Graph.ReportLine(x, max)); seriesAvg.addLine(new Graph.ReportLine(x, sum / series.size())); } return new StatSeries(seriesMin, seriesMax, seriesAvg); } Graph(String graphTitle, String xName, String yName); }
Graph { public static StatSeries statSeries(String title, List<Graph.Series> series) { Graph.Series seriesMin = new Graph.Series(title + "(min)"); Graph.Series seriesMax = new Graph.Series(title + "(max)"); Graph.Series seriesAvg = new Graph.Series(title + "(avg)"); Graph.Series largest = null; for (Graph.Series s : series) { if (largest == null || s.vals.size() > largest.vals.size()) { largest = s; } } for (int i = 0; largest != null && i < largest.vals.size(); i++) { double x = largest.vals.get(i).x; double sum = 0; double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; for (Series s : series) { if (i < s.vals.size()) { double lx = s.vals.get(i).x; if (Math.abs(x - lx) > EPS) { throw new IllegalArgumentException( "We need the indexes to be the same, x=" + x + ", lx=" + lx); } min = Math.min(min, s.vals.get(i).y); max = Math.max(max, s.vals.get(i).y); sum += s.vals.get(i).y; } else { sum += s.vals.get(s.vals.size() - 1).y; } } seriesMin.addLine(new Graph.ReportLine(x, min)); seriesMax.addLine(new Graph.ReportLine(x, max)); seriesAvg.addLine(new Graph.ReportLine(x, sum / series.size())); } return new StatSeries(seriesMin, seriesMax, seriesAvg); } Graph(String graphTitle, String xName, String yName); void setForcedMinY(Double forcedMinY); void save(File dest); void addSerie(Series s); void cleanSeries(); static StatSeries statSeries(String title, List<Graph.Series> series); }
Graph { public static StatSeries statSeries(String title, List<Graph.Series> series) { Graph.Series seriesMin = new Graph.Series(title + "(min)"); Graph.Series seriesMax = new Graph.Series(title + "(max)"); Graph.Series seriesAvg = new Graph.Series(title + "(avg)"); Graph.Series largest = null; for (Graph.Series s : series) { if (largest == null || s.vals.size() > largest.vals.size()) { largest = s; } } for (int i = 0; largest != null && i < largest.vals.size(); i++) { double x = largest.vals.get(i).x; double sum = 0; double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; for (Series s : series) { if (i < s.vals.size()) { double lx = s.vals.get(i).x; if (Math.abs(x - lx) > EPS) { throw new IllegalArgumentException( "We need the indexes to be the same, x=" + x + ", lx=" + lx); } min = Math.min(min, s.vals.get(i).y); max = Math.max(max, s.vals.get(i).y); sum += s.vals.get(i).y; } else { sum += s.vals.get(s.vals.size() - 1).y; } } seriesMin.addLine(new Graph.ReportLine(x, min)); seriesMax.addLine(new Graph.ReportLine(x, max)); seriesAvg.addLine(new Graph.ReportLine(x, sum / series.size())); } return new StatSeries(seriesMin, seriesMax, seriesAvg); } Graph(String graphTitle, String xName, String yName); void setForcedMinY(Double forcedMinY); void save(File dest); void addSerie(Series s); void cleanSeries(); static StatSeries statSeries(String title, List<Graph.Series> series);  }