Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ All notable changes to lectern are documented here.
## [Unreleased]

### Added
- **`reg-canvas discussions`: one running report per term, sorted by week.** With no `--week`, `review` covers every "Week N" discussion and writes `classes/semesters/<term>-discussions-grading.md`, with one section per week. A rerun refreshes it and keeps every deny already ticked. A student with a ticked post stays listed even after posting enough to drop off the list, so a denial is never lost. `--force` starts fresh. `apply` now requires `--week`, because the report includes hand-graded weeks that a blanket apply would overwrite.
- **`canvas_api`: dropped connections are retried when that is safe.** On the first live discussion run, a TLS handshake timed out partway through about 600 like requests. A GET is now retried with backoff, and so is a write the caller marks `idempotent` (grades, likes and posting in `discussions apply`). Other writes are not retried, because a timeout can arrive after Canvas has acted, and a second announcement would notify students twice.
- **`reg-canvas audit` and `reg-canvas discussions`: gradebook audit and discussion grading.** The first full read of the Fa26 gradebooks found no forgotten posting, but it did find three problems. Weeks 5 and 6 were ungraded in every section. 326 §03's Exam 1 was filed under Class Participation, so it counted at 10% instead of 60%. And 378's missing-submission policy was off, so non-posters were blank and left out of the current score. `audit` reports all three kinds of problem, plus hidden grades (missing-work zeros counted apart), and exits 1 when it finds something. `discussions review` grades by post count (2 or more = 5, 1 = 3) and writes a vault note listing only the posts that need a human look: one post, a post under 25 words, or 30% phrase overlap with another student. Each of those posts has a deny box. `discussions apply` reads the ticks back and sets changed scores, likes every credited post, and with `--post` posts the grades. It is a dry run until `--apply`. Posts are read to measure them, as an instructor does in SpeedGrader, and the text is reduced to metrics in memory. It is never written, printed or kept, and a test enforces that. The metrics (length, Flesch-Kincaid grade, sentence-length spread, vocabulary ratio, reply structure, names a classmate, links, overlap) are documented as prompts to read, not an AI detector. `--exclude-sis` and `--full-credit-sis` take `SIS@326-03` to scope to one section. Live-checked read-only on the three Fa26 sections, with the same counts as the prototype scripts. New module `canvas_grading`; runbook sections in `docs/canvas-api.md`.
- **`reg-lms-grades-import --exclude-sis`: course staff with a student role.** A grad assistant who needs the student view is enrolled as a student in every section's Canvas course, so the export lists them like a student and `reg-gradebook import` stops with "in Canvas but not in roster". Their SIS IDs now go to `grades.filtered.csv` with reason `staff`, alongside the Test Student and ISA filters. `reg-canvas grades-export --import` passes the same flag through. Found on the first live `reg-canvas` export, 2026-10-21.
- **`docs/gradescope-workflow.md`: getting Gradescope totals back into lectern.** Gradescope has no instructor API and a Canvas token does not reach it, so the doc now describes the supported route: link the course through Gradescope's Canvas tool (LTI 1.3), post totals to Canvas, and read them with `reg-canvas grades-export`. It warns against pushing the same column from both Gradescope and `reg-canvas grades-push`, and notes that item analysis still needs the per-question export.
Expand Down
8 changes: 4 additions & 4 deletions SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ reg-canvas grades-push --term fa26 --vault-root <V> --course "CECS 326" --sectio
reg-canvas announce --term fa26 --vault-root <V> --course "CECS 326" \
--file '<lab>/posted/fa26-{section}-ANNOUNCE.md' # dry run; add --apply
reg-canvas audit --term fa26 --vault-root <V> # what was never graded or posted
reg-canvas discussions review --term fa26 --vault-root <V> --week "Week 7" \
--workdir ~/tmp/canvas-discussions/fa26-w7 # writes the vault note to judge
reg-canvas discussions apply --workdir ~/tmp/canvas-discussions/fa26-w7 \
--note <V>/classes/semesters/fa26-discussions-w7-grading.md --post # dry run; add --apply
reg-canvas discussions review --term fa26 --vault-root <V> \
--workdir ~/tmp/canvas-discussions/fa26 # term report, a section per week; rerun keeps ticks
reg-canvas discussions apply --workdir ~/tmp/canvas-discussions/fa26 --week "Week 7" \
--note <V>/classes/semesters/fa26-discussions-grading.md --post # dry run; add --apply
```

==Every write is a dry run until `--apply`.== An agent shows the dry run and
Expand Down
29 changes: 20 additions & 9 deletions docs/canvas-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,20 @@ flowchart LR
```

