Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/app/models/report/renderer/mci_renderer.rb b/app/models/report/renderer/mci_renderer.rb
- index 5b2671070..865696494 100644
- --- a/app/models/report/renderer/mci_renderer.rb
- +++ b/app/models/report/renderer/mci_renderer.rb
- @@ -352,7 +352,7 @@ class Report
- @cog_report = cog_report
- @user = @protocol_session.user
- @comparative_group = comparative_group
- - @trends = Report::Trends::V4.new(@user, @cog_report).trend_values
- + @trends = Report::Trends::V4.new(@user, @cog_report, false).trend_values
- end
- def render
- diff --git a/app/models/report/trends.rb b/app/models/report/trends.rb
- index bbe708029..aeca89e76 100644
- --- a/app/models/report/trends.rb
- +++ b/app/models/report/trends.rb
- @@ -3,10 +3,11 @@
- # rubocop:disable Layout/LineLength
- class Report
- class Trends
- - def initialize(user, batch_session)
- + def initialize(user, batch_session, only_valid_scores = true)
- @user = user
- @batch_session = batch_session
- @score_data = {}
- + @only_valid_scores = only_valid_scores
- end
- def trend_values
- @@ -40,7 +41,7 @@ class Report
- end
- def meaningful_changes(scores)
- - TestScore.meaningful_changes(scores)
- + TestScore.meaningful_changes(scores, scores.last, @only_valid_scores)
- .slice(:previous_detection_date, :first_detection_date)
- .compact
- .transform_values { |date| date.short_date_format }
- diff --git a/app/models/report/trends/v4.rb b/app/models/report/trends/v4.rb
- index 66dc973c9..1f659b148 100644
- --- a/app/models/report/trends/v4.rb
- +++ b/app/models/report/trends/v4.rb
- @@ -43,7 +43,13 @@ class Report
- end
- def base_score(scores)
- - calc_trend_value(scores.sort_by(&:created_at).find(&:valid_score?))
- + values = calc_trend_value(scores.sort_by(&:created_at)
- +
- + if @only_valid_scores
- + values.find(&:valid_score?))
- + else
- + values.first
- + end
- end
- def prev_score(scores)
- @@ -85,6 +91,8 @@ class Report
- adjusted_standard: score_data[:adjusted_standard].to_f.round,
- not_rounded_adjusted_percentile: score_data[:adjusted_percentile].to_f * 100,
- adjusted_percentile: (score_data[:adjusted_percentile].to_f * 100).round,
- + # We do not need to change this value.
- + # MciRenderer can ignore these values. And always consider them positive.
- valid: score.valid_score?,
- created_at: score.created_at
- }
- diff --git a/app/models/test_score.rb b/app/models/test_score.rb
- index de8cf8bc5..fede31446 100644
- --- a/app/models/test_score.rb
- +++ b/app/models/test_score.rb
- @@ -482,36 +482,37 @@ class TestScore < Score
- Experiment::Healthcare.raw_score(self)
- end
- - def self.meaningful_change_detected?(t1_score, t2_score, t1_index, t2_index)
- - negative_meaningful_change_detected?(t1_score, t2_score, t1_index, t2_index) ||
- - positive_meaningful_change_detected?(t1_score, t2_score, t1_index, t2_index)
- + def self.meaningful_change_detected?(t1_score, t2_score, t1_index, t2_index, only_valid = true)
- + negative_meaningful_change_detected?(t1_score, t2_score, t1_index, t2_index, only_valid) ||
- + positive_meaningful_change_detected?(t1_score, t2_score, t1_index, t2_index, only_valid)
- end
- - def self.negative_meaningful_change_detected?(t1_score, t2_score, t1_index, t2_index)
- + def self.negative_meaningful_change_detected?(t1_score, t2_score, t1_index, t2_index, only_valid = true)
- # TODO for SAR test meaningful_change are not defined yet
- return false if t1_score.test.name == "SAR"
- - change = meaningful_change(t1_score, t2_score, t1_index, t2_index)
- + change = meaningful_change(t1_score, t2_score, t1_index, t2_index, only_valid)
- change[:score_change] < change[:thresholds][:low]
- end
- - def self.positive_meaningful_change_detected?(t1_score, t2_score, t1_index, t2_index)
- + def self.positive_meaningful_change_detected?(t1_score, t2_score, t1_index, t2_index, only_valid = true)
- # TODO for SAR test meaningful_change are not defined yet
- return false if t1_score.test.name == "SAR"
- - change = meaningful_change(t1_score, t2_score, t1_index, t2_index)
- + change = meaningful_change(t1_score, t2_score, t1_index, t2_index, only_valid)
- change[:score_change] > change[:thresholds][:high]
- end
- # When dealing with any score after the 10th recorded score for this user, we treat that
- # score as if it is the 10th. Similarly, for any etalon comparison after the 9th, we treat
- # it as the 9th.
- - def self.meaningful_change(t1_score, t2_score, t1_index, t2_index)
- + def self.meaningful_change(t1_score, t2_score, t1_index, t2_index, only_valid = false)
- t1_index = 9 if t1_index > 9
- t2_index = 10 if t2_index > 10
- raise ArgumentError.new("t2_index must be more than t1_index") if t2_index <= t1_index
- raise ArgumentError.new("t1_score and t2_score must have the same subclass") if t1_score.subclass != t2_score.subclass
- - return false if !t1_score.valid_score? || !t2_score.valid_score?
- +
- + return false if (!t1_score.valid_score? || !t2_score.valid_score?) && only_valid
- meaningful_changes = t2_score.test.meaningful_changes
- score_change = t2_score.raw_score - t1_score.raw_score
- @@ -574,18 +575,18 @@ class TestScore < Score
- end
- end
- - def self.meaningful_changes(scores, current_score = scores.last)
- - return no_meaningful_changes unless current_score.valid_score?
- + def self.meaningful_changes(scores, current_score = scores.last, only_valid = true)
- + return no_meaningful_changes if only_valid && !current_score.valid_score?
- - valid_scores = scores.select(&:valid_score?)
- + valid_scores = only_valid ? scores.select(&:valid_score?) : scores
- current_score_index = valid_scores.index{ |score| score.id == current_score.id }
- return no_meaningful_changes if valid_scores.count < 2 || current_score_index.nil?
- current_score_index += 1
- - first_mc_data(current_score, current_score_index, valid_scores)
- - .merge!(previous_mc_data(current_score, current_score_index, valid_scores))
- + first_mc_data(current_score, current_score_index, valid_scores, only_valid)
- + .merge!(previous_mc_data(current_score, current_score_index, valid_scores, only_valid))
- end
- private
- @@ -610,12 +611,12 @@ class TestScore < Score
- previous_detection_positive: false }
- end
- - def self.first_mc_data(current_score, current_score_index, valid_scores)
- + def self.first_mc_data(current_score, current_score_index, valid_scores, only_valid = true)
- first_score = valid_scores.first
- return no_first_mc if first_score.nil?
- - mc_params = [first_score, current_score, 1, current_score_index]
- + mc_params = [first_score, current_score, 1, current_score_index, only_valid]
- mc_detected = TestScore.meaningful_change_detected?(*mc_params)
- if mc_detected
- { first_detection_date: first_score.created_at,
- @@ -629,12 +630,12 @@ class TestScore < Score
- end
- end
- - def self.previous_mc_data(current_score, current_score_index, valid_scores)
- + def self.previous_mc_data(current_score, current_score_index, valid_scores, only_valid = false)
- previous_score = valid_scores[-2] if valid_scores.count > 2
- return no_previous_mc if previous_score.nil?
- - mc_params = [previous_score, current_score, current_score_index - 1, current_score_index]
- + mc_params = [previous_score, current_score, current_score_index - 1, current_score_index, only_valid]
- mc_detected = TestScore.meaningful_change_detected?(*mc_params)
- if mc_detected
- { previous_detection_date: previous_score.created_at,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement