Skip to content

Commit

Permalink
improved MCLogLine creationTime accuracy even further
Browse files Browse the repository at this point in the history
  • Loading branch information
doej1367 committed Oct 13, 2021
1 parent 32ba753 commit 97386bd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
Binary file modified RNGDropsDataCollector.jar
Binary file not shown.
Binary file modified bin/main/MainWindow.class
Binary file not shown.
Binary file modified bin/util/MCLogFile.class
Binary file not shown.
22 changes: 17 additions & 5 deletions src/main/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,16 @@ private synchronized void analyze() {
for (File minecraftLogFolder : minecraftLogFolders) {
addOutput("INFO: Gathering log files from " + minecraftLogFolder.getAbsolutePath());
for (File logFile : minecraftLogFolder.listFiles())
allFiles.add(logFile);
if (logFile.getName().matches("[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]+\\.log\\.gz|latest\\.log"))
allFiles.add(logFile);
}

// analyze all found log files
addOutput("INFO: Loading log files (this might take a minute)");
Collections.sort(allFiles, new Comparator<File>() {
@Override
public int compare(File f1, File f2) {
long tmp = getCreationTime(f1) - getCreationTime(f2);
long tmp = getLastModifiedTime(f1) - getLastModifiedTime(f2);
return tmp < 0 ? -1 : tmp > 0 ? 1 : 0;
}
});
Expand All @@ -166,7 +167,7 @@ public int compare(File f1, File f2) {
addOutputTemporaryly(
"INFO: Loading " + fileCount + " files - " + (counter * 100 / fileCount) + "%");
try {
minecraftLogFile = new MCLogFile(logFile);
minecraftLogFile = new MCLogFile(logFile, getPreviousFileInFolder(counter, allFiles));
if (minecraftLogFile.getPlayerName() != null) {
lastLoginName = minecraftLogFile.getPlayerName();
playerNames.put(lastLoginName, playerNames.getOrDefault(lastLoginName, 0) + 1);
Expand Down Expand Up @@ -237,6 +238,17 @@ public int compare(File f1, File f2) {
}
}

private File getPreviousFileInFolder(int counter, ArrayList<File> allFiles) {
File current = allFiles.get(counter - 1);
File previous = null;
for (int i = counter - 1; i > 0; i--) {
previous = allFiles.get(i - 1);
if (previous.getParentFile().equals(current.getParentFile()) && previous.getName().endsWith(".gz"))
return previous;
}
return null;
}

/**
* Launch the application.
*/
Expand Down Expand Up @@ -283,9 +295,9 @@ public void addOutputTemporaryly(String s) {
tmpOutputlength = s.length();
}

private long getCreationTime(File file) {
private long getLastModifiedTime(File file) {
try {
return Files.readAttributes(file.toPath(), BasicFileAttributes.class).creationTime().toMillis();
return Files.readAttributes(file.toPath(), BasicFileAttributes.class).lastModifiedTime().toMillis();
} catch (IOException ignored) {
}
return 0;
Expand Down
12 changes: 6 additions & 6 deletions src/util/MCLogFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class MCLogFile {
private String playerName;
private Stream<String> linesStream;

public MCLogFile(File logFile) throws FileNotFoundException, IOException {
creationTime = getCreationTime(logFile);
public MCLogFile(File logFile, File previousLogFile) throws FileNotFoundException, IOException {
creationTime = previousLogFile != null ? getCreationTime(previousLogFile) : getCreationTime(logFile) - 21600000;
startingTimeOfFile = null;
InputStream inputStream = new FileInputStream(logFile);
if (logFile.getName().endsWith(".gz"))
Expand Down Expand Up @@ -63,10 +63,10 @@ private long getTime(long creationTimeFile, String creationTimeLine) {
if (!creationTimeLine.matches("[0-9:]{8}"))
return creationTimeFile;
String[] array = creationTimeLine.split(":");
long msFromStartOfDay = Integer.parseInt(array[0]) * 3600 + Integer.parseInt(array[1]) * 60
+ Integer.parseInt(array[2]) * 1000;
if (this.startingTimeOfFile == null)
this.startingTimeOfFile = msFromStartOfDay;
long msFromStartOfDay = (Integer.parseInt(array[0]) * 3600 + Integer.parseInt(array[1]) * 60
+ Integer.parseInt(array[2])) * 1000;
if (startingTimeOfFile == null)
startingTimeOfFile = msFromStartOfDay;
return creationTimeFile + (msFromStartOfDay - startingTimeOfFile);
}
}

0 comments on commit 97386bd

Please sign in to comment.