Page de statistiques
This commit is contained in:
59
tools/stats/words_histogram.py
Normal file
59
tools/stats/words_histogram.py
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import json
|
||||
import os
|
||||
|
||||
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
PARENT_DIR = os.path.abspath(os.path.join(CURRENT_DIR, os.pardir))
|
||||
if CURRENT_DIR not in sys.path:
|
||||
sys.path.append(CURRENT_DIR)
|
||||
if PARENT_DIR not in sys.path:
|
||||
sys.path.append(PARENT_DIR)
|
||||
|
||||
from common import load_articles, write_result # noqa: E402
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
payload = json.load(sys.stdin)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
print(f"Failed to read JSON: {exc}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
content_dir = payload.get("contentDir") or "content"
|
||||
output_path = payload.get("outputPath")
|
||||
public_path = payload.get("publicPath")
|
||||
|
||||
articles = load_articles(content_dir)
|
||||
values = [a.get("wordCount") or 0 for a in articles if a.get("wordCount")]
|
||||
|
||||
try:
|
||||
from render_stats_charts import render_words_histogram, setup_rcparams
|
||||
except ImportError as exc: # noqa: BLE001
|
||||
print(f"Failed to import renderer: {exc}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
setup_rcparams()
|
||||
render_words_histogram(
|
||||
{
|
||||
"values": values,
|
||||
"title": "Distribution des longueurs d'article",
|
||||
"bins": 20,
|
||||
},
|
||||
output_path,
|
||||
)
|
||||
|
||||
write_result(
|
||||
{
|
||||
"image": public_path,
|
||||
"meta": {
|
||||
"articles": len(values),
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user