(notebook: DeepnoteFile['project']['notebooks'][number])
| 626 | // ============================================================================ |
| 627 | |
| 628 | function analyzeNotebook(notebook: DeepnoteFile['project']['notebooks'][number]): NotebookStats { |
| 629 | const blockTypesMap = new Map<string, { count: number; loc: number }>() |
| 630 | let totalLoc = 0 |
| 631 | |
| 632 | for (const block of notebook.blocks) { |
| 633 | const loc = countLinesOfCode(block) |
| 634 | totalLoc += loc |
| 635 | |
| 636 | const existing = blockTypesMap.get(block.type) ?? { count: 0, loc: 0 } |
| 637 | blockTypesMap.set(block.type, { |
| 638 | count: existing.count + 1, |
| 639 | loc: existing.loc + loc, |
| 640 | }) |
| 641 | } |
| 642 | |
| 643 | const blockTypes: BlockTypeStats[] = Array.from(blockTypesMap.entries()) |
| 644 | .map(([type, stats]) => ({ |
| 645 | type, |
| 646 | count: stats.count, |
| 647 | linesOfCode: stats.loc, |
| 648 | })) |
| 649 | .sort((a, b) => b.count - a.count) |
| 650 | |
| 651 | return { |
| 652 | name: notebook.name, |
| 653 | id: notebook.id, |
| 654 | blockCount: notebook.blocks.length, |
| 655 | linesOfCode: totalLoc, |
| 656 | blockTypes, |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * Count lines of code in a block's content. |
no test coverage detected