# Path: tlfp/tools/common.py
# def log_print(file=None, only_log=False):
#         def __init__(self, file):
#         def write(self, message):
#         def __getattr__(self, attr):
# def open_csv(dirpath, filename, delimiter=";"):
# def open_json(dirpath, filename=None):
# def download_daily(url_or_collecter, filename, output_directory):
# def print_json(dico, filename=None):
# def debug_file(data, filename):
# def format_date(d):
# def format_display_date(d):
# def real_lower(text):
# def clean_accents(text):
# def clean_text_for_diff(text):
# def compute_approx_similarity(text1, text2):
# def compute_similarity(text1, text2):
# def compute_similarity_by_articles(text1, text2):
# def identify_room(url_or_institution, legislature):
# def national_assembly_text_legislature(url_text):
# def personalize_link(link, obj, urlapi):
# def slug_groupe(g):
#     def __init__(self, sourcedir, load_parls=False):
#     def get_procedure(self):
#     def get_parlementaires(self):
#     def get_parlementaire(self, urlapi, slug):
#     def get_groupes(self):
#     def get_historique_groupes_senat(self):
#     def get_senateur_groupe(self, slug, object_date, urlapi):
#     def add_groupe(self, groupes, gpe, urlapi):
# def get_text_id(texte_url):
#     class Logger:
# class Context(object):


import os, sys, glob, re
from tlfp.tools.common import strip_text, compute_similarity_by_articles, open_json, print_json, \
    clean_text_for_diff, datize, clean_statuses
    stats["total_seances_senat"] = sum([step['total_seances'] for dir, step in intervs.items() if '_senat' in dir])

    # # # AMENDMENTS # # #

    add_amendments_stats(stats, find_amendements(output_dir))

    # # # TEXTS # # #

    first_step, last_step = find_first_and_last_steps(dos)
    first_arts = read_articles(first_step)
    last_arts = read_articles(last_step)

    stats["total_input_articles"] = len(first_arts)
    stats["total_output_articles"] = len(last_arts)
    stats["ratio_articles_growth"] = (stats["total_output_articles"] - stats["total_input_articles"]) / stats["total_input_articles"]

    stats["input_text_length"] = step_text_length(first_step)
    stats["output_text_length"] = step_text_length(last_step)
    stats["ratio_text_length_growth"] = (stats["output_text_length"] - stats["input_text_length"]) / stats["input_text_length"]

    stats["input_text_word_count"] = step_word_count(first_step)
    stats["output_text_word_count"] = step_word_count(last_step)
    stats["ratio_word_count_growth"] = (stats["output_text_word_count"] - stats["input_text_word_count"]) / stats["input_text_word_count"]

    adopted_step = find_first_and_last_steps(dos, include_CC=False)[1]
    if has_been_censored(dos):
        stats["censored_articles"], stats["fully_censored_articles"] = count_censored_articles(last_step)
        stats["output_text_before_CC_length"] = step_text_length(adopted_step)
        stats["output_text_before_CC_word_count"] = step_word_count(adopted_step)


# Path: tlfp/tools/common.py
# def log_print(file=None, only_log=False):
#         def __init__(self, file):
#         def write(self, message):
#         def __getattr__(self, attr):
# def open_csv(dirpath, filename, delimiter=";"):
# def open_json(dirpath, filename=None):
# def download_daily(url_or_collecter, filename, output_directory):
# def print_json(dico, filename=None):
# def debug_file(data, filename):
# def format_date(d):
# def format_display_date(d):
# def real_lower(text):
# def clean_accents(text):
# def clean_text_for_diff(text):
# def compute_approx_similarity(text1, text2):
# def compute_similarity(text1, text2):
# def compute_similarity_by_articles(text1, text2):
# def identify_room(url_or_institution, legislature):
# def national_assembly_text_legislature(url_text):
# def personalize_link(link, obj, urlapi):
# def slug_groupe(g):
#     def __init__(self, sourcedir, load_parls=False):
#     def get_procedure(self):
#     def get_parlementaires(self):
#     def get_parlementaire(self, urlapi, slug):
#     def get_groupes(self):
#     def get_historique_groupes_senat(self):
#     def get_senateur_groupe(self, slug, object_date, urlapi):
#     def add_groupe(self, groupes, gpe, urlapi):
# def get_text_id(texte_url):
#     class Logger:
# class Context(object):


# Path: tlfp/tools/compute_stats.py
import os, sys, glob, re
from tlfp.tools.common import strip_text, compute_similarity_by_articles, open_json, print_json, \
    clean_text_for_diff, datize, clean_statuses

    stats["total_seances_senat"] = sum([step['total_seances'] for dir, step in intervs.items() if '_senat' in dir])

    # # # AMENDMENTS # # #

    add_amendments_stats(stats, find_amendements(output_dir))

    # # # TEXTS # # #

    first_step, last_step = find_first_and_last_steps(dos)
    first_arts = read_articles(first_step)
    last_arts = read_articles(last_step)

    stats["total_input_articles"] = len(first_arts)
    stats["total_output_articles"] = len(last_arts)
    stats["ratio_articles_growth"] = (stats["total_output_articles"] - stats["total_input_articles"]) / stats["total_input_articles"]

    stats["input_text_length"] = step_text_length(first_step)
    stats["output_text_length"] = step_text_length(last_step)
    stats["ratio_text_length_growth"] = (stats["output_text_length"] - stats["input_text_length"]) / stats["input_text_length"]

    stats["input_text_word_count"] = step_word_count(first_step)
    stats["output_text_word_count"] = step_word_count(last_step)
    stats["ratio_word_count_growth"] = (stats["output_text_word_count"] - stats["input_text_word_count"]) / stats["input_text_word_count"]

    adopted_step = find_first_and_last_steps(dos, include_CC=False)[1]
    if has_been_censored(dos):
        stats["censored_articles"], stats["fully_censored_articles"] = count_censored_articles(last_step)
        stats["output_text_before_CC_length"] = step_text_length(adopted_step)
        stats["output_text_before_CC_word_count"] = step_word_count(adopted_step)


    stats["ratio_texte_modif"] = 1 - compute_similarity_by_articles(first_arts, last_arts)