Skip to content

Commit

Permalink
Merge pull request #1524 from instedd/feature/1488-success-rate
Browse files Browse the repository at this point in the history
Get correct number of missing respondents
  • Loading branch information
waj authored Oct 2, 2019
2 parents 7350826 + 7208b76 commit f8962d9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions test/controllers/survey_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion web/models/survey.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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(respondents_by_state)
missing = max(needed - selected_respondents, 0)
%{
success_rate_data: %{
success_rate: current_success_rate |> Float.round(2),
Expand All @@ -438,6 +439,11 @@ defmodule Ask.Survey do
}
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
defp respondents_target(completed_respondents_needed, _), do: completed_respondents_needed

Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# yarn lockfile v1


"@instedd/[email protected].12":
version "1.0.12"
resolved "https://registry.yarnpkg.com/@instedd/surveda-d3-components/-/surveda-d3-components-1.0.12.tgz#0c684079617a0049acdf785ca39a39e1c39f8a91"
"@instedd/[email protected].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"

Expand Down

0 comments on commit f8962d9

Please sign in to comment.