Ejemplo n.º 1
0
  @Test
  public void testIndexSpeed() {
    Global.random = new Random();

    int m = 10000000;

    tic();
    for (int i : Series.series(m)) {
      int index = Global.random.nextInt(Fibonacci.MAX_INDEX + 1);
      long n = Fibonacci.get(index);
      Fibonacci.getIndexApprox(n);
    }
    System.out.println(toc());

    tic();
    for (int i : Series.series(m)) {
      int index = Global.random.nextInt(Fibonacci.MAX_INDEX + 1);
      long n = Fibonacci.get(index);
      Fibonacci.getIndex(n);
    }
    System.out.println(toc());

    tic();
    for (int i : Series.series(m)) {
      int index = Global.random.nextInt(Fibonacci.MAX_INDEX + 1);
      long n = Fibonacci.get(index);
    }
    System.out.println(toc());
  }
Ejemplo n.º 2
0
  /**
   * Creates a Chart with multiple Series for the same X-Axis data with default style
   *
   * @param chartTitle the Chart title
   * @param xTitle The X-Axis title
   * @param yTitle The Y-Axis title
   * @param seriesNames An array of the name of the multiple series
   * @param xData An array containing the X-Axis data
   * @param yData An array of double arrays containing multiple Y-Axis data
   * @return a Chart Object
   */
  public static Chart getChart(
      String chartTitle,
      String xTitle,
      String yTitle,
      String[] seriesNames,
      double[] xData,
      double[][] yData) {

    // Create Chart
    Chart chart = new Chart(WIDTH, HEIGHT);

    // Customize Chart
    chart.setChartTitle(chartTitle);
    chart.setXAxisTitle(xTitle);
    chart.setYAxisTitle(yTitle);

    // Series
    for (int i = 0; i < yData.length; i++) {
      Series series;
      if (seriesNames != null) {
        series = chart.addSeries(seriesNames[i], xData, yData[i]);
      } else {
        chart.getStyleManager().setLegendVisible(false);
        series = chart.addSeries(" " + i, xData, yData[i]);
      }
      series.setMarker(SeriesMarker.NONE);
    }

    return chart;
  }
  @Test
  public void findBySID() {
    Series s = repository.findByImdbId("testSeriesID");
    assertThat(s.getTitle(), is("testSeries1"));

    s = repository.findByImdbId("NonExistingSID");
    assertTrue(s == null);
  }
  /**
   * This is used to acquire all the individual header values from the message. The header values
   * provided by this are unparsed and represent the actual string values that have been added to
   * the message keyed by a given header name.
   *
   * @param name the name of the header to get the values for
   * @return this returns a list of the values for the header name
   */
  @Override
  public List<String> getAll(String name) {
    String token = name.toLowerCase();
    Series series = this.values.get(token);

    if (series == null) return this.getAll(name, token);
    return series.getValues();
  }
Ejemplo n.º 5
0
 public Series getSeries() {
   Series series = new Series(getTitle());
   series.addSeasons(getSeasons());
   series.setImdbId(getId());
   series.setStartYear(getYear());
   series.setImgLink(getImgLink());
   return series;
 }
  /**
   * This is used to acquire all the individual header values from the message. The header values
   * provided by this are unparsed and represent the actual string values that have been added to
   * the message keyed by a given header name.
   *
   * @param name the name of the header to get the values for
   * @return this returns a list of the values for the header name
   */
  public List<String> getAll(String name) {
    String token = name.toLowerCase();
    Series series = values.get(token);

    if (series == null) {
      return getAll(name, token);
    }
    return series.getValues();
  }
  /**
   * This is used to acquire all the individual header values from the message. The header values
   * provided by this are unparsed and represent the actual string values that have been added to
   * the message keyed by a given header name.
   *
   * @param name the name of the header to get the values for
   * @param token this provides a lower case version of the header
   * @return this returns a list of the values for the header name
   */
  private List<String> getAll(String name, String token) {
    Series series = new Series();
    String value = this.names.get(token);

    if (value == null) {
      this.names.put(token, name);
    }
    this.values.put(token, series);

    return series.getValues();
  }
