Sunday, March 3, 2013

Processing class assignments on paper (Part I)

One of my classes is really old-school. I give out exercises on paper. The nature of the class requires the students to write a lot of equations, and draw diagrams. These things are really hard to do electronically, unless every student would have an iPad (or other tablet). Collecting, and keeping the papers is a pain. In addition to the hassle of filing or returning them to the students, I also have to enter the scores into something electronic after grading.

So, I'm developing a system to produce worksheets for the students. The returned sheets can either be graded with pen on paper and then scanned for further processing, or the stack can be scanned into a PDF file, and graded on an iPad. I choose to use QR-Codes to mark the pages. Bar codes seem to be more reliable than deciphering text labels with OCR. In particular, QR-codes can be reliably detected regardless of position, and to a certain degree scale and rotation.

System Requirements

The solution is based on a number of open source packages and libraries. Installation is easy for UNIX systems. I produce the handouts on OS X or Linux, processing of the scanned papers runs on LINUX.
Fortunately, these systems make it easy to install the various packages. Windows users may have a chance with Cygwin/X to get this working.

Creating Worksheets

The worksheets are produced in LaTeX (with help of some PostScript). Fortunately, there are some neat packages, like pgffor, that enable loops and the use of arrays. Some helpful documents are listed here:
Basic conditional if-else structures can be achieved with conditional variables in TeX. http://handyfloss.net/2007.08/latex-programming-how-to-implement-conditionals/

Another thing to point out is how to create LaTeX style files: There is a rather complicated, proper way to do it with documentation files (.dtx). However, for right now, I just put the preamble section of my LaTeX document, i.e. almost everything between \documentclass and \begin{document}, into a file names "worksheet.sty". However, there is one caveat: all \usepackage commands need to be replaced with \RequirePackage (more about that at http://tex.stackexchange.com/questions/19919/whats-the-difference-between-requirepackage-and-usepackage).

An interesting effect: the last page of the assignment already had the name of the next student. Apparently, the new header already became active for the last page. However, a tailing \newpage command forced the last page to be rendered, before the new header is set. Also, multiple new page commands don't create unwanted blank pages.

The following shows an excerpt of the style file:
\RequirePackage[letterpaper,margin=0.75in]{geometry}
\RequirePackage{graphicx}
\RequirePackage{amssymb}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}
\RequirePackage{pstricks}
\RequirePackage{pst-barcode}
\RequirePackage{fancyhdr}
\RequirePackage{pgffor,pgfmath}
\pagestyle{fancy}

\newcommand{\hofilename}{XXX}
\newcommand{\hoclass}{ABC123}
\newcommand{\studentid}{A12345678}
\newcommand{\studentname}{John Doe}
\newcommand{\wsId}[1]{\renewcommand{\hoclass}{#1}}
\newcommand{\wsFile}[1]{\renewcommand{\hofilename}{#1}}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

\setlength{\topmargin}{-1.7in}
\setlength{\headheight}{2.1in}
\setlength{\textheight}{8in}
\setlength{\footskip}{0.5in}

\fancyfoot[C]{%
  \foreach \val in {A, 0, 1, 2, 3, 4, X} {
    \val~\begin{pspicture}(0.7in,0.7in)
                \psbarcode{score=\val}{eclevel=M}{qrcode} \end{pspicture}
  }
}
\fancyfoot[L]{}
\fancyfoot[R]{}
\fancyhead[R]{\footnotesize Do not write over QR codes!}

%%\def\StudentsNames{{ "Smith, Fritz", "Jacobs, Lashonda", "Wu, Sarah" }}
%%\def\StudentsIds{ M12345678, 900123456, 900555123 }

\def\worksheets#1{%
  \foreach \id[count=\xi from 0] in \wsStudentIds {
    \renewcommand{\studentid}{\id}
    \newpage
    \fancyhead[C]{{\LARGE \hoclass:\ \@title}\\ \@date \\[1.5ex]%
        {\bf \pgfmathparse{\wsStudentNames[\xi]}\pgfmathresult}
    }
    \fancyhead[L]{%
        \begin{pspicture}(2in,2in)
          \psbarcode{c=\hoclass\&d=\@date\&f=\hofilename\&p=\thepage\&s=\studentid}{eclevel=M}{qrcode}
        \end{pspicture}
    }
    #1
    \newpage
  }
}
The two arrays, StudentNames and StudentIds should be defined in the main document, or in a separate file that will be included in each assignment.

An assignment would look something like this:

\documentclass[11pt]{article}
\usepackage{worksheet}

\wsId{CIS227}
\wsFile{CE02}

\title{Class Exercise 2}
\date{2013-01-24}

\input{students}

\def\handout{
  \noindent Prove the following tautologies by starting with the left side
  and finding a series of equivalent wff's that will convert the left
  side into the right side.
  \begin{enumerate}
    
  \item $(A \wedge B') \wedge C \leftrightarrow (A \wedge C) \wedge B'$
    \newpage
  \item $(A \vee B) \wedge (A \vee B') \leftrightarrow A$
    \newpage
  \item $A \vee ( B \wedge A') \leftrightarrow A \vee B $
    \newpage
  \item $(A \wedge B')' \vee B \leftrightarrow A' \vee B$
    \newpage
  \item $A \wedge (A \wedge B')' \leftrightarrow A \wedge B$
    \newpage  
  \end{enumerate}
}

\begin{document}
\worksheets{\handout}
\end{document}

Now, that I can produce these worksheets, I just need to develop the program that reads the scanned sheets and processes the grades.

No comments:

Post a Comment