Skip to content

Commit 9d13c9d

Browse files
commit
1 parent 3ebf322 commit 9d13c9d

File tree

7 files changed

+15780
-37
lines changed

7 files changed

+15780
-37
lines changed

README.md

Lines changed: 15582 additions & 31 deletions
Large diffs are not rendered by default.

consolidated_prompts.metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,11 +955,11 @@
955955
},
956956
"last_update": "2025-08-19T16:22:40.918405",
957957
"total_files": 947,
958-
"last_updated": "2025-08-27T13:57:24.017075",
958+
"last_updated": "2025-08-27T14:34:10.850697",
959959
"stats": {
960960
"total_files": 952,
961961
"processed_files": 952,
962-
"updated_files": 7,
962+
"updated_files": 0,
963963
"valid_prompts": 952
964964
}
965965
}

growth_history.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
{
1919
"date": "2025-08-27",
2020
"count": 922,
21-
"created": "2025-08-27T13:57:24.025904"
21+
"created": "2025-08-27T13:57:24.025904",
22+
"updated": "2025-08-27T14:34:10.860225"
2223
}
2324
]
2425
}
File renamed without changes.

index_metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"generated_at": "2025-08-27T13:57:24.030136",
2+
"generated_at": "2025-08-27T14:34:10.865671",
33
"prompt_count": 922,
44
"total_entries": 952,
55
"valid_entries": 922

