Refactor so that interpretOutput is shared. (#1)

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2, Sig, Sigo 2 years ago
parent 828035b23f
commit 8e19d17f9b
  1. 2
      .gitpod.yml
  2. 4
      readers/DDRReader.java
  3. 64
      readers/LoveLiveReader.java
  4. 5
      readers/PopnReader.java
  5. 62
      readers/Reader.java
  6. 4
      readers/SoundVoltexReader.java

@ -1,4 +1,4 @@
vscode: vscode:
extensions: extensions:
- redhat.java@1.6.0 - redhat.java@1.2.0

@ -253,8 +253,8 @@ public class DDRReader extends Reader{
} }
@Override @Override
String interpretOutput(String[] jp_data, String[] en_data) { void interpretResults(String[] finalData) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null;
} }
} }

@ -13,7 +13,6 @@ import java.util.regex.Pattern;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
public class LoveLiveReader extends Reader{ public class LoveLiveReader extends Reader{
final static int REGION_PADDING = 32;
List<Box> extraRegions = new ArrayList<>(); List<Box> extraRegions = new ArrayList<>();
static int lastJump=0; static int lastJump=0;
public LoveLiveReader(){ public LoveLiveReader(){
@ -250,68 +249,7 @@ public class LoveLiveReader extends Reader{
//System.out.println(data[2]); //System.out.println(data[2]);
} }
@Override void interpretResults(String[] finalData) {
String interpretOutput(String[] jp_data,String[] en_data) {
//[6, 0, 218, 0, 218, 48, 6, 48, 32 5 4 1 5, 0.9670235803680689]
//For each data point we want to first see if it's within the correct rectangular bounds and from there parse it as such.
double[] accuracy = new double[readRegions.size()];
String[] finalData = new String[readRegions.size()];
for (int i=0;i<finalData.length;i++) {
finalData[i]="";
}
for (int i=0;i<en_data.length;i+=10) {
int spacing=0;
for (int j=0;j<readRegions.size();j++) {
int midpoint=(Integer.parseInt(en_data[i+1])+Integer.parseInt(en_data[i+5]))/2;
if (midpoint>=spacing&&midpoint<=spacing+readRegions.get(j).h+REGION_PADDING
/*&&accuracy[j]<Double.parseDouble(en_data[i+9]) Only for jp string testing.*/) {
System.out.print("[");
for (int k=0;k<10;k++) {
if (k!=0) {
System.out.print(",");
}
System.out.print(en_data[i+k]);
}
System.out.print("]");
System.out.println(" belongs to region "+j+".");
finalData[j]=finalData[j]+"\n"+en_data[i+8];
accuracy[j]=Double.parseDouble(en_data[i+9]);
break;
}
spacing+=readRegions.get(j).h+REGION_PADDING;
}
}
for (int i=0;i<jp_data.length;i+=10) {
int spacing=0;
for (int j=0;j<readRegions.size();j++) {
int midpoint=(Integer.parseInt(jp_data[i+1])+Integer.parseInt(jp_data[i+5]))/2;
if (midpoint>=spacing&&midpoint<=spacing+readRegions.get(j).h+REGION_PADDING
&&accuracy[j]<Double.parseDouble(jp_data[i+9])) {
System.out.print("JP[");
for (int k=0;k<10;k++) {
if (k!=0) {
System.out.print(",");
}
System.out.print(jp_data[i+k]);
}
System.out.print("]");
System.out.println(" belongs to region "+j+".");
if (accuracy[j]!=0) {
finalData[j]="";
}
finalData[j]=finalData[j]+"\n"+jp_data[i+8];
accuracy[j]=0;
break;
}
spacing+=readRegions.get(j).h+REGION_PADDING;
}
}
System.out.println(Arrays.toString(finalData));
interpretResults(finalData);
return null;
}
private void interpretResults(String[] finalData) {
for (int i=0;i<finalData.length;i++) { for (int i=0;i<finalData.length;i++) {
String[] splitter = finalData[i].split(Pattern.quote("\n")); String[] splitter = finalData[i].split(Pattern.quote("\n"));
switch (i) { switch (i) {

@ -13,7 +13,6 @@ import java.util.regex.Pattern;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
public class PopnReader extends Reader{ public class PopnReader extends Reader{
final static int REGION_PADDING = 32;
List<Box> extraRegions = new ArrayList<>(); List<Box> extraRegions = new ArrayList<>();
static int lastJump=0; static int lastJump=0;
public PopnReader(){ public PopnReader(){
@ -189,8 +188,8 @@ public class PopnReader extends Reader{
} }
@Override @Override
String interpretOutput(String[] jp_data, String[] en_data) { void interpretResults(String[] finalData) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null;
} }
} }

@ -8,6 +8,7 @@ import java.util.List;
import java.awt.Color; import java.awt.Color;
public abstract class Reader{ public abstract class Reader{
final static int REGION_PADDING = 32;
int score; int score;
int rank; int rank;
int[] notes = new int[7]; int[] notes = new int[7];
@ -41,7 +42,66 @@ public abstract class Reader{
} }
return ""; return "";
} }
abstract String interpretOutput(String[] jp_data,String[] en_data); String interpretOutput(String[] jp_data,String[] en_data) {
//[6, 0, 218, 0, 218, 48, 6, 48, 32 5 4 1 5, 0.9670235803680689]
//For each data point we want to first see if it's within the correct rectangular bounds and from there parse it as such.
double[] accuracy = new double[readRegions.size()];
String[] finalData = new String[readRegions.size()];
for (int i=0;i<finalData.length;i++) {
finalData[i]="";
}
for (int i=0;i<en_data.length;i+=10) {
int spacing=0;
for (int j=0;j<readRegions.size();j++) {
int midpoint=(Integer.parseInt(en_data[i+1])+Integer.parseInt(en_data[i+5]))/2;
if (midpoint>=spacing&&midpoint<=spacing+readRegions.get(j).h+REGION_PADDING
/*&&accuracy[j]<Double.parseDouble(en_data[i+9]) Only for jp string testing.*/) {
System.out.print("[");
for (int k=0;k<10;k++) {
if (k!=0) {
System.out.print(",");
}
System.out.print(en_data[i+k]);
}
System.out.print("]");
System.out.println(" belongs to region "+j+".");
finalData[j]=finalData[j]+"\n"+en_data[i+8];
accuracy[j]=Double.parseDouble(en_data[i+9]);
break;
}
spacing+=readRegions.get(j).h+REGION_PADDING;
}
}
for (int i=0;i<jp_data.length;i+=10) {
int spacing=0;
for (int j=0;j<readRegions.size();j++) {
int midpoint=(Integer.parseInt(jp_data[i+1])+Integer.parseInt(jp_data[i+5]))/2;
if (midpoint>=spacing&&midpoint<=spacing+readRegions.get(j).h+REGION_PADDING
&&accuracy[j]<Double.parseDouble(jp_data[i+9])) {
System.out.print("JP[");
for (int k=0;k<10;k++) {
if (k!=0) {
System.out.print(",");
}
System.out.print(jp_data[i+k]);
}
System.out.print("]");
System.out.println(" belongs to region "+j+".");
if (accuracy[j]!=0) {
finalData[j]="";
}
finalData[j]=finalData[j]+"\n"+jp_data[i+8];
accuracy[j]=0;
break;
}
spacing+=readRegions.get(j).h+REGION_PADDING;
}
}
System.out.println(Arrays.toString(finalData));
interpretResults(finalData);
return null;
};
abstract void interpretResults(String[] finalData);
void trimAllData(String[] data) { void trimAllData(String[] data) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i=0;i<data.length;i++) { for (int i=0;i<data.length;i++) {

@ -402,8 +402,8 @@ public class SoundVoltexReader extends Reader{
} }
@Override @Override
String interpretOutput(String[] jp_data, String[] en_data) { void interpretResults(String[] finalData) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null;
} }
} }
Loading…
Cancel
Save