package data; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import org.apache.commons.io.FileUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class GuiData { private ArrayList localLevels = new ArrayList(); private ArrayList qualification = new ArrayList(); private ArrayList id = new ArrayList(); private ArrayList verifier = new ArrayList(); private ArrayList creator = new ArrayList(); private ArrayList ytlink = new ArrayList(); private FetchData data = new FetchData(); public void setId(ArrayList id) { this.id = id; } private int localLength; public int getLocalLength() { return localLength; } public ArrayList getLocalLevels() { return localLevels; } public ArrayList getId() { return id; } public ArrayList getVerifier() { return verifier; } public ArrayList getCreator() { return creator; } public ArrayList getQualification() { return qualification; } public ArrayList getYoutubeLink() { return ytlink; } public void IndexLevelName() throws IOException { FetchData data = new FetchData(); File filelength = new File("C:\\ExtremeDemonList\\levels"); File[] filelengthindex = filelength.listFiles(); String jsonstring; localLength = filelengthindex.length; System.out.println(filelengthindex.length); for(int i = 0; i < filelengthindex.length; i++) { jsonstring = FileUtils.readFileToString(new File("C:\\ExtremeDemonList\\levels\\" + data.allLevels().get(i) + ".json"), StandardCharsets.UTF_8); jsonstring = jsonstring.trim().replace("\n", "").replace("\t", "").replace("\\", ""); JSONObject obj = new JSONObject(jsonstring); localLevels.add(obj.getString("name")); } } public void IndexLevelID() throws IOException { File filelength = new File("C:\\ExtremeDemonList\\levels"); File[] filelengthindex = filelength.listFiles(); String jsonstring; localLength = filelengthindex.length; System.out.println(filelengthindex.length); for(int i = 0; i < filelengthindex.length; i++) { jsonstring = FileUtils.readFileToString(new File("C:\\ExtremeDemonList\\levels\\" + data.allLevels().get(i) + ".json"), StandardCharsets.UTF_8); jsonstring = jsonstring.trim().replace("\n", "").replace("\t", "").replace("\\", ""); JSONObject obj = new JSONObject(jsonstring); id.add(obj.getInt("id") + ""); } } public void IndexVerifiers() throws IOException { FetchData data = new FetchData(); File filelength = new File("C:\\ExtremeDemonList\\levels"); File[] filelengthindex = filelength.listFiles(); String jsonstring; localLength = filelengthindex.length; System.out.println(filelengthindex.length); for(int i = 0; i < filelengthindex.length; i++) { jsonstring = FileUtils.readFileToString(new File("C:\\ExtremeDemonList\\levels\\" + data.allLevels().get(i) + ".json"), StandardCharsets.UTF_8); jsonstring = jsonstring.trim().replace("\n", "").replace("\t", "").replace("\\", ""); JSONObject obj = new JSONObject(jsonstring); verifier.add(obj.getString("verifier")); } } public void IndexCreators() throws IOException { FetchData data = new FetchData(); File filelength = new File("C:\\ExtremeDemonList\\levels"); File[] filelengthindex = filelength.listFiles(); String jsonstring; localLength = filelengthindex.length; System.out.println(filelengthindex.length); for(int i = 0; i < filelengthindex.length; i++) { jsonstring = FileUtils.readFileToString(new File("C:\\ExtremeDemonList\\levels\\" + data.allLevels().get(i) + ".json"), StandardCharsets.UTF_8); jsonstring = jsonstring.trim().replace("\n", "").replace("\t", "").replace("\\", ""); JSONObject obj = new JSONObject(jsonstring); creator.add(obj.getString("author")); } } public void IndexQualification() throws IOException { FetchData data = new FetchData(); File filelength = new File("C:\\ExtremeDemonList\\levels"); File[] filelengthindex = filelength.listFiles(); String jsonstring; localLength = filelengthindex.length; System.out.println(filelengthindex.length); for(int i = 0; i < filelengthindex.length; i++) { jsonstring = FileUtils.readFileToString(new File("C:\\ExtremeDemonList\\levels\\" + data.allLevels().get(i) + ".json"), StandardCharsets.UTF_8); jsonstring = jsonstring.trim().replace("\n", "").replace("\t", "").replace("\\", ""); JSONObject obj = new JSONObject(jsonstring); qualification.add(obj.getInt("percentToQualify") + ""); } } public ArrayList IndexYoutubeLink() throws IOException { FetchData data = new FetchData(); File filelength = new File("C:\\ExtremeDemonList\\levels"); File[] filelengthindex = filelength.listFiles(); String jsonstring; localLength = filelengthindex.length; System.out.println(filelengthindex.length); for(int i = 0; i < filelengthindex.length; i++) { jsonstring = FileUtils.readFileToString(new File("C:\\ExtremeDemonList\\levels\\" + data.allLevels().get(i) + ".json"), StandardCharsets.UTF_8); jsonstring = jsonstring.trim().replace("\n", "").replace("\t", "").replace("\\", ""); JSONObject obj = new JSONObject(jsonstring); ytlink.add(obj.getString("verification") + ""); } return ytlink; } public static ArrayList allVictors(String levelname) throws IOException { ArrayList completed = new ArrayList<>(); // JSON-Datei einlesen String jsonContent = new String(Files.readAllBytes(Paths.get("C:\\ExtremeDemonList\\levels\\" + levelname + ".json"))); JSONObject jsonObject = new JSONObject(jsonContent); // Victors extrahieren JSONArray recordsArray = jsonObject.getJSONArray("records"); for (int i = 0; i < recordsArray.length(); i++) { JSONObject record = recordsArray.getJSONObject(i); int percent = record.getInt("percent"); if (percent == 100) { completed.add(record.getString("user")); } } return completed; } }