Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Jan 19, 2024
1 parent 9e591fa commit fe1b4ea
Showing 1 changed file with 38 additions and 29 deletions.
67 changes: 38 additions & 29 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@
# frozen_string_literal: true

class HomeController < ApplicationController

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def show
# @cases = @current_user.cases.not_archived.includes([ :scores ])
@cases = @current_user.cases_involved_with.not_archived.with_counts

@most_recent_cases = @current_user.cases_involved_with.not_archived.recent.limit(4).with_counts.sort_by(&:case_name)

# Run the prophet!
@prophet_case_data = {}
@most_recent_cases.each do |kase|
data = kase.scores.sampled(kase.id,25).collect{ |score| {ds: score.created_at.to_date.to_fs(:db), y: score.score, datetime: score.created_at.to_date } }.uniq
data = kase.scores.sampled(kase.id, 25).collect do |score|
{ ds: score.created_at.to_date.to_fs(:db), y: score.score, datetime: score.created_at.to_date }
end.uniq
# warning! blunt filter below!
data = data.uniq { |h| h[:ds] }
data = data.map {|h| h.transform_keys(&:to_s) }

do_changepoints = data.length >= 3 ? true : false # need at least 3...

if do_changepoints
df = Rover::DataFrame.new(data)
m = Prophet.new()
m.fit(df)

last_changepoint = DateTime.parse(m.changepoints.last.to_s)
initial = data.find{ |h| h['datetime'].all_day.overlaps?(last_changepoint.all_day)}["y"]
final = kase.scores.last_one.score
change = 100 * (final - initial) / initial

vega_data = data.map{ |d| {x: d['ds'], y: d['y']} }

@prophet_case_data[kase.id] = {
initial: initial,
final: final,
change: change,
last_changepoint: last_changepoint,
vega_data: vega_data
}
end

data = data.map { |h| h.transform_keys(&:to_s) }

do_changepoints = data.length >= 3 # need at least 3...

next unless do_changepoints

df = Rover::DataFrame.new(data)
m = Prophet.new
m.fit(df)

last_changepoint = DateTime.parse(m.changepoints.last.to_s)
initial = data.find { |h| h['datetime'].all_day.overlaps?(last_changepoint.all_day) }['y']
final = kase.scores.last_one.score
change = 100 * (final - initial) / initial

vega_data = data.map { |d| { x: d['ds'], y: d['y'] } }

@prophet_case_data[kase.id] = {
initial: initial,
final: final,
change: change,
last_changepoint: last_changepoint,
vega_data: vega_data,
}
end

@most_recent_books = []
Expand All @@ -59,5 +64,9 @@ def show
@cases
# @grouped_cases = candidate_cases.group_by { |kase| kase.case_name.split(':').first }
# @grouped_cases = @grouped_cases.select { |_key, value| value.count > 1 }
end
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
end

0 comments on commit fe1b4ea

Please sign in to comment.