basic log

This commit is contained in:
Benjamin Bertrand 2016-11-14 07:42:50 +03:00
parent 5ba03e8e40
commit ae5a529602
2 changed files with 36 additions and 3 deletions

View File

@ -1,10 +1,25 @@
#!/usr/bin/env python
# encoding: utf-8
import logging
# création de l'objet logger qui va nous servir à écrire dans les logs
logger = logging.getLogger("generate_bilan")
# on met le niveau du logger à DEBUG, comme ça il écrit tout
logger.setLevel(logging.WARNING)
formatter = logging.Formatter('%(asctime)s :: %(name)s :: %(levelname)s :: %(message)s')
steam_handler = logging.StreamHandler()
steam_handler.setLevel(logging.DEBUG)
steam_handler.setFormatter(formatter)
logger.addHandler(steam_handler)
from .generate_bilan import generate_bilan
import optparse
import os
from path import Path
import sys
# Defaults settings
default_template = "tpl_bilan.tex"
@ -38,18 +53,31 @@ def main():
dest="template",
default=default_template,
help="The template file")
parser.add_option("-d",
"--debug",
action="store_true",
dest="debug_level",
help="Enable debug")
(options, args) = parser.parse_args()
if not options.classe:
raise ValueError("Need to pass a class with -c. See -h for help")
logger.error("Need to pass a class with -c. See -h for help")
sys.exit()
if not options.ds_name:
raise ValueError("Need to pass a evaluation name with -e. See -h for help")
logger.error("Need to pass a evaluation name with -e. See -h for help")
sys.exit()
if options.debug_level:
logger.setLevel(logging.DEBUG)
generate_bilan(options.classe,
options.ds_name,
options.path,
options.template)
logger.info("À fini")
if __name__ == "__main__":
main()

View File

@ -8,6 +8,9 @@ import numpy as np
import xlrd
from path import Path
import logging
logger = logging.getLogger("generate_bilan")
notStudent = ["Trimestre", "Nom", "Date", "Exercice", "Question", "Competence", "Domaine", "Commentaire", "Bareme", "Niveau"]
def extract_students(df, notStudent = notStudent):
@ -92,7 +95,7 @@ def feed_bilan(target, datas, template = "tpl_bilan.tex"):
with open(target, "w") as f:
f.write(bilan.render(**datas))
print("{} est construit! Ya plus qu'à compiler!".format(target))
logger.info("{} est construit! Ya plus qu'à compiler!".format(target))
def generate_bilan(classe, ds_name, path = Path('./'), template = "tpl_bilan.tex"):
""" Generate the bilan of a evaluation for a class
@ -104,9 +107,11 @@ def generate_bilan(classe, ds_name, path = Path('./'), template = "tpl_bilan.tex
"""
ws = get_class_ws(classe, path)
logger.info("Worksheets of {} imported".format(classe))
flat_df = extract_flat_marks(ws)
quest_df, exo_df, eval_df = digest_flat_df(flat_df)
logger.info("Worksheets parsed")
quest_df = select_ds(ds_name, quest_df)
exo_df = select_ds(ds_name, exo_df)