Consolidate statistics into a single place again

This commit is contained in:
Matt Nadareski
2024-03-13 01:22:59 -04:00
parent 5a70802cd8
commit 3f48f5c42c
15 changed files with 519 additions and 884 deletions

View File

@@ -55,7 +55,7 @@ namespace SabreTools.DatTools
#region Perform setup
// If the DAT is not populated and inverse is not set, inform the user and quit
if (datFile.Items.TotalCount == 0 && !inverse)
if (datFile.Items.DatStatistics.TotalCount == 0 && !inverse)
{
logger.User("No entries were found to rebuild, exiting...");
return false;
@@ -205,7 +205,7 @@ namespace SabreTools.DatTools
#region Perform setup
// If the DAT is not populated and inverse is not set, inform the user and quit
if (datFile.Items.TotalCount == 0 && !inverse)
if (datFile.Items.DatStatistics.TotalCount == 0 && !inverse)
{
logger.User("No entries were found to rebuild, exiting...");
return false;

View File

@@ -42,7 +42,7 @@ namespace SabreTools.DatTools
public static (DatFile? extADat, DatFile? extBDat) SplitByExtension(DatFile datFile, List<string> extA, List<string> extB)
{
// If roms is empty, return false
if (datFile.Items.TotalCount == 0)
if (datFile.Items.DatStatistics.TotalCount == 0)
return (null, null);
InternalStopwatch watch = new($"Splitting DAT by extension");

View File

@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices.ComTypes;
#if NET40_OR_GREATER || NETCOREAPP
using System.Threading.Tasks;
#endif
@@ -50,7 +52,6 @@ namespace SabreTools.DatTools
// Init total
DatStatistics totalStats = new()
{
Statistics = [],
DisplayName = "DIR: All DATs",
MachineCount = 0,
IsDirectory = true,
@@ -60,7 +61,6 @@ namespace SabreTools.DatTools
string? lastdir = null;
DatStatistics dirStats = new()
{
Statistics = [],
MachineCount = 0,
IsDirectory = true,
};
@@ -79,11 +79,10 @@ namespace SabreTools.DatTools
#else
dirStats.DisplayName = $"DIR: {WebUtility.HtmlEncode(lastdir)}";
#endif
dirStats.MachineCount = dirStats.Statistics.GameCount;
dirStats.MachineCount = dirStats.GameCount;
stats.Add(dirStats);
dirStats = new DatStatistics
{
Statistics = [],
MachineCount = 0,
IsDirectory = true,
};
@@ -97,23 +96,20 @@ namespace SabreTools.DatTools
// Add single DAT stats (if asked)
if (single)
{
DatStatistics individualStats = new()
{
Statistics = datdata.Items,
DisplayName = datdata.Header.GetStringFieldValue(DatHeader.FileNameKey),
MachineCount = datdata.Items.Keys.Count,
IsDirectory = false,
};
DatStatistics individualStats = datdata.Items.DatStatistics;
individualStats.DisplayName = datdata.Header.GetStringFieldValue(DatHeader.FileNameKey);
individualStats.MachineCount = datdata.Items.Keys.Count;
individualStats.IsDirectory = false;
stats.Add(individualStats);
}
// Add single DAT stats to dir
dirStats.Statistics.AddStatistics(datdata.Items);
dirStats.Statistics.GameCount += datdata.Items.Keys.Count;
dirStats.AddStatistics(datdata.Items.DatStatistics);
dirStats.GameCount += datdata.Items.Keys.Count;
// Add single DAT stats to totals
totalStats.Statistics.AddStatistics(datdata.Items);
totalStats.Statistics.GameCount += datdata.Items.Keys.Count;
totalStats.AddStatistics(datdata.Items.DatStatistics);
totalStats.GameCount += datdata.Items.Keys.Count;
// Make sure to assign the new directory
lastdir = thisdir;
@@ -129,12 +125,12 @@ namespace SabreTools.DatTools
#else
dirStats.DisplayName = $"DIR: {WebUtility.HtmlEncode(lastdir)}";
#endif
dirStats.MachineCount = dirStats.Statistics.GameCount;
dirStats.MachineCount = dirStats.GameCount;
stats.Add(dirStats);
}
// Add total DAT stats
totalStats.MachineCount = totalStats.Statistics.GameCount;
totalStats.MachineCount = totalStats.GameCount;
stats.Add(totalStats);
return stats;

View File

@@ -71,7 +71,7 @@ namespace SabreTools.DatTools
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None);
// Output the number of items we're going to be writing
logger.User($"A total of {datFile.Items.TotalCount - datFile.Items.RemovedCount} items will be written out to '{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}'");
logger.User($"A total of {datFile.Items.DatStatistics.TotalCount - datFile.Items.DatStatistics.RemovedCount} items will be written out to '{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}'");
// Get the outfile names
Dictionary<DatFormat, string> outfiles = datFile.Header.CreateOutFileNames(outDir!, overwrite);
@@ -121,24 +121,22 @@ namespace SabreTools.DatTools
/// <param name="datFile">Current DatFile object to write from</param>
public static void WriteStatsToConsole(DatFile datFile)
{
long diskCount = datFile.Items.GetItemCount(ItemType.Disk);
long mediaCount = datFile.Items.GetItemCount(ItemType.Media);
long romCount = datFile.Items.GetItemCount(ItemType.Rom);
long diskCount = datFile.Items.DatStatistics.GetItemCount(ItemType.Disk);
long mediaCount = datFile.Items.DatStatistics.GetItemCount(ItemType.Media);
long romCount = datFile.Items.DatStatistics.GetItemCount(ItemType.Rom);
if (diskCount + mediaCount + romCount == 0)
datFile.Items.RecalculateStats();
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
datFile.Items.DatStatistics.DisplayName = datFile.Header.GetStringFieldValue(DatHeader.FileNameKey);
datFile.Items.DatStatistics.MachineCount = datFile.Items.Keys.Count;
datFile.Items.DatStatistics.IsDirectory = false;
var statsList = new List<DatStatistics>
{
new()
{
Statistics = datFile.Items,
DisplayName = datFile.Header.GetStringFieldValue(DatHeader.FileNameKey),
MachineCount = datFile.Items.Keys.Count,
IsDirectory = false,
},
datFile.Items.DatStatistics,
};
var consoleOutput = BaseReport.Create(StatReportFormat.None, statsList);
consoleOutput!.WriteToFile(null, true, true);
@@ -210,11 +208,11 @@ namespace SabreTools.DatTools
datFile.Items.RecalculateStats();
// If there's nothing there, abort
if (datFile.Items.TotalCount == 0)
if (datFile.Items.DatStatistics.TotalCount == 0)
return false;
// If every item is removed, abort
if (datFile.Items.TotalCount == datFile.Items.RemovedCount)
if (datFile.Items.DatStatistics.TotalCount == datFile.Items.DatStatistics.RemovedCount)
return false;
return true;