Ejemplo n.º 8
0
  private Series parseForm(Request request) {
    Series series = new Series();
    series.setName(request.formParam("name"));
    series.setDescription(request.formParam("description"));

    String path = request.formParam("path");
    if (path != null && !path.isEmpty()) {
      series.setPath(Paths.get(path));
    }

    return series;
  }
Ejemplo n.º 9
0
 public String constructJavaScript(
     String title, String[] categories, String xAxis, Series... series) {
   String result =
       "$(function () {\n"
           + "        $('#container').highcharts({\n"
           + "            title: {\n"
           + "                text: '"
           + title
           + "',\n"
           + "                x: -20 //center\n"
           + "            },\n"
           + "            xAxis: {\n"
           + "                categories: "
           + convertToCommaDelimited(categories)
           + "\n"
           + "            },\n"
           + "            yAxis: {\n"
           + "                title: {\n"
           + "                    text: '"
           + xAxis
           + "'\n"
           + "                },\n"
           + "                plotLines: [{\n"
           + "                    value: 0,\n"
           + "                    width: 1,\n"
           + "                    color: '#808080'\n"
           + "                }]\n"
           + "            },\n"
           + "            tooltip: {\n"
           + "                valueSuffix: '°C'\n"
           + "            },\n"
           + "            legend: {\n"
           + "                layout: 'vertical',\n"
           + "                align: 'right',\n"
           + "                verticalAlign: 'middle',\n"
           + "                borderWidth: 0\n"
           + "            },\n"
           + "            series: [{\n";
   for (Series serie : series) {
     result +=
         "                name: '"
             + serie.getTitle()
             + "',\n"
             + "                data: "
             + serie.getSeriesDataAsString()
             + "\n"
             + "            }, {\n";
   }
   result = result.substring(0, result.lastIndexOf(','));
   result += "]\n" + "        });\n" + "    });\n" + "    \n" + "\n" + "\n" + "";
   return result;
 }
  /** Tests for series - episode relations */
  @Test
  public void saveAndGetSeriesWithEpisodes() {
    Series serie = new Series("EpisodeSeriesTest", "estID");
    List<Episode> eList = new ArrayList<>();
    eList.add(new Episode("title", "path1", 1, 1));
    eList.add(new Episode("title", "path2", 1, 2));
    serie.setEpisodes(eList);
    repository.save(serie);

    Series serieRe = repository.findByImdbId("estID");
    List<Episode> reEp = serieRe.getEpisodes();
    assertThat(reEp, hasSize(2));
    assertEquals("title", reEp.get(0).getTitle());
  }
Ejemplo n.º 11
0
 Response show(Request request) {
   long id = Long.parseLong(request.urlParam("id"));
   Series series = wa.serieses.get(id);
   return render(
       "series/show.ftl",
       "series",
       series,
       "descriptionHtml",
       Markdown.render(series.getDescription(), request.uri()),
       "crawls",
       wa.crawls.listBySeriesId(id),
       "collections",
       wa.collections.listWhereSeriesId(id));
 }
Ejemplo n.º 12
0
  public Issue(Series series, int number) {
    this.series = series;
    this.number = number;

    DateTime releaseDate = series.getIssueReleaseDate(number);
    this.releaseDate = releaseDate;
  }
 @Test
 public void testIssue2ReleaseDate() {
   // PRJUP 2
   // Calculated: 21.7.2016
   // Perrypedia: Freitag, 22. July 2016
   DateTime expected = new DateTime().withDate(2016, 7, 21).withMillisOfDay(0);
   DateTime actual = testable.getIssueReleaseDate(2);
   assertEquals(expected, actual);
 }
 @Test
 public void testIssue12ReleaseDate() {
   // PRJUP 12
   // Calculated: 23. 6. 2016
   // Perrypedia: Unknown yet...
   DateTime expected = new DateTime().withDate(2016, 12, 8).withMillisOfDay(0);
   DateTime actual = testable.getIssueReleaseDate(12);
   assertEquals(expected, actual);
 }
