def test_two_users(self): self.sub_first_automatic_A = Submission.objects.create(date="1-01-2000 10:10", challenge=self.challenge, is_automatic=False, user=self.user, label="A") self.sub_first_automatic_B = Submission.objects.create(date="1-01-2000 10:12", challenge=self.challenge, is_automatic=False, user=self.user, label="B") self.sub_first_human_A = Submission.objects.create(date="1-01-2000 10:10", challenge=self.challenge, is_automatic=True, user=self.user, label="A") self.sub_first_human_A_late = Submission.objects.create(date="1-01-2000 10:12", challenge=self.challenge, is_automatic=True, user=self.user, label="A") self.sub_second_automatic_A = Submission.objects.create(date="1-01-2000 10:10", challenge=self.challenge, is_automatic=False, user=self.user_second, label="A") self.sub_second_automatic_A_late = Submission.objects.create(date="1-01-2000 10:12", challenge=self.challenge, is_automatic=False, user=self.user_second, label="A") self.sub_second_human_C = Submission.objects.create(date="1-01-2000 10:10", challenge=self.challenge, is_automatic=True, user=self.user_second, label="C") self.sub_second_automatic_C = Submission.objects.create(date="1-01-2000 10:12", challenge=self.challenge, is_automatic=False, user=self.user_second, label="C") print(Submission.get_last_submissions(self.challenge.pk)) self.assertEqual(set(Submission.get_last_submissions(self.challenge.pk)), { self.sub_first_automatic_A, self.sub_first_automatic_B, self.sub_first_human_A_late, self.sub_second_automatic_A_late, self.sub_second_human_C, self.sub_second_automatic_C})
def test_automatic_human(self): self.sub_human = Submission.objects.create(challenge=self.challenge, is_automatic=False, user=self.user, label="A") self.sub_automatic = Submission.objects.create(challenge=self.challenge, is_automatic=True, user=self.user, label="A") self.assertEqual(set(Submission.get_last_submissions(self.challenge.pk)), set([self.sub_human, self.sub_automatic]))
def calculate_metrics(request, pk): challenge = get_list_or_404(Challenge, pk=pk)[0] submissions = Submission.get_last_submissions(pk) FormSet = modelformset_factory(Submission, fields=["alignment"], extra=0) alignment = FormSingle(request.POST if request.method == "POST" else None, instance=challenge) res = FormSet(request.POST if request.method == "POST" else None, queryset=submissions, prefix='formset_input') for f in res: if f.instance.status == 1: alignment.fields["alignment"].disabled = True f.fields["alignment"].disabled = True if request.method == "POST": if res.is_valid() and alignment.is_valid(): if "save" in request.POST: res.save(commit=True) alignment.save() if "metrics" in request.POST: alignment.save() post_keys = set(request.POST.keys()) for s in res: if "single_%s" % s.instance.pk in post_keys or "metrics" in request.POST: res.save() if s.instance.status != 1: spawn_tasks(s.instance.pk) return redirect(reverse('metrics-calculate', args=[pk])) return render( request, "test.html", { "res": res, "challenge": Challenge.objects.get(pk=pk), "alignment": alignment })
def test_date(self): self.sub1 = Submission.objects.create(date="1-01-2000 10:10", challenge=self.challenge, is_automatic=False, user=self.user, label="A") self.sub2 = Submission.objects.create(date="1-01-2000 10:12", challenge=self.challenge, is_automatic=False, user=self.user, label="A") self.assertEqual(set(Submission.get_last_submissions(self.challenge.pk)), set([self.sub2]))
def test_labels(self): self.sub1 = Submission.objects.create(challenge=self.challenge, is_automatic=False, user=self.user, label="A") self.sub2 = Submission.objects.create(challenge=self.challenge, is_automatic=False, user=self.user, label="B") self.assertEqual(set(Submission.get_last_submissions(self.challenge.pk)), set([self.sub1, self.sub2]))
def get_submissions(self): return Submission.get_last_submissions(self.object.pk)