diff --git a/test/controllers/survey_controller_test.exs b/test/controllers/survey_controller_test.exs index 67f0f3a00..2f7876aa6 100644 --- a/test/controllers/survey_controller_test.exs +++ b/test/controllers/survey_controller_test.exs @@ -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, @@ -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, @@ -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, diff --git a/web/models/survey.ex b/web/models/survey.ex index ac39350fd..9a2fa1460 100644 --- a/web/models/survey.ex +++ b/web/models/survey.ex @@ -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,