```sh
W=~/tmp/canvas-discussions/fa26-w7
reg-canvas discussions review --term fa26 --vault-root <V> --week "Week 7" --workdir $W \
W=~/tmp/canvas-discussions/fa26
reg-canvas discussions review --term fa26 --vault-root <V> --workdir $W \
--exclude-sis <staff-id>@326-03 --full-credit-sis <id>@326-01
```

`review` writes the vault note
`classes/semesters/<term>-discussions-<weeks>-grading.md`. The note lists only
these students, each with a SpeedGrader link:
`review` writes one running report per term,
`classes/semesters/<term>-discussions-grading.md`, with a section for each
"Week N" discussion. Run it whenever you like: mid-week to see who has posted,
and again after the due date. ==A rerun adds new posts and keeps every box you
have ticked.== `--week "Week 7"` limits it to one week, and then it writes a
separate note for that week. `--force` starts the note fresh.

In each week's section, the note lists only these students, each with a
SpeedGrader link:

- students who made one post
- students with a post under 25 words
Expand All @@ -298,11 +304,15 @@ Each listed post has a **deny** box. Tick it when the post does not earn
credit, and that student drops one tier.

```sh
reg-canvas discussions apply --workdir $W --note <that note> --post # dry run
reg-canvas discussions apply --workdir $W --note <that note> --post --apply # send
rm -rf $W
N=<V>/classes/semesters/fa26-discussions-grading.md
reg-canvas discussions apply --workdir $W --note $N --week "Week 7" --post # dry run
reg-canvas discussions apply --workdir $W --note $N --week "Week 7" --post --apply # send
rm -rf $W # at the end of the term
```

`apply` needs `--week`. The report covers every week, including any you graded
by hand, and applying a week overwrites the grades already entered for it.

