74 lines
2.2 KiB
Python
74 lines
2.2 KiB
Python
from .generateur_main import generate_from_path
|
|
PAGE_LINES = {
|
|
10: 53,
|
|
12: 49,
|
|
14: 39,
|
|
16: 34,
|
|
18: 31
|
|
}
|
|
MAX_LENGTH = {
|
|
10: 38,
|
|
12: 32,
|
|
14: 25,
|
|
16: 23,
|
|
18: 20
|
|
}
|
|
|
|
|
|
def Csv_generator(path, nb_in_serie, nb_page, police, consigne, writer):
|
|
exo_exemple = generate_from_path(path, 1, 'csv')
|
|
if len(consigne) < MAX_LENGTH[police] and len(consigne) > len(exo_exemple):
|
|
longueur_max = len(consigne) + 5
|
|
elif len(consigne) > MAX_LENGTH[police] and len(consigne) > len(exo_exemple):
|
|
longueur_max = MAX_LENGTH[police]
|
|
elif len(consigne) > MAX_LENGTH[police] and len(consigne) < len(exo_exemple):
|
|
longueur_max = len(exo_exemple)
|
|
elif len(consigne) < MAX_LENGTH[police] and len(consigne) < len(exo_exemple):
|
|
longueur_max = len(exo_exemple)
|
|
else:
|
|
longueur_max = len(exo_exemple)
|
|
|
|
consigne_lines = []
|
|
if len(consigne) > 30:
|
|
cons = consigne.replace(',', ' ').split(' ')
|
|
text_longueur = ''
|
|
for i in cons:
|
|
text_longueur = text_longueur + i + ' '
|
|
if len(text_longueur) > longueur_max:
|
|
consigne_lines.append(text_longueur)
|
|
text_longueur = ''
|
|
#
|
|
else:
|
|
consigne_lines.append(consigne)
|
|
serie_page_vertical = int(PAGE_LINES[police] /
|
|
(nb_in_serie + 1 + len(consigne_lines)))
|
|
|
|
rest_line = PAGE_LINES[police] - (serie_page_vertical * nb_in_serie +
|
|
serie_page_vertical * len(consigne_lines) + serie_page_vertical)
|
|
|
|
max_length = len(exo_exemple) if len(
|
|
exo_exemple) > longueur_max else longueur_max
|
|
max_in_line = 2 * MAX_LENGTH[police]
|
|
space = max_in_line / 8
|
|
|
|
nb_in_line = int(max_in_line / (max_length + space)) + 1
|
|
|
|
for p in range(nb_page):
|
|
for c in range(serie_page_vertical):
|
|
|
|
for w in consigne_lines:
|
|
writer.writerow([*[w, ""] * nb_in_line])
|
|
|
|
for k in range(nb_in_serie):
|
|
calcul_list = list(
|
|
map(lambda calc: calc['calcul'], generate_from_path(path, nb_in_line, 'csv')))
|
|
n = 1
|
|
for i in range(n, len(calcul_list) + n + 1, n+1):
|
|
calcul_list.insert(i, '')
|
|
writer.writerow(calcul_list)
|
|
writer.writerow([''])
|
|
|
|
for r in range(rest_line):
|
|
writer.writerow([''])
|
|
|