Class: Buhos::AnalysisIncExcCriteria

Inherits:
Object
  • Object
show all
Defined in:
lib/buhos/analysis_inc_exc_criteria.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sr) ⇒ AnalysisIncExcCriteria

Returns a new instance of AnalysisIncExcCriteria.



35
36
37
38
39
40
41
42
43
# File 'lib/buhos/analysis_inc_exc_criteria.rb', line 35

def initialize(sr)
  @sr=sr
  @criteria=SrCriterion.join(:criteria, id: :criterion_id).where(systematic_review_id:@sr.id).order(:criteria_type, :criterion_id)
  set_canonical_documents
  @users_id=@sr.group_users.map(&:id)
  @user_n=@users_id.length
  @criteria_id=@criteria.map {|crit| crit[:id]}
  @cd_criteria=CdCriterion.where(systematic_review_id:@sr.id, canonical_document_id:@cd_ids, criterion_id:@criteria_id ).order(:user_id, :canonical_document_id, :criterion_id)
end

Instance Attribute Details

#cd_idsObject (readonly)

Returns the value of attribute cd_ids.



34
35
36
# File 'lib/buhos/analysis_inc_exc_criteria.rb', line 34

def cd_ids
  @cd_ids
end

#criteriaObject (readonly)

Returns the value of attribute criteria.



33
34
35
# File 'lib/buhos/analysis_inc_exc_criteria.rb', line 33

def criteria
  @criteria
end

#srObject (readonly)

Returns the value of attribute sr.



32
33
34
# File 'lib/buhos/analysis_inc_exc_criteria.rb', line 32

def sr
  @sr
end

Instance Method Details

#proportion_by_cdObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/buhos/analysis_inc_exc_criteria.rb', line 51

def proportion_by_cd

  crit_perc=lambda {@criteria.inject({}) { |ac,criterion|
    ac[criterion[:id]]=CdCriterion::PRESENCE_VALID.inject({}) {|ac2,presence| ac2[presence]=0; ac2}
    ac
  }}
  percents=@cd_ids.inject({}) do |ac,cd_id|
    ac[cd_id]=crit_perc.call
    ac
  end
  #$log.info(percents)
  @cd_criteria.each do |row|

    next unless @cd_ids.include? row[:canonical_document_id] and @criteria_id.include? row[:criterion_id]

    percents[row[:canonical_document_id]][row[:criterion_id]][row[:presence]]+= 1.to_f/@user_n
  end
  percents

end