Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

Commit

Permalink
Add: support for microparsons autograding
Browse files Browse the repository at this point in the history
  • Loading branch information
bnmnetp committed Feb 2, 2023
1 parent ef333bd commit b61bea2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
15 changes: 15 additions & 0 deletions models/db_ebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,21 @@
migrate=bookserver_owned("webwork_answers"),
)

# webwork_answers
# ------------
db.define_table(
"microparsons_answers",
Field("timestamp", "datetime"),
Field("div_id", "string"),
Field("sid", "string"),
Field("course_name", "string"),
Field("answer", "json"),
Field("correct", "boolean"),
Field("percent", "double"),
migrate=bookserver_owned("microparsons_answers"),
)


# payments
# --------
db.define_table(
Expand Down
51 changes: 51 additions & 0 deletions modules/rs_grading.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ def _score_one_parsons(row, points, autograde):
return _score_from_pct_correct(pct_correct, points, autograde)


def _score_one_microparsons(row, points, autograde):
# row is from microparsons_answers
if autograde == "pct_correct" and "percent" in row and row.percent is not None:
pct_correct = int(round(row.percent * 100))
else:
if row.correct:
pct_correct = 100
else:
pct_correct = 0
return _score_from_pct_correct(pct_correct, points, autograde)


def _score_one_fitb(row, points, autograde):
# row is from fitb_answers
if autograde == "pct_correct" and "percent" in row and row.percent is not None:
Expand Down Expand Up @@ -329,6 +341,30 @@ def _scorable_parsons_answers(
return db(query).select(orderby=db.parsons_answers.timestamp)


def _scorable_microparsons_answers(
course_name,
sid,
question_name,
points,
deadline,
practice_start_time=None,
db=None,
now=None,
):
query = (
(db.microparsons_answers.course_name == course_name)
& (db.microparsons_answers.sid == sid)
& (db.microparsons_answers.div_id == question_name)
)
if deadline:
query = query & (db.microparsons_answers.timestamp < deadline)
if practice_start_time:
query = query & (db.microparsons_answers.timestamp >= practice_start_time)
if now:
query = query & (db.microparsons_answers.timestamp <= now)
return db(query).select(orderby=db.microparsons_answers.timestamp)


def _scorable_fitb_answers(
course_name,
sid,
Expand Down Expand Up @@ -708,6 +744,21 @@ def _autograde_one_q(
scoring_fn = _score_one_webwork
logger.debug("AGDB - done with webwork")

elif question_type == "hparsons":
logger.debug("grading a microparsons!!")
results = _scorable_microparsons_answers(
course_name,
sid,
question_name,
points,
deadline,
practice_start_time,
db=db,
now=now,
)
scoring_fn = _score_one_microparsons
logger.debug("AGDB - done with microparsons")

elif question_type == "codelens":
if (
autograde == "interact"
Expand Down

0 comments on commit b61bea2

Please sign in to comment.