codegen
library in the Codebase Analytics Dashboard. The metrics include indices of codebase maintainabilith and complexity.
View the full code and setup instructions in our codebase-analytics repository.
calculate_cyclomatic_complexity()
function traverses the Codgen codebase object and uses the above rules to find statement objects within each function and calculate the overall cyclomatic complexity of the codebase.
V = (N1 + N2) * log2(n1 + n2)
This calculation uses codegen’s expression types to make this calculation very efficient - these include BinaryExpression, UnaryExpression and ComparisonExpression. The function extracts operators and operands from the codebase object and calculated in calculate_halstead_volume()
function.
calculate_doi()
function.
M = 171 - 5.2 * ln(HV) - 0.23 * CC - 16.2 * ln(SLOC)
This formula is then normalized to a scale of 0-100, where 100 is the maximum maintainability.
The implementation is handled through the calculate_maintainability_index()
function. The codegen codebase object is used to efficiently extract the Cyclomatic Complexity and Halstead Volume for each function and class in the codebase, which are then used to calculate the maintainability index.
/analyze_repo
with the repository URLmodal serve modal_main.py
.
The server can be connected to the frontend dashboard. This web component is implemented as a Next.js application with appropriate comments and visualizations for the raw server data. To run the frontend locally, install all dependencies and run the server with npm run dev
. This can be connected to the FastAPI server by setting the URL in the request to the /analyze_repo
endpoint.