Ejemplo n.º 15
0
 @Override
 protected void dataItemAdded(
     Series<String, Number> series, int itemIndex, Data<String, Number> item) {
   Node candle = createCandle(getData().indexOf(series), item, itemIndex);
   if (shouldAnimate()) {
     candle.setOpacity(0);
     getPlotChildren().add(candle);
     // fade in new candle
     FadeTransition ft = new FadeTransition(Duration.millis(500), candle);
     ft.setToValue(1);
     ft.play();
   } else {
     getPlotChildren().add(candle);
   }
   // always draw average line on top
   if (series.getNode() != null) {
     series.getNode().toFront();
   }
 }
 @Test
 public void testIssue50ReleaseDate() {
   // PRJUP 50
   // Calculated: null, too big to release
   // Perrypedia: series is only 12 issues
   DateTime expected = null;
   DateTime actual = testable.getIssueReleaseDate(50);
   assertNull(actual);
   assertEquals(expected, actual);
 }
Ejemplo n.º 17
0
  /** Called to update and layout the content for the plot */
  @Override
  protected void layoutPlotChildren() {
    // we have nothing to layout if no data is present
    if (getData() == null) {
      return;
    }
    // update candle positions
    for (int seriesIndex = 0; seriesIndex < getData().size(); seriesIndex++) {
      Series<String, Number> series = getData().get(seriesIndex);
      Iterator<Data<String, Number>> iter = getDisplayedDataIterator(series);
      Path seriesPath = null;
      if (series.getNode() instanceof Path) {
        seriesPath = (Path) series.getNode();
        seriesPath.getElements().clear();
      }
      while (iter.hasNext()) {
        Data<String, Number> item = iter.next();
        double x = getXAxis().getDisplayPosition(getCurrentDisplayedXValue(item));
        double y = getYAxis().getDisplayPosition(getCurrentDisplayedYValue(item));
        Node itemNode = item.getNode();
        BarData bar = (BarData) item.getExtraValue();
        if (itemNode instanceof Candle && item.getYValue() != null) {
          Candle candle = (Candle) itemNode;

          double close = getYAxis().getDisplayPosition(bar.getClose());
          double high = getYAxis().getDisplayPosition(bar.getHigh());
          double low = getYAxis().getDisplayPosition(bar.getLow());
          double candleWidth = 10;
          // update candle
          candle.update(close - y, high - y, low - y, candleWidth);

          // update tooltip content
          candle.updateTooltip(bar.getOpen(), bar.getClose(), bar.getHigh(), bar.getLow());

          // position the candle
          candle.setLayoutX(x);
          candle.setLayoutY(y);
        }
      }
    }
  }
Ejemplo n.º 18
0
  /**
   * Creates a Chart with default style
   *
   * @param chartTitle the Chart title
   * @param xTitle The X-Axis title
   * @param yTitle The Y-Axis title
   * @param seriesNames The name of the series
   * @param xData A Collection containing the X-Axis data
   * @param yData A Collection containing Y-Axis data
   * @return a Chart Object
   */
  public static Chart getChart(
      String chartTitle,
      String xTitle,
      String yTitle,
      String seriesName,
      List<Number> xData,
      List<Number> yData) {

    // Create Chart
    Chart chart = new Chart(WIDTH, HEIGHT);

    // Customize Chart
    chart.setChartTitle(chartTitle);
    chart.setXAxisTitle(xTitle);
    chart.setYAxisTitle(yTitle);

    Series series = chart.addSeries(seriesName, xData, yData);
    series.setMarker(SeriesMarker.NONE);

    return chart;
  }
  @Test
  public void saveGetAndUpdateSeriesWithEpisodes() {
    Series serie = new Series("EpisodeSeriesTest", "estID");
    List<Episode> eList = new ArrayList<>();
    eList.add(new Episode("title", "path1", 1, 1));
    eList.add(new Episode("title", "path2", 1, 2));
    serie.setEpisodes(eList);
    repository.save(serie);

    Series serieRe = repository.findByImdbId("estID");
    List<Episode> reEp = serieRe.getEpisodes();
    assertThat(reEp, hasSize(2));

    serieRe.getEpisodes().add(new Episode("title", "path3", 1, 3));
    repository.save(serieRe);

    serieRe = repository.findByImdbId("estID");
    reEp = serieRe.getEpisodes();
    assertThat(reEp, hasSize(3));

    Episode e = eRepository.findByFilePath("path1");
    assertEquals("title", e.getTitle());

    e = eRepository.findByFilePath("path2");
    assertEquals("title", e.getTitle());
  }
