Пример #1
0
    @Override
    public boolean equals(Object object) {
      if (!(object instanceof Plotter)) {
        return false;
      }

      Plotter plotter = (Plotter) object;
      return plotter.name.equals(name) && plotter.getValue() == getValue();
    }
Пример #2
0
  /**
   * Generic method that posts a plugin to the metrics website
   *
   * @param plugin
   */
  private void postPlugin(Plugin plugin, boolean isPing) throws IOException {
    // Construct the post data
    String response = "ERR No response";
    String data =
        encode("guid")
            + '='
            + encode(guid)
            + gField("version", plugin.getDescription().getVersion())
            + gField("server", Bukkit.getVersion())
            + gField("players", String.valueOf(Bukkit.getServer().getOnlinePlayers().length))
            + gField("revision", String.valueOf(REVISION));

    // If we're pinging, append it
    if (isPing) {
      data += gField("ping", "true");
    }

    // Add any custom data (if applicable)
    Set<Plotter> plotters = customData.get(plugin);

    if (plotters != null) {
      for (Plotter plotter : plotters) {
        data += gField("Custom" + plotter.getColumnName(), Integer.toString(plotter.getValue()));
      }
    }

    // Create the url
    URL url = new URL(BASE_URL + String.format(REPORT_URL, plugin.getDescription().getName()));

    // Connect to the website
    URLConnection connection = url.openConnection();
    connection.setDoOutput(true);

    // Write the data
    OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
    writer.write(data);
    writer.flush();

    // Now read the response
    BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    response = reader.readLine();

    // close resources
    writer.close();
    reader.close();
    if (response.startsWith("ERR")) throw new IOException(response);
  }
Пример #3
0
  public void createGraph() {

    int N = 100;
    int T = 10;
    int x = 0;
    int y = 0;

    Random rando = new Random();

    ArrayList<String> usedPositions = new ArrayList();

    // Create vertices
    for (int i = 0; i < N; i++) {

      do {
        x = rando.nextInt(100) + 1;
        y = rando.nextInt(100) + 1;
      } while (usedPositions.contains(x + "," + y));

      usedPositions.add(x + "," + y);
      graph.insertVertex(new Node(x, y));
    }

    // Create edges
    // n^2
    for (Graph.Vertex v1 : graph.getVertices()) {

      for (Graph.Vertex v2 : graph.getVertices()) {

        Node n1 = (Node) v1.getElement();
        Node n2 = (Node) v2.getElement();

        if (n1.equals(n2)) {
          continue;
        }

        double distance = Math.sqrt(Math.pow((n1.x - n2.x), 2) + Math.pow((n1.y - n2.y), 2));

        if (distance <= T) {
          if (graph.insertEdge(distance, v1, v2)) {
            // plotter.connectCircles(plotter.getCircles().get(n1.index),
            // plotter.getCircles().get(n2.index));
            plotter.drawLine(n1.x, n1.y, n2.x, n2.y);
            // System.out.println("(" + n1.x + "," + n1.y + ")" + "," + "(" + n2.x + "," + n2.y +
            // ")");
          }
        }
      }
    }
  }
