WeBWorK Problems

Compression algorithms and Past Answers

Compression algorithms and Past Answers

by Lee McPherson -
Number of replies: 2

I'm exploring various ways to fit a large amount of data into the student answer that gets recorded into the database.  The limit is around 5k characters.  Access to gzip or something similar would allow pretty good compression of text (like an SVG or a JSON string) and give me a little more flexibility.  As far as I can tell, nothing like that is available to PG problems and it's not possible to add external modules.  Am I missing something?

I'm also aware that a compressed answer wouldn't be readable in the past answers screen.  (But I'm handling it fine on the actual problem page.)  However, even a JSON string that contains various metadata wouldn't be very useful to a student who wants to see past answers, either.  I've looked at the ShowAnswers.pm file and it seems that everything just gets encoded to non-PG, non-HTML, plain text.  How did the Flash applets handle this?  I don't know what kind of answers they would record.

Thanks in advance!

In reply to Lee McPherson

Re: Compression algorithms and Past Answers

by Glenn Rice -
You could consider using the RECORD_EXTRA_ANSWERS method. With that you can record data that is not shown in the past answers table. This data is stored in the last_answer column of the problem_user table, but not in the answer_string of the past_answer column. This is how GeoGebra applet problems store state and how MathQuill saves the LaTeX version of the answers.  (Flash applet problems are gone, as no browsers support flash anymore, but they also stored state in the last_answer column.) The last_answer column is of type TEXT, and so can hold 65,535 bytes of data.

You can add modules to PG, but you need to have administrative access to the server to do it. Add any modules to the $pg{modules} array. This can be done in localOverrides.conf by adding
push(@{ $pg{modules} }, ['module name']);
In reply to Glenn Rice

Re: Compression algorithms and Past Answers

by Lee McPherson -
That makes a lot of sense now. I had discovered RECORD_FORM_LABEL and misunderstood what it actually did. Now taking a look at the source, it's an alias for RECORD_EXTRA_ANSWERS. I think that's what I'll use. Thanks!