\chapter{Some utitlity scripts}% ===> this file was generated automatically by noweave --- better not edit it

\section{Grade statistics}

We have different scripts for assignments with P/F and A-F grading scales.
For these scripts, we simply count how many have each certain grade.
We also output how many have not been graded yet, and how many have not 
submitted anything.

\subsection{Statistics for P/F grading scale}

\nwfilename{utils.nw}\nwbegincode{1}\sublabel{NW487MPY-2O6i44-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW487MPY-2O6i44-1}}}\moddef{pfstats~{\nwtagstyle{}\subpageref{NW487MPY-2O6i44-1}}}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
#!/bin/bash

COURSE="$1"
ASSIGNMENT="$2"
shift 2

results=$(mktemp)
canvaslms submissions -c $COURSE -a "$ASSIGNMENT" $@ | cut -f 4- > $results

function get_results() \{
  cat $results
\}

function print_stats() \{
  total=$(get_results | wc -l)
  echo "Total:     $total (100%)"
  Ps=$(get_results | grep ^P | wc -l)
  echo "P:         $Ps ($(((100 * $Ps / $total)))%)"
  Fxs=$(get_results | grep ^Fx | wc -l)
  echo "Fx:        $Fxs ($(((100 * $Fxs / $total)))%)"
  Fs=$(get_results | grep ^F[^x] | wc -l)
  echo "F:         $Fs ($(((100 * $Fs / $total)))%)"
  remaining=$(get_results | egrep "^[^PF].*[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}" | wc -l)
  echo "Remaining: $remaining ($(((100 * $remaining / $total)))%)"
  nothing=$(get_results | grep "^[^a-fA-F0-9]*$" | wc -l)
  echo "Nothing:   $nothing ($(((100 * $nothing / $total)))%)"
\}

print_stats
\nwnotused{pfstats}\nwendcode{}\nwbegindocs{2}\nwdocspar

\subsection{Statistics for A-F grading scale}

\nwenddocs{}\nwbegincode{3}\sublabel{NW487MPY-3UhZF0-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW487MPY-3UhZF0-1}}}\moddef{afstats~{\nwtagstyle{}\subpageref{NW487MPY-3UhZF0-1}}}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
#!/bin/bash

COURSE="$1"
ASSIGNMENT="$2"
shift 2

results=$(mktemp)
canvaslms submissions -c $COURSE -a "$ASSIGNMENT" $@ | cut -f 4- > $results

function get_results() \{
  cat $results
\}

function print_stats() \{
  total=$(get_results | wc -l)
  echo "Total:     $total (100%)"
  As=$(get_results | grep ^A | wc -l)
  echo "A:         $As ($(((100 * $As / $total)))%)"
  Bs=$(get_results | grep ^B | wc -l)
  echo "B:         $Bs ($(((100 * $Bs / $total)))%)"
  Cs=$(get_results | grep ^C | wc -l)
  echo "C:         $Cs ($(((100 * $Cs / $total)))%)"
  Ds=$(get_results | grep ^D | wc -l)
  echo "D:         $Ds ($(((100 * $Ds / $total)))%)"
  Es=$(get_results | grep ^E | wc -l)
  echo "E:         $Es ($(((100 * $Es / $total)))%)"
  Fxs=$(get_results | grep ^Fx | wc -l)
  echo "Fx:        $Fxs ($(((100 * $Fxs / $total)))%)"
  Fs=$(get_results | grep ^F[^x] | wc -l)
  echo "F:         $Fs ($(((100 * $Fs / $total)))%)"
  remaining=$(get_results | egrep "^[^A-F].*[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}" | wc -l)
  echo "Remaining: $remaining ($(((100 * $remaining / $total)))%)"
  nothing=$(get_results | grep "^[^a-fA-F0-9]*$" | wc -l)
  echo "Nothing:   $nothing ($(((100 * $nothing / $total)))%)"
\}

print_stats
\nwnotused{afstats}\nwendcode{}\nwbegindocs{4}\nwdocspar

\subsection{Results statistics for OLI tests}

We want to see how many students have taken the OLI tests.
We can't tell if they've passed or failed them without additional information.
If they have submitted them, we consider them done.
\nwenddocs{}\nwbegincode{5}\sublabel{NW487MPY-3WsRZx-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW487MPY-3WsRZx-1}}}\moddef{OLIstats~{\nwtagstyle{}\subpageref{NW487MPY-3WsRZx-1}}}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
#!/bin/bash

COURSE="$1"
ASSIGNMENT="$2"
shift 2

results=$(mktemp)
canvaslms submissions -c $COURSE -a "Test:.*$ASSIGNMENT" $@ | \\
  cut -f 4- > $results

function get_results() \{
  cat $results
\}

function print_stats() \{
  total=$(get_results | wc -l)
  echo "Total:     $total (100%)"
  year=$(date +%Y)
  done=$(get_results | grep $year- | wc -l)
  echo "done:      $done ($(((100 * $done / $total)))%)"
  nothing=$(get_results | grep "^[^a-fA-F0-9]*$" | wc -l)
  echo "Nothing:   $nothing ($(((100 * $nothing / $total)))%)"
\}

print_stats
\nwnotused{OLIstats}\nwendcode{}\nwbegindocs{6}\nwdocspar


\section{List user's group memberships}

When we grade someone and report their result to Canvas, we want to check if 
they're in the same group as someone else.
If so, we can't report a grade without reporting for the other student too.
\nwenddocs{}\nwbegincode{7}\sublabel{NW487MPY-9HYCI-1}\nwmargintag{{\nwtagstyle{}\subpageref{NW487MPY-9HYCI-1}}}\moddef{lsgroup~{\nwtagstyle{}\subpageref{NW487MPY-9HYCI-1}}}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
#!/bin/bash

course="$1"
user="$2"

users="/tmp/users-$course.csv"

if test "$#" -lt 2; then
  echo "$0 course user [group prefix]"
  exit 1
fi

group_prefix="$3"
if test -z "$group_prefix"; then
  group_prefix=".*"
fi

test -e "$users" || \\
  canvaslms users -sc "$course" -G "$group_prefix" | cut -f 2- > "$users"

groups="$(egrep "$group_prefix" "$users" | egrep "$user" | cut -f 1)"
if test -z "$groups"; then
  echo "User $user is in no group"
  exit 1
else
  IFS=$'\\n'
  for group in $groups; do
    egrep "^$group" "$users"
  done
fi
\nwnotused{lsgroup}\nwendcode{}

\nwixlogsorted{c}{{afstats}{NW487MPY-3UhZF0-1}{\nwixd{NW487MPY-3UhZF0-1}}}%
\nwixlogsorted{c}{{lsgroup}{NW487MPY-9HYCI-1}{\nwixd{NW487MPY-9HYCI-1}}}%
\nwixlogsorted{c}{{OLIstats}{NW487MPY-3WsRZx-1}{\nwixd{NW487MPY-3WsRZx-1}}}%
\nwixlogsorted{c}{{pfstats}{NW487MPY-2O6i44-1}{\nwixd{NW487MPY-2O6i44-1}}}%
\nwbegindocs{8}\nwdocspar

\nwenddocs{}
