Skip to content

๐Ÿ“Š A powerful code metrics and analysis tool with COCOMO estimation, health analysis, and multi-format reports. Support 50+ languages, zero dependencies.

License

Notifications You must be signed in to change notification settings

TbusOS/CodeMetrics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“Š CodeMetrics

License: MIT Python 3.6+ PRs Welcome GitHub stars

A Powerful Code Metrics and Analysis Tool

English | ไธญๆ–‡


โœจ Features

  • ๐ŸŒณ Directory Tree - Intuitive tree structure visualization
  • ๐Ÿ“Š Detailed Statistics - Separate code/comment/blank line counting
  • ๐ŸŒ Multi-language - Support for 50+ programming languages
  • ๐Ÿ’ฐ COCOMO Estimation - Development cost, effort, and schedule estimation
  • ๐Ÿฅ Health Analysis - Comment ratio, large file warnings, etc.
  • ๐Ÿ“ˆ Top N Analysis - Ranking of largest and most complex files
  • ๐ŸŽจ Multiple Formats - Terminal/JSON/Markdown/HTML output
  • ๐Ÿ“ Auto-save Reports - One-click multi-format report generation
  • โš™๏ธ Global Config - Customizable exclusion rules
  • ๐Ÿš€ Zero Dependencies - Pure Python standard library implementation

๐Ÿ“ฆ Installation

# Clone the repository
git clone https://github.com/TbusOS/CodeMetrics.git
cd CodeMetrics

# One-click installation
./scripts/install.sh

The installation script will automatically:

  • โœ… Check Python version (requires >= 3.6)
  • โœ… Set executable permissions
  • โœ… Create symbolic link to ~/.local/bin/codemetrics
  • โœ… Check and configure PATH

๐Ÿš€ Quick Start

# Analyze embedded project (driver code)
codemetrics /path/to/driver -p embedded

# Analyze web project (medium complexity)
codemetrics /path/to/webapp -p semi-detached

# Analyze utility scripts (simple project)
codemetrics /path/to/scripts -p organic

Default output includes:

  • ๐Ÿ“‚ Directory tree structure
  • ๐Ÿ“Š Language statistics table
  • ๐Ÿ’ฐ COCOMO cost estimation
  • ๐Ÿฅ Code health analysis
  • ๐Ÿ“ˆ Top 10 largest files

๐Ÿ“‹ Command Line Options

Option Short Description
path - Directory path to analyze (required)
--project-type -p Required COCOMO project type: organic/semi-detached/embedded
--top N -n N Number of top files to display (default: 10)
--exclude -e Additional patterns to exclude (comma-separated)
--no-color - Disable colored output
--no-save - Don't save reports

๐Ÿ“Š Project Types

Type Description Use Cases
organic Simple projects Small teams, familiar tech stack
semi-detached Medium projects Medium teams, mixed experience
embedded Complex projects Embedded systems, drivers, real-time systems, hardware-related

๐Ÿ“– Usage Examples

Basic Analysis

codemetrics /path/to/project -p embedded

Save Reports

# Automatically save JSON/Markdown/HTML reports
codemetrics /path/to/project -p embedded
# Reports saved in the output folder of the tool directory

Show Top 20 Files

codemetrics /path/to/project -p embedded -n 20

Exclude Additional Directories

codemetrics /path/to/project -p embedded -e "test/*,docs/*"

๐Ÿ“Š Output Formats

CodeMetrics automatically generates reports in multiple formats:

1. Terminal Output (Default)

  • Colored tree structure
  • Formatted statistics tables
  • Real-time progress display

2. JSON Format

# Location: output/report_YYYYMMDD_HHMMSS.json

Suitable for program parsing, CI/CD integration, data analysis

3. Markdown Format

# Location: output/report_YYYYMMDD_HHMMSS.md

Suitable for documentation generation, GitHub/GitLab display

4. HTML Format

# Location: output/report_YYYYMMDD_HHMMSS.html

Suitable for browser viewing, team sharing, presentation demos

๐ŸŒ Supported Languages

System Programming: C, C++, Rust, Go, Assembly

Scripting Languages: Python, Ruby, Perl, Shell, Bash, Lua

Web Frontend: JavaScript, TypeScript, React JSX, React TSX, HTML, CSS, SCSS, Vue

JVM Languages: Java, Kotlin, Scala, Groovy

.NET Platform: C#, F#

Configuration: JSON, YAML, TOML, XML, INI

Documentation: Markdown, reStructuredText

Others: SQL, Dockerfile, Makefile, CMake

And 50+ more programming languages.

โš™๏ธ Configuration

Global configuration file located in tool directory: config.json

{
  "name": "CodeMetrics Global Configuration",
  "exclude": {
    "patterns": ["*.md", "*.json", "*.o", "*.ko"],
    "dirs": [".git", "node_modules", "__pycache__", "build"]
  },
  "cocomo": {
    "cost_per_month_usd": 5000,
    "cost_per_month_cny": 30000
  },
  "health": {
    "comment_ratio_min": 0.15,
    "comment_ratio_max": 0.30,
    "large_file_threshold": 800
  }
}

๐Ÿงฎ COCOMO Model

COCOMO (Constructive Cost Model) is a software cost estimation model proposed by Barry Boehm.

Calculation Formula

Person-Months (PM) = a ร— (KLOC)^b
Duration (months) = c ร— (PM)^d
Team Size = PM / Duration

Model Parameters

Type a b c d Use Case
organic 2.4 1.05 2.5 0.38 Simple projects
semi-detached 3.0 1.12 2.5 0.35 Medium projects
embedded 3.6 1.20 2.5 0.32 Complex projects

๐Ÿฅ Health Metrics

Metric Recommended Value Description
Comment Ratio 15-30% Code maintainability
Average File Lines 100-500 Modularity level
Large Files (>800 lines) 0 Should be split
Low Comment Files (<5%) 0 Should add comments

๐Ÿ“– Documentation

๐ŸŽฏ Use Cases

  • ๐Ÿ“ฑ Embedded Development - Linux kernel drivers, firmware development, real-time systems
  • ๐ŸŒ Web Development - React/Vue frontend, Node.js/Django/Flask backend
  • ๐Ÿ”ง Utility Scripts - Shell scripts, Python automation tools, DevOps scripts
  • ๐Ÿ“š Project Assessment - Code review, cost estimation, technical debt analysis
  • ๐ŸŽ“ Education & Research - Code metrics research, software engineering courses

๐Ÿค Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

Ways to Contribute

  • ๐Ÿ› Report bugs and issues
  • ๐Ÿ’ก Suggest new features
  • ๐Ÿ“– Improve documentation
  • ๐Ÿ”ง Submit Pull Requests
  • ๐ŸŒ Add translations to other languages

โ“ FAQ

Q: Do I need to install additional Python packages?

A: No! CodeMetrics is implemented using pure Python standard library with zero dependencies.

Q: Does it support Windows?

A: Primarily targeted at Linux/macOS. Windows users need to use WSL or Git Bash.

Q: How to uninstall?

A: Run ./scripts/uninstall.sh.

Q: Where are the output reports saved?

A: By default, saved in the <project_name>_output/ directory within the tool directory.

Q: Can I customize COCOMO parameters?

A: Yes! Edit the cocomo section in the config.json file.

๐Ÿ“„ License

MIT License - See LICENSE file for details.

๐Ÿ”— Links


Made with โค๏ธ for developers worldwide

โญ Star this project if you find it helpful!

About

๐Ÿ“Š A powerful code metrics and analysis tool with COCOMO estimation, health analysis, and multi-format reports. Support 50+ languages, zero dependencies.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published