Skip to content

Commit 91a02f4

Browse files
authored
Merge pull request #35 from gingeleski/master
issue #31 address inconsistency from int cast rounding
2 parents eaa6ea8 + c908f44 commit 91a02f4

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/main/java/org/owasp/benchmark/score/report/ScatterHome.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ private void makeLegend( Set<Report> toolResults, double x, double y, XYSeriesCo
321321
String label = ( ch == 'I' || ch == 'i' ? ch + ": " : ""+ch + ": " );
322322
double score = or.getScore() * 100;
323323
if (!BenchmarkScore.showAveOnlyMode) {
324-
String msg = "\u25A0 " + label + r.getToolNameAndVersion() + " (" + (int)score + "%)";
324+
String msg = "\u25A0 " + label + r.getToolNameAndVersion() + " (" + Math.round(score) + "%)";
325325
XYTextAnnotation stroketext4 = new XYTextAnnotation(msg, x, y + i * -3.3);
326326
stroketext4.setTextAnchor(TextAnchor.CENTER_LEFT);
327327
stroketext4.setBackgroundPaint(Color.white);
@@ -346,7 +346,7 @@ private void makeLegend( Set<Report> toolResults, double x, double y, XYSeriesCo
346346
if (commercialToolCount > 1 || (BenchmarkScore.showAveOnlyMode && commercialToolCount == 1)) {
347347
double averageScore = totalScore/commercialToolCount;
348348
XYTextAnnotation stroketext2 = new XYTextAnnotation("\u25A0 " + ch
349-
+ ": Commercial Average" + " (" + (int)averageScore + "%)", x, y + i * -3.3);
349+
+ ": Commercial Average" + " (" + Math.round(averageScore) + "%)", x, y + i * -3.3);
350350
stroketext2.setTextAnchor(TextAnchor.CENTER_LEFT);
351351
stroketext2.setBackgroundPaint(Color.white);
352352
stroketext2.setPaint(Color.magenta);

src/main/java/org/owasp/benchmark/score/report/ScatterPlot.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public static XYPointerAnnotation makePointer(int x, int y, String msg, TextAnch
123123

124124
public void writeChartToFile(File f, int height) throws IOException {
125125
FileOutputStream stream = new FileOutputStream(f);
126-
ChartUtilities.writeChartAsPNG(stream, chart, (int)(height*1.4), height);
126+
ChartUtilities.writeChartAsPNG(stream, chart, (int)Math.round(height*1.4), height);
127127
stream.close();
128128
}
129129

src/main/java/org/owasp/benchmark/score/report/ScatterTools.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ private void makeLegend(OverallResults or, double x, double y, XYSeriesCollectio
202202
toolCount++;
203203
// Special hack to make it line up better if the letter is an 'I' or 'i'
204204
String label = ( ch == 'I' || ch == 'i' ? ch + ": " : ""+ch + ": " );
205-
int score = (int) (100 * (r.truePositiveRate - r.falsePositiveRate));
206-
String msg = "\u25A0 " + label + r.category + " (" + score + "%)";
205+
double score = 100 * (r.truePositiveRate - r.falsePositiveRate);
206+
String msg = "\u25A0 " + label + r.category + " (" + Math.round(score) + "%)";
207207
totalScore += score;
208208
XYTextAnnotation stroketext = new XYTextAnnotation(msg, x, y + i * -3.3);
209209
stroketext.setTextAnchor(TextAnchor.CENTER_LEFT);
@@ -218,7 +218,7 @@ private void makeLegend(OverallResults or, double x, double y, XYSeriesCollectio
218218

219219
if ( toolCount > 1 ) {
220220
double averageScore = totalScore/toolCount;
221-
XYTextAnnotation stroketext = new XYTextAnnotation("\u25A0 " + ch + ": Average Score for this Tool"+ " (" + (int)averageScore + "%)", x, y + i * -3.3);
221+
XYTextAnnotation stroketext = new XYTextAnnotation("\u25A0 " + ch + ": Average Score for this Tool"+ " (" + Math.round(averageScore) + "%)", x, y + i * -3.3);
222222
stroketext.setTextAnchor(TextAnchor.CENTER_LEFT);
223223
stroketext.setBackgroundPaint(Color.white);
224224
stroketext.setPaint(Color.magenta);

src/main/java/org/owasp/benchmark/score/report/ScatterVulns.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ private void makeLegend(String category, Set<Report> toolResults, double x, doub
301301
// Special hack to make it line up better if the letter is an 'I' or 'i'
302302
String label = ( ch == 'I' || ch == 'i' ? ch + ": " : ""+ch + ": " );
303303
double score = or.getResults(category).score * 100;
304-
String msg = "\u25A0 " + label + r.getToolNameAndVersion() + " (" + (int) score + "%)";
304+
String msg = "\u25A0 " + label + r.getToolNameAndVersion() + " (" + Math.round(score) + "%)";
305305
XYTextAnnotation stroketext3 = new XYTextAnnotation(msg, x, y + i * -3.3);
306306
stroketext3.setTextAnchor(TextAnchor.CENTER_LEFT);
307307
stroketext3.setBackgroundPaint(Color.white);
@@ -342,7 +342,7 @@ private void makeLegend(String category, Set<Report> toolResults, double x, doub
342342
if (!BenchmarkScore.showAveOnlyMode) {
343343
// Special hack to make it line up better if the letter is an 'I' or 'i'
344344
String label = ( ch == 'I' || ch == 'i' ? ch + ": " : ""+ch + ": " );
345-
String msg = "\u25A0 " + label + r.getToolNameAndVersion() + " (" + (int) score + "%)";
345+
String msg = "\u25A0 " + label + r.getToolNameAndVersion() + " (" + Math.round(score) + "%)";
346346
XYTextAnnotation stroketext4 = new XYTextAnnotation(msg, x, y + i * -3.3);
347347
stroketext4.setTextAnchor(TextAnchor.CENTER_LEFT);
348348
stroketext4.setBackgroundPaint(Color.white);
@@ -378,7 +378,7 @@ private void makeLegend(String category, Set<Report> toolResults, double x, doub
378378
if (commercialToolCount > 1 || (BenchmarkScore.showAveOnlyMode && commercialToolCount == 1)) {
379379
commercialAve = commercialTotal / commercialToolCount;
380380
XYTextAnnotation stroketext2 = new XYTextAnnotation("\u25A0 " + ch + ": Commercial Average"
381-
+ " (" + (int) commercialAve + "%)", x, y + i * -3.3);
381+
+ " (" + Math.round(commercialAve) + "%)", x, y + i * -3.3);
382382
stroketext2.setTextAnchor(TextAnchor.CENTER_LEFT);
383383
stroketext2.setBackgroundPaint(Color.white);
384384
stroketext2.setPaint(Color.magenta);
@@ -413,19 +413,19 @@ public int getCommercialToolCount() {
413413
}
414414

415415
public int getCommercialLow() {
416-
return (int) commercialLow;
416+
return (int) Math.round(commercialLow);
417417
}
418418

419419
public TestResults.ToolType getCommercialLowToolType() {
420420
return commercialLowToolType;
421421
}
422422

423423
public int getCommercialAve() {
424-
return (int) commercialAve;
424+
return (int) Math.round(commercialAve);
425425
}
426426

427427
public int getCommercialHigh() {
428-
return (int) commercialHigh;
428+
return (int) Math.round(commercialHigh);
429429
}
430430

431431
public TestResults.ToolType getCommercialHighToolType() {

0 commit comments

Comments
 (0)