Implement start of database storage system. (#8)
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
a6b87b6713
commit
ca6095fe04
@ -1,5 +1,10 @@
|
|||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
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;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
@ -131,9 +136,17 @@ public class ArcadeReader {
|
|||||||
final static int SDVX_B=7;
|
final static int SDVX_B=7;
|
||||||
final static int SDVX_C=8;
|
final static int SDVX_C=8;
|
||||||
final static int SDVX_D=9;
|
final static int SDVX_D=9;
|
||||||
static Reader interpret(String filename) {
|
static Reader interpret(Path p) {
|
||||||
|
BufferedImage img;
|
||||||
try {
|
try {
|
||||||
BufferedImage img = ImageIO.read(Paths.get("tests",filename).toFile());
|
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()) {
|
if (img.getHeight()>img.getWidth()) {
|
||||||
return new SoundVoltexReader();
|
return new SoundVoltexReader();
|
||||||
} else {
|
} else {
|
||||||
@ -154,9 +167,6 @@ public class ArcadeReader {
|
|||||||
return new LoveLiveReader();
|
return new LoveLiveReader();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
static void test(String filename,Class<?> reader,int score,int rank,int[] notes,int diff,double pct,int maxcombo){
|
static void test(String filename,Class<?> reader,int score,int rank,int[] notes,int diff,double pct,int maxcombo){
|
||||||
@ -164,7 +174,7 @@ public class ArcadeReader {
|
|||||||
}
|
}
|
||||||
static void test(String filename,Class<?> reader,int score,int rank,int[] notes,int diff,double pct,int maxcombo,String other){
|
static void test(String filename,Class<?> reader,int score,int rank,int[] notes,int diff,double pct,int maxcombo,String other){
|
||||||
testCount++;
|
testCount++;
|
||||||
Reader r = interpret(filename);
|
Reader r = interpret(Paths.get("tests",filename));
|
||||||
r.interpretBoxes(Paths.get("tests",filename),true);
|
r.interpretBoxes(Paths.get("tests",filename),true);
|
||||||
Reader compare = new TestReader(score,rank,notes,diff,pct,maxcombo,other);
|
Reader compare = new TestReader(score,rank,notes,diff,pct,maxcombo,other);
|
||||||
if (!reader.isInstance(r)) {
|
if (!reader.isInstance(r)) {
|
||||||
@ -175,6 +185,10 @@ public class ArcadeReader {
|
|||||||
ArcadeReader.err(new Exception("Test \""+filename+"\" Failed:\nExpected:"+compare+"\nActual:"+r));
|
ArcadeReader.err(new Exception("Test \""+filename+"\" Failed:\nExpected:"+compare+"\nActual:"+r));
|
||||||
return;
|
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();
|
ArcadeReader.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -651,4 +665,86 @@ public class ArcadeReader {
|
|||||||
21/*maxcombo*/,
|
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*/);
|
"{\"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
|
} else
|
||||||
if (score>=990000) {rank=0;/*AAA*/} else
|
if (score>=990000) {rank=0;/*AAA*/} else
|
||||||
if (score>=950000) {rank=1;/*AA+*/} else
|
if (score>=950000) {rank=1;/*AA+*/} else
|
||||||
if (score>=900000) {rank=2;/*AA*/} else
|
if (score>=910000) {rank=2;/*AA*/} else
|
||||||
//if (score>=890000) {rank=3;/*AA-*/} else
|
if (score>=900000) {rank=3;/*AA-*/} else
|
||||||
if (score>=850000) {rank=4;/*A+*/} else
|
if (score>=850000) {rank=4;/*A+*/} else
|
||||||
if (score>=800000) {rank=5;/*A*/} else
|
if (score>=810000) {rank=5;/*A*/} else
|
||||||
//if (score>=790000) {rank=6;/*A-*/} else
|
if (score>=800000) {rank=6;/*A-*/} else
|
||||||
if (score>=750000) {rank=7;/*B+*/} else
|
if (score>=750000) {rank=7;/*B+*/} else
|
||||||
if (score>=700000) {rank=8;/*B*/} else
|
if (score>=710000) {rank=8;/*B*/} else
|
||||||
//if (score>=690000) {rank=9;/*B-*/} else
|
if (score>=700000) {rank=9;/*B-*/} else
|
||||||
if (score>=650000) {rank=10;/*C+*/} else
|
if (score>=650000) {rank=10;/*C+*/} else
|
||||||
if (score>=600000) {rank=11;/*C*/} else
|
if (score>=610000) {rank=11;/*C*/} else
|
||||||
//if (score>=590000) {rank=12;/*C-*/} else
|
if (score>=600000) {rank=12;/*C-*/} else
|
||||||
if (score>=550000) {rank=13;/*D+*/} else
|
if (score>=550000) {rank=13;/*D+*/} else
|
||||||
{rank=14;/*D*/}
|
{rank=14;/*D*/}
|
||||||
}break;
|
}break;
|
||||||
|
@ -258,7 +258,7 @@ public abstract class Reader{
|
|||||||
};
|
};
|
||||||
|
|
||||||
String convertToString(String[]data){
|
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);}
|
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")
|
+ ", \"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
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
|
BIN
result.png
BIN
result.png
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 int PORT = 8080;
|
||||||
static String SECRET = "";
|
static String SECRET = "";
|
||||||
|
|
||||||
|
final static HashMap<String,HashMap<String,List<String>>> SONG_DATABASE = new HashMap<>();
|
||||||
|
|
||||||
static double COLOR_ROTATION = 0;
|
static double COLOR_ROTATION = 0;
|
||||||
|
|
||||||
static boolean inCodeBlock = false;
|
static boolean inCodeBlock = false;
|
||||||
@ -118,10 +120,12 @@ public class sigPlace {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}*/
|
}*/
|
||||||
//new PopnReader().interpretBoxes(Paths.get("tests","popn8.png"),true);
|
//new PopnReader().interpretBoxes(Paths.get("tests","popn8.png"),true);
|
||||||
ArcadeReader.runTests();
|
//ArcadeReader.runTests();
|
||||||
PopnReader p = new PopnReader();
|
BufferedImage img;
|
||||||
p.interpretBoxes(Paths.get("tests","popn8.png"));
|
ArcadeReader.submitToDatabase(Paths.get("tests","popn8.png"));
|
||||||
System.out.println(p);
|
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");
|
/* Path secretFile = Paths.get(".clientsecret");
|
||||||
List<String> data;
|
List<String> data;
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user