Skip to content

Commit

Permalink
updated the aid by location tooltip to show active projects instead o…
Browse files Browse the repository at this point in the history
…f showing all.
  • Loading branch information
aunindadf committed Apr 5, 2016
1 parent 3b9543b commit 743fa53
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
55 changes: 38 additions & 17 deletions helpers/project_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,52 @@ def dfid_country_map_data
current_last_day_of_financial_year = last_day_of_financial_year(DateTime.now)

oipaCountryProjectBudgetValuesJSON = RestClient.get settings.oipa_api_url + "activities/aggregations/?format=json&reporting_organisation=GB-GOV-1&budget_period_start=#{current_first_day_of_financial_year}&budget_period_end=#{current_last_day_of_financial_year}&group_by=recipient_country&aggregations=count,budget&order_by=recipient_country"
puts "activities/aggregations/?format=json&reporting_organisation=GB-GOV-1&budget_period_start=#{current_first_day_of_financial_year}&budget_period_end=#{current_last_day_of_financial_year}&group_by=recipient_country&aggregations=count,budget&order_by=recipient_country"
projectBudgetValues = JSON.parse(oipaCountryProjectBudgetValuesJSON)
projectBudgetValues = projectBudgetValues['results']
oipaCountryProjectCountJSON = RestClient.get settings.oipa_api_url + "activities/aggregations/?format=json&hierarchy=1&reporting_organisation=GB-GOV-1&group_by=recipient_country&aggregations=count&reporting_organisation=GB-GOV-1"
oipaCountryProjectCountJSON = RestClient.get settings.oipa_api_url + "activities/aggregations/?format=json&hierarchy=1&reporting_organisation=GB-GOV-1&group_by=recipient_country&aggregations=count&reporting_organisation=GB-GOV-1&activity_status=2"
projectValues = JSON.parse(oipaCountryProjectCountJSON)
projectCountValues = projectValues['results']
countriesList = JSON.parse(File.read('data/countries.json'))

# Map the input data structure so that it matches the required input for Tilestream
projectValuesMapInput = projectBudgetValues.map do |elem|
{
elem["recipient_country"]["code"] => {
"country" => countriesList.find do |source|
source["code"].to_s == elem["recipient_country"]["code"]
end["name"],
"id" => elem["recipient_country"]["code"],
"projects" => projectCountValues.find do |project|
project["recipient_country"]["code"].to_s == elem["recipient_country"]["code"]
end["count"],
"budget" => elem["budget"],
"flag" => '/images/flags/' + elem["recipient_country"]["code"].downcase + '.png'
}
}
projectDataHash = {}
projectCountValues.each do |project|
tempBudget = projectBudgetValues.find do |projectBudget|
projectBudget["recipient_country"]["code"].to_s == project["recipient_country"]["code"]
end
tempCountry = countriesList.find do |source|
source["code"].to_s == project["recipient_country"]["code"]
end
projectDataHash[project["recipient_country"]["code"]] = {}
projectDataHash[project["recipient_country"]["code"]]["country"] = tempCountry["name"]
projectDataHash[project["recipient_country"]["code"]]["id"] = project["recipient_country"]["code"]
projectDataHash[project["recipient_country"]["code"]]["projects"] = project["count"]
projectDataHash[project["recipient_country"]["code"]]["budget"] = tempBudget.nil? ? 0 : tempBudget["budget"]
projectDataHash[project["recipient_country"]["code"]]["flag"] = '/images/flags/' + project["recipient_country"]["code"].downcase + '.png'
puts project["recipient_country"]["name"]
end

# Map the input data structure so that it matches the required input for Tilestream

# projectValuesMapInput = projectBudgetValues.map do |elem|
# {
# elem["recipient_country"]["code"] => {
# "country" => countriesList.find do |source|
# source["code"].to_s == elem["recipient_country"]["code"]
# end["name"],
# "id" => elem["recipient_country"]["code"],
# "projects" => projectCountValues.find do |project|
# project["recipient_country"]["code"].to_s == elem["recipient_country"]["code"]
# end["count"],
# "budget" => elem["budget"],
# "flag" => '/images/flags/' + elem["recipient_country"]["code"].downcase + '.png'
# }
# }
# end
# Edit the returned hash object so that the data is in the correct format (e.g. remove enclosing [])
projectValuesMapInput.to_s.gsub("[", "").gsub("]", "").gsub("=>",":").gsub("}}, {","},")
#puts projectValuesMapInput
#projectValuesMapInput.to_s.gsub("[", "").gsub("]", "").gsub("=>",":").gsub("}}, {","},")
projectDataHash.to_s.gsub("[", "").gsub("]", "").gsub("=>",":").gsub("}}, {","},")
end


Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/leaflet/indexmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
" </div>" +
" <div class='six columns'>" +
" <div class='stat'>" +
" <h3>Number of projects</h3>" +
" <h3>Number of Active Project(s)</h3>" +
" </div>" +
" </div>" +
" </div>" +
Expand Down

0 comments on commit 743fa53

Please sign in to comment.