fix: Preview and stat logging are more accurate

The assignment logic in the DTO objects changes the end result of what
gets synced. The preview and stat logic now first assigns config values
to the old DTO object to get a more accurate preview of what the new
values will be.
pull/201/head
Robert Dailey 10 months ago
parent fba8cfa0de
commit 6bb7980827

@ -50,37 +50,29 @@ public class QualityProfilePreviewPhase
.AddColumn("[bold]Current[/]")
.AddColumn("[bold]New[/]");
static string YesNo(bool? val) => val is true ? "Yes" : "No";
static string Null<T>(T? val) => val is null ? "<unset>" : val.ToString() ?? "<invalid>";
var dto = profile.ProfileDto;
var config = profile.ProfileConfig.Profile;
var oldDto = profile.ProfileDto;
var newDto = profile.BuildUpdatedDto();
table.AddRow("Name", dto.Name, config.Name);
table.AddRow("Upgrades Allowed?", YesNo(dto.UpgradeAllowed), YesNo(config.UpgradeAllowed));
table.AddRow("Name", oldDto.Name, newDto.Name);
table.AddRow("Upgrades Allowed?", YesNo(oldDto.UpgradeAllowed), YesNo(newDto.UpgradeAllowed));
table.AddRow("Minimum Format Score", Null(oldDto.MinFormatScore), Null(newDto.MinFormatScore));
if (config.UpgradeUntilQuality is not null)
// ReSharper disable once InvertIf
if (newDto.UpgradeAllowed is true)
{
table.AddRow("Upgrade Until Quality",
Null(dto.Items.FindGroupById(dto.Cutoff)?.Name),
Null(config.UpgradeUntilQuality));
}
Null(oldDto.Items.FindCutoff(oldDto.Cutoff)),
Null(newDto.Items.FindCutoff(newDto.Cutoff)));
if (config.MinFormatScore is not null)
{
table.AddRow("Minimum Format Score",
Null(dto.MinFormatScore),
Null(config.MinFormatScore));
}
if (config.UpgradeUntilScore is not null)
{
table.AddRow("Upgrade Until Score",
Null(dto.CutoffFormatScore),
Null(config.UpgradeUntilScore));
Null(oldDto.CutoffFormatScore),
Null(newDto.CutoffFormatScore));
}
return table;
static string YesNo(bool? val) => val is true ? "Yes" : "No";
static string Null<T>(T? val) => val is null ? "<unset>" : val.ToString() ?? "<invalid>";
}
private static IRenderable SetupQualityItemTable(UpdatedQualityProfile profile)

@ -37,25 +37,20 @@ public class QualityProfileStatCalculator
private void ProfileUpdates(ProfileWithStats stats, UpdatedQualityProfile profile)
{
var dto = profile.ProfileDto;
var config = profile.ProfileConfig.Profile;
var oldDto = profile.ProfileDto;
var newDto = profile.BuildUpdatedDto();
Log("Upgrade Allowed", oldDto.UpgradeAllowed, newDto.UpgradeAllowed);
Log("Cutoff", oldDto.Items.FindCutoff(oldDto.Cutoff), newDto.Items.FindCutoff(newDto.Cutoff));
Log("Cutoff Score", oldDto.CutoffFormatScore, newDto.CutoffFormatScore);
Log("Minimum Score", oldDto.MinFormatScore, newDto.MinFormatScore);
return;
void Log<T>(string msg, T oldValue, T newValue)
{
_log.Debug("{Msg}: {Old} -> {New}", msg, oldValue, newValue);
stats.ProfileChanged |= !EqualityComparer<T>.Default.Equals(oldValue, newValue);
}
var upgradeAllowed = config.UpgradeAllowed is not null;
Log("Upgrade Allowed", dto.UpgradeAllowed, upgradeAllowed);
if (upgradeAllowed)
{
Log("Cutoff", dto.Items.FindCutoff(dto.Cutoff), config.UpgradeUntilQuality);
Log("Cutoff Score", dto.CutoffFormatScore, config.UpgradeUntilScore);
}
Log("Minimum Score", dto.MinFormatScore, config.MinFormatScore);
}
private static void QualityUpdates(ProfileWithStats stats, UpdatedQualityProfile profile)

Loading…
Cancel
Save