예제 #1
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);
  }
예제 #2
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    try {
      // From AxisChartServlet.java:init()
      LegendProperties legendProperties = new LegendProperties();
      ChartProperties chartProperties = new ChartProperties();
      AxisProperties axisProperties = new AxisProperties(false);

      ChartFont axisScaleFont =
          new ChartFont(new Font("Georgia Negreta cursiva", Font.PLAIN, 13), Color.black);
      axisProperties.getXAxisProperties().setScaleChartFont(axisScaleFont);
      axisProperties.getYAxisProperties().setScaleChartFont(axisScaleFont);

      ChartFont axisTitleFont =
          new ChartFont(new Font("Arial Narrow", Font.PLAIN, 14), Color.black);
      axisProperties.getXAxisProperties().setTitleChartFont(axisTitleFont);
      axisProperties.getYAxisProperties().setTitleChartFont(axisTitleFont);

      Stroke[] strokes = {
        LineChartProperties.DEFAULT_LINE_STROKE,
        LineChartProperties.DEFAULT_LINE_STROKE,
        LineChartProperties.DEFAULT_LINE_STROKE
      };
      Shape[] shapes = {
        PointChartProperties.SHAPE_TRIANGLE,
        PointChartProperties.SHAPE_DIAMOND,
        PointChartProperties.SHAPE_CIRCLE
      };
      LineChartProperties lineChartProperties = new LineChartProperties(strokes, shapes);

      String[] xAxisLabels = {"1998", "1999", "2000", "2001", "2002", "2003", "2004"};
      String xAxisTitle = "Years";
      String yAxisTitle = "Problems";
      String title = "Micro$oft At Work";
      DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle, yAxisTitle, title);

      // From AxisChartServlet.java:createAxisChartDataSet
      double[][] data = TestDataGenerator.getRandomNumbers(3, 7, 200, 500);
      String[] legendLabels = {"Bugs", "Security Holes", "Backdoors"};
      Paint[] paints = TestDataGenerator.getRandomPaints(3);
      AxisChartDataSet acds =
          new AxisChartDataSet(data, legendLabels, paints, ChartType.LINE, lineChartProperties);
      dataSeries.addIAxisPlotDataSet(acds);
      AxisChart axisChart =
          new AxisChart(dataSeries, chartProperties, axisProperties, legendProperties, 550, 360);

      ServletEncoderHelper.encodeJPEG13(axisChart, 1.0f, response);

    } catch (Exception e) {
      System.out.println(e);
    }
  }
  // @Override
  public boolean isSeriesEmpty(DataSeriesType type) {
    SeriesManager<Integer, Integer> sf = new SeriesManager<Integer, Integer>(intermediateData);
    List<DataSeries<Integer, Integer>> seriesList = sf.getSeries();

    // Adds the 'All Spectra' series at the end in the local variable 'seriesList'
    // **NOTE** The intermediateData is NOT modified
    seriesList.add(getAllSpectraSeries(seriesList));

    for (DataSeries<Integer, Integer> series : seriesList) {
      if (series.getType() == type) return series.isEmpty(Integer.class, Integer.class);
    }
    return true;
  }
  private DataSeries<Integer, Integer> getAllSpectraSeries(
      List<DataSeries<Integer, Integer>> seriesList) {
    List<Integer> keys = new ArrayList<Integer>();
    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
    for (DataSeries<Integer, Integer> series : seriesList) {
      for (SeriesPair<Integer, Integer> sp : series.getSeriesValues(Integer.class, Integer.class)) {
        Integer key = sp.getX();
        Integer value = map.containsKey(key) ? map.get(key) + sp.getY() : sp.getY();

        if (!keys.contains(key)) keys.add(key);
        map.put(key, value);
      }
    }

    List<SeriesPair<Integer, Integer>> seriesPairs = new ArrayList<SeriesPair<Integer, Integer>>();
    for (Integer key : keys) {
      Integer value = map.get(key);
      SeriesPair<Integer, Integer> seriesPair = new SeriesPair<Integer, Integer>(key, value);
      seriesPairs.add(seriesPair);
    }

    return new DataSeries<Integer, Integer>(
        DataSeriesType.ALL_SPECTRA, DataSeriesType.ALL_SPECTRA.getType(), seriesPairs);
  }
  @Override
  protected void setChart() {
    SeriesManager<Integer, Integer> sf = new SeriesManager<Integer, Integer>(intermediateData);
    List<DataSeries<Integer, Integer>> seriesList = sf.getSeries();

    // Adds the 'All Spectra' series at the end in the local variable 'seriesList'
    // **NOTE** The intermediateData is NOT modified
    seriesList.add(getAllSpectraSeries(seriesList));

    List<Color> seriesColor = new ArrayList<Color>();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (DataSeries<Integer, Integer> series : seriesList) {
      DataSeriesType seriesType = series.getType();
      if (!visibleTypes.contains(seriesType)) continue;

      String serieKey = series.getIdentifier();
      List<SeriesPair<Integer, Integer>> values =
          series.getSeriesValues(Integer.class, Integer.class);

      Map<String, Integer> map = new HashMap<String, Integer>();
      // The map is filled with the intermediate data values
      int greaterThanTopValue = 0;
      for (SeriesPair<Integer, Integer> value : values) {
        int xValue = value.getX();
        int yValue = value.getY();
        if (xValue > TOP_VALUE) {
          greaterThanTopValue += yValue;
        } else {
          map.put("" + xValue, yValue);
        }
      }

      // Finally the JFreeChart data object is created and filled with the processed data
      // DefaultKeyedValues data = new DefaultKeyedValues();
      for (int i = 1; i <= TOP_VALUE; i++) {
        String category = "" + i;
        int value = map.containsKey(category) ? map.get(category) : 0;
        dataset.addValue(value, serieKey, category);
      }
      dataset.addValue(greaterThanTopValue, serieKey, GT_TOP_VALUE_KEY);
      seriesColor.add(seriesType.getColor());
    }

    chart =
        ChartFactory.createBarChart(
            getChartTitle(), // chart title
            "Precursor Ion Charge", // x axis label
            "Frequency", // y axis label
            dataset, // chartData
            PlotOrientation.VERTICAL,
            true, // include legend
            true, // tooltips
            false // urls
            );
    chart.addSubtitle(new TextTitle());

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setBaseItemLabelGenerator(new NumberLegendGenerator());
    for (int i = 0; i < dataset.getRowCount(); i++) {
      renderer.setSeriesItemLabelsVisible(i, Boolean.TRUE);
      renderer.setSeriesPaint(i, seriesColor.get(i));
    }

    plot.getRangeAxis().setUpperMargin(CHART_UPPER_MARGIN);
    plot.setBackgroundAlpha(0f);
    plot.setDomainGridlinePaint(Color.red);
    plot.setRangeGridlinePaint(Color.blue);

    renderer.setShadowVisible(false);
    renderer.setDrawBarOutline(false);
    renderer.setItemMargin(0);
  }
