From f68d04ec7f7eed2f1ee7221343c0f9cbf4858b60 Mon Sep 17 00:00:00 2001 From: devduarte Date: Wed, 25 Sep 2019 17:14:56 -0300 Subject: [PATCH 1/3] Get correct number of missing respondents --- web/models/survey.ex | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/web/models/survey.ex b/web/models/survey.ex index f17cdc9ac..95d0a9151 100644 --- a/web/models/survey.ex +++ b/web/models/survey.ex @@ -420,7 +420,8 @@ defmodule Ask.Survey do pending = respondents_target - completes multiplier = Float.ceil(1/estimated_success_rate, 0) |> round needed = pending*multiplier - missing = max(needed - respondents_total, 0) + selected_respondents = respondents_count(survey.id) + missing = max(needed - selected_respondents, 0) %{ success_rate_data: %{ success_rate: current_success_rate |> Float.round(2), @@ -438,6 +439,21 @@ defmodule Ask.Survey do } end + defp respondents_count(survey_id) do + respondents_by_disposition = %{ + "registered" => 0, + "queued" => 0, + "started" => 0, + "partial" => 0, + "contacted" => 0, + "interim partial" => 0 + } + + Ask.RespondentStats.respondent_count(survey_id: ^survey_id, by: :disposition) + |> Enum.into(respondents_by_disposition) + |> Enum.reduce(0, fn({_k, total}, acc) -> total + acc end) + end + defp respondents_target(:all, respondents_total), do: respondents_total defp respondents_target(completed_respondents_needed, _), do: completed_respondents_needed From dd4908dc972f7f6c4d8eb331bb78432f58d4fc27 Mon Sep 17 00:00:00 2001 From: devduarte Date: Tue, 1 Oct 2019 12:07:00 -0300 Subject: [PATCH 2/3] Updated surveda d3 components to version 1.0.13 and modified calculation of missing respondents --- package.json | 2 +- web/models/survey.ex | 18 ++++-------------- yarn.lock | 6 +++--- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 3a73bad8a..08b0168b6 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "eslint": "eslint --ext .jsx,.js web/static/js/ test/js" }, "dependencies": { - "@instedd/surveda-d3-components": "1.0.12", + "@instedd/surveda-d3-components": "1.0.13", "babel-preset-stage-0": "^6.5.0", "d3": "^3.5.17", "date-fns": "^1.27.2", diff --git a/web/models/survey.ex b/web/models/survey.ex index 95d0a9151..ac39350fd 100644 --- a/web/models/survey.ex +++ b/web/models/survey.ex @@ -420,7 +420,7 @@ defmodule Ask.Survey do pending = respondents_target - completes multiplier = Float.ceil(1/estimated_success_rate, 0) |> round needed = pending*multiplier - selected_respondents = respondents_count(survey.id) + selected_respondents = respondents_count(respondents_by_state) missing = max(needed - selected_respondents, 0) %{ success_rate_data: %{ @@ -439,19 +439,9 @@ defmodule Ask.Survey do } end - defp respondents_count(survey_id) do - respondents_by_disposition = %{ - "registered" => 0, - "queued" => 0, - "started" => 0, - "partial" => 0, - "contacted" => 0, - "interim partial" => 0 - } - - Ask.RespondentStats.respondent_count(survey_id: ^survey_id, by: :disposition) - |> Enum.into(respondents_by_disposition) - |> Enum.reduce(0, fn({_k, total}, acc) -> total + acc end) + defp respondents_count(respondents_by_state) do + filter_key_list = ["active", "pending", "stalled"] + Map.take(respondents_by_state, filter_key_list)|> Enum.reduce(0, fn({_k, total}, acc) -> total + acc end) end defp respondents_target(:all, respondents_total), do: respondents_total diff --git a/yarn.lock b/yarn.lock index 85aadcbf2..f3cfe15c2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,9 +2,9 @@ # yarn lockfile v1 -"@instedd/surveda-d3-components@1.0.11": - version "1.0.11" - resolved "https://registry.yarnpkg.com/@instedd/surveda-d3-components/-/surveda-d3-components-1.0.11.tgz#48d4cdd8122ad4541611292d2ffd6754af041a3a" +"@instedd/surveda-d3-components@1.0.13": + version "1.0.13" + resolved "https://registry.yarnpkg.com/@instedd/surveda-d3-components/-/surveda-d3-components-1.0.13.tgz#5f232408cc1f75e92a591ac47b19cce89016cb7c" dependencies: d3 "^4.0.0" From 74ba119ec8629e6dc67b7af0a275415876a7c998 Mon Sep 17 00:00:00 2001 From: devduarte Date: Tue, 1 Oct 2019 13:31:46 -0300 Subject: [PATCH 3/3] Fix failing tests --- test/controllers/survey_controller_test.exs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/controllers/survey_controller_test.exs b/test/controllers/survey_controller_test.exs index 27f5432d0..2bb2d9f4b 100644 --- a/test/controllers/survey_controller_test.exs +++ b/test/controllers/survey_controller_test.exs @@ -476,7 +476,7 @@ defmodule Ask.SurveyControllerTest do "initial_success_rate" => 1.0, "estimated_success_rate" => 1.0, "completes" => 1, - "missing" => 0, + "missing" => 2, "multiplier" => 1, "needed" => 2, "pending" => 2 @@ -521,7 +521,7 @@ defmodule Ask.SurveyControllerTest do "initial_success_rate" => 1.0, "estimated_success_rate" => 0.75, "completes" => 1, - "missing" => 0, + "missing" => 2, "multiplier" => 2, "needed" => 2, "pending" => 1 @@ -545,7 +545,7 @@ defmodule Ask.SurveyControllerTest do "initial_success_rate" => 1.0, "estimated_success_rate" => 0.85, "completes" => 1, - "missing" => 4, + "missing" => 8, "multiplier" => 2, "needed" => 8, "pending" => 4