from django_unicorn.components import UnicornView

from BasicData.models import Note, Ue


class NoteDetailView(UnicornView):
    ue = None
    ecues = None
    moy_cc = None
    moy_ex = None
    def mount(self):
        ue = Ue.objects.filter(id=self.ue).first()
        self.ecue = ue.ecues.all()
        # self.ecues = self.ue.ecues.all()
        print(f' ue = {ue.libelle} : ')
        # for ec in self.ecues:
        #     print(ec)

        print()
        print("FIN")
        print()
        note_cc = Note.objects.filter(etudiant=self.request.user, evaluation__typeEvaluation__libelle__contains="contr")
        note_ex = Note.objects.filter(etudiant=self.request.user, evaluation__typeEvaluation__libelle__contains="exam")
        moy = 0
        cont = 0
        for note in note_cc:
            moy = note.note * 0.4
            cont += 1


        self.moy_cc = moy/cont if cont > 0 else 1

        moy = 0
        cont = 0
        for note in note_ex:
            moy = note.note * 0.6
            cont += 1
        self.moy_ex = moy/cont if cont > 0 else 1