Refactored code to output scores more reliably in sacrificing name reporting accuracy

master
Joshua Sigona 4 years ago
parent 2be19b9064
commit e68645a73c
  1. BIN
      d4dj_rankTracker.jar
  2. BIN
      paragraph2.png
  3. BIN
      paragraph3.png
  4. 6
      src/main/java/d4dj/d4dj/Annotation.java
  5. 207
      src/main/java/d4dj/d4dj/App.java
  6. BIN
      target/classes/d4dj/d4dj/Annotation.class
  7. BIN
      target/classes/d4dj/d4dj/App.class
  8. BIN
      target/classes/d4dj/d4dj/SubmitThread.class
  9. BIN
      testing_leaderboardnames.png

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B

@ -0,0 +1,6 @@
package d4dj.d4dj;
public class Annotation {
String text;
String vertices;
}

@ -51,10 +51,10 @@ import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import sig.utils.ImageUtils;
class SubmitThread implements Runnable{
String name,description,points;
int event,rank;
String name,description;
int event,rank,points;
SubmitThread(String name,String description,String points,int event,int rank) {
SubmitThread(String name,String description,int points,int event,int rank) {
this.name=name;
this.description=description;
this.points=points;
@ -71,7 +71,7 @@ class SubmitThread implements Runnable{
params.add(new BasicNameValuePair("rank", Integer.toString(rank)));
params.add(new BasicNameValuePair("name", name));
params.add(new BasicNameValuePair("description", description));
params.add(new BasicNameValuePair("points", points));
params.add(new BasicNameValuePair("points", Integer.toString(points)));
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (UnsupportedEncodingException e) {
@ -101,8 +101,8 @@ class SubmitThread implements Runnable{
}
public class App
{
public static Image paragraph;
final static int EVENT = 11;
public static Image paragraph,paragraph2,paragraph3;
final static int EVENT = 12;
public static int[] lastScores = new int[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
public static int[] lastLowerTierScores = new int[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
@ -163,13 +163,15 @@ public class App
Image leaderboard4 = ImageIO.read(list[3]);
Image leaderboard5 = ImageIO.read(list[4]);
paragraph = ImageIO.read(new File("paragraph.png"));
paragraph2 = ImageIO.read(new File("paragraph2.png"));
paragraph3 = ImageIO.read(new File("paragraph3.png"));
BufferedImage cropped1 = new BufferedImage(360,26*114,BufferedImage.TYPE_INT_ARGB);
Graphics2D g = cropped1.createGraphics();
//For comments: down by 40, width is 340.
for (int i=0;i<cropPoints1.length;i++) {
drawData(g,leaderboard, 20, i*26, 200, i*26+26, cropPoints1[i].x, cropPoints1[i].y, cropPoints1[i].x+cropPoints1[i].width, cropPoints1[i].y+cropPoints1[i].height, null);
drawData(g,leaderboard, 20, (i+20)*26, 340, (i+20)*26+26, cropPoints1[i].x, cropPoints1[i].y+40, cropPoints1[i].x+340, cropPoints1[i].y+cropPoints1[i].height+40, null);
drawData(g,leaderboard, 40, (i+40)*26, 150, (i+40)*26+24, cropPoints1[i].x+351, cropPoints1[i].y+34, cropPoints1[i].x+481, cropPoints1[i].y+58, null);
drawData(g,1,leaderboard, 20, (i+38)*26, 200, (i+38)*26+26, cropPoints1[i].x, cropPoints1[i].y, cropPoints1[i].x+cropPoints1[i].width, cropPoints1[i].y+cropPoints1[i].height, null);
drawData(g,2,leaderboard, 20, (i+76)*26, 340, (i+76)*26+26, cropPoints1[i].x, cropPoints1[i].y+40, cropPoints1[i].x+340, cropPoints1[i].y+cropPoints1[i].height+40, null);
drawData(g,0,leaderboard, 40, (i)*26, 150, (i)*26+24, cropPoints1[i].x+351, cropPoints1[i].y+34, cropPoints1[i].x+481, cropPoints1[i].y+58, null);
}
@ -205,24 +207,24 @@ public class App
int YOFFSET = YMarker+1;
for (int i=0;i<cropPoints2.length;i++) {
drawData(g,leaderboard2, 20, (i+9)*26, 200, (i+9)*26+26, cropPoints2[i].x, YOFFSET+cropPoints2[i].y, cropPoints2[i].x+cropPoints2[i].width, YOFFSET+cropPoints2[i].y+cropPoints2[i].height, null);
drawData(g,leaderboard2, 20, (i+29)*26, 340, (i+29)*26+26, cropPoints2[i].x, YOFFSET+cropPoints2[i].y+40, cropPoints2[i].x+340, YOFFSET+cropPoints2[i].y+cropPoints2[i].height+40, null);
drawData(g,leaderboard2, 40, (i+49)*26, 150, (i+49)*26+24, cropPoints2[i].x+351, YOFFSET+cropPoints2[i].y+34, cropPoints2[i].x+481, YOFFSET+cropPoints2[i].y+58, null);
drawData(g,1,leaderboard2, 20, (i+47)*26, 200, (i+47)*26+26, cropPoints2[i].x, YOFFSET+cropPoints2[i].y, cropPoints2[i].x+cropPoints2[i].width, YOFFSET+cropPoints2[i].y+cropPoints2[i].height, null);
drawData(g,2,leaderboard2, 20, (i+85)*26, 340, (i+85)*26+26, cropPoints2[i].x, YOFFSET+cropPoints2[i].y+40, cropPoints2[i].x+340, YOFFSET+cropPoints2[i].y+cropPoints2[i].height+40, null);
drawData(g,0,leaderboard2, 40, (i+9)*26, 150, (i+9)*26+24, cropPoints2[i].x+351, YOFFSET+cropPoints2[i].y+34, cropPoints2[i].x+481, YOFFSET+cropPoints2[i].y+58, null);
}
for (int i=0;i<cropPoints3.length;i++) {
drawData(g,leaderboard3, 20, (i+11)*26, 200, (i+11)*26+26, cropPoints3[i].x, cropPoints3[i].y, cropPoints3[i].x+cropPoints3[i].width, cropPoints3[i].y+cropPoints3[i].height, null);
drawData(g,leaderboard3, 20, (i+31)*26, 340, (i+31)*26+26, cropPoints3[i].x, cropPoints3[i].y+40, cropPoints3[i].x+340, cropPoints3[i].y+cropPoints3[i].height+40, null);
drawData(g,leaderboard3, 40, (i+51)*26, 150, (i+51)*26+24, cropPoints3[i].x+351, cropPoints3[i].y+34, cropPoints3[i].x+481, cropPoints3[i].y+58, null);
drawData(g,1,leaderboard3, 20, (i+49)*26, 200, (i+49)*26+26, cropPoints3[i].x, cropPoints3[i].y, cropPoints3[i].x+cropPoints3[i].width, cropPoints3[i].y+cropPoints3[i].height, null);
drawData(g,2,leaderboard3, 20, (i+87)*26, 340, (i+87)*26+26, cropPoints3[i].x, cropPoints3[i].y+40, cropPoints3[i].x+340, cropPoints3[i].y+cropPoints3[i].height+40, null);
drawData(g,0,leaderboard3, 40, (i+11)*26, 150, (i+11)*26+24, cropPoints3[i].x+351, cropPoints3[i].y+34, cropPoints3[i].x+481, cropPoints3[i].y+58, null);
}
for (int i=0;i<cropPoints1.length;i++) {
drawData(g,leaderboard4, 20, (i+60)*26, 200, (i+60)*26+26, cropPoints1[i].x, cropPoints1[i].y, cropPoints1[i].x+cropPoints1[i].width, cropPoints1[i].y+cropPoints1[i].height, null);
drawData(g,leaderboard4, 20, (i+78)*26, 340, (i+78)*26+26, cropPoints1[i].x, cropPoints1[i].y+40, cropPoints1[i].x+340, cropPoints1[i].y+cropPoints1[i].height+40, null);
drawData(g,leaderboard4, 40, (i+96)*26, 150, (i+96)*26+24, cropPoints1[i].x+351, cropPoints1[i].y+34, cropPoints1[i].x+481, cropPoints1[i].y+58, null);
drawData(g,1,leaderboard4, 20, (i+58)*26, 200, (i+58)*26+26, cropPoints1[i].x, cropPoints1[i].y, cropPoints1[i].x+cropPoints1[i].width, cropPoints1[i].y+cropPoints1[i].height, null);
drawData(g,2,leaderboard4, 20, (i+96)*26, 340, (i+96)*26+26, cropPoints1[i].x, cropPoints1[i].y+40, cropPoints1[i].x+340, cropPoints1[i].y+cropPoints1[i].height+40, null);
drawData(g,0,leaderboard4, 40, (i+20)*26, 150, (i+20)*26+24, cropPoints1[i].x+351, cropPoints1[i].y+34, cropPoints1[i].x+481, cropPoints1[i].y+58, null);
}
for (int i=0;i<cropPoints3.length;i++) {
drawData(g,leaderboard5, 20, (i+69)*26, 200, (i+69)*26+26, cropPoints3[i].x, cropPoints3[i].y, cropPoints3[i].x+cropPoints3[i].width, cropPoints3[i].y+cropPoints3[i].height, null);
drawData(g,leaderboard5, 20, (i+87)*26, 340, (i+87)*26+26, cropPoints3[i].x, cropPoints3[i].y+40, cropPoints3[i].x+340, cropPoints3[i].y+cropPoints3[i].height+40, null);
drawData(g,leaderboard5, 40, (i+105)*26, 150, (i+105)*26+24, cropPoints3[i].x+351, cropPoints3[i].y+34, cropPoints3[i].x+481, cropPoints3[i].y+58, null);
drawData(g,1,leaderboard5, 20, (i+67)*26, 200, (i+67)*26+26, cropPoints3[i].x, cropPoints3[i].y, cropPoints3[i].x+cropPoints3[i].width, cropPoints3[i].y+cropPoints3[i].height, null);
drawData(g,2,leaderboard5, 20, (i+105)*26, 340, (i+105)*26+26, cropPoints3[i].x, cropPoints3[i].y+40, cropPoints3[i].x+340, cropPoints3[i].y+cropPoints3[i].height+40, null);
drawData(g,0,leaderboard5, 40, (i+29)*26, 150, (i+29)*26+24, cropPoints3[i].x+351, cropPoints3[i].y+34, cropPoints3[i].x+481, cropPoints3[i].y+58, null);
}
ImageIO.write(cropped1,"png",new File("testing_leaderboardnames.png"));
g.dispose();
@ -258,9 +260,19 @@ public class App
}
}
private static void drawData(Graphics2D g, Image leaderboard, int i, int j, int k, int l, int x, int y, int m,
private static void drawData(Graphics2D g, int type,Image leaderboard, int i, int j, int k, int l, int x, int y, int m,
int n, ImageObserver object) {
g.drawImage(paragraph, 0, j, 18, l, 0, 0, 18, 23, object);
switch (type) {
case 0:{
g.drawImage(paragraph, 0, j, 18, l, 0, 0, 18, 23, object);
}break;
case 1:{
g.drawImage(paragraph2, 0, j, 18, l, 0, 0, 18, 23, object);
}break;
case 2:{
g.drawImage(paragraph3, 0, j, 18, l, 0, 0, 18, 23, object);
}break;
}
g.drawImage(leaderboard, i, j, k, l, x, y, m, n, object);
}
@ -280,6 +292,7 @@ public class App
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
StringBuilder reader = new StringBuilder();
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
List<AnnotateImageResponse> responses = response.getResponsesList();
@ -293,105 +306,95 @@ public class App
// For full list of available annotations, see http://g.co/cloud/vision/docs
for (EntityAnnotation annotation : res.getTextAnnotationsList()) {
reader.append(annotation.getDescription());
//System.out.format("Position : %s%n", annotation.getBoundingPoly());
break;
//System.out.println(annotation.getDescription());
//System.out.format("Text: %s%n", annotation.getDescription());
//System.out.format("Position : %s%n", annotation.getBoundingPoly());
}
}
client.close();
}
//System.out.println(reader);
List<String> descriptions = new ArrayList<String>();
List<String> names = new ArrayList<String>();
List<Integer> scores = new ArrayList<Integer>();
int[] ranks = new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
50,100,500,1000,2000,5000,10000,20000,30000,50000};
String[] s = reader.toString().split("\n");
String[] data = new String[s.length];
int count=0;
boolean scoreNext=false;
for (String ss : s) {
//System.out.println(ss.replaceFirst("A","").trim());
String newString = ss.replaceFirst("A","").trim();
data[count++]=newString;
}
System.out.println(Arrays.toString(data));
String[] t20names = new String[20];
int arrayOffset = 0;
for (int i=0;i<20;i++) {
t20names[i]=data[arrayOffset++];
}
String[] t20desc = new String[20];
for (int i=0;i<20;i++) {
t20desc[i]=data[arrayOffset++];
}
String[] t20scores = new String[20];
for (int i=0;i<20;i++) {
if (data[arrayOffset+1].length()>0) {
arrayOffset++;
//String newString = ss;//.replaceFirst("A","").trim();
if (StringUtils.isNumeric(ss)) {
if (scores.size()>20) {
//See if this score is already in list.
int thisScore = Integer.parseInt(ss);
boolean found=false;
for (int i=0;i<scores.size();i++) {
if (thisScore==scores.get(i)) {
found=true;
break;
}
}
if (!found&&scores.size()<ranks.length) {
scores.add(thisScore);
}
} else {
scores.add(Integer.parseInt(ss));
}
} else
if (ss.charAt(0)=='A') {
//Expect the next value to be a score.
//scoreNext=true;
} else
if (ss.charAt(0)=='B') {
//Expect the next value to be a score.
//scoreNext=true;
String newString = ss.replaceFirst("B","").trim();
names.add(newString);
} else
if (ss.charAt(0)=='C') {
//Expect the next value to be a score.
//scoreNext=true;
String newString = ss.replaceFirst("C","").trim();
descriptions.add(newString);
}
t20scores[i]=data[arrayOffset++];
//data[count++]=newString;
}
String[] tempLowerTierNames = new String[18];
for (int i=0;i<18;i++) {
tempLowerTierNames[i]=data[arrayOffset++];
for (int i=0;i<scores.size();i++) {
//System.out.println(names.get(i)+": "+scores.get(i)+" "+descriptions.get(i));
String desc = (descriptions.size()>i)?descriptions.get(i):"";
String name = (names.size()>i)?names.get(i):"";
System.out.println(ranks[i]+"-"+name+": "+scores.get(i));
new Thread(
new SubmitThread(name,desc,scores.get(i),EVENT,ranks[i]))
.start();
}
String[] tempLowerTierDesc = new String[18];
for (int i=0;i<18;i++) {
tempLowerTierDesc[i]=data[arrayOffset++];
}
String[] tempLowerTierScores = new String[18];
for (int i=0;i<18;i++) {
if (data[arrayOffset+1].length()>0) {
arrayOffset++;
}
tempLowerTierScores[i]=data[arrayOffset++];
}
//System.out.println(Arrays.toString(t20scores));
//System.out.println(Arrays.toString(tempLowerTierScores));
//Lower tier order is: 50,100,500,1000,2000,5000,10000,20000,30000,50000
String[] lowerTierNames = new String[]{"","","","","","","","","",""};
String[] lowerTierDesc = new String[]{"","","","","","","","","",""};
String[] lowerTierScores = new String[]{"0","0","0","0","0","0","0","0","0","0"};
/*System.out.println(scores);
System.out.println(names);
System.out.println(descriptions);*/
for (int i=0;i<9;i++) {
lowerTierNames[i]=tempLowerTierNames[i];
lowerTierDesc[i]=tempLowerTierDesc[i];
lowerTierScores[i]=tempLowerTierScores[i];
}
for (int i=9;i<18;i++) {
//Look at the upper tier scores, if it exists we skip it.
boolean exists=false;
for (int j=0;j<9;j++) {
if (tempLowerTierScores[i].equalsIgnoreCase(tempLowerTierScores[j])) {
exists=true;
break;
}
}
if (!exists) {
lowerTierNames[9]=tempLowerTierNames[i];
lowerTierDesc[9]=tempLowerTierDesc[i];
lowerTierScores[9]=tempLowerTierScores[i];
break;
}
}
System.out.println(Arrays.toString(t20scores));
System.out.println(Arrays.toString(lowerTierScores));
boolean error1=false;
for (int i=0;i<20;i++) {
if (!StringUtils.isNumeric(t20scores[i])) {
error1=true;
break;
}
}//227
boolean error2=false;
for (int i=0;i<10;i++) {
if (!StringUtils.isNumeric(lowerTierScores[i])) {
error2=true;
break;
/*
for (int i=0;i<data.length;i++) {
//System.out.print(data[i].length()+",");
if (data[i].length()>0) {
if (scores.size()<)
}
}
}*/
//System.out.println(Arrays.toString(t20scores));
//System.out.println(Arrays.toString(tempLowerTierScores));
//Lower tier order is: 50,100,500,1000,2000,5000,10000,20000,30000,50000
/*
if (!error1) {
for (int i=0;i<20;i++) {
new Thread(
@ -417,7 +420,7 @@ public class App
} else {
System.out.println("Cannot submit lower tier scores. Invalid array params.");
}
*/
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 259 KiB

After

Width:  |  Height:  |  Size: 280 KiB

Loading…
Cancel
Save