Skip to content

Commit

Permalink
Added more information to command history analyzer (#2495)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
AndreasArvidsson and pokey authored Jul 30, 2024
1 parent d323e35 commit f56004e
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions packages/cursorless-engine/src/CommandHistoryAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,32 @@ class Period {
private readonly actions: Record<string, number> = {};
private readonly modifiers: Record<string, number> = {};
private readonly scopeTypes: Record<string, number> = {};
private count: number = 0;
private readonly dates = new Set<string>();
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),
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -76,6 +91,10 @@ class Period {
}
}
}

if (hasDecoratedMark) {
this.decoratedMarkCommandCount++;
}
}

private incrementAction(actionName: string) {
Expand Down

0 comments on commit f56004e

Please sign in to comment.