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

View File

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

View File

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

View File

@@ -53,11 +53,4 @@ public class FileInfo {
public void resetChanges() {
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;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@Getter
@Slf4j
public class ResultStatistic {
private static final String result = "Total files: %s%n" +
"├─ 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 final String PRINT_TEMPLATE = "Total: %s, Changing: %s (Successful: %s, Failed %s), Unchanged: %s, Excluded: %s, Unknown/Failed: %s\nRuntime: %s";
private static ResultStatistic instance;
private int excluded = 0;
private int shouldChange = 0;
private int failedChanging = 0;
private int successfullyChanged = 0;
private int changePlanned = 0;
private int changeFailed = 0;
private int changeSuccessful = 0;
private int unchanged = 0;
private int excluded = 0;
private int unknownFailed = 0;
private int noSuitableConfigFound = 0;
private int alreadyFits = 0;
private int failed = 0;
@Getter(AccessLevel.NONE)
private long startTime = 0;
private long runtime = 0;
@@ -43,43 +35,39 @@ public class ResultStatistic {
}
public int total() {
return shouldChange + noSuitableConfigFound + alreadyFits + failed;
return changePlanned + noSuitableConfigFound + alreadyFits + failed;
}
public void increaseExcludedBy(int 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() {
excluded++;
}
public synchronized void shouldChange() {
shouldChange++;
}
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 synchronized void unknownFailed() {
unknownFailed++;
}
public void startTimer() {
@@ -90,11 +78,6 @@ public class ResultStatistic {
runtime = System.currentTimeMillis() - startTime;
}
public void printResult() {
System.out.println(prettyPrint());
log.info(this.toString());
}
private String formatTimer() {
int seconds = (int) (runtime / 1000);
int minutes = seconds / 60;
@@ -112,22 +95,14 @@ public class ResultStatistic {
}
}
public String prettyPrint() {
return String.format(result, total(), excluded, shouldChange, failedChanging, successfullyChanged,
noSuitableConfigFound, alreadyFits, failed, formatTimer());
public void print() {
String result = this.toString();
System.out.println(result);
log.info(result);
}
@Override
public String toString() {
return "ResultStatistic: " + "total=" + total() +
", excluded=" + excluded +
", shouldChange=" + shouldChange +
" (failedChanging=" + failedChanging +
", successfullyChanged=" + successfullyChanged +
"), noSuitableConfigFound=" + noSuitableConfigFound +
", alreadyFits=" + alreadyFits +
", failed=" + failed +
", runtime=" + formatTimer();
return String.format(PRINT_TEMPLATE, total(), changePlanned, changeSuccessful, changeFailed, unchanged, excluded, unknownFailed, formatTimer());
}
}