WeBWorK Main Forum

Achievements - preamble.at

Achievements - preamble.at

by Andrew Swanson -
Number of replies: 4
So I'm looking into using achievements for my fall course. This is a course that tends to have a lot of froth in the enrollment for the first week. I wanted achievements turned off (or even better, only a limited set of them tested, so I could write an orientation question that talked about achievements.) until after the orientation set was completed, but this might vary as different students join late. I saw this line in the wiki:
  • Sometimes instructors don't want achievements to register for the initial "orientation" set. This can be done by not assigning achievements until after the set has been completed, or by using the preamble.atfile described at Achievement Evaluator.
However, I found no documentation there. Does anybody have any idea how to use "preamble.at" or know where any documentation of it is?

I notice that an empty file of that name exists in the achievements directory.
In reply to Andrew Swanson

Re: Achievements - preamble.at

by Andrew Parker -
I'd also like to know how to use this feature - for pretty much the same reason.
In reply to Andrew Swanson

Re: Achievements - preamble.at

by Michael Gage -
I can't give you much detail since I haven't worked much with achievements myself, but I can tell you where the hooks involving preamble.at exist.

In defaults.config we have:
/defaults.config:175: $achievementPreambleFile = "preamble.at";

which specifies the name of the preamble file. That file is concatenated
ahead of the source file for every achievement.


in lib/WeBWorK/AchievementEvaluator.pm:
/Volumes/WW_test/opt/webwork/webwork2_2014/lib/WeBWorK/AchievementEvaluator.pm:205: open(PREAMB, '<', "$ce->{courseDirs}->{achievements}/$ce->{achievementPreambleFile}");

Then the contents of the achievementPreambleFile is read into the string $preamble.

then

my $earned = $compartment->reval($preamble."\n".$source);
warn "There were errors in achievement $achievement_id\n".$@ if $@;

So I believe that creating a file preamble.at in the achievements directory and placing some code in the file that checks to see if the current set is the orientation set and then deciding whether or not to execute the rest of the achievement code would do what you want.

https://github.com/openwebwork/webwork2/blob/master/lib/WeBWorK/AchievementEvaluator.pm#L240

Let us know how this works out.
In reply to Michael Gage

Re: Achievements - preamble.at

by Andrew Swanson -
This is basically what I ended up doing.

I decided to allow achievements on the first question so I could talk about them in the second, then disable them for the rest of the introductory assignment.

Here's my preamble.at file:

#Identify the introductory assignment and it's first problem
 my %introproblems = (
 '0_Intro_to_WeBWorK' => {
 '1' => 1, }
 );
 #If we are in the intro set on any question other than the first one, disable achievements.
 if ($introproblems{$problem->set_id} &&
 !($introproblems{$problem->set_id}{$problem->problem_id} )){
 return 0; 
 }