noz-cli/Noz.PowerShell/Cmdlets/MeasureNozGardenCmdlet.cs
kryptomrx f45b31defa feat: graph and search API client with PS analysis cmdlets
Get-NozGraph, Find-NozNote, Measure-NozGarden, Set-NozNoteStatus,
Get-NozOrphans — graph edges, Meilisearch search, garden stats,
frontmatter status patch, orphan detection from inbound link analysis.
2026-05-17 00:27:45 +02:00

41 lines
1.3 KiB
C#

using System.Management.Automation;
namespace Noz.PowerShell.Cmdlets;
[Cmdlet(VerbsDiagnostic.Measure, "NozGarden")]
[OutputType(typeof(NozGardenStats))]
public sealed class MeasureNozGardenCmdlet : NozCmdletBase
{
protected override void ProcessRecord()
{
var notesTask = Api.GetNotesAsync();
var graphTask = Api.GetGraphAsync();
var notes = Run(notesTask);
var graph = Run(graphTask);
var targets = new HashSet<string>(graph.Edges.Select(e => e.Target));
var orphans = notes.Count(n => !targets.Contains(n.Slug));
var byTopic = notes
.GroupBy(n => n.Topic ?? "—")
.ToDictionary(g => g.Key, g => g.Count());
var byLang = notes
.GroupBy(n => n.Lang)
.ToDictionary(g => g.Key, g => g.Count());
WriteObject(new NozGardenStats
{
TotalNotes = notes.Count,
SeedCount = notes.Count(n => n.Status == "seed"),
BuddingCount = notes.Count(n => n.Status == "budding"),
EvergreenCount = notes.Count(n => n.Status == "evergreen"),
TopicCount = byTopic.Count,
LinkCount = graph.Edges.Count,
OrphanCount = orphans,
NotesByTopic = byTopic,
NotesByLang = byLang,
});
}
}