Skip to content

Commit e24d8fd

Browse files
committed
Pushed new changes.
1 parent 9dd0343 commit e24d8fd

7 files changed

Lines changed: 105 additions & 59 deletions

File tree

data/odas.json

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
[
44
{
55
"name":"Foreign, Commonwealth and Development Office",
6-
"year":"2023",
7-
"value": 9491,
6+
"year":"2024",
7+
"value": 9465,
88
"percentage": 61.90,
99
"shortName": "FCDO",
1010
"note": "This figure is calculated by summing the those for the recently combined Department for International Development (DFID) and Foreign and Commonwealth Office (FCO) to reflect the new department. The source data describes these institutions separately."
@@ -14,8 +14,8 @@
1414
[
1515
{
1616
"name":"Home Office",
17-
"year":"2023",
18-
"value": 2954,
17+
"year":"2024",
18+
"value": 2384,
1919
"percentage": 19.30,
2020
"shortName": "Home Office",
2121
"note": ""
@@ -25,30 +25,19 @@
2525
[
2626
{
2727
"name":"Department of Health and Social Care",
28-
"year":"2023",
29-
"value": 535,
28+
"year":"2024",
29+
"value": 433,
3030
"percentage": 3.50,
3131
"shortName": "DoH",
3232
"note": ""
3333
}
3434
],
35-
"MHCLG":
36-
[
37-
{
38-
"name":"Ministry of Housing, Communities and Local Government",
39-
"year":"2023",
40-
"value": 466,
41-
"percentage": 3.00,
42-
"shortName": "MHCLG",
43-
"note": ""
44-
}
45-
],
4635
"DESNZ":
4736
[
4837
{
4938
"name":"Department for Energy Security and Net Zero",
50-
"year":"2023",
51-
"value": 440,
39+
"year":"2024",
40+
"value": 408,
5241
"percentage": 2.90,
5342
"shortName": "DESNZ",
5443
"note": ""
@@ -58,54 +47,65 @@
5847
[
5948
{
6049
"name":"UK Integrated Security Fund",
61-
"year":"2023",
62-
"value": 326,
50+
"year":"2024",
51+
"value": 369,
6352
"percentage": 2.10,
6453
"shortName": "CSSF",
6554
"note": ""
6655
}
6756
],
68-
"DWP":
57+
"DSIT":
6958
[
7059
{
71-
"name":"Department for Work and Pensions",
72-
"year":"2023",
73-
"value": 257,
74-
"percentage": 1.70,
75-
"shortName": "DWP",
60+
"name":"Department for Science, Innovation and Technology",
61+
"year":"2024",
62+
"value": 215,
63+
"percentage": 1.10,
64+
"shortName": "DSIT",
7665
"note": ""
7766
}
7867
],
79-
"DFE":
68+
"DEFRA":
8069
[
8170
{
82-
"name":"Department for Education",
83-
"year":"2023",
84-
"value": 169,
71+
"name":"Department for Environment Food and Rural Affairs",
72+
"year":"2024",
73+
"value": 186,
8574
"percentage": 1.10,
86-
"shortName": "DoE",
75+
"shortName": "DEFRA",
8776
"note": ""
8877
}
8978
],
90-
"DSIT":
79+
"MHCLG":
9180
[
9281
{
93-
"name":"Department for Science, Innovation and Technology",
94-
"year":"2023",
95-
"value": 167,
96-
"percentage": 1.10,
97-
"shortName": "DSIT",
82+
"name":"Ministry of Housing, Communities and Local Government",
83+
"year":"2024",
84+
"value": 98,
85+
"percentage": 3.00,
86+
"shortName": "MHCLG",
9887
"note": ""
9988
}
10089
],
101-
"DEFRA":
90+
"DWP":
10291
[
10392
{
104-
"name":"Department for Environment Food and Rural Affairs",
105-
"year":"2023",
106-
"value": 165,
93+
"name":"Department for Work and Pensions",
94+
"year":"2024",
95+
"value": 93,
96+
"percentage": 1.70,
97+
"shortName": "DWP",
98+
"note": ""
99+
}
100+
],
101+
"DFE":
102+
[
103+
{
104+
"name":"Department for Education",
105+
"year":"2024",
106+
"value": 91,
107107
"percentage": 1.10,
108-
"shortName": "DEFRA",
108+
"shortName": "DoE",
109109
"note": ""
110110
}
111111
],

helpers/common_helpers.rb

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,9 +1390,30 @@ def hasSpecialCharacter(input_string)
13901390
end
13911391

13921392
def generateCountryDatav7()
1393+
###
1394+
filename = "data/cache/dumped-data.csv"
1395+
new_file = !File.exist?(filename)
1396+
FileUtils.touch(filename) if new_file
1397+
puts new_file ? "Created new file: #{filename}" : "File already exists: #{filename}"
1398+
File.open(filename, 'a') do |file|
1399+
# Write headers if it's a new file
1400+
if new_file
1401+
headers = "countryCode,percentileBudget,totalBudget,iati_identifier\n"
1402+
file.write(headers)
1403+
end
1404+
1405+
# 3.times do
1406+
# # Generate a random line (you can customize this)
1407+
# random_line = "#{rand(1..100)},#{rand(1..50)},#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}\n"
1408+
# file.write(random_line)
1409+
# end
1410+
end
1411+
####
1412+
totalB = 0
1413+
totalB_s = 0
13931414
count = 20
13941415
activityTracker = Set.new
1395-
newApiCall = settings.oipa_api_url + "activity?q=budget_period_start_iso_date:[#{settings.current_first_day_of_financial_year}T00:00:00Z TO *] AND budget_period_end_iso_date:[* TO #{settings.current_last_day_of_financial_year}T00:00:00Z] AND budget_value_gbp:* AND participating_org_ref:(GB-GOV-* OR GB-COH-*) AND reporting_org_ref:(#{settings.goverment_department_ids.gsub(","," OR ")}) AND recipient_country_code:*&fl=reporting_org_ref,recipient_country_percentage,activity_status_code,iati_identifier,budget.period-start.quarter,budget.period-end.quarter,recipient_country_code,budget_period_start_iso_date,budget_period_end_iso_date,budget_value_gbp,recipient_country_name,hierarchy,related_activity_type,related_activity_ref&start=0&rows=#{count}"
1416+
newApiCall = settings.oipa_api_url + "activity?q=budget_period_start_iso_date:[#{settings.current_first_day_of_financial_year}T00:00:00Z TO *] AND budget_period_end_iso_date:[* TO #{settings.current_last_day_of_financial_year}T00:00:00Z] AND budget_value_gbp:* AND participating_org_ref:(GB-GOV-* OR GB-COH-*) AND reporting_org_ref:(#{settings.goverment_department_ids.gsub(","," OR ")}) AND recipient_country_code:*&fl=recipient_region_percentage,reporting_org_ref,recipient_country_percentage,activity_status_code,iati_identifier,budget.period-start.quarter,budget.period-end.quarter,recipient_country_code,budget_period_start_iso_date,budget_period_end_iso_date,budget_value_gbp,recipient_country_name,hierarchy,related_activity_type,related_activity_ref&start=0&rows=#{count}"
13961417
##pagination stuff
13971418
page = 1
13981419
page = page.to_i - 1
@@ -1408,7 +1429,7 @@ def generateCountryDatav7()
14081429
for p in 2..pages do
14091430
p = p - 1
14101431
finalPage = p * count
1411-
tempData = JSON.parse(RestClient.get settings.oipa_api_url + "activity?q=budget_period_start_iso_date:[#{settings.current_first_day_of_financial_year}T00:00:00Z TO *] AND budget_period_end_iso_date:[* TO #{settings.current_last_day_of_financial_year}T00:00:00Z] AND budget_value_gbp:* AND participating_org_ref:(GB-GOV-* OR GB-COH-*) AND reporting_org_ref:(#{settings.goverment_department_ids.gsub(","," OR ")}) AND recipient_country_code:*&fl=reporting_org_ref,recipient_country_percentage,activity_status_code,iati_identifier,budget.period-start.quarter,budget.period-end.quarter,recipient_country_code,budget_period_start_iso_date,budget_period_end_iso_date,budget_value_gbp,recipient_country_name,hierarchy,related_activity_type,related_activity_ref&start=#{finalPage}&rows=#{count}")
1432+
tempData = JSON.parse(RestClient.get settings.oipa_api_url + "activity?q=budget_period_start_iso_date:[#{settings.current_first_day_of_financial_year}T00:00:00Z TO *] AND budget_period_end_iso_date:[* TO #{settings.current_last_day_of_financial_year}T00:00:00Z] AND budget_value_gbp:* AND participating_org_ref:(GB-GOV-* OR GB-COH-*) AND reporting_org_ref:(#{settings.goverment_department_ids.gsub(","," OR ")}) AND recipient_country_code:*&fl=recipient_region_percentage,reporting_org_ref,recipient_country_percentage,activity_status_code,iati_identifier,budget.period-start.quarter,budget.period-end.quarter,recipient_country_code,budget_period_start_iso_date,budget_period_end_iso_date,budget_value_gbp,recipient_country_name,hierarchy,related_activity_type,related_activity_ref&start=#{finalPage}&rows=#{count}")
14121433
tempData = tempData['response']['docs']
14131434
tempData.each do |item|
14141435
pulledData.push(item)
@@ -1426,8 +1447,19 @@ def generateCountryDatav7()
14261447
element['budget_value_gbp'].each_with_index do |data, index|
14271448
if(element['budget_period_start_iso_date'][index].to_datetime >= settings.current_first_day_of_financial_year && element['budget_period_end_iso_date'][index].to_datetime <= settings.current_last_day_of_financial_year)
14281449
tempTotalBudget = tempTotalBudget + data.to_f
1450+
#totalB_s = totalB_s + data.to_f
14291451
end
14301452
end
1453+
# if element.has_key?('recipient_region_percentage')
1454+
# puts element['recipient_region_percentage']
1455+
# region_percentage = 0
1456+
# element['recipient_region_percentage'].each do |p|
1457+
# region_percentage = region_percentage + p
1458+
# end
1459+
# tCountryPercentage = 100 - region_percentage
1460+
# tempTotalBudget = tempTotalBudget*(tCountryPercentage/100)
1461+
# totalB_s = totalB_s + tempTotalBudget
1462+
# end
14311463
## Process project budget and count now
14321464
# Get the parent identifier for this activity
14331465
# if element["hierarchy"].to_i != 1
@@ -1448,6 +1480,11 @@ def generateCountryDatav7()
14481480
countryPercentage = 100
14491481
end
14501482
countryBudget = tempTotalBudget*countryPercentage/100
1483+
totalB = totalB + countryBudget
1484+
File.open(filename, 'a') do |file|
1485+
row = "#{c},#{countryBudget},#{tempTotalBudget},#{element['iati_identifier']}\n"
1486+
file.write(row)
1487+
end
14511488
#budgetTracker = budgetTracker - countryBudget
14521489
if(projectDataHash.has_key?(c))
14531490
# if(isNewProgramme)
@@ -1468,10 +1505,6 @@ def generateCountryDatav7()
14681505
pd = RestClient.get call
14691506
pd = JSON.parse(pd)
14701507
numOProgs = pd['response']['numFound'].to_i
1471-
if c == 'BD'
1472-
puts call
1473-
puts numOProgs
1474-
end
14751508
projectDataHash[c]["projects"] = numOProgs
14761509
projectDataHash[c]["budget"] = countryBudget.round(2)
14771510
projectDataHash[c]["flag"] = '/images/flags/' + c.downcase + '.png'
@@ -1482,6 +1515,8 @@ def generateCountryDatav7()
14821515
finalOutput.push(projectDataHash.to_s.gsub("[", "").gsub("]", "").gsub("=>",":").gsub("}}, {","},"))
14831516
finalOutput.push(projectDataHash)
14841517
output = {}
1518+
puts 'Total budget: ' + totalB.to_s
1519+
puts 'Total budget no country filter: ' + totalB_s.to_s
14851520
output['map_data'] = finalOutput
14861521
output
14871522
end

helpers/country_helpers.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,16 +664,23 @@ def get_country_all_projects_rss(countryCode)
664664
end
665665

666666
def total_country_budget_locationv2
667-
newApiCall = settings.oipa_api_url + "activity?q=participating_org_ref:GB-GOV-* AND reporting_org_ref:(#{settings.goverment_department_ids.gsub(","," OR ")}) AND budget_period_start_iso_date:[#{settings.current_first_day_of_financial_year}T00:00:00Z TO *] AND budget_period_end_iso_date:[* TO #{settings.current_last_day_of_financial_year}T00:00:00Z] AND recipient_country_code:* AND budget_value_gbp:* AND participating_org_ref:(GB-GOV-* OR GB-COH-*)&fl=recipient_country_code,budget_period_start_iso_date,budget_period_end_iso_date,budget_value_gbp,recipient_country_name&rows=50000"
667+
newApiCall = settings.oipa_api_url + "activity?q=participating_org_ref:GB-GOV-* AND reporting_org_ref:(#{settings.goverment_department_ids.gsub(","," OR ")}) AND budget_period_start_iso_date:[#{settings.current_first_day_of_financial_year}T00:00:00Z TO *] AND budget_period_end_iso_date:[* TO #{settings.current_last_day_of_financial_year}T00:00:00Z] AND recipient_country_code:* AND budget_value_gbp:* AND participating_org_ref:(GB-GOV-* OR GB-COH-*)&fl=recipient_country_code,budget_period_start_iso_date,budget_period_end_iso_date,budget_value_gbp,recipient_country_name,recipient_region_percentage&rows=50000"
668668
pulledData = RestClient.get newApiCall
669669
pulledData = JSON.parse(pulledData)['response']['docs']
670670
totalBudget = 0
671671
pulledData.each do |element|
672+
totalRegionPercentage = 0
673+
if element.has_key?('recipient_region_percentage')
674+
element['recipient_region_percentage'].each do |p|
675+
totalRegionPercentage = totalRegionPercentage + p
676+
end
677+
end
678+
totalCountryPercentage = 100 - totalRegionPercentage
672679
if (element.has_key?('recipient_country_code'))
673680
tempTotalBudget = 0
674681
element['budget_period_start_iso_date'].each_with_index do |data, index|
675682
if(data.to_datetime >= settings.current_first_day_of_financial_year && element['budget_period_end_iso_date'][index].to_datetime <= settings.current_last_day_of_financial_year)
676-
tempTotalBudget = tempTotalBudget + element['budget_value_gbp'][index].to_f
683+
tempTotalBudget = tempTotalBudget + (element['budget_value_gbp'][index].to_f*(totalCountryPercentage/100))
677684
end
678685
end
679686
totalBudget = totalBudget + tempTotalBudget

helpers/region_helpers.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def dfid_regional_projects_datav2(regionType)
168168
newApiCall = settings.oipa_api_url + "activity?q=budget_value_gbp:* AND participating_org_ref:(GB-GOV-* OR GB-COH-*) AND reporting_org_ref:(#{settings.goverment_department_ids.gsub(","," OR ")}) AND budget_period_start_iso_date:[#{settings.current_first_day_of_financial_year}T00:00:00Z TO *] AND budget_period_end_iso_date:[* TO #{settings.current_last_day_of_financial_year}T00:00:00Z] AND recipient_region_code:* AND -recipient_region_code:998&fl=recipient_region_code,budget_period_start_iso_date,budget_period_end_iso_date,budget_value_gbp,recipient_region_name,sector_code,sector_percentage,hierarchy,related_activity_type,related_activity_ref&rows=50000"
169169
else
170170
newApiCall = settings.oipa_api_url + "activity?q=budget_value_gbp:* AND participating_org_ref:(GB-GOV-* OR GB-COH-*) AND reporting_org_ref:(#{settings.goverment_department_ids.gsub(","," OR ")}) AND budget_period_start_iso_date:[#{settings.current_first_day_of_financial_year}T00:00:00Z TO *] AND budget_period_end_iso_date:[* TO #{settings.current_last_day_of_financial_year}T00:00:00Z] AND recipient_region_code:(998)&fl=recipient_region_code,budget_period_start_iso_date,budget_period_end_iso_date,budget_value_gbp,recipient_region_name,sector_code,sector_percentage,hierarchy,related_activity_type,related_activity_ref&rows=50000"
171+
puts newApiCall
171172
end
172173
pulledData = RestClient.get newApiCall
173174
pulledData = JSON.parse(pulledData)['response']['docs']
@@ -192,7 +193,10 @@ def dfid_regional_projects_datav2(regionType)
192193
end
193194
end
194195
end
195-
196+
if regionType == 'global'
197+
globaldata = allRegionsChartData.filter{|item| item['code'].to_s == '998'}
198+
allRegionsChartData = globaldata
199+
end
196200
# Find the total budget for all of the Regions
197201
totalBudget = Float(allRegionsChartData.map { |s| s["budget"].to_f }.inject(:+))
198202

views/index.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ layout: cw_landing
116116
</div>
117117
</div>-->
118118

119-
<h2 class="govuk-heading-l">UK Government priorities</h2>
119+
<%# <h2 class="govuk-heading-l">UK Government priorities</h2> %>
120120
<div class="govuk-grid-row">
121121
<div class="govuk-grid-column-one-half">
122122
<div class="app-card">
123-
<h4 class="govuk-heading-m">Top 10 things we do</h4>
123+
<h4 class="govuk-heading-m">What we do</h4>
124124
<p class="govuk-body-s app-card__intro app-card__intro--fixed-height">
125125
The sectors that Programmes have allocated their budget to, consistent with the Development Assistance Committee's classifications.
126126
</p>
@@ -143,7 +143,7 @@ layout: cw_landing
143143
</div>
144144
<div class="govuk-grid-column-one-half">
145145
<div class="app-card">
146-
<h4 class="govuk-heading-m">Top 10 places we work</h4>
146+
<h4 class="govuk-heading-m">Where we work</h4>
147147
<p class="govuk-body-s app-card__intro app-card__intro--fixed-height">The countries where most money has been identified as being spent.</p>
148148
<%if !top_5_countries.nil? %>
149149
<div class="app-progress-bar">
@@ -165,7 +165,7 @@ layout: cw_landing
165165
<div class="govuk-grid-column-full">
166166
<div class="app-card app-top10-departments">
167167
<h4 class="govuk-heading-m">Top 10 departments</h4>
168-
<p class="govuk-body-s app-card__intro">UK ODA spend by government department (<a style="font-size: 12px" target="_BLANK" href="https://www.gov.uk/government/collections/statistics-on-international-development#-statistics-on-international-development:-aid-spend-2023">Source, Statistics on International Development 2023</a>) </p>
168+
<p class="govuk-body-s app-card__intro">UK ODA spend by government department (<a style="font-size: 12px" target="_BLANK" href="https://www.gov.uk/government/collections/statistics-on-international-development#statistics-on-international-development:-uk-oda-spend-2024">Source, Statistics on International Development 2024</a>) </p>
169169
<% odas.each do |oda| %>
170170
<div class="app-top10-department">
171171
<%if oda[0]=='PF' || oda[0]=='CSSF' || oda[0]=='MHCLG' || oda[0]=='HMRC' %>

views/new_layout/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
</div>
5757
</div>
5858
</div>
59-
<h2 class="govuk-heading-l">UK Government priorities</h2>
59+
<%# <h2 class="govuk-heading-l">UK Government priorities</h2> %>
6060
<div class="govuk-grid-row">
6161
<div class="govuk-grid-column-one-half">
6262
<div class="app-card">

views/partials/_location-tabs.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
</div>
1919
<nav class="moj-sub-navigation" aria-label="Sub navigation">
2020
<ul class="moj-sub-navigation__list">
21-
<li class="moj-sub-navigation__item"><a href="/location/country" class="moj-sub-navigation__link" <%= active=="country" ? "aria-current='page'" : ""%>>Current <span>Programmes</span></a></li>
21+
<li class="moj-sub-navigation__item"><a href="/location/country" class="moj-sub-navigation__link" <%= active=="country" ? "aria-current='page'" : ""%>>Country <span>Programmes</span></a></li>
2222
<li class="moj-sub-navigation__item"><a href="/location/regional" class="moj-sub-navigation__link" <%= active=="regional" ? "aria-current='page'" : ""%>>Regional <span>Programmes</span></a></li>
2323
<li class="moj-sub-navigation__item"><a href="/location/global" class="moj-sub-navigation__link" <%= active=="global" ? "aria-current='page'" : ""%>>Global <span>Programmes</span></a></li>
2424
</ul>
2525
</nav>
2626

2727
<h1 class="govuk-heading-l">
2828
<% if active=="country" %>
29-
Current
29+
Country
3030
<% end %>
3131
<% if active=="regional" %>
3232
Regional

0 commit comments

Comments
 (0)