Class: SakaiInfo::QuizAttempt

Inherits:
SakaiObject show all
Defined in:
lib/sakai-info/quiz.rb

Constant Summary collapse

ATTEMPT_STATUS =

status definitions from samigo-api/src/java/org/sakaiproject/tool/assessment/data/ifc/grading/AssessmentGradingIfc.java

{
  "0" => "unsubmitted",
  "1" => "submitted-ungraded",
  "2" => "submitted-auto-graded",
  "3" => "submitted-needs-human-attention",
  "4" => "needs-resubmit",
  "5" => "unsubmitted-but-graded",
  "6" => "updated-in-progress",
}

Instance Attribute Summary collapse

Attributes inherited from SakaiObject

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SakaiObject

#dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml

Constructor Details

#initialize(dbrow) ⇒ QuizAttempt

Returns a new instance of QuizAttempt.



779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
# File 'lib/sakai-info/quiz.rb', line 779

def initialize(dbrow)
  @dbrow = dbrow

  @id = dbrow[:assessmentgradingid]
  @submitted_at = dbrow[:submitteddate]
  @user_id = dbrow[:agentid]
  @quiz_id = dbrow[:publishedassessmentid]
  @total_auto_score = dbrow[:totalautoscore]
  @status = dbrow[:status]
  @attempted_at = dbrow[:attemptdate]
  @time_elapsed = dbrow[:timeelapsed]
  @is_auto_submitted = dbrow[:isautosubmitted]
  @is_late = dbrow[:islate]
  @comments = dbrow[:comments]
end

Instance Attribute Details

#commentsObject (readonly)

Returns the value of attribute comments.



772
773
774
# File 'lib/sakai-info/quiz.rb', line 772

def comments
  @comments
end

#dbrowObject (readonly)

Returns the value of attribute dbrow.



772
773
774
# File 'lib/sakai-info/quiz.rb', line 772

def dbrow
  @dbrow
end

#quiz_idObject (readonly)

Returns the value of attribute quiz_id.



772
773
774
# File 'lib/sakai-info/quiz.rb', line 772

def quiz_id
  @quiz_id
end

#statusObject (readonly)

Returns the value of attribute status.



772
773
774
# File 'lib/sakai-info/quiz.rb', line 772

def status
  @status
end

#time_elapsedObject (readonly)

Returns the value of attribute time_elapsed.



772
773
774
# File 'lib/sakai-info/quiz.rb', line 772

def time_elapsed
  @time_elapsed
end

#total_auto_scoreObject (readonly)

Returns the value of attribute total_auto_score.



772
773
774
# File 'lib/sakai-info/quiz.rb', line 772

def total_auto_score
  @total_auto_score
end

#user_idObject (readonly)

Returns the value of attribute user_id.



772
773
774
# File 'lib/sakai-info/quiz.rb', line 772

def user_id
  @user_id
end

Class Method Details

.all_serializationsObject



924
925
926
# File 'lib/sakai-info/quiz.rb', line 924

def self.all_serializations
  [:default, :items]
end

.clear_cacheObject



774
775
776
# File 'lib/sakai-info/quiz.rb', line 774

def self.clear_cache
  @@cache = {}
end

.count_by_quiz_id(quiz_id) ⇒ Object



812
813
814
# File 'lib/sakai-info/quiz.rb', line 812

def self.count_by_quiz_id(quiz_id)
  QuizAttempt.query_by_quiz_id(quiz_id).count
end

.find(id) ⇒ Object



795
796
797
798
799
800
801
802
803
804
805
806
# File 'lib/sakai-info/quiz.rb', line 795

def self.find(id)
  id = id.to_s
  if @@cache[id].nil?
    row = DB.connect[:sam_assessmentgrading_t].where(:assessmentgradingid => id).first
    if row.nil?
      raise ObjectNotFoundException.new(QuizAttempt, id)
    end

    @@cache[id] = QuizAttempt.new(row)
  end
  @@cache[id]
end

.find_by_quiz_id(quiz_id) ⇒ Object



816
817
818
819
# File 'lib/sakai-info/quiz.rb', line 816

