up follow livre
This commit is contained in:
parent
b4b4398bb0
commit
3a7a3849ae
12242 changed files with 2564461 additions and 6914 deletions
|
@ -1,10 +1,8 @@
|
|||
import re
|
||||
from collections import defaultdict
|
||||
import os
|
||||
|
||||
|
||||
regex_chapitre = r'\*\* (.+)'
|
||||
regex_target = r':target_(\d+):'
|
||||
fichier_livre = 'livre.org'
|
||||
|
||||
# Ouvrir le fichier livre.org
|
||||
|
@ -13,11 +11,10 @@ with open("livre.org", "r") as livre:
|
|||
|
||||
# Définir la fonction pour séparer les mots d'une ligne
|
||||
def split_words(line):
|
||||
return re.split(r'[\s]+', line)
|
||||
return re.split('[\s]+', line)
|
||||
|
||||
# Initialisation des dictionnaires pour stocker les informations des chapitres
|
||||
# Initialisation du dictionnaire pour stocker le nombre de mots par chapitre
|
||||
chapters_word_count = defaultdict(int)
|
||||
chapters_target = {}
|
||||
|
||||
# Parcours des lignes du fichier
|
||||
# Parcourir chaque ligne du fichier livre.org
|
||||
|
@ -26,17 +23,8 @@ for ligne in content.strip().split("\n"):
|
|||
# Rechercher le titre du chapitre
|
||||
match_chapitre = re.search(regex_chapitre, ligne)
|
||||
if match_chapitre:
|
||||
chapitre_title = match_chapitre.group(1)
|
||||
# Nettoyer le titre du chapitre
|
||||
chapitre = re.sub(r":title:|:target_\d+:", "", chapitre_title).strip()
|
||||
|
||||
# Rechercher une cible de mots dans le titre du chapitre
|
||||
match_target = re.search(regex_target, chapitre_title)
|
||||
if match_target:
|
||||
target_words = int(match_target.group(1))
|
||||
chapters_target[chapitre] = target_words
|
||||
chapitre = re.sub( ":title:", "", match_chapitre.group(1))
|
||||
print(chapitre)
|
||||
|
||||
words = split_words(ligne)
|
||||
chapters_word_count[chapitre] += len(words)
|
||||
|
||||
|
@ -107,47 +95,4 @@ print(f"Estimation du temps de lecture: {format_time(temps_de_lecture(sum_mots))
|
|||
print(f"Estimation du temps de rédaction à 30 mots/minute: {format_time(temps_de_redaction(sum_mots, 30))}")
|
||||
print(f"Estimation du temps de rédaction à 70 mots/minute: {format_time(temps_de_redaction(sum_mots, 70))}")
|
||||
|
||||
# Générer un rapport en markdown sur l'atteinte des cibles de mots
|
||||
def generate_target_report():
|
||||
# Compter les chapitres sans cible
|
||||
chapters_without_target = sum(1 for chapitre in chapters_word_count.keys()
|
||||
if chapitre != '(chapitre not found)' and chapitre not in chapters_target)
|
||||
|
||||
# Créer le rapport markdown
|
||||
report = "# Rapport d'atteinte des cibles de mots\n\n"
|
||||
|
||||
# Ajouter un résumé
|
||||
report += f"## Résumé\n\n"
|
||||
report += f"- **Chapitres avec cible définie**: {len(chapters_target)}\n"
|
||||
report += f"- **Chapitres sans cible définie**: {chapters_without_target}\n"
|
||||
report += f"- **Total des chapitres**: {len(chapters_target) + chapters_without_target}\n\n"
|
||||
|
||||
# Ajouter les détails pour chaque chapitre avec une cible
|
||||
if chapters_target:
|
||||
report += "## Détails par chapitre\n\n"
|
||||
report += "| Chapitre | Mots actuels | Cible | Statut | Progression |\n"
|
||||
report += "|----------|--------------|-------|--------|-------------|\n"
|
||||
|
||||
for chapitre, target in sorted(chapters_target.items()):
|
||||
word_count = chapters_word_count[chapitre]
|
||||
percentage = (word_count / target) * 100
|
||||
status = "✅ Atteint" if word_count >= target else "❌ Non atteint"
|
||||
# Create a more visually informative progress bar for markdown
|
||||
bar_length = 20
|
||||
filled_length = int(bar_length * percentage / 100)
|
||||
bar = '█' * filled_length + '░' * (bar_length - filled_length)
|
||||
progress_bar = f"[{bar}] {percentage:.1f}%"
|
||||
|
||||
report += f"| {chapitre} | {word_count} | {target} | {status} | {progress_bar} |\n"
|
||||
|
||||
# Écrire le rapport dans un fichier
|
||||
with open("rapport_cibles_mots.md", "w") as f:
|
||||
f.write(report)
|
||||
|
||||
print(f"\nRapport d'atteinte des cibles de mots généré: rapport_cibles_mots.md")
|
||||
return report
|
||||
|
||||
# Générer le rapport
|
||||
generate_target_report()
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue