From f56004e5a5918ca1f653b3af9829e4c2e0755648 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 30 Jul 2024 16:43:24 +0200 Subject: [PATCH] Added more information to command history analyzer (#2495) Added some more aggregated information about your command history ``` # Totals Command count: 53863 Days usage: 166 Average commands / day: 324 Commands with hats: 8592 (16%) ``` ## Checklist - [/] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet --------- Co-authored-by: Pokey Rule <755842+pokey@users.noreply.github.com> --- .../src/CommandHistoryAnalyzer.ts | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/packages/cursorless-engine/src/CommandHistoryAnalyzer.ts b/packages/cursorless-engine/src/CommandHistoryAnalyzer.ts index 464695ab4c..a7cfdd9e89 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 commandCount: number; + private decoratedMarkCommandCount: number = 0; constructor(period: string, entries: CommandHistoryEntry[]) { this.period = period; + this.commandCount = entries.length; for (const entry of entries) { this.append(entry); } } toString(): string { + const avgCommandsPerDay = Math.round(this.commandCount / this.dates.size); + const percentageDecoratedMarkCommands = Math.round( + (100 * this.decoratedMarkCommandCount) / this.commandCount, + ); + const meta = [ + `Command count: ${this.commandCount}`, + `Days used: ${this.dates.size}`, + `Average commands / day: ${avgCommandsPerDay}`, + `Commands with hats: ${this.decoratedMarkCommandCount} (${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,7 +64,7 @@ class Period { } private append(entry: CommandHistoryEntry) { - this.count++; + this.dates.add(entry.date); const command = canonicalizeAndValidateCommand(entry.command); this.incrementAction(command.action.name); @@ -63,11 +76,13 @@ class Period { private parsePrimitiveTargets( partialPrimitiveTargets: PartialPrimitiveTargetDescriptor[], ) { + let hasDecoratedMark = false; for (const target of partialPrimitiveTargets) { - if (target.modifiers == null) { - continue; + if (target.mark?.type === "decoratedSymbol") { + hasDecoratedMark = true; } - for (const modifier of target.modifiers) { + + for (const modifier of target.modifiers ?? []) { this.incrementModifier(modifier); const scopeType = getScopeType(modifier); @@ -76,6 +91,10 @@ class Period { } } } + + if (hasDecoratedMark) { + this.decoratedMarkCommandCount++; + } } private incrementAction(actionName: string) {