def self.find_by_quiz_id(quiz_id)
  QuizAttempt.query_by_quiz_id(quiz_id).
    all.collect { |row| QuizAttempt.new(row) }
end

.find_by_user_id_and_quiz_id(user_id, quiz_id) ⇒ Object



825
826
827
828
# File 'lib/sakai-info/quiz.rb', line 825

def self.find_by_user_id_and_quiz_id(user_id, quiz_id)
  QuizAttempt.query_by_user_id_and_quiz_id(user_id, quiz_id).
    all.collect { |row| QuizAttempt.new(row) }
end

.query_by_quiz_id(quiz_id) ⇒ Object



808
809
810
# File 'lib/sakai-info/quiz.rb', line 808

def self.query_by_quiz_id(quiz_id)
  DB.connect[:sam_assessmentgrading_t].where(:publishedassessmentid => quiz_id)
end

.query_by_user_id_and_quiz_id(user_id, quiz_id) ⇒ Object



821
822
823
# File 'lib/sakai-info/quiz.rb', line 821

def self.query_by_user_id_and_quiz_id(user_id, quiz_id)
  DB.connect[:sam_assessmentgrading_t].where(:publishedassessmentid => quiz_id, :agentid => user_id)
end

Instance Method Details

#attempted_atObject



854
855
856
857
858
859
860
# File 'lib/sakai-info/quiz.rb', line 854

def attempted_at
  if @attempted_at.nil?
    nil
  else
    @attempted_at.strftime("%Y-%m-%d %H:%M:%S")
  end
end

#auto_submitted?Boolean

Returns:

  • (Boolean)


846
847
848
# File 'lib/sakai-info/quiz.rb', line 846

def 
  @is_auto_submitted == 1
end

#default_serializationObject



885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
# File 'lib/sakai-info/quiz.rb', line 885

def default_serialization
  {
    "id" => self.id,
    "user" => self.user.serialize(:summary),
    "quiz" => self.quiz.serialize(:summary),
    "item_count" => self.item_count,
    "attempted_at" => self.attempted_at,
    "submitted_at" => self.,
    "time_elapsed" => self.time_elapsed,
    "is_auto_submitted" => self.,
    "is_late" => self.late?,
    "status" => self.status,
    "total_auto_score" => self.total_auto_score
  }
end

#item_countObject



834
835
836
# File 'lib/sakai-info/quiz.rb', line 834

def item_count
  @item_count ||= QuizAttemptItem.count_by_attempt_id(self.id)
end

#itemsObject



830
831
832
# File 'lib/sakai-info/quiz.rb', line 830

def items
  @items ||= QuizAttemptItem.find_by_attempt_id(self.id)
end

#items_serializationObject



918
919
920
921
922
# File 'lib/sakai-info/quiz.rb', line 918

def items_serialization
  {
    "items" => self.items.collect { |i| i.serialize(:attempt_summary) }
  }
end

#late?Boolean

Returns:

  • (Boolean)


850
851
852
# File 'lib/sakai-info/quiz.rb', line 850

def late?
  @is_late == 1
end

#quizObject



842
843
844
# File 'lib/sakai-info/quiz.rb', line 842

def quiz
  @quiz ||= PublishedQuiz.find(@quiz_id)
end

#quiz_summary_serializationObject



910
911
912
913
914
915
916
# File 'lib/sakai-info/quiz.rb', line 910

def quiz_summary_serialization
  {
    "id" => self.id,
    "eid" => User.get_eid(self.user_id),
    "status" => self.status
  }
end

#submitted_atObject



862
863
864
865
866
867
868
# File 'lib/sakai-info/quiz.rb', line 862

def 
  if @submitted_at.nil?
    nil
  else
    @submitted_at.strftime("%Y-%m-%d %H:%M:%S")
  end
end

#summary_serializationObject



901
902
903
904
905
906
907
908
# File 'lib/sakai-info/quiz.rb', line 901

def summary_serialization
  {
    "id" => self.id,
    "eid" => User.get_eid(self.user_id),
    "quiz_id" => self.quiz_id,
    "status" => self.status
  }
end

#userObject



838
839
840
# File 'lib/sakai-info/quiz.rb', line 838

def user
  @user ||= User.find(@user_id)
end