Skip to content

Commit

Permalink
more options for report
Browse files Browse the repository at this point in the history
  • Loading branch information
optyfr committed Jun 17, 2024
1 parent 9ee9a90 commit ea6e558
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 66 deletions.
2 changes: 1 addition & 1 deletion jrmcore/src/main/java/jrm/misc/SettingsEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public enum SettingsEnum implements EnumWithDefault
dir2dat_do_not_scan_archives(false, "dir2dat.do_not_scan_archives"), // NOSONAR
dir2dat_match_profile(false, "dir2dat.match_profile"), // NOSONAR
dir2dat_include_empty_dirs(false, "dir2dat.include_empty_dirs"), // NOSONAR
report_settings("[\"STATS\",\"COMPACT\"]","report.settings"); // NOSONAR
report_settings("[\"STATS\",\"COMPACT\",\"GROUP_BY_TYPE_AND_STATUS\"]","report.settings"); // NOSONAR

private String name = null;
private Object dflt = null;
Expand Down
12 changes: 12 additions & 0 deletions jrmcore/src/main/java/jrm/profile/report/EntryNote.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package jrm.profile.report;

import java.util.Optional;

import jrm.profile.data.Entity;
import jrm.profile.data.EntityBase;
import lombok.Getter;
Expand Down Expand Up @@ -51,6 +53,16 @@ public String getSha1()
return null;
}

@Override
public String getHash()
{
if(entity instanceof Entity e)
{
return Optional.ofNullable(e.getSha1()).or(() -> Optional.ofNullable(e.getMd5())).or(() -> Optional.ofNullable(e.getCrc())).orElse(null);
}
return null;
}

