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:
extensions:
- redhat.java@1.6.0
- redhat.java@1.2.0

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

@ -13,7 +13,6 @@ import java.util.regex.Pattern;
import javax.imageio.ImageIO;
public class LoveLiveReader extends Reader{
final static int REGION_PADDING = 32;
List<Box> extraRegions = new ArrayList<>();
static int lastJump=0;
public LoveLiveReader(){
@ -250,68 +249,7 @@ public class LoveLiveReader extends Reader{
//System.out.println(data[2]);
}
@Override
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) {
void interpretResults(String[] finalData) {
for (int i=0;i<finalData.length;i++) {
String[] splitter = finalData[i].split(Pattern.quote("\n"));
switch (i) {

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

@ -8,6 +8,7 @@ import java.util.List;
import java.awt.Color;
public abstract class Reader{
final static int REGION_PADDING = 32;
int score;
int rank;
int[] notes = new int[7];
@ -41,7 +42,66 @@ public abstract class Reader{
}
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) {
StringBuilder sb = new StringBuilder();
for (int i=0;i<data.length;i++) {

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