From 0bc9b321cf4b9cf294218d872ec3d32b4c473638 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Fri, 12 Jul 2024 13:48:23 +0200 Subject: [PATCH] Added more information to command history analyzer --- .../src/CommandHistoryAnalyzer.ts | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/packages/cursorless-engine/src/CommandHistoryAnalyzer.ts b/packages/cursorless-engine/src/CommandHistoryAnalyzer.ts index 464695ab4c..8c40f4bf80 100644 --- a/packages/cursorless-engine/src/CommandHistoryAnalyzer.ts +++ b/packages/cursorless-engine/src/CommandHistoryAnalyzer.ts @@ -21,19 +21,32 @@ class Period { private readonly actions: Record = {}; private readonly modifiers: Record = {}; private readonly scopeTypes: Record = {}; - private count: number = 0; + private readonly dates = new Set(); + private readonly countCommands: number; + private countDecoratedMarkCommands: number = 0; constructor(period: string, entries: CommandHistoryEntry[]) { this.period = period; + this.countCommands = entries.length; for (const entry of entries) { this.append(entry); } } toString(): string { + const avgCommandsPerDay = Math.round(this.countCommands / this.dates.size); + const percentageDecoratedMarkCommands = Math.round( + this.countDecoratedMarkCommands / this.countCommands, + ); + const meta = [ + `Command count: ${this.countCommands}`, + `Days usage: ${this.dates.size}`, + `Average commands / day: ${avgCommandsPerDay}`, + `Commands with hats: ${this.countDecoratedMarkCommands} (${percentageDecoratedMarkCommands}%)`, + ].join("\n"); return [ `# ${this.period}`, - `Total command count: ${this.count}`, + meta, this.serializeMap("Actions", this.actions), this.serializeMap("Modifiers", this.modifiers), this.serializeMap("Scope types", this.scopeTypes), @@ -51,13 +64,30 @@ class Period { } private append(entry: CommandHistoryEntry) { - this.count++; + this.dates.add(entry.date); const command = canonicalizeAndValidateCommand(entry.command); this.incrementAction(command.action.name); - this.parsePrimitiveTargets( - getPartialPrimitiveTargets(getPartialTargetDescriptors(command.action)), + const partialPrimitiveTargets = getPartialPrimitiveTargets( + getPartialTargetDescriptors(command.action), ); + + if (this.hasDecoratedMark(partialPrimitiveTargets)) { + this.countDecoratedMarkCommands++; + } + + this.parsePrimitiveTargets(partialPrimitiveTargets); + } + + private hasDecoratedMark( + partialPrimitiveTargets: PartialPrimitiveTargetDescriptor[], + ) { + for (const target of partialPrimitiveTargets) { + if (target.mark?.type === "decoratedSymbol") { + return true; + } + } + return false; } private parsePrimitiveTargets(