mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 07:02:10 +01:00 
			
		
		
		
	Process notation sheets when there are 4 or 5 teams
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
		@@ -271,28 +271,38 @@ class UploadNotesForm(forms.Form):
 | 
			
		||||
 | 
			
		||||
    def process(self, csvfile: Iterable[str], cleaned_data: dict):
 | 
			
		||||
        parsed_notes = {}
 | 
			
		||||
        valid_lengths = [1 + 6 * 3, 1 + 7 * 4, 1 + 6 * 5]  # Per pool sizes
 | 
			
		||||
        pool_size = 0
 | 
			
		||||
        line_length = 0
 | 
			
		||||
        for line in csvfile:
 | 
			
		||||
            line = [s for s in line if s]
 | 
			
		||||
            if len(line) < 19:
 | 
			
		||||
                continue
 | 
			
		||||
            name = line[0]
 | 
			
		||||
            if name in ["moyenne", "coefficient", "sous-total"]:
 | 
			
		||||
                continue
 | 
			
		||||
            notes = line[1:19]
 | 
			
		||||
            if not all(s.isnumeric() for s in notes):
 | 
			
		||||
                continue
 | 
			
		||||
            notes = list(map(int, notes))
 | 
			
		||||
            if max(notes) < 3 or min(notes) < 0:
 | 
			
		||||
            if line and line[0] == 'Problème':
 | 
			
		||||
                pool_size = len(line) - 1
 | 
			
		||||
                if pool_size < 3 or pool_size > 5:
 | 
			
		||||
                    self.add_error('file', _("Can't determine the pool size. Are you sure your file is correct?"))
 | 
			
		||||
                    return
 | 
			
		||||
                line_length = valid_lengths[pool_size - 3]
 | 
			
		||||
                continue
 | 
			
		||||
 | 
			
		||||
            max_notes = 3 * [20, 16, 9, 10, 9, 10]
 | 
			
		||||
            if pool_size == 0 or len(line) < line_length:
 | 
			
		||||
                continue
 | 
			
		||||
 | 
			
		||||
            name = line[0]
 | 
			
		||||
            if name in ["Rôle", "Juré", "moyenne", "coefficient", "sous-total", "Equipe"]:
 | 
			
		||||
                continue
 | 
			
		||||
            notes = line[1:line_length]
 | 
			
		||||
            if not all(s.isnumeric() or s[0] == '-' and s[1:].isnumeric() for s in notes):
 | 
			
		||||
                continue
 | 
			
		||||
            notes = list(map(int, notes))
 | 
			
		||||
 | 
			
		||||
            max_notes = pool_size * ([20, 16, 9, 10, 9, 10] + ([4] if pool_size == 4 else []))
 | 
			
		||||
            for n, max_n in zip(notes, max_notes):
 | 
			
		||||
                if n > max_n:
 | 
			
		||||
                    self.add_error('file',
 | 
			
		||||
                                   _("The following note is higher of the maximum expected value:")
 | 
			
		||||
                                   + str(n) + " > " + str(max_n))
 | 
			
		||||
 | 
			
		||||
            first_name, last_name = tuple(name.split(' ', 1))
 | 
			
		||||
            first_name, last_name = tuple(name.replace('’', '\'').split(' ', 1))
 | 
			
		||||
 | 
			
		||||
            jury = User.objects.filter(first_name=first_name, last_name=last_name,
 | 
			
		||||
                                       registration__volunteerregistration__isnull=False)
 | 
			
		||||
 
 | 
			
		||||
@@ -809,9 +809,11 @@ class PoolUploadNotesView(VolunteerMixin, FormView, DetailView):
 | 
			
		||||
            if vr not in pool.juries.all():
 | 
			
		||||
                form.add_error('file', _("The following user is not registered as a jury:") + " " + str(vr))
 | 
			
		||||
 | 
			
		||||
            # There is an observer note for 4-teams pools
 | 
			
		||||
            notes_count = 7 if pool.passages.count() == 4 else 6
 | 
			
		||||
            for i, passage in enumerate(pool.passages.all()):
 | 
			
		||||
                note = Note.objects.get_or_create(jury=vr, passage=passage)[0]
 | 
			
		||||
                passage_notes = notes[6 * i:6 * (i + 1)]
 | 
			
		||||
                passage_notes = notes[notes_count * i:notes_count * (i + 1)]
 | 
			
		||||
                note.set_all(*passage_notes)
 | 
			
		||||
                note.save()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user