`--exclude-sis` leaves course staff who hold a student enrolment out of
grading. `--full-credit-sis` gives a student full credit whatever the count,
for an agreed arrangement. Both take `SIS` for every section or `SIS@326-03`
Expand Down Expand Up @@ -359,6 +369,7 @@ and tell your Canvas administrators the same day.
| `expected one Canvas course, found …` | `reg-canvas courses` lists two courses with the same class number, or none. | Write the `canvas:` block into the class note by hand. |
| `names assignments this course does not have` | The import file's `(id)` columns come from another section's export. | Export that section again, rebuild the overlay, and push it. |
| `discussions apply` says "no plan in …" | `ls <workdir>` shows no `plan.json`. | Run `discussions review` with the same `--workdir` first. |
| `review` refuses to overwrite the note | The note already exists and may hold your ticks. | Finish that round, or pass `--force` to start again. |
| `apply` says "name the week(s) to apply" | You left out `--week`. | Add `--week "Week N"` for the week you reviewed. |
| `apply` stops with "cannot reach Canvas" | A dropped connection that outlasted the retries. | Run the same command again. Grades and likes are only set once. |
| A like fails with `HTTP 403` | The topic does not allow liking. | Turn on **Allow liking** in the discussion's settings. |
| An export has fewer columns than Canvas's own | `reg-canvas grades-export --stdout --course-id <id> \| head -1` lists the assignment columns. Unpublished and hidden assignments are left out. | Publish the assignment, or ignore the column if it is not graded yet. |
12 changes: 8 additions & 4 deletions lectern/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,22 +769,26 @@ def writes(sp):
act = sp.add_subparsers(dest="action", required=True)
r = act.add_parser("review", help="write the short list to judge (reads only)")
target(r)
r.add_argument("--week", action="append", required=True,
help='assignment name prefix, e.g. "Week 5" (repeatable)')
r.add_argument("--week", action="append",
help='assignment name prefix, e.g. "Week 5" (repeatable; '
'default: every "Week N" discussion)')
r.add_argument("--workdir", required=True, help="private working dir (mode 700); "
"holds student records, delete after apply")
r.add_argument("--exclude-sis", nargs="+", default=[], metavar="SIS[@SEC]",
help="staff enrolled as students; not graded")
r.add_argument("--full-credit-sis", nargs="+", default=[], metavar="SIS[@SEC]",
help="full credit whatever the count (an agreed arrangement)")
r.add_argument("--note", help="vault note to write (default with --term/--vault-root: "
"classes/semesters/<term>-discussions-<weeks>-grading.md)")
"classes/semesters/<term>-discussions-grading.md, one section per week)")
r.add_argument("--no-note", action="store_true", help="write no vault note")
r.add_argument("--force", action="store_true", help="overwrite an existing note")
r.add_argument("--force", action="store_true",
help="start the note fresh, dropping ticks (default: a rerun keeps them)")
r.set_defaults(func=cmd_discussions)
ap_ = act.add_parser("apply", help="set scores and likes from the review")
ap_.add_argument("--workdir", required=True)
ap_.add_argument("--note", help="read the ticked deny boxes from this note")
ap_.add_argument("--week", action="append",
help='the week to apply, e.g. "Week 7" (required; repeatable)')
ap_.add_argument("--post", action="store_true",
help="also post the grades (shows students every hidden grade)")
writes(ap_)
Expand Down
27 changes: 20 additions & 7 deletions lectern/canvas_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,14 @@ def _url(self, path: str, params: dict | list | None = None) -> str:
def _scrub(self, text: str) -> str:
return text.replace(self.token, "[token]") if self.token else text

def request(self, method: str, path: str, params=None, data=None):
"""One call. Returns ``(parsed JSON, response headers)``."""
def request(self, method: str, path: str, params=None, data=None, idempotent=None):
"""One call. Returns ``(parsed JSON, response headers)``.

A dropped connection is retried for a GET, or for a write the caller
marks ``idempotent`` (setting a grade or a like). Other writes are not
retried: a timeout can arrive after Canvas has acted, and a second
announcement would notify students twice.
"""
url = self._url(path, params)
if urllib.parse.urlsplit(url).netloc != self.host:
raise CanvasError(f"refusing to send the token to {urllib.parse.urlsplit(url).netloc}")
Expand All @@ -196,8 +202,15 @@ def request(self, method: str, path: str, params=None, data=None):
body = json.dumps(data).encode("utf-8")
headers["Content-Type"] = "application/json"

safe = method == "GET" if idempotent is None else idempotent
for attempt in range(self.retries + 1):
status, rh, raw = self.transport(method, url, headers, body)
try:
status, rh, raw = self.transport(method, url, headers, body)
except CanvasError as e:
if e.status is None and safe and attempt < self.retries:
self.sleep(2 ** attempt)
continue
raise
text = raw.decode("utf-8", errors="replace")
# Canvas throttles with 403 + "Rate Limit Exceeded"; 429 on some hosts.
throttled = status == 429 or (status == 403 and "Rate Limit Exceeded" in text)
Expand Down Expand Up @@ -255,11 +268,11 @@ def get_all(self, path: str, params=None) -> Iterator[dict]:
return
page, headers = self.request("GET", nxt)

def post(self, path: str, data: dict):
return self.request("POST", path, data=data)[0]
def post(self, path: str, data: dict, idempotent: bool = False):
return self.request("POST", path, data=data, idempotent=idempotent)[0]

def put(self, path: str, data: dict):
return self.request("PUT", path, data=data)[0]
def put(self, path: str, data: dict, idempotent: bool = False):
return self.request("PUT", path, data=data, idempotent=idempotent)[0]

def wait_progress(self, progress: dict, timeout: float = 120.0) -> dict:
"""Poll a Canvas Progress object until it completes or fails."""
Expand Down
Loading
Loading