Improve logging/scoring system
This commit is contained in:
parent
0153ed0448
commit
7c27db9694
@ -44,3 +44,7 @@ internal class SearchParams
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal class AdvancedSearchParams
|
||||||
|
{
|
||||||
|
}
|
@ -48,4 +48,32 @@ internal static class ScoringModelExtensions
|
|||||||
Console.WriteLine(e.ToString());
|
Console.WriteLine(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int CalculateMaxScore(this ScoringModel score)
|
||||||
|
{
|
||||||
|
// Score should never be null here, but if it is we're fucked so just return 0.
|
||||||
|
if (score == null) { return 0; }
|
||||||
|
|
||||||
|
var propInfos = typeof(SearchParams).GetProperties();
|
||||||
|
|
||||||
|
int maxScore = 0;
|
||||||
|
|
||||||
|
foreach (var propInfo in propInfos)
|
||||||
|
{
|
||||||
|
object value = propInfo.GetValue(score.RemapModel.SearchParams);
|
||||||
|
|
||||||
|
if (value == null) continue;
|
||||||
|
|
||||||
|
if (value is HashSet<string> hashset)
|
||||||
|
{
|
||||||
|
maxScore += hashset.Count * 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
maxScore++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxScore;
|
||||||
|
}
|
||||||
}
|
}
|
@ -251,6 +251,18 @@ internal class Remapper
|
|||||||
|
|
||||||
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
||||||
Logger.Log($"Renaming {highestScore.Definition.Name} to {highestScore.ProposedNewName}", ConsoleColor.Green);
|
Logger.Log($"Renaming {highestScore.Definition.Name} to {highestScore.ProposedNewName}", ConsoleColor.Green);
|
||||||
|
Logger.Log($"Max possible score: {highestScore.CalculateMaxScore()}", ConsoleColor.Green);
|
||||||
|
Logger.Log($"Scored: {highestScore.Score} points", ConsoleColor.Green);
|
||||||
|
|
||||||
|
if (scores.Count > 1)
|
||||||
|
{
|
||||||
|
Logger.Log($"Warning! There were {scores.Count} possible matches. Considering adding more search parameters", ConsoleColor.Yellow);
|
||||||
|
|
||||||
|
foreach (var score in scores)
|
||||||
|
{
|
||||||
|
Logger.Log($"{score.Definition.Name} - Score [{score.Score}]", ConsoleColor.Yellow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Rename type and all associated type members
|
// Rename type and all associated type members
|
||||||
RenameService.RenameAll(highestScore);
|
RenameService.RenameAll(highestScore);
|
||||||
|
@ -16,8 +16,6 @@ internal static class RenameService
|
|||||||
RenameAllProperties(score, types);
|
RenameAllProperties(score, types);
|
||||||
|
|
||||||
score.Definition.Name = score.ProposedNewName;
|
score.Definition.Name = score.ProposedNewName;
|
||||||
|
|
||||||
types.FirstOrDefault(t => t.Name == score.ProposedNewName).Name = score.ProposedNewName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RenameAllDirect(RemapModel remap, TypeDefinition type)
|
public static void RenameAllDirect(RemapModel remap, TypeDefinition type)
|
||||||
@ -44,7 +42,7 @@ internal static class RenameService
|
|||||||
|
|
||||||
if (field.Name == newFieldName) { continue; }
|
if (field.Name == newFieldName) { continue; }
|
||||||
|
|
||||||
Logger.Log($"Renaming field: `{field.Name}` on Type `{type.Name}` to {newFieldName}");
|
Logger.Log($"Renaming field: `{field.Name}` on Type `{type.Name}` to {newFieldName}", ConsoleColor.Green);
|
||||||
|
|
||||||
field.Name = newFieldName;
|
field.Name = newFieldName;
|
||||||
|
|
||||||
@ -76,7 +74,7 @@ internal static class RenameService
|
|||||||
{
|
{
|
||||||
var newName = propertyCount > 0 ? $"{score.RemapModel.NewTypeName}_{propertyCount}" : score.RemapModel.NewTypeName;
|
var newName = propertyCount > 0 ? $"{score.RemapModel.NewTypeName}_{propertyCount}" : score.RemapModel.NewTypeName;
|
||||||
|
|
||||||
Logger.Log($"Renaming Property: `{property.Name}` on Type `{type}` to {newName}");
|
Logger.Log($"Renaming Property: `{property.Name}` on Type `{type}` to {newName}", ConsoleColor.Green);
|
||||||
property.Name = newName;
|
property.Name = newName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user