Advertisement
uopspop

Untitled

Oct 26th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. package com.sm2;
  2.  
  3. import org.apache.commons.lang3.builder.ToStringBuilder;
  4.  
  5. // ref: http://www.blueraja.com/blog/477/a-better-spaced-repetition-learning-algorithm-sm2
  6. public abstract class SM2_Impl {
  7.     private Double easiness = new Double(2.5);
  8.     private Double consecutiveCorrectAnswers = new Double(0);
  9.     private Double nextDueDate = new Double(0);
  10.    
  11.     public Double getEasiness() {
  12.         return easiness;
  13.     }
  14.     public void setEasiness(Double easiness) {
  15.         this.easiness = easiness;
  16.     }
  17.     public Double getConsecutiveCorrectAnswers() {
  18.         return consecutiveCorrectAnswers;
  19.     }
  20.     public void setConsecutiveCorrectAnswers(Double consecutiveCorrectAnswers) {
  21.         this.consecutiveCorrectAnswers = consecutiveCorrectAnswers;
  22.     }
  23.     public Double getNextDueDate() {
  24.         return nextDueDate;
  25.     }
  26.     public void setNextDueDate(Double nextDueDate) {
  27.         this.nextDueDate = nextDueDate;
  28.     }
  29.    
  30.     public void ans(PerformanceRatingEnum performanceRating) {
  31.         performanceRating.getLevel();
  32.         this.easiness +=  -0.8 + 0.28*performanceRating.getLevel() + 0.02*Math.pow(performanceRating.getLevel(), 2);
  33.         if (this.easiness < 1.3) {
  34.             this.easiness = 1.3; // the min val
  35.         }else if (this.easiness > 3) {
  36.             this.easiness = 3.0; // the max val
  37.         }
  38.        
  39.        
  40.         switch(performanceRating) {
  41.         case CORRECT_RESPONSE_03:
  42.         case CORRECT_RESPONSE_04:
  43.         case PERFECT_RESPONSE_05:
  44.             this.consecutiveCorrectAnswers++;
  45.             this.nextDueDate = this.nextDueDate + (6 * Math.pow(this.easiness, this.consecutiveCorrectAnswers - 1));
  46.             break;
  47.         case COMPLETE_BLACKOUT_00:
  48.         case INCORRECT_RESPONSE_01:
  49.         case INCORRECT_RESPONSE_02:
  50.             this.consecutiveCorrectAnswers = 0.0;
  51.             this.nextDueDate = this.nextDueDate + 1;
  52.             break;
  53.         default:
  54.             break;
  55.         }
  56.        
  57.     }
  58.    
  59.     @Override
  60.     public String toString() {
  61.         return ToStringBuilder.reflectionToString(this);
  62.     }
  63.    
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement