Exemple #1
0
  private HashMap<Point2D, String> makePointList(String category, List<Report> toolResults) {
    HashMap<Point2D, String> map = new HashMap<Point2D, String>();
    char ch = 'A';

    // make a list of all points.  Add in a tiny random to prevent exact duplicate coordinates in
    // map
    for (Report r : toolResults) {
      OverallResult or = r.getOverallResults().getResults(category);
      double x = or.getFalsePositiveRate() * 100 + sr.nextDouble() * .000001;
      double y =
          or.getTruePositiveRate() * 100
              + sr.nextDouble() * .000001
              - 1; // this puts the label just below the point
      Point2D p = new Point2D.Double(x, y);
      String label = "" + ch;
      map.put(p, label);
      ch++;
    }
    Point2D ap =
        new Point2D.Double(
            afr * 100 + sr.nextDouble() * .000001, atr * 100 + sr.nextDouble() * .000001 - 1);

    map.put(ap, "" + ch);
    dedupify(map);
    return map;
  }
Exemple #2
0
 public int compareTo(Report r) {
   return this.getToolNameAndVersion()
       .toLowerCase()
       .compareTo(r.getToolNameAndVersion().toLowerCase());
 }
Exemple #3
0
  private JFreeChart display(
      String title, int height, int width, String category, List<Report> toolResults) {

    JFrame f = new JFrame(title);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // averages
    ArrayList<Double> averageFalseRates = new ArrayList<Double>();

    ArrayList<Double> averageTrueRates = new ArrayList<Double>();
    double averageFalseRate = 0;
    double averageTrueRate = 0;

    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series = new XYSeries("Scores");
    for (int i = 0; i < toolResults.size(); i++) {
      Report toolReport = toolResults.get(i);
      OverallResult overallResults = toolReport.getOverallResults().getResults(category);
      series.add(
          overallResults.getFalsePositiveRate() * 100, overallResults.getTruePositiveRate() * 100);
      if (toolReport.isCommercial()) {
        averageFalseRates.add(overallResults.getFalsePositiveRate());

        averageTrueRates.add(overallResults.getTruePositiveRate());
      }
    }

    for (double d : averageFalseRates) {
      averageFalseRate += d;
    }
    averageFalseRate = averageFalseRate / averageFalseRates.size();

    for (double d : averageTrueRates) {
      averageTrueRate += d;
    }
    averageTrueRate = averageTrueRate / averageTrueRates.size();

    series.add(averageFalseRate * 100, averageTrueRate * 100);
    dataset.addSeries(series);
    afr = averageFalseRate;
    atr = averageTrueRate;

    chart =
        ChartFactory.createScatterPlot(
            title,
            "False Positive Rate",
            "True Positive Rate",
            dataset,
            PlotOrientation.VERTICAL,
            true,
            true,
            false);
    String fontName = "Arial";
    DecimalFormat pctFormat = new DecimalFormat("0'%'");

    theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme();
    theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title
    theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title
    theme.setRegularFont(new Font(fontName, Font.PLAIN, 16));
    theme.setSmallFont(new Font(fontName, Font.PLAIN, 12));
    theme.setRangeGridlinePaint(Color.decode("#C0C0C0"));
    theme.setPlotBackgroundPaint(Color.white);
    theme.setChartBackgroundPaint(Color.white);
    theme.setGridBandPaint(Color.red);
    theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    theme.setBarPainter(new StandardBarPainter());
    theme.setAxisLabelPaint(Color.decode("#666666"));
    theme.apply(chart);

    XYPlot xyplot = chart.getXYPlot();
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();

    xyplot.setOutlineVisible(true);

    rangeAxis.setRange(-5, 109.99);
    rangeAxis.setNumberFormatOverride(pctFormat);
    rangeAxis.setTickLabelPaint(Color.decode("#666666"));
    rangeAxis.setMinorTickCount(5);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setAxisLineVisible(true);
    rangeAxis.setMinorTickMarksVisible(true);
    rangeAxis.setTickMarksVisible(true);
    rangeAxis.setLowerMargin(10);
    rangeAxis.setUpperMargin(10);
    xyplot.setRangeGridlineStroke(new BasicStroke());
    xyplot.setRangeGridlinePaint(Color.lightGray);
    xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setRangeMinorGridlinesVisible(true);

    domainAxis.setRange(-5, 105);
    domainAxis.setNumberFormatOverride(pctFormat);
    domainAxis.setTickLabelPaint(Color.decode("#666666"));
    domainAxis.setMinorTickCount(5);
    domainAxis.setTickUnit(new NumberTickUnit(10));
    domainAxis.setAxisLineVisible(true);
    domainAxis.setTickMarksVisible(true);
    domainAxis.setMinorTickMarksVisible(true);
    domainAxis.setLowerMargin(10);
    domainAxis.setUpperMargin(10);
    xyplot.setDomainGridlineStroke(new BasicStroke());
    xyplot.setDomainGridlinePaint(Color.lightGray);
    xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setDomainMinorGridlinesVisible(true);

    chart.setTextAntiAlias(true);
    chart.setAntiAlias(true);
    chart.removeLegend();
    chart.setPadding(new RectangleInsets(20, 20, 20, 20));
    xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7"));

    //        // setup item labels
    //        XYItemRenderer renderer = xyplot.getRenderer();
    //        Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f);
    //        for ( int i = 0; i < dataset.getSeriesCount(); i++ ) {
    //            renderer.setSeriesShape(i, circle);
    //            renderer.setSeriesPaint(i, Color.blue);
    //            String label = ""+((String)dataset.getSeries(i).getKey());
    //            int idx = label.indexOf( ':');
    //            label = label.substring( 0, idx );
    //            StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(label);
    //            renderer.setSeriesItemLabelGenerator(i, generator);
    //            renderer.setSeriesItemLabelsVisible(i, true);
    //            ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
    // TextAnchor.BASELINE_CENTER );
    //            renderer.setSeriesPositiveItemLabelPosition(i, position);
    //        }

    makeDataLabels(category, toolResults, xyplot);
    makeLegend(category, toolResults, 57, 48, dataset, xyplot);

    Stroke dashed =
        new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] {6, 3}, 0);
    for (XYDataItem item : (List<XYDataItem>) series.getItems()) {
      double x = item.getX().doubleValue();
      double y = item.getY().doubleValue();
      double z = (x + y) / 2;
      XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue);
      xyplot.addAnnotation(score);
    }

    //        // put legend inside plot
    //        LegendTitle lt = new LegendTitle(xyplot);
    //        lt.setItemFont(theme.getSmallFont());
    //        lt.setPosition(RectangleEdge.RIGHT);
    //        lt.setItemFont(theme.getSmallFont());
    //        XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT);
    //        ta.setMaxWidth(0.48);
    //        xyplot.addAnnotation(ta);

    // draw guessing line
    XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red);
    xyplot.addAnnotation(guessing);

    XYPointerAnnotation worse =
        makePointer(75, 5, "Worse than guessing", TextAnchor.TOP_CENTER, 90);
    xyplot.addAnnotation(worse);

    XYPointerAnnotation better =
        makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270);
    xyplot.addAnnotation(better);

    XYTextAnnotation stroketext =
        new XYTextAnnotation("                     Random Guess", 88, 107);
    stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT);
    stroketext.setBackgroundPaint(Color.white);
    stroketext.setPaint(Color.red);
    stroketext.setFont(theme.getRegularFont());
    xyplot.addAnnotation(stroketext);

    XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red);
    xyplot.setBackgroundPaint(Color.white);
    xyplot.addAnnotation(strokekey);

    ChartPanel cp =
        new ChartPanel(
            chart, height, width, 400, 400, 1200, 1200, false, false, false, false, false, false);
    f.add(cp);
    f.pack();
    f.setLocationRelativeTo(null);
    //      f.setVisible(true);

    return chart;
  }
