364 lines
17 KiB
Python
364 lines
17 KiB
Python
"""
|
||
FORMATION INITIALE :
|
||
A l’image de la gestion des admissions, le système sera paramétrable par un utilisateur pour définir les règles de calcul.
|
||
En attendant de mettre en le module de règle dynamique, une liste de règles statiques seront codées en dure le dans le système.
|
||
Ainsi l’administrateur pourra choisir la règle adaptée à sa formation.
|
||
Pour les cas particuliers, les équipes de MTT feront des développements spécifiques pour les clients qui le souhaite.
|
||
|
||
Par defaut, les regles de calcul implémentées :
|
||
• Nom : calcul_mode_1
|
||
Detail : ( (Moyenne Art. (TD) + Moyenne Art(TP) * 2)/3 + Examen Final ) / 2
|
||
|
||
|
||
• Nom : calcul_mode_2
|
||
Detail : ( Note Stage + Examen Final ) / 2
|
||
|
||
|
||
• Nom : calcul_mode_2
|
||
Detail : (Moyenne Art.(TD) + Moyenne Art.(Contrôle Continue) + Examen Final*1.5 ) / 3
|
||
|
||
/!\ Important :
|
||
La collection : "note_evaluation" :
|
||
- Elle contient toutes les evaluations (pas les note mais les evaluation).
|
||
- Elle contient les informations : class_id, class_eu_id, type_eval_id, session_id, eval_date_heure_debut, eval_date_heure_fin
|
||
|
||
La collection : "note_evaluation_participant" :
|
||
- Elle contient les notes attribuées à un apprenant sur une evaluation.
|
||
- Elle contient les informations :evaluation_id, inscription_id, group_inscription_id, note (la note obtenue par l'apprenant)
|
||
"""
|
||
import bson
|
||
import pymongo
|
||
from pymongo import MongoClient
|
||
import json
|
||
from bson import ObjectId
|
||
import re
|
||
from datetime import datetime
|
||
import prj_common as mycommon
|
||
import secrets
|
||
import inspect
|
||
import sys, os
|
||
import csv
|
||
import pandas as pd
|
||
from pymongo import ReturnDocument
|
||
import GlobalVariable as MYSY_GV
|
||
from math import isnan
|
||
import GlobalVariable as MYSY_GV
|
||
import ela_index_bdd_classes as eibdd
|
||
import email_mgt as email
|
||
import jinja2
|
||
from flask import send_file
|
||
from xhtml2pdf import pisa
|
||
from email.message import EmailMessage
|
||
from email.mime.text import MIMEText
|
||
from email import encoders
|
||
import smtplib
|
||
from email.mime.multipart import MIMEMultipart
|
||
from email.mime.text import MIMEText
|
||
from email.mime.base import MIMEBase
|
||
from email import encoders
|
||
|
||
|
||
"""
|
||
Cette fonction permet d'appliquer la regle de calcul :
|
||
• Nom : calcul_mode_1
|
||
Detail : ( (Moyenne Art. (TD) + Moyenne Art(TP) * 2)/3 + Examen Final ) / 2
|
||
|
||
Les données en entrée :
|
||
- La formation,
|
||
- La session
|
||
- Liste des inscrit
|
||
"""
|
||
def run_calcul_mode_1(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'class_id', 'session_id', 'eu_id', 'tab_inscriptions_ids' ]
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', 'class_id', 'session_id', 'eu_id', 'tab_inscriptions_ids' ]
|
||
|
||
for val in field_list_obligatoire:
|
||
if val not in diction:
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
|
||
# Verifier la validité de la session
|
||
is_session_valide_count = MYSY_GV.dbname['session_formation'].count_documents({'_id':ObjectId(str(diction['session_id'])),
|
||
'valide':'1',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if( is_session_valide_count != 1 ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de la session est invalide ")
|
||
return False, " L'identifiant de la session est invalide"
|
||
|
||
is_session_valide_data = MYSY_GV.dbname['session_formation'].find_one(
|
||
{'_id': ObjectId(str(diction['session_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
|
||
# Verifier la validité de l'unité d'enseignement
|
||
is_ue_valide_count = MYSY_GV.dbname['unite_enseignement'].count_documents(
|
||
{'_id': ObjectId(str(diction['eu_id'])),
|
||
'valide': '1',
|
||
'locked':'0',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_ue_valide_count != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de l'unité d'enseignement est invalide ")
|
||
return False, " L'identifiant de l'unité d'enseignement est invalide"
|
||
|
||
is_ue_valide_data = MYSY_GV.dbname['unite_enseignement'].find_one(
|
||
{'_id': ObjectId(str(diction['eu_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
|
||
# Verifier si la formartion est valide
|
||
is_myclass_valide_count = MYSY_GV.dbname['myclass'].count_documents(
|
||
{'_id': ObjectId(str(diction['class_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_myclass_valide_count != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de la formation est invalide ")
|
||
return False, " L'identifiant de la formation est invalide"
|
||
|
||
is_myclass_valide_data = MYSY_GV.dbname['myclass'].find_one(
|
||
{'_id': ObjectId(str(diction['class_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
# Verifier la validité de la liste des inscrits fournie
|
||
tab_inscriptions_ids = ""
|
||
if ("tab_inscriptions_ids" in diction.keys()):
|
||
if diction['tab_inscriptions_ids']:
|
||
tab_inscriptions_ids = diction['tab_inscriptions_ids']
|
||
|
||
tab_inscriptions_ids_splited = str(tab_inscriptions_ids).split(",")
|
||
|
||
# Controle de validité de toutes info avant de commencer les traitements
|
||
for my_inscription in tab_inscriptions_ids_splited:
|
||
my_inscription = str(my_inscription).strip()
|
||
|
||
# Verifier que l'inscription est valide
|
||
my_inscription_is_valide = MYSY_GV.dbname['inscription'].count_documents(
|
||
{'_id': ObjectId(str(my_inscription)), 'status': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (my_inscription_is_valide != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'inscription_id '" + my_inscription + "' n'est pas valide ")
|
||
return False, " L'inscription_id '" + my_inscription + "' n'est pas valide "
|
||
|
||
"""
|
||
La formule : ( (Moyenne Art. (TD) + Moyenne Art(TP) * 2)/3 + Examen Final ) / 2
|
||
"""
|
||
|
||
"""
|
||
Etape 1 :
|
||
Aller cherche la liste des TD et faire la moyenne arithmétique pour chaque apprenant fourni en entrée
|
||
0) Recuperer les types d'evaluation associée à une formation / UE
|
||
a) Pour chaque apprenant aller chercher les evaluations concernées,
|
||
b) Pour chaque evaluation concerné aller cherche les note
|
||
"""
|
||
|
||
"""
|
||
TRAITEMENT DES TD
|
||
"""
|
||
evaluation_type_TD_id = ""
|
||
for val in MYSY_GV.dbname['type_evaluation'].find({'partner_owner_recid':str(my_partner['recid']),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'code': {'$regex': "TD", "$options": "i"}}):
|
||
evaluation_type_TD_id = str(val['_id'])
|
||
|
||
|
||
liste_note_evaluation_TD_ids = []
|
||
|
||
print(" ~#### QTRYYY = ", {'partner_owner_recid':str(my_partner['recid']),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'class_id':str(diction['class_id']),
|
||
'class_eu_id': str(diction['eu_id']),
|
||
'type_eval_id':str(evaluation_type_TD_id)}
|
||
)
|
||
|
||
|
||
for val in MYSY_GV.dbname['note_evaluation'].find({'partner_owner_recid':str(my_partner['recid']),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'class_id':str(diction['class_id']),
|
||
'class_eu_id': str(diction['eu_id']),
|
||
'type_eval_id':str(evaluation_type_TD_id)}):
|
||
liste_note_evaluation_TD_ids.append(str(val['_id']))
|
||
|
||
|
||
print(" ### la liste des evaluations de type TD sont : ", liste_note_evaluation_TD_ids)
|
||
|
||
nb_eval_td = len(liste_note_evaluation_TD_ids)
|
||
|
||
for my_inscription in tab_inscriptions_ids_splited:
|
||
somme_note_td = 0
|
||
moyenne_note_td = 0
|
||
tab_apprenant_note_td = []
|
||
print("###############################################")
|
||
for note_evaluation_participant in MYSY_GV.dbname['note_evaluation_participant'].find(
|
||
{'partner_owner_recid':str(my_partner['recid']),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'inscription_id' : str(my_inscription),
|
||
'evaluation_id':{'$in':liste_note_evaluation_TD_ids}
|
||
}):
|
||
|
||
inscri_data = MYSY_GV.dbname['inscription'].find_one({'partner_owner_recid':str(my_partner['recid']),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'_id':ObjectId(str(my_inscription).strip())},
|
||
{'nom':1, 'prenom':1, 'email':1}
|
||
)
|
||
|
||
"""
|
||
A supprimer après, la c'est juste pour voir les data
|
||
"""
|
||
evaluation_data = MYSY_GV.dbname['note_evaluation'].find_one({'partner_owner_recid':str(my_partner['recid']),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'_id':ObjectId(str(note_evaluation_participant['evaluation_id']))})
|
||
|
||
|
||
|
||
|
||
somme_note_td = somme_note_td + mycommon.tryFloat(str(note_evaluation_participant['note']))
|
||
|
||
print("$$$$$$$$$$$$$$$$$$$$ ", evaluation_data['code'], " Du ", evaluation_data['eval_date_heure_debut'], " Au ", evaluation_data['eval_date_heure_fin'])
|
||
print(" Session : is_session_valide_data = ", is_session_valide_data['code_session'])
|
||
print(" Unit. Ensei : is_ue_valide_data = ", is_ue_valide_data['code'])
|
||
print(" Apprenant : my_inscription = ", my_inscription, " Nom = ",inscri_data['nom'], " Email = ", str(inscri_data['email']) )
|
||
print(" note_evaluation_participant = ", note_evaluation_participant['note'])
|
||
tab_apprenant_note_td.append(str(note_evaluation_participant['note']))
|
||
|
||
moyenne_note_td = somme_note_td / nb_eval_td
|
||
print("")
|
||
print(" ## Somme_note TD = ", str(somme_note_td), " ## Moyenne TP = ", str(moyenne_note_td))
|
||
print("")
|
||
print("")
|
||
|
||
"""
|
||
FIN TRAITEMENT DES TD
|
||
"""
|
||
|
||
print(" TPPPPPPPPPPPPPPPPPPPPPP")
|
||
"""
|
||
TRAITEMENT DES TP
|
||
"""
|
||
evaluation_type_TP_id = ""
|
||
for val in MYSY_GV.dbname['type_evaluation'].find({'partner_owner_recid': str(my_partner['recid']),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'code': {'$regex': "TP", "$options": "i"}}):
|
||
evaluation_type_TP_id = str(val['_id'])
|
||
|
||
liste_note_evaluation_TP_ids = []
|
||
|
||
|
||
|
||
for val in MYSY_GV.dbname['note_evaluation'].find({'partner_owner_recid': str(my_partner['recid']),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'class_id': str(diction['class_id']),
|
||
'class_eu_id': str(diction['eu_id']),
|
||
'type_eval_id': str(evaluation_type_TP_id)}):
|
||
liste_note_evaluation_TP_ids.append(str(val['_id']))
|
||
|
||
print(" ### la liste des evaluations de type TPP sont : ", liste_note_evaluation_TP_ids)
|
||
|
||
nb_eval_tp = len(liste_note_evaluation_TP_ids)
|
||
|
||
for my_inscription in tab_inscriptions_ids_splited:
|
||
somme_note_tp = 0
|
||
moyenne_note_tp = 0
|
||
tab_apprenant_note_tp = []
|
||
print("###############################################")
|
||
for note_evaluation_participant in MYSY_GV.dbname['note_evaluation_participant'].find(
|
||
{'partner_owner_recid': str(my_partner['recid']),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'inscription_id': str(my_inscription),
|
||
'evaluation_id': {'$in': liste_note_evaluation_TP_ids}
|
||
}):
|
||
|
||
print(" ### note_evaluation_participant TPPP= ", note_evaluation_participant)
|
||
inscri_data = MYSY_GV.dbname['inscription'].find_one({'partner_owner_recid': str(my_partner['recid']),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'_id': ObjectId(str(my_inscription).strip())},
|
||
{'nom': 1, 'prenom': 1, 'email': 1}
|
||
)
|
||
|
||
"""
|
||
A supprimer après, la c'est juste pour voir les data
|
||
"""
|
||
evaluation_data = MYSY_GV.dbname['note_evaluation'].find_one(
|
||
{'partner_owner_recid': str(my_partner['recid']),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'_id': ObjectId(str(note_evaluation_participant['evaluation_id']))})
|
||
|
||
somme_note_tp = somme_note_tp + mycommon.tryFloat(str(note_evaluation_participant['note']))
|
||
|
||
print("$$$$$$$$$$$$$$$$$$$$ ", evaluation_data['code'], " Du ",
|
||
evaluation_data['eval_date_heure_debut'], " Au ", evaluation_data['eval_date_heure_fin'])
|
||
print(" Session : is_session_valide_data = ", is_session_valide_data['code_session'])
|
||
print(" Unit. Ensei : is_ue_valide_data = ", is_ue_valide_data['code'])
|
||
print(" Apprenant : my_inscription = ", my_inscription, " Nom = ", inscri_data['nom'], " Email = ",
|
||
str(inscri_data['email']))
|
||
print(" note_evaluation_participant = ", note_evaluation_participant['note'])
|
||
tab_apprenant_note_tp.append(str(note_evaluation_participant['note']))
|
||
|
||
moyenne_note_tp = somme_note_tp / nb_eval_tp
|
||
print("")
|
||
print(" ## Somme_note TP = ", str(somme_note_tp), " ## Moyenne TP= ", str(moyenne_note_tp))
|
||
print("")
|
||
print("")
|
||
|
||
|
||
return True, " Les notes avec le -calcul_mode_1- ont été correctement calculées"
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de calculer les notes avec le -calcul_mode_1- " |