示例#1
0
def Tournament(form: TournamentForm) -> list:
    if form.validate_on_submit():
        probId = form.probId.data
        startTimeStr = form.start.data
        id = None
        try:
            id = int(probId)
            if storage.getProblem(id) == None:
                raise ValueError()
        except ValueError:
            return [0, ("No problem with this id!", "message red")]
        if (startTimeStr == ''):
            useCasesAPI.makeTournament(id)
            return [1, ("Tournament Successfully created.", "message green")]
        else:
            try:
                startTime = int(startTimeStr)
            except ValueError:
                return [0, ("Incorrect time", "message red")]
            if (startTime < unixTime()):
                return [0, ("Too early", "message red")]
            if (startTime > MaxStartTime):
                return [0, ("Too late", "message red")]
            useCasesAPI.createDelayedTournament(id, startTime)
            return [
                1, ("Looking forward for tournament start", "message green")
            ]
    return [0, ("Enter id of problem", "message blue")]
示例#2
0
def update():
    time = unixTime()
    problemCnt = storage.getProblemsCount()
    for i in range(problemCnt):
        tourTime = storage.getCertainField('problems', i, 'nextTournament')
        if (tourTime != -1 and tourTime <= time):
            useCasesAPI.makeTournament(i)
            prob = storage.getProblem(i)
            prob.nextTournament = -1
            storage.saveProblem(prob)
示例#3
0
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
示例#4
0
def createMessage(content, info):
    message = Message(-1, info['id'], unixTime(), content)
    storage.saveMessage(message)
示例#5
0
    if (command == 'subs'):
        if (len(params) == 2 and isInt(params[1])):
            res = storage.getSubmissionListU(int(params[1]))
            print(res)

        if (len(params) == 3 and isInt(params[1]) and isInt(params[2])):
            res = storage.getSubmissionListUP(int(params[1]), int(params[2]))
            print(res)

    if (command == 'parse'):
        if (len(params) == 2):
            print(parser.parseArchive(params[1]))

    if (command == 'time'):
        print(unixTime())

    if (command == 'upd'):
        timer.update()

    if (command == 'delayTour'):
        if (len(params) < 3 or not (isInt(params[1]))
                or not (isInt(params[2]))):
            continue

        try:
            useCasesAPI.createDelayedTournament(int(params[1]), int(params[2]))
        except:
            pass

    if (command == 'close'):