예제 #6
0
  public void update(MultihopMsg msg) {
    String info;
    SurgeMsg SMsg = new SurgeMsg(msg.dataGet(), msg.offset_data(0));
    if (SMsg.get_type() == 0) {

      if (SMsg.get_parentaddr() == MainFrame.BEACON_BASE_ADDRESS) {
        isDirectChild = true;
      } else {
        isDirectChild = false;
      }

      // Update message count and rate
      // Only update if this message is coming to the root from
      // a direct child
      int saddr = msg.get_sourceaddr();
      NodeInfo ni = (NodeInfo) SensorAnalyzer.proprietaryNodeInfo.get(new Integer(saddr));
      if (ni != null) {
        if (ni.isDirectChild) {
          msgCount++;
          int new_seq_no = (int) SMsg.get_seq_no() & 0x7fffff;
          if (stats_start_sequence_number == 0) stats_start_sequence_number = new_seq_no;
          if (seq_no == 0) seq_no = new_seq_no - 1;
          int diff = new_seq_no - seq_no;
          if (diff > 1000) diff = 1;
          active = true;
          long curtime = System.currentTimeMillis();
          packetTimes[packetTimesPointer++] = curtime - lastTime;
          packetTimesPointer %= SensorAnalyzer.HISTORY_LENGTH;
          packetSkips[packetSkipsPointer++] = diff;
          packetSkipsPointer %= SensorAnalyzer.HISTORY_LENGTH;
          msgRate = calcMsgRate(0);
          msgYield = calcMsgYield(0);

          SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");

          String log = "";
          log += nodeNumber + "#";
          log += msgCount + "#";
          log += formatter.format(new Date()) + "#";
          log += curtime + "#";
          log += (curtime - lastTime) + "#";
          log += SMsg.get_parentaddr() + "#";

          parent_count[SMsg.get_parentaddr()]++;
          log += msgRate + "#";
          seq_no = new_seq_no;
          batt = (int) SMsg.get_seq_no() >> 23 & 0x1ff;

          log += seq_no + "#";
          log += hopcount + "#";

          level_sum += hopcount;
          log += SMsg.get_reading() + "#";
          log += batt + "#";
          for (int i = 0; i < 5; i++) {
            log += neighbors[i].id + "#";
            log += neighbors[i].hopcount + "#";
            log += neighbors[i].link_quality / 255.0 + "#";
          }
          log += SMsg.get_temp() + "#";
          log += SMsg.get_light() + "#";
          log += SMsg.get_accelx() + "#";
          log += SMsg.get_accely() + "#";
          log += SMsg.get_magx() + "#";
          log += SMsg.get_magy() + "#";
          System.out.println(log);

          double batt_val = (double) batt;
          batt_val = 1.25 * 1023.0 / batt_val;
          batt_val *= 256.0 / 4.0;
          // System.out.println(batt_val);
          // Store the sensor readings.
          yield_series.insertNewReading(total_yield++, new Integer((int) (yield() * 256.0)));
          time_series.insertNewReading(seq_no, new Long(curtime));
          batt_series.insertNewReading(seq_no, new Integer((int) batt_val));
          temp_series.insertNewReading(seq_no, new Integer(SMsg.get_temp()));
          light_series.insertNewReading(seq_no, new Integer(SMsg.get_light()));
          accelx_series.insertNewReading(seq_no, new Integer(SMsg.get_accelx()));
          accely_series.insertNewReading(seq_no, new Integer(SMsg.get_accely()));
          magx_series.insertNewReading(seq_no, new Integer(SMsg.get_magx()));
          magy_series.insertNewReading(seq_no, new Integer(SMsg.get_magy()));

          link_quality = neighbors[0].link_quality / 255;

          // update the edge quality as well...
          MainClass.locationAnalyzer.setQualityForEdge(
              nodeNumber.intValue(), SMsg.get_parentaddr(), (int) (link_quality * 255.0));

          lastTime = curtime;
        }
      }

      if (self_calc != false) info = msgCount + " msgs ";
      else info = "";

      this.value = SMsg.get_reading();
      if (panel != null) {
        panel.YieldLabel.setText(String.valueOf(percent_yield()) + " %");
        panel.SensorLabel.setText(String.valueOf(value));
        panel.ParentLabel.setText(String.valueOf(SMsg.get_parentaddr()));
        panel.SequenceLabel.setText(String.valueOf(seq_no));
        panel.CountLabel.setText(String.valueOf(msgCount));
        panel.DepthLabel.setText(String.valueOf(hopcount));
        panel.repaint();
      }

      this.infoString = info;
    }
  }