colles.mp2i-vms.fr/colloscope/pdfexport.py

195 lines
6.3 KiB
Python

from datetime import date, timedelta
from fpdf import FPDF
from fpdf.fonts import FontFace
from fpdf.enums import TableCellFillMode
calendrier_zoneC = date(2023, 9, 18), [
( date(2023, 10, 21), date(2023, 11, 6) ),
( date(2023, 12, 23), date(2024, 1, 8) ),
( date(2024, 2, 10), date(2024, 2, 26) ),
( date(2024, 4, 6), date(2024, 4, 22) ),
]
def jour_of_sem(n, cal):
sem_1, vac = cal
jour = sem_1 + (n-1) * timedelta(weeks=1)
for (debut, fin) in vac:
if jour >= debut:
jour += 2*timedelta(weeks=1)
return jour
etudiants = [
['Aboujaib', 'Alexandre', 4, 'A', '', ''],
['Ajan', 'George', 4, 'A', '', ''],
['Akrad', 'Lina', 1, 'SI', '', ''],
['Aubert', 'Nicolas', 1, 'SI', '', ''],
['Badr', 'Roman', 4, 'A', '', ''],
['Bazire', 'Aurélien', 5, 'A', '', ''],
['Boit', 'Arthur', 5, 'A', '', ''],
['Boubker', 'Youssef', 5, 'A', '', ''],
['Boudjema', 'Dylan', 1, 'SI', '', ''],
['Chiriac', 'Mihnea', 6, 'A', '', ''],
['Courier', 'Marine', 6, 'A', '', ''],
['Daguin', 'Joseph', 6, 'A', '', ''],
['Dauguen', 'Gabriel', 7, 'A', '', ''],
['De Weer', 'Matthias', 7, 'A', '', ''],
['Desbouis', 'Katell', 2, 'SI', '', ''],
['Dupouy', 'Jérémie', 7, 'A', '', ''],
['Hariri--Gautier-Picard', 'Grégoire', 8, 'A', '', ''],
['Juricevic', 'Matteo', 8, 'A', '', ''],
['Knanoua', 'Anas', 8, 'A', '', ''],
['Lesenne', 'Pierrick', 9, 'A', '', ''],
['Lin', 'Hao', 2, 'SI', '', ''],
['Masbatin', 'Lucas', 2, 'SI', '', ''],
['Mayuran', 'Mithushan', 9, 'A', '', ''],
['Messahli', 'Yassine', 9, 'A', '', ''],
['Moguérou', 'Valentin', 10, 'B', '', ''],
['Mohellebi', 'Mathéo', 10, 'B', '', ''],
['Mouisset--Ferrara', 'Maël', 10, 'B', '', ''],
['Ottavi', 'Corentin', 11, 'B', '', ''],
['Ponce', 'Alexian', 11, 'B', '', ''],
['Pujol', 'Raphaël', 11, 'B', '', ''],
['Pustetto', 'Mathis', 12, 'B', '', ''],
['Radice', 'Roman', 12, 'B', '', ''],
['Rat', 'Evelyn', 12, 'B', '', ''],
['Rousse', 'Louis', 3, 'SI', '', ''],
['Roux', 'Gaëtan', 3, 'SI', '', ''],
['Rouyre--Cros', 'Célian', 3, 'SI', '', ''],
['Sourbé', 'François-Gabriel', 13, 'B', '', ''],
['Stourbe', 'Simon', 13, 'B', '', ''],
['Thai', 'Dany', 13, 'B', '', ''],
['Théodore', 'Jonathan', 14, 'B', '', ''],
['Vandroux', 'Benoît', 14, 'B', '', ''],
['Veyssière', 'Thibaud', 14, 'B', '', ''],
['Vié', 'Adrien', 15, 'B', '', ''],
['Ye', 'Luan', 15, 'B', '', ''],
['Zarka', 'Amélie', 15, 'B', '', ''],
]
creneaux = [
["Mathématiques", "vendredi", "17:00", "M. OUBAHA", "C382"],
["Anglais", "mercredi", "14:00", "Mme LE GOURIELLEC", "C393"],
["Mathématiques", "mercredi", "15:00", "M. BOULLY", "R004"],
["Physique", "mardi", "14:00", "Mme CHEVALIER", "R103"],
["Mathématiques", "mardi", "18:00", "M. RAPIN", "V152"],
["Anglais", "mardi", "14:00", "Mme BELAGGOUNE", "C4??"],
["pas de colle", "", "", "", ""],
["Physique", "mardi", "17:00", "M. COLIN", "C386"],
["Mathématiques", "mercredi", "13:30", "M. BOUVEROT", "??"],
["Anglais", "lundi", "13:00", "M. HERBAUT", "V052"],
]
semaines = list(range(24, 34))
rotations = [
# [semaine, groupe, creneau]
(24, 1, 1),
(24, 2, 2),
(24, 3, 3),
(27, 3, 3),
(28, 3, 3),
(31, 3, 3),
]
class PDF(FPDF):
def liste_eleves(self, etudiants):
with self.table(
align="RIGHT",
col_widths=(4, 3, 1, 1, 1, 1),
width=80,
line_height=3) as table:
header = table.row()
for th in ("Nom", "Prénom", "Grp.", "TD", "LV1", "LV2"):
header.cell(th)
for etu in etudiants:
row = table.row()
row.cell(etu[0].upper()) # Nom
row.cell(etu[1]) # Prénom
row.cell(str(etu[2])) # Groupe
row.cell(etu[3]) # TD
row.cell(etu[4]) # LV1
row.cell(etu[5]) # LV2
def table_colloscope(self, creneaux, semaines, rotations):
with self.table(
align="LEFT",
width=190,
line_height=3,
col_widths=(2, 1, 1, 3, 1, *(1,)*len(semaines)),
num_heading_rows=2) as table:
header = table.row()
for th in ("Matière", "Jour", "Heure", "Colleur", "Salle"):
header.cell(th, align="CENTER", rowspan=2)
for sem in semaines:
header.cell(str(sem), align="CENTER")
header2 = table.row()
for sem in semaines:
header2.cell(jour_of_sem(sem, calendrier_zoneC).strftime("%d/%m/%y"), align="CENTER")
for i, tr in enumerate(creneaux):
matiere, jour, heure, colleur, salle = tr
row = table.row()
row.cell(matiere)
row.cell(jour)
row.cell(heure)
row.cell(colleur)
row.cell(salle)
for s in semaines:
for rot in rotations:
if rot[2] == i and rot[0] == s:
row.cell(str(rot[1]), align="CENTER")
break
else:
row.cell()
def table_travaux(self):
with self.table(
align="LEFT",
width=190,
line_height=3,
col_widths=(2, 1, 1, 4, *(1,)*len(semaines)),
first_row_as_headings=False) as table:
row = table.row()
row.cell("TP Physique")
row.cell("lundi")
row.cell("8:30")
row.cell()
for _ in range(len(semaines)):
row.cell("9 à 15", align="CENTER")
def generate():
pdf = PDF(orientation="landscape", format="a4")
pdf.set_font("helvetica", size=6)
pdf.set_title("colloscope mp2i semestre 5/2")
pdf.set_author("projet colloscope")
pdf.set_author("projet colloscope")
pdf.add_page()
pdf.cell(text="Colloscope MP2I Semestre 5/2", center=True, border=1, h=5)
base_y = pdf.t_margin + 10
pdf.set_y(base_y)
pdf.liste_eleves(etudiants)
pdf.set_y(base_y)
pdf.table_colloscope(creneaux, semaines, rotations)
pdf.y += 3
pdf.table_travaux()
pdf.output("test.pdf")
if __name__ == "__main__":
generate()