Function bodies 58 total
generate_markdown_report function · python · L161-L243 (83 LOC)src/site-metrics/get-ibook-metrics.py
def generate_markdown_report(metrics: Dict, output_file: Path) -> None:
"""Generate a markdown report of the book metrics."""
with open(output_file, 'w', encoding='utf-8') as f:
f.write("# Book Metrics\n\n")
f.write(f"*Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}*\n\n")
f.write("## Overview\n\n")
f.write("This page provides comprehensive metrics for the IT Management Graph intelligent textbook.\n\n")
f.write("## Content Metrics\n\n")
f.write("| Metric | Count |\n")
f.write("|--------|-------|\n")
f.write(f"| **Chapters** | {metrics['chapters']['count']} |\n")
f.write(f"| **Total Sections** | {metrics['chapters']['total_sections']} |\n")
f.write(f"| **Learning Graph Concepts** | {metrics['concepts']} |\n")
f.write(f"| **Glossary Terms** | {metrics['glossary_terms']} |\n")
f.write(f"| **MicroSims** | {metrics['microsims']} |\n")
f.write(f"| **AI Prompts** | {metrmain function · python · L246-L287 (42 LOC)src/site-metrics/get-ibook-metrics.py
def main():
"""Main function to calculate and report metrics."""
# Use repository root as base
repo_root = Path(__file__).parent.parent.parent
docs_dir = repo_root / 'docs'
if not docs_dir.exists():
print(f"Error: docs directory not found at {docs_dir}")
return 1
print("Calculating book metrics...")
# Calculate all metrics
chapters_data = analyze_chapters(docs_dir)
total_images, image_breakdown = count_images(docs_dir)
metrics = {
'chapters': chapters_data,
'concepts': count_learning_graph_concepts(docs_dir),
'glossary_terms': count_glossary_terms(docs_dir),
'microsims': count_microsims(docs_dir),
'prompts': count_prompts(docs_dir),
'total_words': count_words_in_markdown(docs_dir),
'markdown_files': count_markdown_files(docs_dir),
'total_images': total_images,
'image_breakdown': image_breakdown
}
# Generate markdown report
output_file = docs_dcount_markdown_files function · python · L9-L11 (3 LOC)src/site-metrics/get-metrics-json.py
def count_markdown_files(docs_dir):
"""Count total number of markdown files in the docs directory."""
return len(list(Path(docs_dir).glob('**/*.md')))count_images function · python · L13-L17 (5 LOC)src/site-metrics/get-metrics-json.py
def count_images(docs_dir):
"""Count total number of image files (png and jpg) in the docs directory."""
png_count = len(list(Path(docs_dir).glob('**/*.png')))
jpg_count = len(list(Path(docs_dir).glob('**/*.jpg')))
return png_count + jpg_countcount_words_in_markdown function · python · L19-L34 (16 LOC)src/site-metrics/get-metrics-json.py
def count_words_in_markdown(docs_dir):
"""Count total number of words in all markdown files."""
total_words = 0
for md_file in Path(docs_dir).glob('**/*.md'):
with open(md_file, 'r', encoding='utf-8') as f:
content = f.read()
# Remove code blocks to avoid counting code as words
content = re.sub(r'```.*?```', '', content, flags=re.DOTALL)
# Remove inline code
content = re.sub(r'`.*?`', '', content)
# Remove URLs
content = re.sub(r'http[s]?://\S+', '', content)
# Split and count remaining words
words = content.split()
total_words += len(words)
return total_wordscount_microsims function · python · L36-L41 (6 LOC)src/site-metrics/get-metrics-json.py
def count_microsims(docs_dir):
"""Count number of subdirectories in the /docs/sims directory."""
sims_dir = Path(docs_dir) / 'sims'
if not sims_dir.exists():
return 0
return len([d for d in sims_dir.iterdir() if d.is_dir()])count_glossary_terms function · python · L43-L55 (13 LOC)src/site-metrics/get-metrics-json.py
def count_glossary_terms(docs_dir):
"""Count number of level 4 headers (####) in the glossary.md file."""
glossary_path = Path(docs_dir) / 'glossary.md'
if not glossary_path.exists():
return 0
term_count = 0
with open(glossary_path, 'r', encoding='utf-8') as f:
content = f.read()
# Count level 4 headers (####)
terms = re.findall(r'^####\s+.*$', content, re.MULTILINE)
term_count = len(terms)
return term_countWant this analysis on your repo? https://repobility.com/scan/
main function · python · L57-L79 (23 LOC)src/site-metrics/get-metrics-json.py
def main():
parser = argparse.ArgumentParser(description='Calculate metrics for an intelligent textbook repository.')
parser.add_argument('repo_root', help='Root directory of the checked out repository')
args = parser.parse_args()
docs_dir = os.path.join(args.repo_root, 'docs')
if not os.path.exists(docs_dir):
print(f"Error: docs directory not found at {docs_dir}")
return 1
# Calculate metrics
metrics = {
'markdown-file-count': count_markdown_files(docs_dir),
'image-count': count_images(docs_dir),
'word-count': count_words_in_markdown(docs_dir),
'microsim-count': count_microsims(docs_dir),
'glossary-term-count': count_glossary_terms(docs_dir)
}
# Output results as JSON
import json
print(json.dumps(metrics, indent=2))‹ prevpage 2 / 2