Skip to content

Commit

Permalink
Pass stats response without rounding numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
devduarte authored and waj committed Oct 9, 2019
1 parent f8962d9 commit 63fd132
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 10 additions & 5 deletions test/controllers/survey_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,9 @@ defmodule Ask.SurveyControllerTest do
insert(:respondent, survey: survey, state: "started")

conn = get conn, project_survey_survey_path(conn, :stats, project, survey)

assert json_response(conn, 200)["data"] == %{
controller_response = json_response(conn, 200)["data"]
response_rounded = Map.new(controller_response, fn{k, v} -> {k,Float.round(v/1, 2)} end)
assert response_rounded == %{
"success_rate" => 1.0,
"completion_rate" => 0.33,
"initial_success_rate" => 1.0,
Expand All @@ -492,8 +493,9 @@ defmodule Ask.SurveyControllerTest do
insert(:respondent, survey: survey, state: "completed")

conn = get conn, project_survey_survey_path(conn, :stats, project, survey)

assert json_response(conn, 200)["data"] == %{
controller_response = json_response(conn, 200)["data"]
response_rounded = Map.new(controller_response, fn{k, v} -> {k,Float.round(v/1, 2)} end)
assert response_rounded == %{
"success_rate" => 0.67,
"completion_rate" => 1.0,
"initial_success_rate" => 1.0,
Expand Down Expand Up @@ -539,7 +541,10 @@ defmodule Ask.SurveyControllerTest do

conn = get conn, project_survey_survey_path(conn, :stats, project, survey)

assert json_response(conn, 200)["data"] == %{
controller_response = json_response(conn, 200)["data"]
response_rounded = Map.new(controller_response, fn{k, v} -> {k,Float.round(v/1, 2)} end)

assert response_rounded== %{
"success_rate" => 0.25,
"completion_rate" => 0.2,
"initial_success_rate" => 1.0,
Expand Down
10 changes: 5 additions & 5 deletions web/models/survey.ex
Original file line number Diff line number Diff line change
Expand Up @@ -418,16 +418,16 @@ defmodule Ask.Survey do
estimated_success_rate = estimated_success_rate(initial_success_rate, current_success_rate, completion_rate)
completes = respondents_by_state["completed"]
pending = respondents_target - completes
multiplier = Float.ceil(1/estimated_success_rate, 0) |> round
multiplier = Float.ceil(1/estimated_success_rate, 0)
needed = pending*multiplier
selected_respondents = respondents_count(respondents_by_state)
missing = max(needed - selected_respondents, 0)
%{
success_rate_data: %{
success_rate: current_success_rate |> Float.round(2),
completion_rate: completion_rate |> Float.round(2),
initial_success_rate: initial_success_rate |> Float.round(2),
estimated_success_rate: estimated_success_rate |> Float.round(2),
success_rate: current_success_rate,
completion_rate: completion_rate,
initial_success_rate: initial_success_rate,
estimated_success_rate: estimated_success_rate,
},
queue_size_data: %{
completes: completes,
Expand Down

0 comments on commit 63fd132

Please sign in to comment.