Ejemplo n.º 20
0
  @Test
  public void groupOfSerieShouldRetrieveOnlyDataSinceTimeStamp() {
    Serie serie1 = new Serie("serie1");
    serie1.addSample(1, 1);
    serie1.addSample(2, 1);
    serie1.addSample(3, 1);

    Serie serie2 = new Serie("serie2");
    serie2.addSample(1, 2);
    serie2.addSample(2, 2);
    serie2.addSample(3, 2);

    Series series = new Series();
    series.addSerie(serie1.getLegend(), serie1);
    series.addSerie(serie2.getLegend(), serie2);

    assertThat(series.getDatas(serie1.getLegend(), 0).size(), is(3));
    assertThat(series.getDatas(serie2.getLegend(), 0).size(), is(3));

    assertThat(series.getDatas(serie1.getLegend(), 1).size(), is(3));
    assertThat(series.getDatas(serie2.getLegend(), 1).size(), is(3));

    assertThat(series.getDatas(serie1.getLegend(), 2).size(), is(2));
    assertThat(series.getDatas(serie2.getLegend(), 2).size(), is(2));

    assertThat(series.getDatas(serie1.getLegend(), 3).size(), is(1));
    assertThat(series.getDatas(serie2.getLegend(), 3).size(), is(1));
  }
Ejemplo n.º 21
0
 /**
  * This is called when the range has been invalidated and we need to update it. If the axis are
  * auto ranging then we compile a list of all data that the given axis has to plot and call
  * invalidateRange() on the axis passing it that data.
  */
 @Override
 protected void updateAxisRange() {
   // For candle stick chart we need to override this method as we need to let the axis know that
   // they need to be able
   // to cover the whole area occupied by the high to low range not just its center data value
   final Axis<String> xa = getXAxis();
   final Axis<Number> ya = getYAxis();
   List<String> xData = null;
   List<Number> yData = null;
   if (xa.isAutoRanging()) {
     xData = new ArrayList<>();
   }
   if (ya.isAutoRanging()) {
     yData = new ArrayList<>();
   }
   if (xData != null || yData != null) {
     for (Series<String, Number> series : getData()) {
       for (Data<String, Number> data : series.getData()) {
         if (xData != null) {
           xData.add(data.getXValue());
         }
         if (yData != null) {
           BarData extras = (BarData) data.getExtraValue();
           if (extras != null) {
             yData.add(extras.getHigh());
             yData.add(extras.getLow());
           } else {
             yData.add(data.getYValue());
           }
         }
       }
     }
     if (xData != null) {
       xa.invalidateRange(xData);
     }
     if (yData != null) {
       ya.invalidateRange(yData);
     }
   }
 }
Ejemplo n.º 22
0
 @Override
 protected void seriesAdded(Series<String, Number> series, int seriesIndex) {
   // handle any data already in series
   for (int j = 0; j < series.getData().size(); j++) {
     Data item = series.getData().get(j);
     Node candle = createCandle(seriesIndex, item, j);
     if (shouldAnimate()) {
       candle.setOpacity(0);
       getPlotChildren().add(candle);
       // fade in new candle
       FadeTransition ft = new FadeTransition(Duration.millis(500), candle);
       ft.setToValue(1);
       ft.play();
     } else {
       getPlotChildren().add(candle);
     }
   }
   // create series path
   Path seriesPath = new Path();
   seriesPath.getStyleClass().setAll("candlestick-average-line", "series" + seriesIndex);
   series.setNode(seriesPath);
   getPlotChildren().add(seriesPath);
 }
