Clean imports and start packaging it

This commit is contained in:
Benjamin Bertrand 2016-11-08 11:07:03 +03:00
parent 95bcc6a16b
commit 3eafad5841
5 changed files with 95 additions and 13 deletions

View File

@ -0,0 +1,9 @@
#!/usr/bin/env python
# encoding: utf-8
from generate_bilan import generate_bilan
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del

View File

@ -0,0 +1,17 @@
#!/usr/bin/env python
# encoding: utf-8
from generate_bilan import generate_bilan
import optparse
parser = optparse.OptionParser()
parser.add_option("-c","--classe",action="store",type="string",dest="classe", help="The classe")
parser.add_option("-e","--evaluation",action="store",type="string",dest="ds_name", help="The evaluation name.")
(options, args) = parser.parse_args()
build_bilan(options.classe, options.ds_name)
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del

View File

@ -1,12 +1,10 @@
#!/usr/bin/env python
# encoding: utf-8
from extract import extract_flat_marks, get_class_ws
from df_marks_manip import digest_flat_df, students_pov
from opytex import texenv
from notes_tools import extract_flat_marks, get_class_ws, digest_flat_df, students_pov
from generate_bilan.texenv import texenv
import pandas as pd
import numpy as np
import optparse
import xlrd
notStudent = ["Trimestre", "Nom", "Date", "Exercice", "Question", "Competence", "Domaine", "Commentaire", "Bareme", "Niveau"]
@ -84,7 +82,7 @@ def feed_bilan(target, datas, template = "./tpl_bilan.tex"):
f.write(bilan.render(**datas))
print("{} est construit! Ya plus qu'à compiler!".format(target))
def build_bilan(classe, ds_name):
def generate_bilan(classe, ds_name):
ws = get_class_ws(classe)
flat_df = extract_flat_marks(ws)
@ -103,14 +101,6 @@ def build_bilan(classe, ds_name):
feed_bilan(target, datas)
if __name__ == "__main__":
parser = optparse.OptionParser()
parser.add_option("-c","--classe",action="store",type="string",dest="classe", help="The classe")
parser.add_option("-e","--evaluation",action="store",type="string",dest="ds_name", help="The evaluation name.")
(options, args) = parser.parse_args()
build_bilan(options.classe, options.ds_name)
# -----------------------------
# Reglages pour 'vim'

53
generate_bilan/texenv.py Normal file
View File

@ -0,0 +1,53 @@
#!/usr/bin/env python
# encoding: utf-8
import jinja2, os
__all__ = ["texenv"]
# Definition of jinja syntax for latex
texenv = jinja2.Environment(
block_start_string = '\Block{',
# Gros WTF!! Si on le met en maj ça ne marche pas alors que c'est en maj dans le template...
block_end_string = '}',
variable_start_string = '\Var{',
variable_end_string = '}',
loader = jinja2.FileSystemLoader(os.path.abspath('.')),
extensions = ['jinja2.ext.do']
)
# Filters
def do_calculus(steps, name = "A", sep = "=", end = "", joining = " \\\\ \n"):
"""Display properly the calculus
Generate this form string:
"name & sep & a_step end joining"
:param steps: list of steps
:returns: latex string ready to be endbeded
"""
ans = joining.join([name + " & " + sep + " & " + str(s) + end for s in steps])
return ans
texenv.filters['calculus'] = do_calculus
from random import shuffle
texenv.filters['shuffle'] = shuffle
if __name__ == '__main__':
from pymath.expression import Expression
exp = Expression("2/4 + 18")
print(do_calculus(exp.simplify()))
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del

View File

@ -0,0 +1,13 @@
#!/usr/bin/env python
# encoding: utf-8
from notes_tools.extract import extract_flat_marks, get_class_ws
from notes_tools.df_marks_manip import digest_flat_df, students_pov
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del