scripts/update_readme_stats.py

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Update README.md with current system prompt count and growth visualization.
4+
5+
This script reads from growth_history.json and index_metadata.json to add
6+
current statistics and a sparkline chart to the README header.
7+
"""
8+
9+
import json
10+
import re
11+
from pathlib import Path
12+
from datetime import datetime
13+
from typing import List, Dict
14+
15+
16+
def generate_sparkline(counts: List[int]) -> str:
17+
"""Generate a sparkline chart from count data."""
18+
if len(counts) < 2:
19+
return "📈 ▁"
20+
21+
min_val = min(counts)
22+
max_val = max(counts)
23+
24+
if min_val == max_val:
25+
return "📈 " + "▄" * len(counts)
26+
27+
# Normalize to 0-7 range for Unicode blocks
28+
normalized = []
29+
for count in counts:
30+
norm = int(7 * (count - min_val) / (max_val - min_val))
31+
normalized.append(norm)
32+
33+
# Unicode block characters for sparkline
34+
blocks = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"]
35+
sparkline = "📈 " + "".join(blocks[n] for n in normalized)
36+
37+
return sparkline
38+
39+
40+
def load_growth_data(repo_root: Path) -> tuple:
41+
"""Load growth history and current metadata."""
42+
growth_file = repo_root / "growth_history.json"
43+
metadata_file = repo_root / "index_metadata.json"
44+
45+
# Load growth history
46+
if growth_file.exists():
47+
with open(growth_file, 'r') as f:
48+
growth_data = json.load(f)
49+
else:
50+
growth_data = {"entries": []}
51+
52+
# Load current metadata
53+
if metadata_file.exists():
54+
with open(metadata_file, 'r') as f:
55+
metadata = json.load(f)
56+
else:
57+
metadata = {"prompt_count": 0}
58+
59+
return growth_data, metadata
60+
61+
62+
def update_readme_with_stats(repo_root: Path):
63+
"""Update README.md with current statistics and growth chart."""
64+
readme_file = repo_root / "README.md"
65+
66+
if not readme_file.exists():
67+
print("❌ README.md not found")
68+
return False
69+
70+
# Load data
71+
growth_data, metadata = load_growth_data(repo_root)
72+
73+
current_count = metadata.get("prompt_count", 0)
74+
last_updated = metadata.get("generated_at", datetime.now().isoformat())
75+
76+
# Parse the date for display
77+
try:
78+
update_date = datetime.fromisoformat(last_updated.replace('Z', '+00:00'))
79+
formatted_date = update_date.strftime('%Y-%m-%d')
80+
except:
81+
formatted_date = datetime.now().strftime('%Y-%m-%d')
82+
83+
# Generate sparkline from growth history
84+
counts = [entry["count"] for entry in growth_data.get("entries", [])]
85+
if not counts:
86+
counts = [current_count]
87+
88+
sparkline = generate_sparkline(counts)
89+
90+
# Create stats section
91+
stats_section = f"""
92+
## 📊 Library Statistics
93+
94+
{sparkline}
95+
96+
**Total System Prompts:** {current_count:,} | **Last Updated:** {formatted_date}
97+
98+
*This library has grown from {counts[0] if counts else 0} to {current_count} prompts since tracking began*
99+
100+
"""
101+
102+
# Read current README
103+
with open(readme_file, 'r', encoding='utf-8') as f:
104+
content = f.read()
105+
106+
# Check if stats section already exists
107+
stats_pattern = r'## 📊 Library Statistics.*?(?=##|\Z)'
108+
109+
if re.search(stats_pattern, content, re.DOTALL):
110+
# Replace existing stats section
111+
new_content = re.sub(stats_pattern, stats_section.strip() + '\n\n', content, flags=re.DOTALL)
112+
print("✅ Updated existing statistics section")
113+
else:
114+
# Insert stats section after the badges but before Table of Contents
115+
# Look for the pattern: badges -> image -> Table of Contents
116+
toc_pattern = r'(!\[alt text\].*?\n\n)(## Table of Contents)'
117+
118+
if re.search(toc_pattern, content, re.DOTALL):
119+
new_content = re.sub(
120+
toc_pattern,
121+
r'\1' + stats_section + r'\2',
122+
content,
123+
flags=re.DOTALL
124+
)
125+
print("✅ Added new statistics section before Table of Contents")
126+
else:
127+
# Fallback: add after the first heading
128+
lines = content.split('\n')
129+
insert_pos = 1
130+
for i, line in enumerate(lines):
131+
if line.startswith('##') and 'Table of Contents' in line:
132+
insert_pos = i
133+
break
134+
135+
lines.insert(insert_pos, stats_section.strip())
136+
new_content = '\n'.join(lines)
137+
print("✅ Added new statistics section (fallback method)")
138+
139+
# Write updated content
140+
with open(readme_file, 'w', encoding='utf-8') as f:
141+
f.write(new_content)
142+
143+
print(f"📊 Updated README with {current_count:,} prompts and growth chart")
144+
return True
145+
146+
147+
def main():
148+
"""Main function."""
149+
repo_root = Path(__file__).parent.parent
150+
151+
print("🚀 Updating README with library statistics...")
152+
success = update_readme_with_stats(repo_root)
153+
154+
if success:
155+
print("✅ README statistics update completed successfully")
156+
else:
157+
print("❌ Failed to update README statistics")
158+
return 1
159+
160+
return 0
161+
162+
163+
if __name__ == "__main__":
164+
exit(main())

update_library_unified.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,34 @@ def update_readme(self) -> bool:
361361
self.log("README updated successfully", "SUCCESS")
362362
return True
363363

364+
def update_readme_stats(self) -> bool:
365+
"""Update README with current statistics and growth chart."""
366+
self.log("Updating README statistics", "PROGRESS")
367+
368+
try:
369+
# Import the update function from our stats script
370+
import sys
371+
sys.path.append(str(self.repo_root / "scripts"))
372+
from update_readme_stats import update_readme_with_stats
373+
374+
success = update_readme_with_stats(self.repo_root)
375+
if success:
376+
self.log("README statistics updated successfully", "SUCCESS")
377+
else:
378+
self.log("Failed to update README statistics", "ERROR")
379+
return success
380+
381+
except Exception as e:
382+
self.log(f"Error updating README statistics: {e}", "ERROR")
383+
return False
384+
364385
def run_full_update(self, force_rebuild: bool = False) -> bool:
365386
"""Run the complete update process."""
366387
self.log("🚀 Starting System Prompt Library Update", "INFO")
367388
self.log(f"Repository: {self.repo_root}")
368389

369390
success_count = 0
370-
total_tasks = 3
391+
total_tasks = 4 # Updated to include README stats
371392

372393
# Step 1: Consolidate JSON files
373394
success, processed, valid = self.consolidate_prompts(force_rebuild)
@@ -383,12 +404,18 @@ def run_full_update(self, force_rebuild: bool = False) -> bool:
383404
else:
384405
self.log("Index generation failed, continuing with README update", "WARNING")
385406

386-
# Step 3: Update README
407+
# Step 3: Update README with latest content
387408
if self.update_readme():
388409
success_count += 1
389410
else:
390411
self.log("README update failed", "WARNING")
391412

413+
# Step 4: Update README statistics with growth chart
414+
if self.update_readme_stats():
415+
success_count += 1
416+
else:
417+
self.log("README statistics update failed", "WARNING")
418+
392419
# Summary
393420
self.log(f"📊 Completed {success_count}/{total_tasks} tasks successfully")
394421

0 commit comments

Comments
 (0)