Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011 Michael Ruflin, Andr´┐Ż Locher, Claudia von Bastian. This file is part of Tatool. Tatool is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Tatool is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Tatool. If not, see <http://www.gnu.org/licenses/>. /
 
 package ch.tatool.core.element.handler.score;
 
 import java.util.List;
 
Default implementation of a score and level handler. Checks for the performance (% correct) after n (sampleSize) trials and decides on level up or down depending on the maxThreshold and minThreshold parameters. if performance is >= maxThreshold then do a level-up if performance is <= minThreshold then do a level-down

Author(s):
Andre Locher
 
 
 	private int sampleSize = 3;
 
 	private double maxThreshold = 80;
 
 	private double minThreshold = 60;
 
 	private double performance = 0;
 
 	public static final String PROPERTY_LEVEL_COUNTER = "levelCounter";
 
 	public static final String PROPERTY_LEVEL_PERFORMANCE = "levelPerformance";
 	public static final String PROPERTY_LEVEL_TOTALPOINTS = "levelTotalPoints";
 	public static final String PROPERTY_LEVEL_MAXPOINTS = "levelMaxPoints";
 
 	private static DoubleProperty performanceProperty = new DoubleProperty(
 
 	private double totalScore = 0;
 	private double maxScore = 0;
 	private int trialCounter;
 
 	// statistics data
 
 		super("level-handler");
 	}

Initializes the algorithm with the values of the DB at session start
 
 	protected void initializeHandler(ExecutionContext context) {
 		 = 0;
 		 = 0;
 
 		// session data
 		 = 0;
 	}

Initializes the algorithm with the values of the DB.
 
 	public void initializeAlgorithm(ExecutionContext event) {
 		Module module = event.getExecutionData().getModule();
 
		// get the counters from the module
	}
	protected int checkLevelChange(ExecutionContext contextint currentLevel) {
		List<Trialtrials = context.getExecutionData().getTrials();
		int oldLevel = currentLevel;
		int newLevel = oldLevel;
		Executable executable = context.getActiveExecutable();
		// loop through all trials
		for (int i = 0; i < trials.size(); i++) {
			Trial trial = trials.get(i);
			 += Points.getPointsProperty().getValue(trialtrial.getParentId(), 0);
			 += Points.getMaxPointsProperty().getValue(trialtrial.getParentId(), 0);
			if (trials.isEmpty()) return currentLevel;
			String trialOutcome = Misc.getOutcomeProperty().getValue(trialexecutable);
			// only do calculation if trial is finished and compound element is done
			if (trialOutcome != null
					&& isCompoundDone(context)) {
				if ( >= ( - 1)) {
					 = ( / ) * 100;
					// level up counter
						newLevel = changeLevel(contextoldLevel, 1);
						// level down counter
else if ( <=  && oldLevel > 1) {
						newLevel = changeLevel(contextoldLevel, -1);
					}
					// save data to trial
					 = 0;
							.getModule(), this);
else {
				}
						.getModule(), this);
			}
		}
		return newLevel;
	}

Changes level and adapts all parameters of the adaptive algorithm.

Returns:
the new level
	private int changeLevel(ExecutionContext eventint oldLevelint addition) {
		int newLevel;
		newLevel = oldLevel + addition;
		return newLevel;
	}

Checks whether the current trial is complete. The algorithm only gets triggered if a compound element is finished

Returns:
whether the trial is complete
	private boolean isCompoundDone(ExecutionContext context) {
		Node currElement = context.getActiveElement();
        boolean isDone = true;
        while (this.getParent() != null) {
            // CompoundElement
            if (currElement instanceof CompoundElement) {
                CompoundElement comp = (CompoundElementcurrElement;
                for (Object handler : comp.getHandlers()) {
                    if (handler instanceof CompoundSelector) {
                        CompoundSelector selector = (CompoundSelectorhandler;
                        isDone = selector.isDone();
                    }
                }
            }
            
            if (this.getParent().getId().equals(currElement.getId())) {
            	return isDone;
            }
            
            if (currElement.getParent() != null) {
                currElement = currElement.getParent();
            } else {
                return true;
            }
        }
        return isDone;
    }
	}
		return ;
	}
	public double getMaxThreshold() {
		return ;
	}
	public void setMaxThreshold(double maxThreshold) {
		this. = maxThreshold;
	}
	public double getMinThreshold() {
		return ;
	}
	public void setMinThreshold(double minThreshold) {
		this. = minThreshold;
	}
	public int getSampleSize() {
		return ;
	}
	public void setSampleSize(int sampleSize) {
		this. = sampleSize;
	}
New to GrepCode? Check out our FAQ X