Skip to content

Commit

Permalink
fixeups
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Jun 17, 2024
1 parent f0b3b30 commit f3db693
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
11 changes: 6 additions & 5 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def case_prophet

sampled_scores = @case.scores.sampled(@case.id, 25)

@for_single_day = sampled_scores.first.updated_at.all_day.overlaps?(sampled_scores.last.updated_at.all_day)
unless sampled_scores.empty?
@for_single_day = sampled_scores.first.updated_at.all_day.overlaps?(sampled_scores.last.updated_at.all_day)
@final = @case.scores.last_one.score
end

data = sampled_scores.collect do |score|
if @for_single_day
Expand All @@ -60,8 +63,6 @@ def case_prophet
data = data.uniq { |h| h[:ds] }
data = data.map { |h| h.transform_keys(&:to_s) }

final = @case.scores.last_one.score

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

Expand All @@ -71,15 +72,15 @@ def case_prophet

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

end

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

@prophet_case_data = {
initial: initial,
final: final,
final: @final,
changepoint: changepoint.nil? ? 0 : changepoint,
last_changepoint: last_changepoint,
vega_data: vega_data,
Expand Down
9 changes: 4 additions & 5 deletions app/views/home/case_prophet.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
<h5 class="card-title"><%= number_with_precision(@case.last_score.score, precision: 2) unless @case.scores.empty? %> <%= @case.scorer.name %></h5>
<p class="card-text">
<% if @case.scores.empty? %>
<small><code>no scores yet</code></small>
<% else %>
<small><code>no scores yet</code></small>
<% else %>
<%= @case.first_score.updated_at.to_date.to_fs(:short) %>
<% if @case.scores.count > 1 and @case.first_score.updated_at.to_date.to_fs(:short) != @case.last_score.updated_at.to_date.to_fs(:short) %>
- <%= @case.last_score.updated_at.to_date.to_fs(:short)%>
Expand All @@ -19,12 +18,12 @@
<p class="card-text text-danger"><%= number_to_percentage(@prophet_case_data[:changepoint] , precision:0) %> decrease since <%=time_ago_in_words(@prophet_case_data[:last_changepoint]) %> ago</p>
<% end %>
<% else %>
<p class="card-text">&nbsp; <%=@prophet_case_data[:changepoint]%></p>
<p class="card-text">&nbsp;</p>
<% end %>
<%
if @for_single_day
# may not work since not sure about utc and time zones
# may not work since not sure about utc and time zones
vega_time = {scale: {type: "time"}, "domain": {"timeUnit": "hours"}}
else
vega_time = {scale: {type: "utc"}, axis: {format: "%b %e"}}
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/v1/bulk/queries_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class QueriesControllerTest < ActionController::TestCase
post :create, params: data
end

assert result.real < 1.0
assert result.real < 2.0
# puts "Elapsed time: #{result.real} seconds\n"

acase.reload
Expand Down

0 comments on commit f3db693

Please sign in to comment.