def changeMainSubmission(userId, subId): newMainSubmission = storage.getSubmission(subId) if ((newMainSubmission is None) or newMainSubmission.userId != userId): return 0 user = storage.getUser(userId) probId = newMainSubmission.probId problem = storage.getProblem(probId) if newMainSubmission.type == StrategyState.Main: newMainSubmission.type = StrategyState.NonMain problem.submissions.remove(subId) returnCode = 1 else: for anotherSubmissionId in user.submissions[probId]: anotherSubmission = storage.getSubmission(anotherSubmissionId) if (anotherSubmission.type == StrategyState.Main): anotherSubmission.type = StrategyState.NonMain storage.saveSubmission(anotherSubmission) problem.submissions.remove(anotherSubmissionId) newMainSubmission.type = StrategyState.Main problem.submissions.add(subId) returnCode = 2 storage.saveSubmission(newMainSubmission) storage.saveProblem(problem) return returnCode
def showSource(subId): submission = storage.getSubmission(subId) if (submission is None): flash('No such submission', 'message red') return redirect('/home') Info = info() title = "Code #" + subId if (Info['logged_in'] == 1 and Info['id'] == submission.userId): code = [easyParser(line) for line in useCasesAPI.getSubmissionCode(subId).split('\n')] return render_template('source.html.j2', id = subId, code = code, info = info(), title = title) return render_template('message.html.j2', text = "You can't see this source :)", info = info())
def testStrategies(id1, id2, saveLogs=False): sub1 = storage.getSubmission(id1) sub2 = storage.getSubmission(id2) if (sub1.probId != sub2.probId): raise Exception( 'Trying to judge two strategies for different problems') problemId = sub1.probId problem = storage.getProblem(problemId) loadProblem(problem) loadSubmission(sub1, problem) loadSubmission(sub2, problem) invocationResult = judge.run( getGameModule(problem), [getStrategyModule(sub1), getStrategyModule(sub2)], saveLogs=saveLogs) return invocationResult
def runPage(strId): if (request.method == 'POST'): st1 = request.form.get('st1') st2 = request.form.get('st2') if ((st1 is not None) and (st2 is not None)): return redirect('/test?id1=' + st1 + '&id2=' + st2) try: probId = int(strId) idList = json.loads(storage.getCertainField('problems', probId, 'allSubmissions')) except: flash('Incorrect problem id', 'message red') return redirect('/home') probName = storage.getCertainField('problems', probId, 'name') subList = [] for id in idList: submission = storage.getSubmission(id) subList.append({'id': id, 'username': storage.getCertainField('users', submission.userId, 'username'), 'probName': probName, 'type': structures.visualize(submission.type)}) return render_template('runPage.html.j2', subList = subList, probId = probId, info = info(), title = 'Run invocation')
def tournament(problemId): problem = storage.getProblem(problemId) problem.type = ProblemState.Testing storage.saveProblem(problem) loadProblem(problem) subCnt = len(problem.submissions) subs = [storage.getSubmission(subId) for subId in problem.submissions] scores = [[0, subs[i].id] for i in range(subCnt)] for i in range(subCnt): loadSubmission(subs[i], problem) problemPath = os.path.join('problems', str(problemId)) for i in range(subCnt): for j in range(subCnt): if (i != j): print("judging ", i, j) invocationResult = judge.run( getGameModule(problem), getClassesModule(problem), [getStrategyModule(subs[i]), getStrategyModule(subs[j])], saveLogs=False) print(invocationResult.results[0].goodStr()) print(invocationResult.results[1].goodStr()) scores[i][0] += invocationResult.results[0].score scores[j][0] += invocationResult.results[1].score scores.sort(reverse=True) newTournament = Tournament(-1, problemId, problem.revisionId, unixTime(), scores) newTournamentId = storage.saveTournament(newTournament) problem.tournaments.append(newTournamentId) storage.saveProblem(problem) return newTournamentId
def getSubmissionCode(subId): submission = storage.getSubmission(subId) if (submission is None): return "" else: return submission.code
if (command == 'look'): if (len(params) < 3 or (not isInt(params[2]))): continue if (params[1][0] == 'u'): id = int(params[2]) resp = storage.getUser(id) if (params[1][0] == 'p'): id = int(params[2]) resp = storage.getProblem(id) if (params[1][0] == 's'): id = int(params[2]) resp = storage.getSubmission(id) if (params[1][0] == 't'): id = int(params[2]) resp = storage.getTournament(id) if (resp is not None): resp.print() if (command == 'add'): if (len(params) < 2): continue if (params[1][0] == 's'): if (len(params) < 5): continue