Пример #4
0
  /** Generic method that posts a plugin to the metrics website */
  private void postPlugin(boolean isPing) throws IOException {
    // Construct the post data
    String data =
        encode("guid")
            + '='
            + encode(guid)
            + encodeDataPair("version", Mafiacraft.getCore().getVersionDetailed())
            + encodeDataPair("server", Mafiacraft.getImpl().getServerVersion())
            + encodeDataPair("players", Integer.toString(Mafiacraft.getOnlinePlayers().size()))
            + encodeDataPair("revision", String.valueOf(REVISION));

    // If we're pinging, append it
    if (isPing) {
      data += encodeDataPair("ping", "true");
    }

    // Acquire a lock on the graphs, which lets us make the assumption we also lock everything
    // inside of the graph (e.g plotters)
    synchronized (graphs) {
      Iterator<Graph> iter = graphs.iterator();

      while (iter.hasNext()) {
        Graph graph = iter.next();

        // Because we have a lock on the graphs set already, it is reasonable to assume
        // that our lock transcends down to the individual plotters in the graphs also.
        // Because our methods are private, no one but us can reasonably access this list
        // without reflection so this is a safe assumption without adding more code.
        for (Plotter plotter : graph.getPlotters()) {
          // The key name to send to the metrics server
          // The format is C-GRAPHNAME-PLOTTERNAME where separator - is defined at the top
          // Legacy (R4) submitters use the format Custom%s, or CustomPLOTTERNAME
          String key =
              String.format(
                  "C%s%s%s%s",
                  CUSTOM_DATA_SEPARATOR,
                  graph.getName(),
                  CUSTOM_DATA_SEPARATOR,
                  plotter.getColumnName());

          // The value to send, which for the foreseeable future is just the string
          // value of plotter.getValue()
          String value = Integer.toString(plotter.getValue());

          // Add it to the http post data :)
          data += encodeDataPair(key, value);
        }
      }
    }

    // Create the url
    URL url = new URL(BASE_URL + String.format(REPORT_URL, "Mafiacraft"));

    // Connect to the website
    URLConnection connection;

    // Mineshafter creates a socks proxy, so we can safely bypass it
    // It does not reroute POST requests so we need to go around it
    if (isMineshafterPresent()) {
      connection = url.openConnection(Proxy.NO_PROXY);
    } else {
      connection = url.openConnection();
    }

    connection.setDoOutput(true);

    // Write the data
    OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
    writer.write(data);
    writer.flush();

    // Now read the response
    BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String response = reader.readLine();

    // close resources
    writer.close();
    reader.close();

    if (response.startsWith("ERR")) {
      throw new IOException(response); // Throw the exception
    } else {
      // Is this the first update this hour?
      if (response.contains("OK This is your first update this hour")) {
        synchronized (graphs) {
          Iterator<Graph> iter = graphs.iterator();

          while (iter.hasNext()) {
            Graph graph = iter.next();

            for (Plotter plotter : graph.getPlotters()) {
              plotter.reset();
            }
          }
        }
      }
    }
    // if (response.startsWith("OK")) - We should get "OK" followed by an optional description if
    // everything goes right
  }
