summaryrefslogtreecommitdiff
path: root/leningrade.py
blob: d37a846005fdd386bea6247f8c52b55da683f500 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import argparse
from worker import GitWorker, GiteaWorker, JOJWorker, CanvasWorker
from problem_info import problem_info
from config import *


parser = argparse.ArgumentParser("leningrade")
parser.add_argument(
    "-n",
    "--homework-number",
    type=int,
    required=True,
    help="An integer. For h1, the value should be 1.",
)
parser.add_argument(
    "-i",
    "--homework-id",
    required=False,
    help=(
        "A hexadecimal string obtained from the JOJ URL of the homework. "
        "Can be omitted if -J is set."
    ),
)
parser.add_argument(
    "-I",
    "--no-individual",
    action="store_true",
    default=False,
    help="Do not check individual submissions.",
)
parser.add_argument(
    "-G",
    "--no-group",
    action="store_true",
    default=False,
    help="Do not check group submission.",
)
parser.add_argument(
    "-J",
    "--no-joj",
    action="store_true",
    default=False,
    help=(
        "Do not upload group code to JOJ. JOJ may consume a lot of time. "
        "Set this flag if your group work has proven to pass JOJ."
    ),
)

cli_args = parser.parse_args()


class Arguments:
    hw = cli_args.homework_number
    rejudge = HGROUP_NO  # I do not understand the naming
    dir = True
    tidy = True
    score = True


args = Arguments()

gitWorker = GitWorker(args, HGROUP, None, LANGUAGE, MANDATORY_FILES, OPTIONAL_FILES)
giteaWorker = GiteaWorker(args, GITEA_API_BASE, GITEA_ORG, GITEA_TOKEN, HGROUP)
jojWorker = JOJWorker(args, JOJ_COURSE_ID, JOJ_SESSION_ID, HGROUP)

indvScores = {}
groupScores = {}
jojScores = {}

# individual
if not cli_args.no_individual:
    print("Checking individual submissions...")
    indvScores = gitWorker.checkIndv()
# group
if not cli_args.no_group:
    print("Checking group submissions...")
    groupScores = gitWorker.checkGroup()
    tmpScores = giteaWorker.checkReview()
    for key in groupScores.keys():
        groupScores[key] = {**groupScores.get(key, {}), **tmpScores.get(key, {})}
# JOJ (This will consume a lot of time when the code is in MATLAB)
if not cli_args.no_joj:
    JOJ_INFO = {
        "homeworkID": cli_args.homework_id,
        "lang": LANGUAGE,
        # "problemInfo": [
        #     # filenames, problem ID, # of test cases
        #     (["ex2.m"], "61553cffb3c06a0006f45da3", 10),
        #     (["ex4.m"], "61553e5fb3c06a0006f45da9", 10),
        #     (["ex5.m"], "61553f8cb3c06a0006f45db2", 10),
        #     (["ex6.m"], "6155414cb3c06a0006f45dc7", 10),
        # ],
        "problemInfo": problem_info(cli_args.homework_id),
    }
    print("JOJ is now running (this may take a while)...")
    jojScores = jojWorker.checkGroupJOJ(JOJ_INFO)

# initialize a CanvasWorker instance so that we can output grades
# the way they do it on Canvas
member_names = [member[1] for member in HGROUP_MEMBERS]
canvasWorker = CanvasWorker(
    args,
    RUBRIC,
    None,
    None,
    member_names,
    indvScores,
    groupScores,
    jojScores,
)
scoreInfo = canvasWorker.scores
for member in member_names:
    print(f"===== {member} =====")
    data = canvasWorker.generateHomeworkData(scoreInfo[member])
    print("Grade: " + str(data["submission"]["posted_grade"]))
    print(data["comment"]["text_comment"])
    print("\n")