Skip to content

Commit

Permalink
sector_hierarchies.json - added missing DAC sectors. devtracker.rb - …
Browse files Browse the repository at this point in the history
…minor update to calls. sector_helpers.rb - added new method sector_budgets to return the top five sectors (work in progress). index.html.erb - minor changes to reflect the datacomming from sector_helpers
  • Loading branch information
Ross Clements committed Sep 16, 2015
1 parent c42e566 commit 0dfe945
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 26 deletions.
90 changes: 85 additions & 5 deletions data/sector_hierarchies.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,26 @@
"Category Name":"WATER AND SANITATION",
"Category Description":""
},
{
"Code (L3)":14021,
"High Level Code (L1)":3,
"High Level Sector Description":"Water",
"Name":"Water supply - large systems",
"Description":"Potable water treatment plants; intake works; storage; water supply pumping stations; large scale transmission / conveyance and distribution systems.",
"Category (L2)":140,
"Category Name":"WATER AND SANITATION",
"Category Description":""
},
{
"Code (L3)":14022,
"High Level Code (L1)":3,
"High Level Sector Description":"Water",
"Name":"Sanitation - large systems",
"Description":"Large scale sewerage including trunk sewers and sewage pumping stations; domestic and industrial waste water treatment plants.",
"Category (L2)":140,
"Category Name":"WATER AND SANITATION",
"Category Description":""
},
{
"Code (L3)":14030,
"High Level Code (L1)":3,
Expand All @@ -319,6 +339,26 @@
"Category Name":"WATER AND SANITATION",
"Category Description":""
},
{
"Code (L3)":14031,
"High Level Code (L1)":3,
"High Level Sector Description":"Water",
"Name":"Basic drinking water supply",
"Description":"Rural water supply schemes using handpumps, spring catchments, gravity-fed systems, rainwater collection and fog harvesting, storage tanks, small distribution systems typically with shared connections/points of use. Urban schemes using handpumps and local neighbourhood networks including those with shared connections.",
"Category (L2)":140,
"Category Name":"WATER AND SANITATION",
"Category Description":""
},
{
"Code (L3)":14032,
"High Level Code (L1)":3,
"High Level Sector Description":"Water",
"Name":"Basic sanitation",
"Description":"Latrines, on-site disposal and alternative sanitation systems, including the promotion of household and community investments in the construction of these facilities. (Use code 12261 for activities promoting improved personal hygiene practices.)",
"Category (L2)":140,
"Category Name":"WATER AND SANITATION",
"Category Description":""
},
{
"Code (L3)":14040,
"High Level Code (L1)":3,
Expand Down Expand Up @@ -359,6 +399,36 @@
"Category Name":"Government and civil society, general",
"Category Description":"N.B. Use code 51010 for general budget support."
},
{
"Code (L3)":15111,
"High Level Code (L1)":4,
"High Level Sector Description":"Government and Civil Society",
"Name":"Public finance management",
"Description":"Fiscal policy and planning; support to ministries of finance; strengthening financial and managerial accountability; public expenditure management; improving financial management systems; tax policy and administration; budget drafting; inter-governmental fiscal relations, public audit, public debt. (Use code 33120 for customs.)",
"Category (L2)":151,
"Category Name":"Government and civil society, general",
"Category Description":"N.B. Use code 51010 for general budget support."
},
{
"Code (L3)":15112,
"High Level Code (L1)":4,
"High Level Sector Description":"Government and Civil Society",
"Name":"Decentralisation and support to subnational government",
"Description":"Decentralisation processes (including political, administrative and fiscal dimensions); intergovernmental relations and federalism; strengthening departments of regional and local government, regional and local authorities and their national associations. (Use specific sector codes for decentralisation of sector management and services.)",
"Category (L2)":151,
"Category Name":"Government and civil society, general",
"Category Description":"N.B. Use code 51010 for general budget support."
},
{
"Code (L3)":15113,
"High Level Code (L1)":4,
"High Level Sector Description":"Government and Civil Society",
"Name":"Anti-corruption organisations and institutions",
"Description":"Specialised organisations, institutions and frameworks for the prevention of and combat against corruption, bribery, money-laundering and other aspects of organised crime, with or without law enforcement powers, e.g. anti-corruption commissions and monitoring bodies, special investigation services, institutions and initiatives of integrity and ethics oversight, specialised NGOs, other civil society and citizens’ organisations directly concerned with corruption.",
"Category (L2)":151,
"Category Name":"Government and civil society, general",
"Category Description":"N.B. Use code 51010 for general budget support."
},
{
"Code (L3)":15120,
"High Level Code (L1)":4,
Expand Down Expand Up @@ -400,7 +470,7 @@
"Category Description":"N.B. Use code 51010 for general budget support."
},
{
"Code (L3)":15161,
"Code (L3)":15151,
"High Level Code (L1)":4,
"High Level Sector Description":"Government and Civil Society",
"Name":"Elections",
Expand All @@ -410,7 +480,7 @@
"Category Description":"N.B. Use code 51010 for general budget support."
},
{
"Code (L3)":15162,
"Code (L3)":15152,
"High Level Code (L1)":4,
"High Level Sector Description":"Government and Civil Society",
"Name":"Human rights",
Expand All @@ -420,7 +490,7 @@
"Category Description":"N.B. Use code 51010 for general budget support."
},
{
"Code (L3)":15163,
"Code (L3)":15153,
"High Level Code (L1)":4,
"High Level Sector Description":"Government and Civil Society",
"Name":"Free flow of information",
Expand All @@ -430,11 +500,21 @@
"Category Description":"N.B. Use code 51010 for general budget support."
},
{
"Code (L3)":15164,
"Code (L3)":15160,
"High Level Code (L1)":4,
"High Level Sector Description":"Government and Civil Society",
"Name":"Human rights",
"Description":"Measures to support specialised official human rights institutions and mechanisms at universal, regional, national and local levels in their statutory roles to promote and protect civil and political, economic, social and cultural rights as defined in international conventions and covenants; translation of international human rights commitments into national legislation; reporting and follow-up; human rights dialogue. Human rights defenders and human rights NGOs; human rights advocacy, activism, mobilisation; awareness raising and public human rights education. Human rights programming targeting specific groups, e.g. children, persons with disabilities, migrants, ethnic, religious, linguistic and sexual minorities, indigenous people and those suffering from caste discrimination, victims of trafficking, victims of torture. (Use code 15230 when in the context of an international peacekeeping operation)",
"Category (L2)":151,
"Category Name":"Government and civil society, general",
"Category Description":"N.B. Use code 51010 for general budget support."
},
{
"Code (L3)":15170,
"High Level Code (L1)":4,
"High Level Sector Description":"Government and Civil Society",
"Name":"Women's equality organisations and institutions",
"Description":"Support for institutions and organisations (governmental and non-governmental) working for gender equality and women's empowerment.",
"Description": "Support for institutions and organisations (governmental and non-governmental) working for gender equality and women's empowerment.",
"Category (L2)":151,
"Category Name":"Government and civil society, general",
"Category Description":"N.B. Use code 51010 for general budget support."
Expand Down
4 changes: 2 additions & 2 deletions devtracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
include ProjectHelpers

# Developer Machine: set global settings
#set :oipa_api_url, 'http://dfid-oipa.zz-clients.net/api/'
set :oipa_api_url, 'http://dfid-oipa.zz-clients.net/api/'

# Server Machine: set global settings
set :oipa_api_url, 'http://127.0.0.1:6081/api/'
#set :oipa_api_url, 'http://127.0.0.1:6081/api/'

#ensures that we can use the extension html.erb rather than just .erb
Tilt.register Tilt::ERBTemplate, 'html.erb'
Expand Down
65 changes: 53 additions & 12 deletions helpers/sector_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,75 @@ def high_level_sectors_structure_legacy
=end
end

def group_hashes arr, group_fields
arr(0).group_by {|hash| hash.values_at(*group_fields).join ":" }.values.map do |grouped|
grouped.inject do |merged, n|
merged.merge(n) do |key, v1, v2|
group_fields.include?(key) ? v1 : (v1.to_f + v2.to_f).to_s
end
end
end
end


def sector_budgets

# TODO - Need to change the hard coded Budget period to variable
oipaSectorValuesJSON = RestClient.get "http://dfid-oipa.zz-clients.net/api/activities/aggregations?reporting_organisation=GB-1&group_by=sector&aggregations=budget&budget_period_start=2015-04-01&budget_period_end=2016-03-31&order_by=-budget&format=json"
sectorValuesJSON=JSON.parse(oipaSectorValuesJSON)

highLevelSector = JSON.parse(File.read('data/sector_hierarchies.json'))

=begin
# Create an hash of DAC5 sector budgets from the API call input (i.e. flatten the data so that the budget is at the same level as the code and name attributes)
dac5SectorBudget = sectorValuesJSON.map do |elem|
{
"Code (L3)" => elem["sector"]["code"],
:budget => elem["budget"]
}
end
=end


# Test code to show that value of contained in the high level sectors has been aggregated correctly

sectorBudgets = []

# Create an array of sector budgets from the API call input (i.e. flatten the data so that the budget is at the same level as the code and name attributes)
sectorValuesJSON.each do |elem|
getHighLevelSector = highLevelSector.select {|h| h["Code (L3)"].to_s == elem["sector"]["code"]}.first
p = [ elem["sector"]["code"], elem["budget"]]
sectorBudgets << p
end

highLevelSectorBudgets = []

#!getHighLevelSector.nil?
sectorBudgets.each do |elem|
getHighLevelSector = highLevelSector.select {|h| h["Code (L3)"].to_s == elem[0]}.first
if !getHighLevelSector.nil? then
p = [getHighLevelSector["High Level Code (L1)"],getHighLevelSector["High Level Sector Description"],getHighLevelSector["Category (L2)"],getHighLevelSector["Category Name"],getHighLevelSector["Code (L3)"],getHighLevelSector["Name"],elem["budget"]]
sectorBudgets << p
p = ["High Level Code", getHighLevelSector["High Level Code (L1)"], "High Level Sector" ,getHighLevelSector["High Level Sector Description"], "Budget", elem[1]]
highLevelSectorBudgets << p
end
end
end

highLevelSectorBudgets

=begin Create a hash table from the multi dimensional array to pass into the group by function
highLevelSectorBudgetsHash = Hash.new
highLevelSectorBudgets.each_index do { |e|
# year = e[0]
# month = e[1]
entry = e[0]
#sectorBudgets
# Add to years array
# years[year] ||= Hash.new
# years[year][month] ||= Array.new
highLevelSectorBudgetsHash["test"] << entry
} end
sectorBudgets = sectorBudgets.group_by{|b| b[1]}.map{|h1Name, budgets|
summedBudgets = budgets.reduce(0) {|memo, budget| memo + budget[6]}
[h1Name, summedBudgets]
}.sort
highLevelSectorBudgetsHash
=end

sectorBudgets.sort{|sectorBudgets,b| b[1] <=> sectorBudgets[1]}.first(5)
# group_hashes highLevelSectorBudgetsHash, ["order", "idx", "account"]

end

Expand Down
19 changes: 12 additions & 7 deletions views/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ layout: landing
<div class="four columns" id="top-5-sectors">
<%#= what_we_do %>
<%if !what_we_do.nil? %>
<div class="top-five-header">
<%= what_we_do.length %>
<br/><br/>
<%= what_we_do %>

<div class="top-five-header">
<span class="top-five-title">Top 5 things we do</span>
<a class="more-info-link float-right move-up-4" id="moreinfolink2" target="2"><img src="/images/icon-information.png" alt="More Information about the top 5 things we do"/></a>
<aside id="moreinfo2" class="more-info">
Expand All @@ -104,12 +109,12 @@ layout: landing
</aside>
</div>
<ol>
<% what_we_do.each do |sector| %>
<li>
<a href="/sector/<%=sector[0]%>"><%=sector[0]%></a>
<em><span class="visually-hidden">Budget</span><%= format_million_stg sector[1] %></em>
<!-- <em>&pound;<%#=format_round_m sector[:budget] || 0.0 %></em> -->
</li>
<%# <% what_we_do.each do |sector| %>
<%# <li>
<%# <a href="/sector/<%=sector[0]%> <%# "><%=sector[0]%></a>
<%# <em><span class="visually-hidden">Budget</span><%= format_million_stg sector[1] %></em>
<%# <em>&pound;<%#=format_round_m sector[:budget] || 0.0 %></em>
<%# </li>
<% end %>
</ol>
<%end%>
Expand Down

0 comments on commit 0dfe945

Please sign in to comment.