MCPcopy Index your code
hub / github.com/CodeGraphContext/CodeGraphContext / stats_helper

Function stats_helper

src/codegraphcontext/cli/cli_helpers.py:604–689  ·  view source on GitHub ↗

Show indexing statistics for a repository or overall.

(path: str = None, context: Optional[str] = None)

Source from the content-addressed store, hash-verified

602
603
604def stats_helper(path: str = None, context: Optional[str] = None):
605 """Show indexing statistics for a repository or overall."""
606 services = _initialize_services(context)
607 if not all(services[:3]):
608 return
609
610 db_manager, _, code_finder, ctx = services
611
612 try:
613 if path:
614 # Stats for specific repository
615 path_obj = Path(path).resolve()
616 console.print(f"[cyan]📊 Statistics for: {path_obj}[/cyan]\n")
617
618 with db_manager.get_driver().session() as session:
619 # Get repository node
620 repo_query = """
621 MATCH (r:Repository {path: $path})
622 RETURN r
623 """
624 result = session.run(repo_query, path=str(path_obj))
625 if not result.single():
626 console.print(f"[red]Repository not found: {path_obj}[/red]")
627 return
628
629 # Get stats
630 # Get stats using separate queries to handle depth and avoid Cartesian products
631 # 1. Files
632 file_query = "MATCH (r:Repository {path: $path})-[:CONTAINS*]->(f:File) RETURN count(f) as c"
633 file_count = session.run(file_query, path=str(path_obj)).single()["c"]
634
635 # 2. Functions (including methods in classes)
636 func_query = "MATCH (r:Repository {path: $path})-[:CONTAINS*]->(func:Function) RETURN count(func) as c"
637 func_count = session.run(func_query, path=str(path_obj)).single()["c"]
638
639 # 3. Classes
640 class_query = "MATCH (r:Repository {path: $path})-[:CONTAINS*]->(c:Class) RETURN count(c) as c"
641 class_count = session.run(class_query, path=str(path_obj)).single()["c"]
642
643 # 4. Modules (imported) - Note: Module nodes are outside the repo structure usually, connected via IMPORTS
644 # We need to traverse from files to modules
645 module_query = "MATCH (r:Repository {path: $path})-[:CONTAINS*]->(f:File)-[:IMPORTS]->(m:Module) RETURN count(DISTINCT m) as c"
646 module_count = session.run(module_query, path=str(path_obj)).single()["c"]
647
648 table = Table(show_header=True, header_style="bold magenta")
649 table.add_column("Metric", style="cyan")
650 table.add_column("Count", style="green", justify="right")
651
652 table.add_row("Files", str(file_count))
653 table.add_row("Functions", str(func_count))
654 table.add_row("Classes", str(class_count))
655 table.add_row("Imported Modules", str(module_count))
656
657 console.print(table)
658 else:
659 # Overall stats
660 console.print("[cyan]📊 Overall Database Statistics[/cyan]\n")
661

Callers 1

statsFunction · 0.85

Calls 7

_initialize_servicesFunction · 0.85
resolveMethod · 0.80
sessionMethod · 0.45
get_driverMethod · 0.45
runMethod · 0.45
singleMethod · 0.45
close_driverMethod · 0.45

Tested by

no test coverage detected