Implement start of database storage system. (#8)

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2, Sig, Sigo 2 years ago
parent a6b87b6713
commit ca6095fe04
  1. 142
      ArcadeReader.java
  2. 16
      readers/DDRReader.java
  3. 50
      readers/Reader.java
  4. BIN
      result.png
  5. 12
      sigPlace.java
  6. BIN
      sub.png

@ -1,5 +1,10 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
@ -131,40 +136,45 @@ public class ArcadeReader {
final static int SDVX_B=7;
final static int SDVX_C=8;
final static int SDVX_D=9;
static Reader interpret(String filename) {
static Reader interpret(Path p) {
BufferedImage img;
try {
BufferedImage img = ImageIO.read(Paths.get("tests",filename).toFile());
if (img.getHeight()>img.getWidth()) {
return new SoundVoltexReader();
} else {
Color col1 = new Color(img.getRGB(31, 41),true);
ColorRange range1 = new ColorRange(245,255,235,240,70,80);
Color col2 = new Color(img.getRGB(27, 1012),true);
ColorRange range2 = new ColorRange(245,255,160,170,195,205);
if (range1.colorInRange(col1)) {
return new PopnReader();
}
if (col1.equals(Color.BLACK)) {
return new DDRReader();
}
if (col1.equals(Color.WHITE)) {
return new ITGReader();
}
if (range2.colorInRange(col2)) {
return new LoveLiveReader();
}
}
img = ImageIO.read(p.toFile());
return interpret(img);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
static Reader interpret(BufferedImage img) {
if (img.getHeight()>img.getWidth()) {
return new SoundVoltexReader();
} else {
Color col1 = new Color(img.getRGB(31, 41),true);
ColorRange range1 = new ColorRange(245,255,235,240,70,80);
Color col2 = new Color(img.getRGB(27, 1012),true);
ColorRange range2 = new ColorRange(245,255,160,170,195,205);
if (range1.colorInRange(col1)) {
return new PopnReader();
}
if (col1.equals(Color.BLACK)) {
return new DDRReader();
}
if (col1.equals(Color.WHITE)) {
return new ITGReader();
}
if (range2.colorInRange(col2)) {
return new LoveLiveReader();
}
}
return null;
}
static void test(String filename,Class<?> reader,int score,int rank,int[] notes,int diff,double pct,int maxcombo){
test(filename,reader,score,rank,notes,diff,pct,maxcombo,"");
}
static void test(String filename,Class<?> reader,int score,int rank,int[] notes,int diff,double pct,int maxcombo,String other){
testCount++;
Reader r = interpret(filename);
Reader r = interpret(Paths.get("tests",filename));
r.interpretBoxes(Paths.get("tests",filename),true);
Reader compare = new TestReader(score,rank,notes,diff,pct,maxcombo,other);
if (!reader.isInstance(r)) {
@ -175,6 +185,10 @@ public class ArcadeReader {
ArcadeReader.err(new Exception("Test \""+filename+"\" Failed:\nExpected:"+compare+"\nActual:"+r));
return;
}
if (gamePath(r)==null) {
ArcadeReader.err(new Exception("Test \""+filename+"\" Failed:\nReason: gamePath for this reader type ("+r.getClass().getSimpleName()+") does not exist. Check the gamePath() function!"));
return;
}
ArcadeReader.success();
}
@ -651,4 +665,86 @@ public class ArcadeReader {
21/*maxcombo*/,
"{\"ex\":457,\"chip_scritical\":13,\"chip_critical\":15,\"chip_near\":31,\"chip_error\":201,\"long_scritical\":44,\"long_error\":241,\"vol_scritical\":91,\"vol_error\":272,\"failed\":true}"/*other*/);
}
public static Path gamePath(Reader data) {
switch (data.getClass().getSimpleName()) {
case "DDRReader":{
return Paths.get("database","ddr");
}
case "ITGReader":{
return Paths.get("database","itg");
}
case "LoveLiveReader":{
return Paths.get("database","lovelive");
}
case "PopnReader":{
return Paths.get("database","popn");
}
case "SoundVoltexReader":{
return Paths.get("database","sdvx");
}
}
return null;
}
public static int getScore(String record) {
String searchString = "\"score\":";
int index = record.indexOf(searchString)+searchString.length();
int endIndex=record.indexOf(",",index);
return Integer.parseInt(record.substring(index,endIndex));
}
public static String convertTitle(String str) {
return str.replaceAll(Pattern.quote("#"),"")
.replaceAll(Pattern.quote("%"),"")
.replaceAll(Pattern.quote("&"),"")
.replaceAll(Pattern.quote("{"),"")
.replaceAll(Pattern.quote("}"),"")
.replaceAll(Pattern.quote("\\"),"")
.replaceAll(Pattern.quote("<"),"")
.replaceAll(Pattern.quote(">"),"")
.replaceAll(Pattern.quote("*"),"")
.replaceAll(Pattern.quote("\""),"")
.replaceAll(Pattern.quote("?"),"")
.replaceAll(Pattern.quote("'"),"")
.replaceAll(Pattern.quote("/"),"")
.replaceAll(Pattern.quote("$"),"")
.replaceAll(Pattern.quote("!"),"")
.replaceAll(Pattern.quote(":"),"")
.replaceAll(Pattern.quote("@"),"")
.replaceAll(Pattern.quote("+"),"")
.replaceAll(Pattern.quote("`"),"")
.replaceAll(Pattern.quote("|"),"")
.replaceAll(Pattern.quote("="),"");
}
public static void submitToDatabase(Path p) {
//First we read and interpret what this image is.
BufferedImage img;
try {
img = ImageIO.read(p.toFile());
Reader newImg = interpret(img);
Path getGamePath = gamePath(newImg);
newImg.interpretBoxes(p);
HashMap<String,HashMap<String,List<String>>> DATA = sigPlace.SONG_DATABASE;
HashMap<String,List<String>> SONG_DATA=DATA.getOrDefault(newImg.getClass().getSimpleName(),new HashMap<>());
List<String> RECORDS = SONG_DATA.getOrDefault(convertTitle(newImg.getTitle()),new ArrayList<>());
boolean found=false;
for (int i=0;i<RECORDS.size();i++) {
String s = RECORDS.get(i);
int score = getScore(s);
if (score<newImg.getScore()) {
//Insert here.
found=true;
RECORDS.add(i, newImg.toString());
break;
}
}
if (!found) {
RECORDS.add(newImg.toString());
}
SONG_DATA.put(convertTitle(newImg.getTitle()),RECORDS);
DATA.put(newImg.getClass().getSimpleName(),SONG_DATA);
System.out.println(DATA);
} catch (IOException e) {
e.printStackTrace();
}
}
}

@ -281,17 +281,17 @@ public class DDRReader extends Reader{
} else
if (score>=990000) {rank=0;/*AAA*/} else
if (score>=950000) {rank=1;/*AA+*/} else
if (score>=900000) {rank=2;/*AA*/} else
//if (score>=890000) {rank=3;/*AA-*/} else
if (score>=910000) {rank=2;/*AA*/} else
if (score>=900000) {rank=3;/*AA-*/} else
if (score>=850000) {rank=4;/*A+*/} else
if (score>=800000) {rank=5;/*A*/} else
//if (score>=790000) {rank=6;/*A-*/} else
if (score>=810000) {rank=5;/*A*/} else
if (score>=800000) {rank=6;/*A-*/} else
if (score>=750000) {rank=7;/*B+*/} else
if (score>=700000) {rank=8;/*B*/} else
//if (score>=690000) {rank=9;/*B-*/} else
if (score>=710000) {rank=8;/*B*/} else
if (score>=700000) {rank=9;/*B-*/} else
if (score>=650000) {rank=10;/*C+*/} else
if (score>=600000) {rank=11;/*C*/} else
//if (score>=590000) {rank=12;/*C-*/} else
if (score>=610000) {rank=11;/*C*/} else
if (score>=600000) {rank=12;/*C-*/} else
if (score>=550000) {rank=13;/*D+*/} else
{rank=14;/*D*/}
}break;

@ -258,7 +258,7 @@ public abstract class Reader{
};
String convertToString(String[]data){
return String.join("\n",data).replaceFirst(Pattern.quote("\n"),"");
return String.join(" ",data).replaceFirst(Pattern.quote(" "),"");
}
double convertToDouble(String[]data){return convertToDouble("",data);}
@ -339,6 +339,54 @@ public abstract class Reader{
+ ", \"other\":" + other + ", \"pct\":" + pct + ", \"rank\":" + rank + ", \"score\":" + score + ", \"title\":\"" + title.replaceAll(Pattern.quote("\n"),"\\\\n")
+ "\"}";
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public int getRank() {
return rank;
}
public void setRank(int rank) {
this.rank = rank;
}
public int[] getNotes() {
return notes;
}
public void setNotes(int[] notes) {
this.notes = notes;
}
public int getDifficulty() {
return difficulty;
}
public void setDifficulty(int difficulty) {
this.difficulty = difficulty;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public double getPct() {
return pct;
}
public void setPct(double pct) {
this.pct = pct;
}
public int getMaxcombo() {
return maxcombo;
}
public void setMaxcombo(int maxcombo) {
this.maxcombo = maxcombo;
}
public String getOther() {
return other;
}
public void setOther(String other) {
this.other = other;
}
@Override
public int hashCode() {
final int prime = 31;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 KiB

After

Width:  |  Height:  |  Size: 161 KiB

@ -36,6 +36,8 @@ public class sigPlace {
static int PORT = 8080;
static String SECRET = "";
final static HashMap<String,HashMap<String,List<String>>> SONG_DATABASE = new HashMap<>();
static double COLOR_ROTATION = 0;
static boolean inCodeBlock = false;
@ -118,10 +120,12 @@ public class sigPlace {
e.printStackTrace();
}*/
//new PopnReader().interpretBoxes(Paths.get("tests","popn8.png"),true);
ArcadeReader.runTests();
PopnReader p = new PopnReader();
p.interpretBoxes(Paths.get("tests","popn8.png"));
System.out.println(p);
//ArcadeReader.runTests();
BufferedImage img;
ArcadeReader.submitToDatabase(Paths.get("tests","popn8.png"));
ArcadeReader.submitToDatabase(Paths.get("tests","popn7.png"));
ArcadeReader.submitToDatabase(Paths.get("tests","popn6.png"));
ArcadeReader.submitToDatabase(Paths.get("tests","popn5.png"));
/* Path secretFile = Paths.get(".clientsecret");
List<String> data;
try {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Loading…
Cancel
Save