ScoDoc-Lille/misc/count_inscriptions.py

52 lines
1.5 KiB
Python
Raw Normal View History

2020-09-26 16:19:37 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Affiche nombre d'inscriptions aux semestres pour chaque etudiant
et supprime les etudiants jamais inscrits ayant un homonyme exact
(erreur passage GEA, fev 2007)
"""
2021-07-09 21:44:39 +02:00
from __future__ import print_function
2020-09-26 16:19:37 +02:00
import csv
2021-07-09 21:44:39 +02:00
import pdb
import sys
import psycopg2
2020-09-26 16:19:37 +02:00
2021-07-09 21:44:39 +02:00
DBCNXSTRING = "host=localhost user=scogea dbname=SCOXXXX password=XXXXX"
2020-09-26 16:19:37 +02:00
2021-07-09 21:44:39 +02:00
SCO_ENCODING = "utf-8"
2020-09-26 16:19:37 +02:00
2021-07-09 21:44:39 +02:00
cnx = psycopg2.connect(DBCNXSTRING)
2020-09-26 16:19:37 +02:00
cursor = cnx.cursor()
cursor.execute("select * from identite i order by nom")
R = cursor.dictfetchall()
nzero = 0
nhomonoins = 0
2021-07-09 21:44:39 +02:00
print("etudid, nom, prenom, nb_inscriptions")
2020-09-26 16:19:37 +02:00
for e in R:
2021-07-09 21:44:39 +02:00
cursor.execute(
"select count(*) from notes_formsemestre_inscription where etudid=%(etudid)s",
{"etudid": e["etudid"]},
)
2020-09-26 16:19:37 +02:00
nbins = cursor.fetchone()[0]
if nbins == 0:
nzero += 1
# recherche homonyme
2021-07-09 21:44:39 +02:00
cursor.execute(
"select * from identite i where nom=%(nom)s and prenom=%(prenom)s", e
)
2020-09-26 16:19:37 +02:00
H = cursor.dictfetchall()
if len(H) == 2:
2021-07-09 21:44:39 +02:00
nhomonoins += 1
print(e["etudid"], e["nom"], e["prenom"], nbins)
2020-09-26 16:19:37 +02:00
# etudiant non inscrit ayant un homonyme exact:
2021-07-09 21:44:39 +02:00
# il doit etre supprimé !!!
# cursor.execute("delete from admissions where etudid=%(etudid)s", e)
# cursor.execute("delete from identite where etudid=%(etudid)s", e)
2020-09-26 16:19:37 +02:00
cnx.commit()
2021-07-09 21:44:39 +02:00
print("= %d etudiants, %d jamais inscrits, %d avec homo" % (len(R), nzero, nhomonoins))