def handle(self, *args, **options): # print(args, options) PATH = options.get('path') print(PATH) languages = Language.objects.all() typee = ProblemType.objects.first() group = ProblemGroup.objects.first() for f in listdir(PATH): problemfile = open(join(PATH, f)) problemjson = json.load(problemfile) print(problemjson['code']) if Problem.objects.filter(code=problemjson['code']).exists(): continue problem = Problem(code=problemjson['code']) print('creating', problem.code) problem.name = problemjson['name'] problem.description = problemjson['description'] problem.points = problemjson['points'] problem.is_public = problemjson[ 'is_public'] if 'is_public' in problemjson else True problem.memory_limit = problemjson[ 'memory_limit'] if 'memory_limit' in problemjson else 65536 problem.time_limit = problemjson[ 'time_limit'] if 'time_limit' in problemjson else 10 problem.group = group problem.save() for l in languages: problem.allowed_languages.add(l) problem.types.add(typee) problem.save()
def handle(self, *args, **options): problem = Problem() problem.code = options['code'] problem.name = options['name'] problem.description = options['body'] problem.group = ProblemGroup.objects.get(name=options['group']) problem.types = [ProblemType.objects.get(name=options['type'])] problem.save()
def save(self, user, problemid=None): cd = self.cleaned_data title = cd['title'] description = cd['description'] input = cd['input'] output = cd['output'] program = cd['program'] sample_input1 = cd['sample_input1'] sample_output1 = cd['sample_output1'] sample_input2 = cd['sample_input2'] sample_output2 = cd['sample_output2'] time_limit = cd['time_limit'] memory_limit = cd['memory_limit'] keypoint = cd['keypoint'].split(',') if problemid: problem = Problem.objects.get(pk=problemid) problem.title = title problem.description = description problem.time_limit = time_limit problem.memory_limit = memory_limit problem.input = input problem.output = output problem.sample_input = sample_input1 problem.sample_output = sample_output1 problem.sample_input2 = sample_input2 problem.sample_output2 = sample_output2 #problem.creater = user problem.knowledgePoint1.clear() problem.knowledgePoint2.clear() problem.program = program else: problem = Problem( title=title, description=description, time_limit=time_limit, memory_limit=memory_limit, input=input, output=output, sample_input=sample_input1, sample_output=sample_output1, sample_input2=sample_input2, sample_output2=sample_output2, creater=user, problem_type="编程", program=program ) problem.save() for point in keypoint: problem.knowledgePoint2.add(KnowledgePoint2.objects.get(pk=point)) for point in problem.knowledgePoint2.all(): problem.knowledgePoint1.add(point.upperPoint) for point in problem.knowledgePoint1.all(): problem.classname.add(point.classname) problem.save() return problem
def handle(self, *args, **options): if len(args) != 5: self.usage('create_problem') code, name, body, type, group = args problem = Problem() problem.code = code problem.name = name problem.description = body problem.group = ProblemGroup.objects.get(name=group) problem.types = [ProblemType.objects.get(name=type)] problem.save()
def test_abstract_problem(self): """Abstract methods in a Problem raise exceptions""" collection = Collection() collection.save() problem = Problem(title_md='Dates', text_md='Example with dates', create_sql=' ', insert_sql=' ', collection=collection) self.assertRaises(NotImplementedError, problem.template) self.assertRaises(NotImplementedError, problem.judge, '', None) self.assertRaises(NotImplementedError, problem.problem_type)
def migrate_problems(db): PROBLEM_MAPPING = { "No": "id", "ID": "slug", "Updated": "updated_on", "State": "state", "Source": "source", "Name": "name", "Description": "description", "Input": "input", "Output": "output", "SampleInput": "sample_input", "SampleOutput": "sample_output", "Note": "note", "JudgeModule": "judge_module", "TimeLimit": "time_limit", "MemoryLimit": "memory_limit", "Accepted": "accepted_count", "Submissions": "submissions_count", } imported = 0 categories = dict([(cat["No"], cat["Name"]) for cat in fetch_all(db, "GDN_ProblemCategory")]) for k, v in categories.items(): print k, v for problem in fetch_all(db, "GDN_Problem", State=3): kwargs = {} kwargs["user"] = User.objects.get(id=problem["Author"]) for k, v in PROBLEM_MAPPING.items(): kwargs[v] = problem[k] new_problem = Problem(**kwargs) new_problem.save() tags = [] for rel in fetch_all(db, "GDN_ProblemCategoryActualRelation", Problem=problem["No"]): if rel["Category"] in categories: tags.append(categories[rel["Category"]]) print new_problem.slug, tags new_problem.tags = ",".join(tags) new_problem.save() # we don't have timestamp information for old problems. patch("new-problem-%d" % new_problem.id, datetime.datetime(2009, 7, 11, 0, 0, 0, 0)) imported += 1 print "imported %d problems." % imported
def problem_new(request): if request.method == 'POST': form = ProblemForm(request.POST, request.FILES) if form.is_valid(): problem = Problem() problem.title = form.cleaned_data['title'] testcases = form.files.getlist('testcases') problem.testcase = len(testcases)/2 problem.save() tc = JUDGE_ROOT+'/testcase/{}'.format(problem.pk) if not os.path.exists(tc): os.makedirs(tc) for f in testcases: with open('{}/{}'.format(tc, f.name), 'wb+') as dest: for chunk in f.chunks(): dest.write(chunk) return redirect('judge:problem_list') else: form = ProblemForm() return render(request, 'judge/problem_new.html', {'form': form})
def handle(self, *args, **options): problem = Problem() problem.code = options['code'] problem.name = options['name'] problem.description = options['body'] problem.save()