Пример #5
0
  /** Generic method that posts a plugin to the metrics website */
  private void postPlugin(final boolean isPing) throws IOException {
    // Server software specific section
    PluginDescriptionFile description = plugin.getDescription();
    String pluginName = description.getName();
    boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if
    // online mode
    // is enabled
    String pluginVersion = description.getVersion();
    String serverVersion = Bukkit.getVersion();
    int playersOnline = Bukkit.getServer().getOnlinePlayers().size();

    // END server software specific section -- all code below does not use
    // any code outside of this class / Java

    // Construct the post data
    final StringBuilder data = new StringBuilder();

    // The plugin's description file containg all of the plugin data such as
    // name, version, author, etc
    data.append(encode("guid")).append('=').append(encode(guid));
    encodeDataPair(data, "version", pluginVersion);
    encodeDataPair(data, "server", serverVersion);
    encodeDataPair(data, "players", Integer.toString(playersOnline));
    encodeDataPair(data, "revision", String.valueOf(REVISION));

    // New data as of R6
    String osname = System.getProperty("os.name");
    String osarch = System.getProperty("os.arch");
    String osversion = System.getProperty("os.version");
    String java_version = System.getProperty("java.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    // normalize os arch .. amd64 -> x86_64
    if (osarch.equals("amd64")) {
      osarch = "x86_64";
    }

    encodeDataPair(data, "osname", osname);
    encodeDataPair(data, "osarch", osarch);
    encodeDataPair(data, "osversion", osversion);
    encodeDataPair(data, "cores", Integer.toString(coreCount));
    encodeDataPair(data, "online-mode", Boolean.toString(onlineMode));
    encodeDataPair(data, "java_version", java_version);

    // If we're pinging, append it
    if (isPing) {
      encodeDataPair(data, "ping", "true");
    }

    // Acquire a lock on the graphs, which lets us make the assumption we
    // also lock everything
    // inside of the graph (e.g plotters)
    synchronized (graphs) {
      final Iterator<Graph> iter = graphs.iterator();

      while (iter.hasNext()) {
        final Graph graph = iter.next();

        for (Plotter plotter : graph.getPlotters()) {
          // The key name to send to the metrics server
          // The format is C-GRAPHNAME-PLOTTERNAME where separator -
          // is defined at the top
          // Legacy (R4) submitters use the format Custom%s, or
          // CustomPLOTTERNAME
          final String key =
              String.format(
                  "C%s%s%s%s",
                  CUSTOM_DATA_SEPARATOR,
                  graph.getName(),
                  CUSTOM_DATA_SEPARATOR,
                  plotter.getColumnName());

          // The value to send, which for the foreseeable future is
          // just the string
          // value of plotter.getValue()
          final String value = Integer.toString(plotter.getValue());

          // Add it to the http post data :)
          encodeDataPair(data, key, value);
        }
      }
    }

    // Create the url
    URL url = new URL(BASE_URL + String.format(REPORT_URL, encode(pluginName)));

    // Connect to the website
    URLConnection connection;

    // Mineshafter creates a socks proxy, so we can safely bypass it
    // It does not reroute POST requests so we need to go around it
    if (isMineshafterPresent()) {
      connection = url.openConnection(Proxy.NO_PROXY);
    } else {
      connection = url.openConnection();
    }

    connection.setDoOutput(true);

    // Write the data
    final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
    writer.write(data.toString());
    writer.flush();

    // Now read the response
    final BufferedReader reader =
        new BufferedReader(new InputStreamReader(connection.getInputStream()));
    final String response = reader.readLine();

    // close resources
    writer.close();
    reader.close();

    if (response == null || response.startsWith("ERR")) {
      throw new IOException(response); // Throw the exception
    } else {
      // Is this the first update this hour?
      if (response.contains("OK This is your first update this hour")) {
        synchronized (graphs) {
          final Iterator<Graph> iter = graphs.iterator();

          while (iter.hasNext()) {
            final Graph graph = iter.next();

            for (Plotter plotter : graph.getPlotters()) {
              plotter.reset();
            }
          }
        }
      }
    }
  }
Пример #6
0
  @Override
  protected void exportSlide(Slide S) {

    int i, j, k, m;
    int rowcount = 0;
    int colcount;
    Row row, xrow, yrow, zrow;
    String legend;

    JFreeChart chart = plotter.makeSlideChart(S);
    Sheet sheet = wb.createSheet(String.format("%d", S.id));

    // slide title
    row = sheet.createRow(rowcount++);
    row.createCell(0).setCellValue("Slide title:");
    row.createCell(1).setCellValue(S.title);

    // loop through plots
    for (i = 0; i < S.plots.size(); i++) {

      rowcount++;
      row = sheet.createRow(rowcount++);
      row.createCell(0).setCellValue(String.format("Plot %d", i + 1));
      row.createCell(1).setCellValue(S.plots.get(i).type.toString());

      row = sheet.createRow(rowcount++);
      row.createCell(0).setCellValue("X label:");
      row.createCell(1).setCellValue(S.plots.get(i).xlabel);
      row = sheet.createRow(rowcount++);
      row.createCell(0).setCellValue("Y label:");
      row.createCell(1).setCellValue(S.plots.get(i).ylabel);

      if (S.plots.get(i).zlabel != null) {
        row = sheet.createRow(rowcount++);
        row.createCell(0).setCellValue("Z label:");
        row.createCell(1).setCellValue(S.plots.get(i).zlabel);
      }

      XYPlot plot = null;
      if (S.plots.size() > 1) {
        CombinedDomainXYPlot cplot = (CombinedDomainXYPlot) chart.getXYPlot();
        plot = (XYPlot) cplot.getSubplots().get(i);
      } else {
        plot = chart.getXYPlot();
      }

      // loop through elements
      for (j = 0; j < S.plots.get(i).elements.size(); j++) {
        PlotElement e = S.plots.get(i).elements.get(j);

        rowcount++;
        row = sheet.createRow(rowcount++);
        row.createCell(0).setCellValue(String.format("Element %d", j + 1));
        row.createCell(1).setCellValue(e.type.toString());

        switch (e.type) {
          case contour:
            DefaultXYZDataset xyzdataset = (DefaultXYZDataset) plot.getDataset();
            colcount = 0;
            xrow = sheet.createRow(rowcount++);
            yrow = sheet.createRow(rowcount++);
            zrow = sheet.createRow(rowcount++);
            for (m = 0; m < xyzdataset.getItemCount(0); m++) {
              xrow.createCell(colcount).setCellValue(xyzdataset.getX(0, m).toString());
              yrow.createCell(colcount).setCellValue(xyzdataset.getY(0, m).toString());
              zrow.createCell(colcount).setCellValue(xyzdataset.getZ(0, m).toString());
              colcount++;
              if (colcount >= 254) break;
            }

            break;

          case multiline:
          case scatter:
            DefaultXYDataset xydataset = (DefaultXYDataset) plot.getDataset();

            // loop through XY series
            for (k = 0; k < xydataset.getSeriesCount(); k++) {
              colcount = 0;
              xrow = sheet.createRow(rowcount++);
              yrow = sheet.createRow(rowcount++);
              legend = xydataset.getSeriesKey(k).toString();

              xrow.createCell(colcount).setCellValue(legend);
              yrow.createCell(colcount).setCellValue(legend);
              colcount++;

              xrow.createCell(colcount).setCellValue("X:");
              yrow.createCell(colcount).setCellValue("Y:");
              colcount++;

              for (m = 0; m < xydataset.getItemCount(k); m++) {
                xrow.createCell(colcount).setCellValue(xydataset.getX(k, m).toString());
                yrow.createCell(colcount).setCellValue(xydataset.getY(k, m).toString());
                colcount++;
              }
            }
            break;

          case minmax:
            System.out.println("ERROR: NOT IMPLEMENTED");
            break;
        }
      }
    }
  }
Пример #7
0
  /** Generic method that posts a plugin to the metrics website */
  private void postPlugin(final boolean isPing) throws IOException {
    // Server software specific section
    PluginDescriptionFile description = plugin.getDescription();
    String pluginName = description.getName();
    boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
    String pluginVersion = description.getVersion();
    String serverVersion = Bukkit.getVersion();
    int playersOnline = Bukkit.getServer().getOnlinePlayers().length;

    // END server software specific section -- all code below does not use any code outside of this
    // class / Java

    // Construct the post data
    StringBuilder json = new StringBuilder(1024);
    json.append('{');

    // The plugin's description file containg all of the plugin data such as name, version, author,
    // etc
    appendJSONPair(json, "guid", guid);
    appendJSONPair(json, "plugin_version", pluginVersion);
    appendJSONPair(json, "server_version", serverVersion);
    appendJSONPair(json, "players_online", Integer.toString(playersOnline));

    // New data as of R6
    String osname = System.getProperty("os.name");
    String osarch = System.getProperty("os.arch");
    String osversion = System.getProperty("os.version");
    String java_version = System.getProperty("java.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    // normalize os arch .. amd64 -> x86_64
    if (osarch.equals("amd64")) {
      osarch = "x86_64";
    }

    appendJSONPair(json, "osname", osname);
    appendJSONPair(json, "osarch", osarch);
    appendJSONPair(json, "osversion", osversion);
    appendJSONPair(json, "cores", Integer.toString(coreCount));
    appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
    appendJSONPair(json, "java_version", java_version);

    // If we're pinging, append it
    if (isPing) {
      appendJSONPair(json, "ping", "1");
    }

    if (graphs.size() > 0) {
      synchronized (graphs) {
        json.append(',');
        json.append('"');
        json.append("graphs");
        json.append('"');
        json.append(':');
        json.append('{');

        boolean firstGraph = true;

        final Iterator<Graph> iter = graphs.iterator();

        while (iter.hasNext()) {
          Graph graph = iter.next();

          StringBuilder graphJson = new StringBuilder();
          graphJson.append('{');

          for (Plotter plotter : graph.getPlotters()) {
            appendJSONPair(
                graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
          }

          graphJson.append('}');

          if (!firstGraph) {
            json.append(',');
          }

          json.append(escapeJSON(graph.getName()));
          json.append(':');
          json.append(graphJson);

          firstGraph = false;
        }

        json.append('}');
      }
    }

    // close json
    json.append('}');

    // Create the url
    URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));

    // Connect to the website
    URLConnection connection;

    // Mineshafter creates a socks proxy, so we can safely bypass it
    // It does not reroute POST requests so we need to go around it
    if (isMineshafterPresent()) {
      connection = url.openConnection(Proxy.NO_PROXY);
    } else {
      connection = url.openConnection();
    }

    byte[] uncompressed = json.toString().getBytes();
    byte[] compressed = gzip(json.toString());

    // Headers
    connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
    connection.addRequestProperty("Content-Type", "application/json");
    connection.addRequestProperty("Content-Encoding", "gzip");
    connection.addRequestProperty("Content-Length", Integer.toString(compressed.length));
    connection.addRequestProperty("Accept", "application/json");
    connection.addRequestProperty("Connection", "close");

    connection.setDoOutput(true);

    if (debug) {
      System.out.println(
          "[Metrics] Prepared request for "
              + pluginName
              + " uncompressed="
              + uncompressed.length
              + " compressed="
              + compressed.length);
    }

    // Write the data
    OutputStream os = connection.getOutputStream();
    os.write(compressed);
    os.flush();

    // Now read the response
    final BufferedReader reader =
        new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String response = reader.readLine();

    // close resources
    os.close();
    reader.close();

    if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
      if (response == null) {
        response = "null";
      } else if (response.startsWith("7")) {
        response = response.substring(response.startsWith("7,") ? 2 : 1);
      }

      throw new IOException(response);
    } else {
      // Is this the first update this hour?
      if (response.equals("1") || response.contains("This is your first update this hour")) {
        synchronized (graphs) {
          final Iterator<Graph> iter = graphs.iterator();

          while (iter.hasNext()) {
            final Graph graph = iter.next();

            for (Plotter plotter : graph.getPlotters()) {
              plotter.reset();
            }
          }
        }
      }
    }
  }
