Пример #1
0
def update_atcoder_problems():
    url = "https://kenkoooo.com/atcoder/resources/contests.json"
    res = requests.get(url)
    data = res.json()

    for contest in data:

        if len(atcoder_contest.objects.filter(contestId=contest['id'])) == 0:

            new_contest = atcoder_contest()
            new_contest.name = contest['title']
            new_contest.contestId = contest['id']
            new_contest.startTime = contest['start_epoch_second']
            new_contest.duration = contest['duration_second']
            new_contest.save()

    url = "https://kenkoooo.com/atcoder/resources/problems.json"
    res = requests.get(url)
    data = res.json()

    for prob in data:

        if len(Problem.objects.filter(prob_id=prob['id'], platform='A')) == 0:

            new_problem = Problem()
            new_problem.prob_id = prob['id']
            new_problem.contest_id = prob['contest_id']
            new_problem.name = prob['title']
            new_problem.url = "https://atcoder.jp/contests/" + prob[
                'contest_id'] + "/tasks/" + prob['id']
            new_problem.index = prob['id'].split("_")[-1]
            new_problem.platform = 'A'
            new_problem.save()

    url = "https://kenkoooo.com/atcoder/resources/problem-models.json"
    res = requests.get(url)
    data = res.json()

    problems = Problem.objects.filter(difficulty=None, platform='A')

    for prob in problems:

        if prob.prob_id in data:

            if 'difficulty' in data[prob.prob_id]:

                old = data[prob.prob_id]['difficulty']
                if old < -1000:
                    NewValue = (((old + 10000) * 50) / 9000) + 800
                elif old <= 0:
                    NewValue = (((old + 1000) * 350) / 1000) + 850
                else:
                    NewValue = ((old * 2400) / 5000) + 1200

                prob.rating = str(int(NewValue))
                prob.difficulty = rating_to_difficulty(int(NewValue))
                prob.save()
Пример #2
0
def update_uva_problems():

    url = "https://uhunt.onlinejudge.org/api/p"
    res = requests.get(url)
    data = res.json()

    for p in data:

        if len(Problem.objects.filter(prob_id=p[0])) > 0:
            continue

        new_problem = Problem()
        new_problem.prob_id = p[0]
        new_problem.index = p[1]
        new_problem.name = p[2]
        dacu = p[3]
        wa = p[16]

        if dacu != 0:
            rating = min(3600, max(800, (20 - min(log2(dacu), 20)) * 200))
            new_problem.rating = str(int(rating))
            new_problem.difficulty = rating_to_difficulty(rating)

        new_problem.platform = 'U'
        new_problem.url = "https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=" + str(
            p[0])
        new_problem.save()

    url = "https://uhunt.onlinejudge.org/api/cpbook/3"
    res = requests.get(url)
    data = res.json()

    for p in data:
        title1 = p['title']
        for q in p['arr']:
            title2 = q['title']
            for r in q['arr']:
                title3 = r[0]
                for i in range(1, len(r)):
                    prob_num = abs(r[i])
                    tags = [title1, title2, title3]
                    Problem.objects.filter(index=prob_num).update(tags=tags)
Пример #3
0
def codeforces_update_problems():
    # check whether we have updated the problems of a particular contest ,
    # if no , update the problems , else not ..
    url = "https://codeforces.com/api/contest.list"
    res = requests.get(url)
    data = res.json()

    if (data["status"] != 'OK'):
        return

    for codeforces_contest in data['result']:

        url = "https://codeforces.com/api/contest.standings?contestId=" + str(
            codeforces_contest['id']) + "&from=1&count=1"
        res = requests.get(url)
        data = res.json()

        if (data["status"] != 'OK'):
            continue

        new_contest = contest()
        if 'startTimeSeconds' in codeforces_contest:
            new_contest.startTime = codeforces_contest['startTimeSeconds']

        new_contest.Type = 'R'
        new_contest.contestId = codeforces_contest['id']
        new_contest.name = codeforces_contest['name']
        new_contest.duration = codeforces_contest['durationSeconds']

        if len(contest.objects.filter(
                contestId=codeforces_contest['id'])) == 0:
            new_contest.save()

        for contest_problem in data['result']['problems']:
            new_problem = Problem()
            new_problem.name = contest_problem['name']
            new_problem.contest_id = contest_problem['contestId']
            new_problem.prob_id = str(
                contest_problem['contestId']) + contest_problem['index']
            new_problem.url = "https://codeforces.com/contest/" + str(
                contest_problem['contestId']
            ) + "/problem/" + contest_problem['index']
            new_problem.platform = 'F'
            new_problem.index = contest_problem['index']
            new_problem.tags = contest_problem['tags']
            if 'rating' in contest_problem:
                new_problem.rating = contest_problem['rating']
                new_problem.difficulty = rating_to_difficulty(
                    int(contest_problem['rating']))

            if len(
                    Problem.objects.filter(
                        prob_id=str(contest_problem['contestId']) +
                        contest_problem['index'])) == 0:
                new_problem.save()

    url = "https://codeforces.com/api/contest.list?gym=true"
    res = requests.get(url)
    data = res.json()

    if (data["status"] != 'OK'):
        return

    for codeforces_contest in data['result']:

        url = "https://codeforces.com/api/contest.standings?contestId=" + str(
            codeforces_contest['id']) + "&from=1&count=1"
        res = requests.get(url)
        data = res.json()

        if (data["status"] != 'OK'):
            continue

        new_contest = contest()
        if 'startTimeSeconds' in codeforces_contest:
            new_contest.startTime = codeforces_contest['startTimeSeconds']

        new_contest.Type = 'R'
        new_contest.contestId = codeforces_contest['id']
        new_contest.name = codeforces_contest['name']
        new_contest.duration = codeforces_contest['durationSeconds']

        if len(contest.objects.filter(
                contestId=codeforces_contest['id'])) == 0:
            new_contest.save()

        for contest_problem in data['result']['problems']:
            new_problem = Problem()
            new_problem.name = contest_problem['name']
            new_problem.contest_id = contest_problem['contestId']
            new_problem.prob_id = str(
                contest_problem['contestId']) + contest_problem['index']
            new_problem.url = "https://codeforces.com/gym/" + str(
                contest_problem['contestId']
            ) + "/problem/" + contest_problem['index']
            new_problem.platform = 'F'
            new_problem.index = contest_problem['index']
            new_problem.tags = contest_problem['tags']
            if 'rating' in contest_problem:
                new_problem.rating = contest_problem['rating']
                new_problem.difficulty = rating_to_difficulty(
                    int(contest_problem['rating']))

            if len(
                    Problem.objects.filter(
                        prob_id=str(contest_problem['contestId']) +
                        contest_problem['index'])) == 0:
                new_problem.save()

    return