modify similar result format

This commit is contained in:
HandsomeHow 2018-12-13 14:20:37 +08:00
parent 19cee5d10d
commit 2e463b9c0b
3 changed files with 13 additions and 4 deletions

View File

@ -42,7 +42,15 @@ def similar_task(contest_id):
if owner[sub1] == owner[sub2]: if owner[sub1] == owner[sub2]:
continue continue
sim = splited_line[3] sim = splited_line[3]
data_to_write.append("#".join([problem._id, sub1, owner[sub1], sub2, owner[sub2], sim])) to_append = {
"problem_id": problem._id,
"submission_a": sub1,
"user_a": owner[sub1],
"submission_b": sub2,
"user_b": owner[sub2],
"similarity": sim
}
data_to_write.append(to_append)
f.close() f.close()
os.remove(output_dir) os.remove(output_dir)

View File

@ -63,7 +63,7 @@ class ContestAPITest(APITestCase):
def setUp(self): def setUp(self):
user = self.create_admin() user = self.create_admin()
self.contest = Contest.objects.create(created_by=user, **DEFAULT_CONTEST_DATA) self.contest = Contest.objects.create(created_by=user, **DEFAULT_CONTEST_DATA)
self.contest.similarity_check_result = ["aaa", "bbb", "ccc"] self.contest.similarity_check_result = [{"user1": "aaa", "user2": "bbb"}, {"user1": "ccc", "user2": "ddd"}]
self.contest.save() self.contest.save()
self.url = self.reverse("contest_api") + "?id=" + str(self.contest.id) self.url = self.reverse("contest_api") + "?id=" + str(self.contest.id)
@ -103,7 +103,8 @@ class ContestAPITest(APITestCase):
self.create_user("test", "test123") self.create_user("test", "test123")
url = self.reverse("contest_get_similar_api") url = self.reverse("contest_get_similar_api")
resp = self.client.get(url + "?contest_id=" + str(self.contest.id)) resp = self.client.get(url + "?contest_id=" + str(self.contest.id))
self.assertEqual(resp.data["data"]["similarity_check_result"], ["aaa", "bbb", "ccc"]) self.assertEqual(resp.data["data"]["similarity_check_result"][0], {"user1": "aaa", "user2": "bbb"})
self.assertEqual(resp.data["data"]["similarity_check_result"][1], {"user1": "ccc", "user2": "ddd"})
class ContestAnnouncementAdminAPITest(APITestCase): class ContestAnnouncementAdminAPITest(APITestCase):

View File

@ -9,7 +9,7 @@ from django.db.models import F
from account.models import User from account.models import User
from conf.models import JudgeServer from conf.models import JudgeServer
from contest.models import ContestRuleType, ACMContestRank, OIContestRank, ContestStatus from contest.models import ContestRuleType, ACMContestRank, OIContestRank
from judge.languages import languages, spj_languages from judge.languages import languages, spj_languages
from options.options import SysOptions from options.options import SysOptions
from problem.models import Problem, ProblemRuleType from problem.models import Problem, ProblemRuleType