Exemple #4
0
  private void makeLegend(
      String category,
      List<Report> toolResults,
      int x,
      int y,
      XYSeriesCollection dataset,
      XYPlot xyplot) {
    char ch = 'A';
    int i = -2;

    // print commercial label
    XYTextAnnotation stroketext = new XYTextAnnotation("commercial", x, y + i * -3.3);
    stroketext.setTextAnchor(TextAnchor.CENTER_LEFT);
    stroketext.setBackgroundPaint(Color.white);
    stroketext.setPaint(Color.gray);
    stroketext.setFont(theme.getRegularFont());
    i++;

    // commercial tools
    for (Report r : toolResults) {
      OverallResults or = r.getOverallResults();
      if (r.isCommercial()) {
        String label = (ch == 'I' ? ch + ":  " : "" + ch + ": ");
        int score = (int) (or.getResults(category).getScore() * 100);
        String msg = "\u25A0 " + label + r.getToolName() + " (" + score + "%)";
        XYTextAnnotation stroketext4 = new XYTextAnnotation(msg, x, y + i * -3.3);
        stroketext4.setTextAnchor(TextAnchor.CENTER_LEFT);
        stroketext4.setBackgroundPaint(Color.white);
        stroketext4.setPaint(Color.blue);
        stroketext4.setFont(theme.getRegularFont());
        xyplot.addAnnotation(stroketext4);

        i++;

        ch++;
      }
    }
    // print non commercial label
    XYTextAnnotation stroketext1 = new XYTextAnnotation("non - commercial", x, y + i * -3.3);
    stroketext1.setTextAnchor(TextAnchor.CENTER_LEFT);
    stroketext1.setBackgroundPaint(Color.white);
    stroketext1.setPaint(Color.gray);
    stroketext1.setFont(theme.getRegularFont());
    i++;

    // non-commercial results
    for (Report r : toolResults) {
      OverallResults or = r.getOverallResults();
      if (!r.isCommercial()) {
        String label = (ch == 'I' ? ch + ":  " : "" + ch + ": ");
        int score = (int) (or.getResults(category).getScore() * 100);
        String msg = "\u25A0 " + label + r.getToolName() + " (" + score + "%)";
        XYTextAnnotation stroketext3 = new XYTextAnnotation(msg, x, y + i * -3.3);
        stroketext3.setTextAnchor(TextAnchor.CENTER_LEFT);
        stroketext3.setBackgroundPaint(Color.white);
        stroketext3.setPaint(Color.blue);
        stroketext3.setFont(theme.getRegularFont());
        xyplot.addAnnotation(stroketext3);

        i++;

        ch++;
      }
    }

    // commercial average

    XYTextAnnotation stroketext2 =
        new XYTextAnnotation("\u25A0 M: Commercial Average", x, y + i * -3.3);
    stroketext2.setTextAnchor(TextAnchor.CENTER_LEFT);
    stroketext2.setBackgroundPaint(Color.white);
    stroketext2.setPaint(Color.black);
    stroketext2.setFont(theme.getRegularFont());

    xyplot.addAnnotation(stroketext);
    xyplot.addAnnotation(stroketext1);
    xyplot.addAnnotation(stroketext2);
  }