protected void calculationStart() {
double progress = 0.0;
String s1 = steamIdTextArea.getText();
int accountId = Integer.parseInt(s1);
MatchHistory history = null;
try {
history = api.getMatchHistory(MATCHES_AMOUNT, accountId);
} catch (RuntimeException e) {
System.out.println(e.getMessage());
System.out.println("Task can't be completed");
throw new RuntimeException("Closing ...");
} catch (IOException e) {
e.printStackTrace();
}
List<Long> matchesList = calc.matchIdList(history);
ArrayList<MatchDetails> matchDetailses = new ArrayList<>();
for (Long matchId : matchesList) {
try {
progress += 0.05;
matchDetailses.add(api.getMatchDetails(matchId));
final double finalProgress = progress;
Platform.runLater(() -> progressBar.setProgress(finalProgress));
} catch (IOException e) {
progress += 0.05;
final double finalProgress = progress;
resultText.setText(e.getMessage());
Platform.runLater(() -> progressBar.setProgress(finalProgress));
}
}
List<int[]> scoreList = calc.playerScore(matchDetailses, accountId);
double averageKDA = calc.averageKda(scoreList);
Platform.runLater(() -> resultText.setText("Average KDA for last " + MATCHES_AMOUNT + " rating games = " + averageKDA));
}
public static int runProcess(File workDir, String... command) throws Exception {
ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(workDir);
pb.environment().put("JAVA_HOME", System.getProperty("java.home"));
if(!pb.environment().containsKey("MAVEN_OPTS")) {
pb.environment().put("MAVEN_OPTS", "-Xmx1024M");
}
Process ps = pb.start();
(new Thread(new Builder.StreamRedirector(ps.getInputStream(), System.out))).start();
(new Thread(new Builder.StreamRedirector(ps.getErrorStream(), System.err))).start();
int status = ps.waitFor();
if(status != 0) {
throw new RuntimeException("Error running command, return status !=0: " + Arrays.toString(command));
} else {
return status;
}
}
private static class StreamRedirector implements Runnable {
private final InputStream in;
private final PrintStream out;
public void run() {
BufferedReader br = new BufferedReader(new InputStreamReader(this.in));
try {
String ex;
while((ex = br.readLine()) != null) {
this.out.println(ex);
}
} catch (IOException var3) {
throw Throwables.propagate(var3);
}
}
@ConstructorProperties({"in", "out"})
public StreamRedirector(InputStream in, PrintStream out) {
this.in = in;
this.out = out;
}
}