コード例 #1
0
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
コード例 #2
0
ファイル: fromvanilla.py プロジェクト: Dongjinmedia/algospot
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