Skip to content

Commit

Permalink
todo review and probably revert: progressions visualizer shows all paths
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-zhur committed Jul 20, 2024
1 parent 2a5e0bb commit c8b569c
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace HarmonyDB.Index.Analysis.Services;

public class ProgressionsVisualizer
public class ProgressionsVisualizer(ProgressionsOptimizer progressionsOptimizer, IndexExtractor indexExtractor)
{
public const string AttributeSearch = "search";
public const string AttributeSearchFirst = "search-first";
Expand Down Expand Up @@ -56,8 +56,11 @@ public string VisualizeBlocksAsOne(ReadOnlyMemory<CompactHarmonyMovement> sequen
{
var rootsTrace = CreateRootsTraceByIndices(sequence, roots, 0, sequence.Length - 1, out var positions, typesToo);

var gridPositions = positions.Where((x, i) => i % 6 == 5).ToList();

var gridPositions = positions.Where((_, i) => i % 6 == 5).ToList();

var blocksToIds = new Dictionary<IBlock, int>();

var blockId = 0;
var lines = blocks
.GroupBy(x => x switch
{
Expand All @@ -67,6 +70,13 @@ public string VisualizeBlocksAsOne(ReadOnlyMemory<CompactHarmonyMovement> sequen
})
.Select(grouping =>
{
blockId++;

foreach (var block in grouping)
{
blocksToIds[block] = blockId;
}

List<int> periodPositions = new(), almostPeriodPositions = new();
foreach (var loop in grouping.OfType<LoopBlock>())
{
Expand Down Expand Up @@ -109,11 +119,19 @@ public string VisualizeBlocksAsOne(ReadOnlyMemory<CompactHarmonyMovement> sequen
? '+'
: ' ';
})),
right: $"{(grouping.Count() == 1 ? grouping.Single().GetType().Name : $"{grouping.Key} \u00d7{grouping.Count()}")}");
right: $"{blockId}: {(grouping.Count() == 1 ? grouping.Single().GetType().Name : $"{grouping.Key} \u00d7{grouping.Count()}")}");
})
.ToList();

lines.Insert(0, (rootsTrace, string.Empty));

lines.Add((string.Empty, string.Empty));

var graph = indexExtractor.FindGraph(blocks);
var paths = progressionsOptimizer.GetAllPossiblePaths(graph);

lines.Add((string.Join(Environment.NewLine, paths.Select(p => string.Join(" ", p.Select(x => blocksToIds[x])))), string.Empty));

return lines;
}

Expand Down

0 comments on commit c8b569c

Please sign in to comment.