Ejemplo n.º 23
0
 @Override
 protected void seriesRemoved(Series<String, Number> series) {
   // remove all candle nodes
   for (XYChart.Data<String, Number> d : series.getData()) {
     final Node candle = d.getNode();
     if (shouldAnimate()) {
       // fade out old candle
       FadeTransition ft = new FadeTransition(Duration.millis(500), candle);
       ft.setToValue(0);
       ft.setOnFinished(
           (ActionEvent actionEvent) -> {
             getPlotChildren().remove(candle);
           });
       ft.play();
     } else {
       getPlotChildren().remove(candle);
     }
   }
 }
Ejemplo n.º 24
0
 private Alias generateAliasFor(Series content) {
   return PaHelper.getSeriesAlias(
       content.getId().toString(), content.getSeriesNumber().toString());
 }
Ejemplo n.º 25
0
 public PlotWithOverviewSeriesHandler(Series series, SeriesDataStrategy strategy) {
   provider = new AsyncDataProviderWrapper(new LocalDataProvider(strategy.getData()));
   windowHandler = windowModel.addSeries(series, PlotModelStrategy.defaultStrategy());
   overviewHandler = overviewModel.addSeries(Series.create(), strategy);
 }
Ejemplo n.º 26
0
 /**
  * Returns the HTTP status series of this status code.
  *
  * @see HttpStatus.Series
  */
 public Series series() {
   return Series.valueOf(this);
 }
 /** @param max maximum item count for all series */
 public void setMaxItemCount(int max) {
   for (Series series : seriesList) {
     series.setMaximumItemCount(max);
   }
 }
  /**
   * Series edition
   *
   * @param series Series to edit
   */
  void editSeries(final Series series) {
    String[] style = series.getStyle().split(";");
    String strColor = "black";
    final TextField editWidth = new TextField();

    String tempS = "null";
    for (String e : style) {
      if (e.contains("color: ")) {
        strColor = e.replace("color: ", "");
      } else if (e.contains("width: ")) {
        editWidth.setText(e.replace("width: ", ""));
      } else if (e.contains("shape: ")) {
        tempS = e.replace("shape: ", "");
      }
    }
    final String symbol = tempS;

    final List<SeriesShape> symbolList = new ArrayList<>();
    final ObservableList<SeriesShape> symbolListModel;
    final ListView<SeriesShape> comboSymbol = new ListView();
    symbolList.add(new SeriesShape("null", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("rectangle", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("circle", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("triangle", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("crux", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("diamond", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("empty rectangle", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("empty circle", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("empty triangle", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("empty diamond", javafx.scene.paint.Color.web(strColor)));

    symbolListModel = FXCollections.observableList(symbolList);
    comboSymbol.setItems(symbolListModel);
    comboSymbol.setCellFactory(
        new Callback<ListView<SeriesShape>, ListCell<SeriesShape>>() {
          @Override
          public ListCell<SeriesShape> call(ListView<SeriesShape> p) {
            ListCell<SeriesShape> cell =
                new ListCell<SeriesShape>() {
                  @Override
                  protected void updateItem(SeriesShape t, boolean bln) {
                    super.updateItem(t, bln);
                    if (t != null) {
                      setText("");
                      setGraphic(t.getShapeGraphic());
                    }
                  }
                };

            return cell;
          }
        });
    for (SeriesShape smb : symbolListModel) {
      if (smb.getName().equals(symbol)) {
        comboSymbol.getSelectionModel().select(smb);
      }
    }

    final ColorPicker colorPicker = new ColorPicker(javafx.scene.paint.Color.web(strColor));

    colorPicker.setOnAction(
        (ActionEvent t) -> {
          String sc = colorPicker.getValue().toString();
          symbolListModel.clear();
          symbolListModel.add(new SeriesShape("null", javafx.scene.paint.Color.web(sc)));
          symbolListModel.add(new SeriesShape("rectangle", javafx.scene.paint.Color.web(sc)));
          symbolListModel.add(new SeriesShape("circle", javafx.scene.paint.Color.web(sc)));
          symbolListModel.add(new SeriesShape("triangle", javafx.scene.paint.Color.web(sc)));
          symbolListModel.add(new SeriesShape("crux", javafx.scene.paint.Color.web(sc)));
          symbolListModel.add(new SeriesShape("diamond", javafx.scene.paint.Color.web(sc)));
          symbolListModel.add(new SeriesShape("empty rectangle", javafx.scene.paint.Color.web(sc)));
          symbolListModel.add(new SeriesShape("empty circle", javafx.scene.paint.Color.web(sc)));
          symbolListModel.add(new SeriesShape("empty triangle", javafx.scene.paint.Color.web(sc)));
          symbolListModel.add(new SeriesShape("empty diamond", javafx.scene.paint.Color.web(sc)));

          comboSymbol.setItems(symbolListModel);
          for (SeriesShape smb : symbolListModel) {
            if (smb.getName().equals(symbol)) {
              comboSymbol.getSelectionModel().select(smb);
            }
          }
        });

    GridPane grid = new GridPane();

    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(0, 10, 0, 10));

    grid.add(new Label("Series"), 0, 0);
    grid.add(new Label(series.getKey().toString()), 1, 0);
    grid.add(new Label("Color"), 0, 1);
    grid.add(colorPicker, 1, 1);
    grid.add(new Label("Width"), 0, 2);
    grid.add(editWidth, 1, 2);
    grid.add(new Label("Shape"), 0, 3);
    grid.add(comboSymbol, 1, 3);

    new PseudoModalDialog(skeleton, grid, true) {
      @Override
      public boolean validation() {
        String strColor = colorPicker.getValue().toString();
        String strWidth = editWidth.getText();
        double dWidth = Double.valueOf(strWidth);
        String strSimbolo = "null";
        SeriesShape simb =
            new SeriesShape(
                comboSymbol.getSelectionModel().getSelectedItem().toString(),
                javafx.scene.paint.Color.web(strColor));

        XYItemRenderer renderer = (XYItemRenderer) plot.getRenderer(series.getAxisIndex());

        renderer.setSeriesPaint(series.getSeriesIndex(), scene2awtColor(colorPicker.getValue()));

        try {
          if (Double.valueOf(strWidth) > 0) {
            ((XYLineAndShapeRenderer) renderer)
                .setSeriesLinesVisible(series.getSeriesIndex(), true);
            renderer.setSeriesStroke(
                series.getSeriesIndex(), new BasicStroke(Integer.valueOf(strWidth)));
          } else {
            ((XYLineAndShapeRenderer) renderer)
                .setSeriesLinesVisible(series.getSeriesIndex(), false);
          }
        } catch (NumberFormatException ex) {

        }

        if (simb.getName().contains("null")) {
          ((XYLineAndShapeRenderer) renderer)
              .setSeriesShapesVisible(series.getSeriesIndex(), false);
          renderer.setSeriesShape(series.getSeriesIndex(), null);
        } else {
          ((XYLineAndShapeRenderer) renderer).setSeriesShapesVisible(series.getSeriesIndex(), true);
          renderer.setSeriesShape(series.getSeriesIndex(), simb.getShapeAWT());
          if (simb.getName().contains("empty")) {
            ((XYLineAndShapeRenderer) renderer)
                .setSeriesShapesFilled(series.getSeriesIndex(), false);
          } else {
            ((XYLineAndShapeRenderer) renderer)
                .setSeriesShapesFilled(series.getSeriesIndex(), true);
          }
        }

        series.setStyle(
            "color: "
                + strColor
                + ";width: "
                + editWidth.getText()
                + ";shape: "
                + strSimbolo
                + ";");

        for (Node le : legendFrame.getChildren()) {
          if (le instanceof LegendAxis) {
            for (Node nn : ((LegendAxis) le).getChildren()) {
              if (nn instanceof Label) {
                if (((Label) nn).getText().equals(series.getKey().toString())) {
                  ((Label) nn).setGraphic(simb.getShapeGraphic());
                }
              }
            }
          }
        }
        return true;
      }
    }.show();
  }