Auto grading script

I’m now teaching a section of sixth grade technology class. In a nutshelll – it’s typing. Not to demean that – I believe good typing skills are essential. They certainly have served me well.

I’m using moodle to collect everything from my students, because I can’t stand using paper – I’ll lose it faster than you can imagine. Still, that left me with the unpleasant task of grading these files. Essentially, I end up with about 20 files that should be exactly identical to the key. At first, I thought I would use Word’s built in compare documents feature. While this certainly would be better than grading by hand, it was tedious and the results were still difficult to translate into a reasonable grade.

After being recently introduced to the for loop, I figured that a bash script had to be the answer. I wrote this script last night and revised it throughout the day today. I learned how to pass arguments from the command line thanks to help from my brother. He also helped me clean up the code a bit, for which I’m grateful.

For this script to work, you need to have docx2txt installed as well as dwdiff. if you’re on ubuntu, it’s just a simple “sudo apt-get install” and you’re on your way.

Usage –

autograde /path/to/files/to/be/graded /path/to/answerkey.txt

This will output files with a percentage common, inserted, and deleted all in the filename. Yeah, it makes a huge filename, but I like having all that info right there.

Feel free to modify it for your own needs or make suggestions on how I can improve it. For what it’s worth, the usage statement is correct in the actual script, but somehow I can’t get the arguments to display in wordpress.

#!/bin/bash
WORKDIR=$1
KEYFILE=$2
GRADEDDIR=$WORKDIR/graded/

# first check if there are two arguments:
if [ "$#" -ne 2 ]; then
    echo "usage: $0   "
    exit
fi

#checks to see if $GRADEDDIR exists and creates it if it does not
if [ ! -d "$GRADEDDIR" ]; then
        mkdir -p "$GRADEDDIR"
fi

#converts MS Word format to plain text
for UNGRADED in $WORKDIR/*.docx; do
docx2txt.sh $UNGRADED;
done

#compares text files against key and outputs to .GRADED.txt file
for GRADED in $WORKDIR/*.txt; do
dwdiff -s $KEYFILE $GRADED > $GRADED.GRADED.txt
done

#renames .GRADED.txt file with information dwdiff writes to end of file
for RENAMED in $WORKDIR/*.GRADED.txt; do
mv $RENAMED "$RENAMED.$(grep "old:" $RENAMED).txt"
done

#moves graded files to graded directory
for MOVED in $WORKDIR/*old:*.txt; do
mv "$MOVED" $GRADEDDIR
done

#removes ungraded.txt files from $WORKDIR
rm $WORKDIR/*.txt

I’m really enjoying learning how to script. This one will save me many hours of valuable time. The next thing I want to do is to have the script echo the proper usage when entered without arguments. That’s probably just a few google searches away, but that’s for another day.  (done). Next I want to see if there’s a way I can save the color output. I can do output in color using “dwdiff -c” within the script, but I need to figure out if there’s a way that I can save that color coding into a file format that retains the color information so I can give it to students as feedback. Thus far, I have only succeeded at seeing the color within the terminal window.

Abstaining from political topics

At the moment, I’m going through a bit of a purging, as a friend of mine likes to call it. Specifically, I’m not allowing myself to log into facebook for any reason – I even deactivated my account. I am also preventing myself from posting anything anywhere online about anything political until November 1.

Why? It was just getting the better of me. I’ll get back to shouting out my opinions later on, but right now, I just need the break.

Start mythtv from remote control

I’ve been trying to find a way to start mythtv from the remote control for quite a while now. While I love Mythtv, it is definitely not ready for mainstream yet. I don’t mind tinkering with stuff – ok, I actually really enjoy it. My family however, does not appreciate it when something goes wrong and I’m not there to fix it.

It’s rare when the frontend crashes, but it does happen. My usual solution is just to vnc into the box and restart it (no keyboard or mouse, it’s an htpc hooked up to our tv). Although not too difficult, that’s really more of a pain than you can reasonably expect your family to endure.

First, I had to figure out why lirc wasn’t working every time the system rebooted. After much searching, it turns out I had to comment out the following lines in /lib/udev/rules.d

ACTION=="add", KERNEL=="lirc[0-9]", RUN="/etc/init.d/lirc restart udev"
ACTION=="remove", KERNEL=="lirc[0-9]", RUN="/etc/init.d/lirc stop udev"

Upon rebooting, that solved the problem of no lirc. That was a relief, because prior to this edit, I had to restart lirc and then restart the front end. That’s just a pain.

I went about things a little backwards and went ahead and mapped a button to a script that was executed via irexec. I added the following to my ~/.lircrc

begin
        remote = mceusb
        Button = Blue
        prog = irexec
        repeat = 0
        config = /usr/local/bin/startmythfrontend.sh
end

Naturally, you’ll want to change that to whatever matches your remote, button and script name that you’re using.

After a great deal of searching, experimentation, and learning how to use “if” in a bash script, I came up with the following script:

#!/bin/bash
if [ $LOGNAME == "root" ]; then
echo "Hello root, you should be running this script as \"mythtv\" user, goodbye.";
exit
fi

if [  $(pidof mythfrontend.real) ]; then
echo "mythfrontend is already started"; else
echo "starting mythfrontend"
DISPLAY=:0 mythfrontend > /var/log/mythtv/mythfrontend.log 2>&1 &
fi

I modified a script on the mythtv wiki to come up with one to meet my needs. I saved it as startmythfrontend.sh and did a

sudo chmod +x startmythfrontend.sh

After that, I realized that this wasn’t going to do me any good if I couldn’t get an irexec daemon to always run. I tried messing with the init.d, but my script writing skills aren’t quite up to that point yet. Instead, I just added this line at the beginning of /usr/bin/mythfrontend

/usr/local/bin/startirexec

Then, I wrote the following script, named it startirexec and then chmodded it +x :

#!/bin/bash
if [ ! $(pidof irexec) ]; then
echo "starting irexec daemon"
irexec -d
else echo "irexec already started"
fi

Now whenever I press the right button on my remote, the frontend starts if it isn’t started, and nothing happens if it’s already started.

I’m a beginning scripter, so let me know if there’s anything I can do more efficiently or elegantly.

Passing of a loved one

Recently, I learned that my Aunt Phyllis had passed away. My dad was the youngest of 10 kids, and my Aunt Phyllis was the oldest, so she was old enough to be my grandmother. While her death did not come as a shock, I was still saddened. Even though I hadn’t seen her in about 5 years, she will be missed.

After I heard, I couldn’t help but think back of all the memories I have of her. All of the memories I can think of are good ones.

Now that’s something worth blogging about.

Taking a break from politics & social networking

I’ve never really had much use for social networking. I deleted my myspace page about 2 years ago, and never really did much with facebook. This summer, I started to dabble more and sort of enjoyed it.

Alas, it was not to be. I ended up with about 150 or so friends, most of whom I knew a very long time ago and none of whom really know me very well. Most didn’t know me all that well when they did know me. Let’s just say I got frustrated by the small mindedness that exists.

I don’t care whether or not you agree with me, but one should always be open to the possibility that you might be wrong. If you can’t do that, I’m not interested in having political discussion with you. I most certainly believe I might be wrong in some cases, despite strong beliefs and opinions.

So anyway, for the next while, I’m going to try to get back to blogging about things that really matter – like food and family.