@Override
public boolean equals(Object obj)
{
Expand Down
2 changes: 2 additions & 0 deletions jrmcore/src/main/java/jrm/profile/report/Note.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public abstract class Note implements StatusRendererFactory, Serializable
public abstract String getMd5();

public abstract String getSha1();

public abstract String getHash();

public int getId()
{
Expand Down
220 changes: 162 additions & 58 deletions jrmcore/src/main/java/jrm/profile/report/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
Expand All @@ -58,8 +59,8 @@
import jrm.profile.data.Anyware;
import jrm.security.Session;
import lombok.Getter;
import lombok.Setter;
import one.util.streamex.IntStreamEx;
import one.util.streamex.StreamEx;

/**
* The report node root
Expand Down Expand Up @@ -138,27 +139,34 @@ public static class Stats implements Serializable
{
private static final long serialVersionUID = 2L;

private @Getter @Setter int missingSetCnt = 0;
private @Getter @Setter int missingRomsCnt = 0;
private @Getter @Setter int missingDisksCnt = 0;
private @Getter @Setter int missingSamplesCnt = 0;

private @Getter @Setter int setUnneeded = 0;
private @Getter @Setter int setMissing = 0;
private @Getter @Setter int setFound = 0;
private @Getter @Setter int setFoundOk = 0;
private @Getter @Setter int setFoundFixPartial = 0;
private @Getter @Setter int setFoundFixComplete = 0;
private @Getter @Setter int setCreate = 0;
private @Getter @Setter int setCreatePartial = 0;
private @Getter @Setter int setCreateComplete = 0;
private @Getter int missingSetCnt = 0;
private @Getter int missingRomsCnt = 0;
private @Getter int missingDisksCnt = 0;
private @Getter int missingSamplesCnt = 0;

private @Getter int fixableRomsCnt = 0;
private @Getter int fixableDisksCnt = 0;

private @Getter int setUnneeded = 0;
private @Getter int setMissing = 0;
private @Getter int setFound = 0;
private @Getter int setFoundOk = 0;
private @Getter int setFoundFixPartial = 0;
private @Getter int setFoundFixComplete = 0;
private @Getter int setCreate = 0;
private @Getter int setCreatePartial = 0;
private @Getter int setCreateComplete = 0;

public Stats(Stats org)
{
this.missingSetCnt = org.missingSetCnt;
this.missingRomsCnt = org.missingRomsCnt;
this.missingDisksCnt = org.missingDisksCnt;
this.missingSamplesCnt = org.missingSamplesCnt;

this.fixableRomsCnt = org.fixableRomsCnt;
this.fixableDisksCnt = org.fixableDisksCnt;

this.setUnneeded = org.setUnneeded;
this.setMissing = org.setMissing;
this.setFound = org.setFound;
Expand Down Expand Up @@ -195,6 +203,16 @@ public void incMissingSamplesCnt()
++missingSamplesCnt;
}

public void incFixableRomsCnt()
{
++fixableRomsCnt;
}

public void incFixableDisksCnt()
{
++fixableDisksCnt;
}

public void incSetUnneeded()
{
++setUnneeded;
Expand Down Expand Up @@ -262,6 +280,15 @@ public void clear()
*/
missingSamplesCnt = 0;

/**
* number of fixable roms
*/
fixableRomsCnt = 0;
/**
* number of fixable disks
*/
fixableDisksCnt = 0;

/**
* number of unneeded set
*/
Expand Down Expand Up @@ -572,8 +599,11 @@ enum ReportMode
STATS,
OK,
FIXABLE,
MISSING,
OTHERS,
COMPACT
COMPACT,
NO_ENTRIES,
GROUP_BY_TYPE_AND_STATUS
}

/**
Expand Down Expand Up @@ -607,67 +637,141 @@ public void write(final Session session)
if(modes.contains(ReportMode.STATS))
{
reportWriter.println("=== Statistics ===");
reportWriter.println(String.format(Messages.getString("Report.MissingSets"), stats.missingSetCnt, profile.getMachinesCnt())); //$NON-NLS-1$
reportWriter.println(String.format(Messages.getString("Report.MissingRoms"), stats.missingRomsCnt, profile.getRomsCnt())); //$NON-NLS-1$
reportWriter.println(String.format(Messages.getString("Report.MissingDisks"), stats.missingDisksCnt, profile.getDisksCnt())); //$NON-NLS-1$
int total = stats.setCreate + stats.setFound + stats.setMissing;
int ok = stats.setCreateComplete + stats.setFoundFixComplete + stats.setFoundOk;
reportWriter.println(String.format("Missing sets after Fix : %d%n", total - ok)); //$NON-NLS-1$
reportWriter.println(String.format(Messages.getString("Report.MissingRoms"), stats.missingRomsCnt, stats.missingRomsCnt - stats.fixableRomsCnt, profile.getRomsCnt())); //$NON-NLS-1$
reportWriter.println(String.format(Messages.getString("Report.MissingDisks"), stats.missingDisksCnt, stats.missingDisksCnt - stats.fixableDisksCnt, profile.getDisksCnt())); //$NON-NLS-1$
reportWriter.println(String.format(Messages.getString("Report.MissingSets"), profile.getMachinesCnt() - stats.setFoundOk, profile.getMachinesCnt() - stats.setFoundOk - stats.setFoundFixComplete, profile.getMachinesCnt())); //$NON-NLS-1$
reportWriter.println();
}
reportWriter.println("=== Scanner Report ===");
subjects.forEach(subject -> {
if(subject instanceof SubjectSet ss)
if(modes.contains(ReportMode.GROUP_BY_TYPE_AND_STATUS))
{
if(modes.contains(ReportMode.NO_ENTRIES))
{
if(ss.isOK() && modes.contains(ReportMode.OK))
{
if (!modes.contains(ReportMode.COMPACT))
reportWriter.println(ss);
subject.notes.forEach(note -> writeReport(reportWriter, note, modes.contains(ReportMode.COMPACT))); //$NON-NLS-1$
}
else if(ss.isMissing())
{
if (!modes.contains(ReportMode.COMPACT))
reportWriter.println(subject);
subject.notes.forEach(note -> writeReport(reportWriter, note, modes.contains(ReportMode.COMPACT))); //$NON-NLS-1$
}
else if(ss.isFixable() && modes.contains(ReportMode.FIXABLE))
{
if (!modes.contains(ReportMode.COMPACT))
reportWriter.println(subject);
subject.notes.forEach(note -> {
if (modes.contains(ReportMode.OK) && note instanceof EntryOK)
writeReport(reportWriter, note, modes.contains(ReportMode.COMPACT));
if (modes.contains(ReportMode.FIXABLE) && (note instanceof EntryAdd || note instanceof EntryMissingDuplicate || note instanceof EntryUnneeded || note instanceof EntryWrongName))
writeReport(reportWriter, note, modes.contains(ReportMode.COMPACT));
if (note instanceof EntryWrongHash || note instanceof EntryMissing)
writeReport(reportWriter, note, modes.contains(ReportMode.COMPACT));
});
}
final Map<ReportMode, List<Subject>> grouped = subjects.stream().collect(Collectors.groupingBy(s -> {
if(s instanceof SubjectSet ss)
{
if(ss.isFixable())
return ReportMode.FIXABLE;
if(ss.isMissing())
return ReportMode.MISSING;
return ReportMode.OK;
}
return ReportMode.OTHERS;
}));
grouped.forEach((mode, list) -> {
reportWriter.println();
reportWriter.println("== %s ==".formatted(mode));
list.stream().sorted(Subject.getComparator()).forEachOrdered(n -> writeReport(reportWriter, n, modes));
reportWriter.println();
});
}
else if(modes.contains(ReportMode.OTHERS))
else
{
if (!modes.contains(ReportMode.COMPACT))
reportWriter.println(subject);
subject.notes.forEach(note -> writeReport(reportWriter, note, modes.contains(ReportMode.COMPACT))); //$NON-NLS-1$
final Map<String, List<Note>> grouped = subjects.stream().flatMap(s -> s.stream()).collect(Collectors.groupingBy(Note::getAbbrv));
grouped.forEach((abbrv, list) -> {
reportWriter.println();
reportWriter.println("== %s ==".formatted(abbrv));
list.stream().sorted((n1,n2) -> {
int ret = n1.parent != null && n2.parent != null ? Subject.getComparator().compare(n1.parent, n2.parent) : 0;
if(ret == 0)
return n1.getName().compareToIgnoreCase(n2.getName());
return ret;
}).forEachOrdered(n -> writeReport(reportWriter, n, modes));
reportWriter.println();
});
}
});
}
else
{
subjects.stream().filter(new ReportSubjectFilter(modes)).sorted(Subject.getComparator()).forEachOrdered(subject -> writeReport(reportWriter, subject, modes));
}
reportWriter.println();
}
catch(final IOException e)
{
Log.err(e.getMessage(),e);
}
}


class ReportSubjectFilter implements Predicate<Subject>
{
private final Set<ReportMode> modes;

public ReportSubjectFilter(Set<ReportMode> modes)
{
this.modes = modes;
}

@Override
public boolean test(Subject subject)
{
if(subject instanceof SubjectSet ss)
{
if(ss.isOK() && modes.contains(ReportMode.OK))
return true;
if(ss.isFixable() && modes.contains(ReportMode.FIXABLE))
return true;
if(ss.isMissing()) // NOSONAR
return true;
return false;
}
else if(modes.contains(ReportMode.OTHERS))
return true;
return false;
}

}


private void writeReport(PrintWriter reportWriter, Subject subject, final EnumSet<ReportMode> modes)
{
if(modes.contains(ReportMode.NO_ENTRIES))
reportWriter.println(subject);
else
{
if (!modes.contains(ReportMode.COMPACT))
reportWriter.println(subject);
subject.notes.stream().filter(new ReportNoteFilter(modes)).forEach(note -> writeReport(reportWriter, note, modes));
}
}

class ReportNoteFilter implements Predicate<Note>
{
private final Set<ReportMode> modes;

public ReportNoteFilter(Set<ReportMode> modes)
{
this.modes = modes;
}

@Override
public boolean test(Note note)
{
if (modes.contains(ReportMode.OK) && note instanceof EntryOK)
return true;
if (modes.contains(ReportMode.FIXABLE) && (note instanceof EntryAdd || note instanceof EntryMissingDuplicate || note instanceof EntryUnneeded || note instanceof EntryWrongName))
return true;
if (note instanceof EntryWrongHash || note instanceof EntryMissing) //NOSONAR
return true;
return false;
}

}

private void writeReport(PrintWriter reportWriter, Note note, boolean compact)
private void writeReport(PrintWriter reportWriter, Note note, final EnumSet<ReportMode> modes)
{
if(compact)
if (modes.contains(ReportMode.COMPACT))
{
if (note.parent != null)
reportWriter.println(note.getAbbrv()+" :\t[" + note.parent.getWare().getBaseName() + "]\t" + note.getName() + "\t(" + note.getSha1() + ")");
{
if(modes.contains(ReportMode.GROUP_BY_TYPE_AND_STATUS))
reportWriter.println("[" + note.parent.getWare().getBaseName() + "]\t" + note.getName() + "\t(" + note.getHash() + ")");
else
reportWriter.println(note.getAbbrv() + " :\t[" + note.parent.getWare().getBaseName() + "]\t" + note.getName() + "\t(" + note.getHash() + ")");
}
else
reportWriter.println(note.getName() + " (" + note.getSha1() + ")");
reportWriter.println(note.getName() + " (" + note.getHash() + ")");
}
else
reportWriter.println("\t" + note);
Expand Down
6 changes: 5 additions & 1 deletion jrmcore/src/main/java/jrm/profile/scan/Scan.java
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,7 @@ private void scanDisksForMissingContainer(final List<Disk> disks, final Director
Entry foundEntry = searchDiskInAllScans(disk);
if (foundEntry != null)
{
report.getStats().incFixableDisksCnt();
reportSubject.add(new EntryAdd(disk, foundEntry));
CreateContainer.getInstance(createSet, directory, format, 0L).addAction(new AddEntry(disk, foundEntry));
disksFound++;
Expand Down Expand Up @@ -1038,11 +1039,12 @@ private void scanDisksForFoundContainer(final List<Disk> disks, final Directory

if (foundEntry == null) // did not find rom in container
{
report.getStats().incMissingRomsCnt();
report.getStats().incMissingDisksCnt();

foundEntry = searchDiskInAllScans(disk);
if (foundEntry != null) // found an entry
{
report.getStats().incFixableDisksCnt();
reportSubject.add(new EntryAdd(disk, foundEntry));
OpenContainer.getInstance(scanData.addSet, directory, format, 0L).addAction(new AddEntry(disk, foundEntry));
}
Expand Down Expand Up @@ -1320,6 +1322,7 @@ private void scanRomsForFoundContainer(final List<Rom> roms, final Container arc
foundEntry = searchRomInAllScans(rom);
if (foundEntry != null) // found an entry
{
report.getStats().incFixableRomsCnt();
reportSubject.add(new EntryAdd(rom, foundEntry));
OpenContainer.getInstance(scanData.addSet, archive, format, estimatedRomsSize).addAction(new AddEntry(rom, foundEntry));
}
Expand Down Expand Up @@ -1547,6 +1550,7 @@ private void scanRomsForMissingContainer(final List<Rom> roms, final Container a
final Entry entryFound = searchRomInAllScans(rom);
if (null != entryFound)
{
report.getStats().incFixableRomsCnt();
reportSubject.add(new EntryAdd(rom, entryFound));
CreateContainer.getInstance(createSet, archive, format, estimatedRomsSize).addAction(new AddEntry(rom, entryFound));
romsFound++;
Expand Down
6 changes: 3 additions & 3 deletions jrmcore/src/main/resources/jrm/resources/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ Progress.btnCancel.text = Cancel
RenameEntry.Rename = Rename %s to %s
RenameEntry.Renaming = Renaming %s to %s

Report.MissingDisks = Missing disks : %s/%s
Report.MissingRoms = Missing roms : %s/%s
Report.MissingSets = Missing sets : %s/%s
Report.MissingDisks = Missing Disks (before/after/total) : %s/%s/%s
Report.MissingRoms = Missing Roms (before/after/total) : %s/%s/%s
Report.MissingSets = Missing Sets (before/after/total) : %s/%s/%s
Report.Status = Found:%d (OK:%d, PartialFix:%d, CompleteFix:%d) | Create:%d (Partial:%d, Complete:%d) | Miss:%d | Unneeded:%d | Total:%d/%d

ReportFrame.Title = Report
Expand Down
Loading

0 comments on commit ea6e558

Please sign in to comment.