Improve result print

This commit is contained in:
RatzzFatzz
2025-12-17 14:27:27 +01:00
parent 76d25fca1b
commit 15128583df
5 changed files with 54 additions and 97 deletions

View File

@@ -63,7 +63,7 @@ public abstract class AttributeUpdater {
// writeLastExecutionDate(); // writeLastExecutionDate();
statistic.stopTimer(); statistic.stopTimer();
statistic.printResult(); statistic.print();
} }
protected abstract List<File> getFiles(); protected abstract List<File> getFiles();
@@ -82,34 +82,23 @@ public abstract class AttributeUpdater {
* @param fileInfo contains information about file and desired configuration. * @param fileInfo contains information about file and desired configuration.
*/ */
protected void checkStatusAndUpdate(FileInfo fileInfo) { protected void checkStatusAndUpdate(FileInfo fileInfo) {
switch (fileInfo.getStatus()) { if (!fileInfo.getChanges().isEmpty()) {
case CHANGE_NECESSARY: statistic.changePlanned();
statistic.shouldChange();
commitChange(fileInfo);
break;
case NO_SUITABLE_CONFIG:
statistic.noSuitableConfigFound();
break;
case ALREADY_SUITED:
statistic.alreadyFits();
break;
case UNKNOWN:
default:
statistic.failure();
break;
}
}
private void commitChange(FileInfo fileInfo) { if (config.isSafeMode()) return;
if (config.isSafeMode()) return;
try { try {
fileProcessor.update(fileInfo); fileProcessor.update(fileInfo);
statistic.success(); statistic.changeSuccessful();
log.info("Commited {} to '{}'", fileInfo.getMatchedConfig().toStringShort(), fileInfo.getFile().getPath()); log.info("Commited {} to '{}'", fileInfo.getMatchedConfig().toStringShort(), fileInfo.getFile().getPath());
} catch (IOException | MkvToolNixException e) { } catch (IOException | MkvToolNixException e) {
statistic.failedChanging(); statistic.changeFailed();
log.warn("Couldn't commit {} to '{}'", fileInfo.getMatchedConfig().toStringShort(), fileInfo.getFile().getPath(), e); log.warn("Couldn't commit {} to '{}'", fileInfo.getMatchedConfig().toStringShort(), fileInfo.getFile().getPath(), e);
}
} else if (fileInfo.getChanges().isEmpty()) {
statistic.unchanged();
} else {
statistic.unknownFailed();
} }
} }

View File

@@ -65,7 +65,7 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
if (config.isForceCoherent()) { if (config.isForceCoherent()) {
log.info("No coherent match found, aborting: {}", rootDir.getPath()); log.info("No coherent match found, aborting: {}", rootDir.getPath());
statistic.increaseNoSuitableConfigFoundBy(files.size()); statistic.increaseUnchangedBy(files.size());
return; return;
} }
@@ -84,7 +84,7 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
if (fileInfo.getTracks().isEmpty()) { if (fileInfo.getTracks().isEmpty()) {
log.warn("No attributes found for file {}", file); log.warn("No attributes found for file {}", file);
statistic.failure(); statistic.unknownFailed();
break; break;
} }

View File

@@ -32,7 +32,7 @@ public class SingleFileAttributeUpdater extends AttributeUpdater {
if (fileInfo.getTracks().isEmpty()) { if (fileInfo.getTracks().isEmpty()) {
log.warn("No attributes found for file {}", file); log.warn("No attributes found for file {}", file);
statistic.failure(); statistic.unknownFailed();
return; return;
} }

View File

@@ -53,11 +53,4 @@ public class FileInfo {
public void resetChanges() { public void resetChanges() {
changes = new PlannedChange(); changes = new PlannedChange();
} }
public FileStatus getStatus() {
if (!changes.isEmpty()) return FileStatus.CHANGE_NECESSARY;
if (matchedConfig == null) return FileStatus.NO_SUITABLE_CONFIG;
if (changes.isEmpty()) return FileStatus.ALREADY_SUITED;
return FileStatus.UNKNOWN;
}
} }

View File

@@ -1,33 +1,25 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model; package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Getter @Getter
@Slf4j @Slf4j
public class ResultStatistic { public class ResultStatistic {
private static final String result = "Total files: %s%n" + private static final String PRINT_TEMPLATE = "Total: %s, Changing: %s (Successful: %s, Failed %s), Unchanged: %s, Excluded: %s, Unknown/Failed: %s\nRuntime: %s";
"├─ Excluded: %s%n" +
"├─ Should change: %s%n" +
"│ ├─ Failed changing: %s%n" +
"│ └─ Successfully changed: %s%n" +
"├─ No suitable config found: %s%n" +
"├─ Already fit config: %s%n" +
"└─ Failed: %s%n" +
"Runtime: %s";
private static ResultStatistic instance; private static ResultStatistic instance;
private int excluded = 0;
private int shouldChange = 0; private int changePlanned = 0;
private int failedChanging = 0; private int changeFailed = 0;
private int successfullyChanged = 0; private int changeSuccessful = 0;
private int unchanged = 0;
private int excluded = 0;
private int unknownFailed = 0;
private int noSuitableConfigFound = 0; private int noSuitableConfigFound = 0;
private int alreadyFits = 0; private int alreadyFits = 0;
private int failed = 0; private int failed = 0;
@Getter(AccessLevel.NONE)
private long startTime = 0; private long startTime = 0;
private long runtime = 0; private long runtime = 0;
@@ -43,43 +35,39 @@ public class ResultStatistic {
} }
public int total() { public int total() {
return shouldChange + noSuitableConfigFound + alreadyFits + failed; return changePlanned + noSuitableConfigFound + alreadyFits + failed;
} }
public void increaseExcludedBy(int amount) { public void increaseExcludedBy(int amount) {
excluded += amount; excluded += amount;
} }
public synchronized void changePlanned() {
changePlanned++;
}
public synchronized void changeSuccessful() {
changeSuccessful++;
}
public synchronized void changeFailed() {
changeFailed++;
}
public synchronized void unchanged() {
unchanged++;
}
public synchronized void increaseUnchangedBy(int amount) {
unchanged += amount;
}
public synchronized void excluded() { public synchronized void excluded() {
excluded++; excluded++;
} }
public synchronized void shouldChange() { public synchronized void unknownFailed() {
shouldChange++; unknownFailed++;
}
public synchronized void success() {
successfullyChanged++;
}
public synchronized void failedChanging() {
failedChanging++;
}
public synchronized void noSuitableConfigFound() {
noSuitableConfigFound++;
}
public synchronized void increaseNoSuitableConfigFoundBy(int amount) {
noSuitableConfigFound += amount;
}
public synchronized void alreadyFits() {
alreadyFits++;
}
public synchronized void failure() {
failed++;
} }
public void startTimer() { public void startTimer() {
@@ -90,11 +78,6 @@ public class ResultStatistic {
runtime = System.currentTimeMillis() - startTime; runtime = System.currentTimeMillis() - startTime;
} }
public void printResult() {
System.out.println(prettyPrint());
log.info(this.toString());
}
private String formatTimer() { private String formatTimer() {
int seconds = (int) (runtime / 1000); int seconds = (int) (runtime / 1000);
int minutes = seconds / 60; int minutes = seconds / 60;
@@ -112,22 +95,14 @@ public class ResultStatistic {
} }
} }
public String prettyPrint() { public void print() {
return String.format(result, total(), excluded, shouldChange, failedChanging, successfullyChanged, String result = this.toString();
noSuitableConfigFound, alreadyFits, failed, formatTimer()); System.out.println(result);
log.info(result);
} }
@Override @Override
public String toString() { public String toString() {
return "ResultStatistic: " + "total=" + total() + return String.format(PRINT_TEMPLATE, total(), changePlanned, changeSuccessful, changeFailed, unchanged, excluded, unknownFailed, formatTimer());
", excluded=" + excluded +
", shouldChange=" + shouldChange +
" (failedChanging=" + failedChanging +
", successfullyChanged=" + successfullyChanged +
"), noSuitableConfigFound=" + noSuitableConfigFound +
", alreadyFits=" + alreadyFits +
", failed=" + failed +
", runtime=" + formatTimer();
} }
} }