Пример #8
0
  /** Generic method that posts a plugin to the metrics website */
  private void postPlugin(final boolean isPing) throws IOException {
    // The plugin's description file containg all of the plugin data such as name, version, author,
    // etc
    final PluginDescriptionFile description = plugin.getDescription();

    // Construct the post data
    final StringBuilder data = new StringBuilder();
    data.append(encode("guid")).append('=').append(encode(guid));
    encodeDataPair(data, "version", description.getVersion());
    encodeDataPair(data, "server", Bukkit.getVersion());
    encodeDataPair(data, "players", Integer.toString(Bukkit.getServer().getOnlinePlayers().length));
    encodeDataPair(data, "revision", String.valueOf(REVISION));

    // If we're pinging, append it
    if (isPing) {
      encodeDataPair(data, "ping", "true");
    }

    // Acquire a lock on the graphs, which lets us make the assumption we also lock everything
    // inside of the graph (e.g plotters)
    synchronized (graphs) {
      final Iterator<Graph> iter = graphs.iterator();

      while (iter.hasNext()) {
        final Graph graph = iter.next();

        for (Plotter plotter : graph.getPlotters()) {
          // The key name to send to the metrics server
          // The format is C-GRAPHNAME-PLOTTERNAME where separator - is defined at the top
          // Legacy (R4) submitters use the format Custom%s, or CustomPLOTTERNAME
          final String key =
              String.format(
                  "C%s%s%s%s",
                  CUSTOM_DATA_SEPARATOR,
                  graph.getName(),
                  CUSTOM_DATA_SEPARATOR,
                  plotter.getColumnName());

          // The value to send, which for the foreseeable future is just the string
          // value of plotter.getValue()
          final String value = Integer.toString(plotter.getValue());

          // Add it to the http post data :)
          encodeDataPair(data, key, value);
        }
      }
    }

    // Create the url
    URL url =
        new URL(BASE_URL + String.format(REPORT_URL, encode(plugin.getDescription().getName())));

    // Connect to the website
    URLConnection connection;

    // Mineshafter creates a socks proxy, so we can safely bypass it
    // It does not reroute POST requests so we need to go around it
    if (isMineshafterPresent()) {
      connection = url.openConnection(Proxy.NO_PROXY);
    } else {
      connection = url.openConnection();
    }

    connection.setDoOutput(true);

    // Write the data
    final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
    writer.write(data.toString());
    writer.flush();

    // Now read the response
    final BufferedReader reader =
        new BufferedReader(new InputStreamReader(connection.getInputStream()));
    final String response = reader.readLine();

    // close resources
    writer.close();
    reader.close();

    if (response == null || response.startsWith("ERR")) {
      throw new IOException(response); // Throw the exception
    } else {
      // Is this the first update this hour?
      if (response.contains("OK This is your first update this hour")) {
        synchronized (graphs) {
          final Iterator<Graph> iter = graphs.iterator();

          while (iter.hasNext()) {
            final Graph graph = iter.next();

            for (Plotter plotter : graph.getPlotters()) {
              plotter.reset();
            }
          }
        }
      }
    }
  }