Skip to content

Commit

Permalink
AB#14174 Made necesary changes for using fcdo.iati.cloud api instead …
Browse files Browse the repository at this point in the history
…of OIPA.
  • Loading branch information
aunindadf committed Sep 20, 2021
1 parent f918e75 commit 5e71b6b
Show file tree
Hide file tree
Showing 21 changed files with 265 additions and 239 deletions.
8 changes: 3 additions & 5 deletions data/mappingSolrFilters/activity_status.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
{
"code":
[
1,
2,
3
2
],
"name":"Active"
},
{
"code":
[
3,
4,
5,
6
5
],
"name":"Closed"
}
Expand Down
2 changes: 1 addition & 1 deletion data/solr-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"field": "activity_status_code",
"url": "search/activity/?facet=on&facet.field=activity_status_code&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:GB-* AND ",
"mappingFile": "data/mappingSolrFilters/activity_status.json",
"defaultValue": "1 OR 2 OR 3",
"defaultValue": "2",
"isFieldTypeString": "0"
},
{
Expand Down
80 changes: 48 additions & 32 deletions devtracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
results = ''
countryYearWiseBudgets = ''
countrySectorGraphData = ''
tempActivityCount = Oj.load(RestClient.get api_simple_log(settings.oipa_api_url + "activities/?format=json&recipient_country="+n+"&reporting_organisation_identifier=#{settings.goverment_department_ids}&page_size=1"))
tempActivityCount = Oj.load(RestClient.get api_simple_log(settings.oipa_api_url + "activities/?format=json&recipient_country="+n+"&reporting_org_identifier=#{settings.goverment_department_ids}&page_size=1"))
if n == 'AF'
tempActivityCount['count'] = 0
end
Expand All @@ -142,7 +142,7 @@
geoJsonData = getCountryBounds(n)
# Get a list of map markers
mapMarkers = getCountryMapMarkers(n)
countryBudgetBarGraphDataSplit2 = budgetBarGraphDataD(settings.oipa_api_url + "budgets/aggregations/?format=json&reporting_organisation_identifier=#{settings.goverment_department_ids}&group_by=recipient_country,reporting_organisation,budget_period_start_quarter&aggregations=value&recipient_country=#{n}&order_by=budget_period_start_year,budget_period_start_quarter", 'i')
countryBudgetBarGraphDataSplit2 = budgetBarGraphDataD('https://devtracker-entry.oipa.nl/api/' + "budgets/aggregations/?format=json&reporting_organisation_identifier=#{settings.goverment_department_ids}&group_by=recipient_country,reporting_organisation,budget_period_start_quarter&aggregations=value&recipient_country=#{n}&order_by=budget_period_start_year,budget_period_start_quarter", 'i') #using OLD OIPA route until the API is fixed
#puts countryBudgetBarGraphDataD
settings.devtracker_page_title = 'Country ' + country[:name] + ' Summary Page'
erb :'countries/country',
Expand All @@ -168,7 +168,7 @@
get '/countries/:country_code/projects/?' do |n|
query = '('+n+')'
filters = prepareFilters(query.to_s, 'C')
response = solrResponse(query, 'AND activity_status_code:(1 OR 2 OR 3)', 'C', 0, '', '')
response = solrResponse(query, 'AND activity_status_code:(2)', 'C', 0, '', '')
if(response['numFound'].to_i > 0)
response = addTotalBudgetWithCurrency(response)
end
Expand Down Expand Up @@ -261,7 +261,7 @@
get '/regions/:region_code/projects/?' do |n|
query = '('+n+')'
filters = prepareFilters(query.to_s, 'R')
response = solrResponse(query, 'AND activity_status_code:(1 OR 2 OR 3)', 'R', 0, '', '')
response = solrResponse(query, 'AND activity_status_code:(2)', 'R', 0, '', '')
if(response['numFound'].to_i > 0)
response = addTotalBudgetWithCurrency(response)
end
Expand Down Expand Up @@ -312,10 +312,11 @@
# get the funding projects Count from the API
fundingProjectsCount = get_funding_project_count(n)
# get the funded projects Count from the API
fundedProjectsCount = get_funded_project_details(n).length
fundedProjectsCount = JSON.parse(RestClient.get api_simple_log(settings.oipa_api_url + "activities/?format=json&transaction_provider_activity=#{getProjectIdentifierList(n)['projectIdentifierList']}&page_size=1&fields=id&ordering=title"))['count']
#Policy markers
begin
getPolicyMarkers = get_policy_markers(n)
puts 'policy markers grabbed'
rescue
getPolicyMarkers = Array.new
end
Expand Down Expand Up @@ -359,7 +360,7 @@
fundingProjectsCount = get_funding_project_count(n)

# get the funded projects Count from the API
fundedProjectsCount = get_funded_project_details(n).length
fundedProjectsCount = JSON.parse(RestClient.get api_simple_log(settings.oipa_api_url + "activities/?format=json&transaction_provider_activity=#{getProjectIdentifierList(n)['projectIdentifierList']}&page_size=1&fields=id&ordering=title"))['count']

settings.devtracker_page_title = 'Project '+project['iati_identifier']+' Documents'
erb :'projects/documents',
Expand Down Expand Up @@ -413,7 +414,7 @@
fundingProjectsCount = get_funding_project_count(n)

# get the funded projects Count from the API
fundedProjectsCount = get_funded_project_details(n).length
fundedProjectsCount = JSON.parse(RestClient.get api_simple_log(settings.oipa_api_url + "activities/?format=json&transaction_provider_activity=#{getProjectIdentifierList(n)['projectIdentifierList']}&page_size=1&fields=id&ordering=title"))['count']

settings.devtracker_page_title = 'Project '+project['iati_identifier']+' Transactions'
erb :'projects/transactions',
Expand Down Expand Up @@ -564,15 +565,30 @@
#####################################################################

get '/search/?' do
query= ''
filters = []
response =
{
'numFound' => -1,
'docs' => []
}
settings.devtracker_page_title = 'Search Page'
#erb :'search/solrSearch',
if (!params['query'])
query= ''
filters = []
response =
{
'numFound' => -1,
'docs' => []
}
settings.devtracker_page_title = 'Search Page'
didYouMeanData = {}
didYouMeanData['dfidCountryBudgets'] = 0
didYouMeanData['dfidRegionBudgets'] = 0
else
query = params['query']
activityStatuses = 'AND activity_status_code:(2)'
filters = prepareFilters(query.to_s, 'F')
response = solrResponse(query, activityStatuses, 'F', 0, '', '')
if(response['numFound'].to_i > 0)
response = addTotalBudgetWithCurrency(response)
end
settings.devtracker_page_title = 'Search Results For : ' + query
didYouMeanQuery = sanitize_input(params['query'],"a")
didYouMeanData = generate_did_you_mean_data(didYouMeanQuery,'2')
end
erb :'search/solrTemplate',
:layout => :'layouts/layout',
:locals =>
Expand All @@ -585,17 +601,20 @@
activityStatus: Oj.load(File.read('data/activity_status.json')),
searchType: 'F',
breadcrumbURL: '',
breadcrumbText: ''
breadcrumbText: '',
fcdoCountryBudgets: didYouMeanData['dfidCountryBudgets'],
fcdoRegionBudgets: didYouMeanData['dfidRegionBudgets'],
isIncludeClosedProjects: 0
}
end

post '/search/?' do
query = params['query']
isIncludeClosedProjects = params['includeClosedProject']
if(isIncludeClosedProjects.to_i != 1)
activityStatuses = 'AND activity_status_code:(1 OR 2 OR 3)'
activityStatuses = 'AND activity_status_code:(2)'
else
activityStatuses = 'AND activity_status_code:(1 OR 2 OR 3 OR 4 OR 5)'
activityStatuses = 'AND activity_status_code:(2 OR 3 OR 4 OR 5)'
end
filters = prepareFilters(query.to_s, 'F')
response = solrResponse(query, activityStatuses, 'F', 0, '', '')
Expand All @@ -604,7 +623,7 @@
end
settings.devtracker_page_title = 'Search Results For : ' + query
didYouMeanQuery = sanitize_input(params['query'],"a")
didYouMeanData = generate_did_you_mean_data(didYouMeanQuery,'1,2,3')
didYouMeanData = generate_did_you_mean_data(didYouMeanQuery,'2')
#erb :'search/solrSearch',
erb :'search/solrTemplate',
:layout => :'layouts/layout',
Expand All @@ -621,7 +640,7 @@
breadcrumbText: '',
fcdoCountryBudgets: didYouMeanData['dfidCountryBudgets'],
fcdoRegionBudgets: didYouMeanData['dfidRegionBudgets'],
isIncludeClosedProjects: isIncludeClosedProjects
isIncludeClosedProjects: isIncludeClosedProjects
}
end

Expand All @@ -632,7 +651,6 @@
else
filters = ''
end
puts(filters)
searchType = params['data']['queryType']
startPage = params['data']['page']
response = solrResponse(query, filters, searchType, startPage, params['data']['dateRange'], params['data']['sortType'])
Expand All @@ -645,7 +663,7 @@
get '/regions/?' do
query = '(298 OR 798 OR 89 OR 589 OR 389 OR 189 OR 679 OR 289 OR 380)'
filters = prepareFilters(query.to_s, 'R')
response = solrResponse(query, 'AND activity_status_code:(1 OR 2 OR 3)', 'R', 0, '', '')
response = solrResponse(query, 'AND activity_status_code:(2)', 'R', 0, '', '')
if(response['numFound'].to_i > 0)
response = addTotalBudgetWithCurrency(response)
end
Expand Down Expand Up @@ -675,7 +693,7 @@
get '/solr-regions/:region_code/?' do |n|
query = '('+n+')'
filters = prepareFilters(query.to_s, 'R')
response = solrResponse(query, 'AND activity_status_code:(1 OR 2 OR 3)', 'R', 0, '', '')
response = solrResponse(query, 'AND activity_status_code:(2)', 'R', 0, '', '')
if(response['numFound'].to_i > 0)
response = addTotalBudgetWithCurrency(response)
end
Expand All @@ -700,7 +718,7 @@
get '/solr-countries/:country_code/?' do |n|
query = '('+n+')'
filters = prepareFilters(query.to_s, 'C')
response = solrResponse(query, 'AND activity_status_code:(1 OR 2 OR 3)', 'C', 0, '', '')
response = solrResponse(query, 'AND activity_status_code:(2)', 'C', 0, '', '')
if(response['numFound'].to_i > 0)
response = addTotalBudgetWithCurrency(response)
end
Expand All @@ -724,7 +742,7 @@
get '/global/?' do
query = '(998)'
filters = prepareFilters(query.to_s, 'R')
response = solrResponse(query, 'AND activity_status_code:(1 OR 2 OR 3)', 'R', 0, '', '')
response = solrResponse(query, 'AND activity_status_code:(2)', 'R', 0, '', '')
if(response['numFound'].to_i > 0)
response = addTotalBudgetWithCurrency(response)
end
Expand Down Expand Up @@ -773,7 +791,7 @@
settings.devtracker_page_title = ogds[dept_id]["name"]
query = deptIdentifier
filters = prepareFilters(query.to_s, 'O')
response = solrResponse(query, 'AND activity_status_code:(1 OR 2 OR 3)', 'O', 0, '', '')
response = solrResponse(query, 'AND activity_status_code:(2)', 'O', 0, '', '')
if(response['numFound'].to_i > 0)
response = addTotalBudgetWithCurrency(response)
end
Expand Down Expand Up @@ -813,9 +831,8 @@
sectorData['sectorName'] = ""
#Segment
query = "(" + sectorCode[0, sectorCode.length - 3] + ")"
puts query
filters = prepareFilters(query.to_s, 'S')
response = solrResponse(query, 'AND activity_status_code:(1 OR 2 OR 3)', 'S', 0, '', '')
response = solrResponse(query, 'AND activity_status_code:(2)', 'S', 0, '', '')
if(response['numFound'].to_i > 0)
response = addTotalBudgetWithCurrency(response)
end
Expand Down Expand Up @@ -859,9 +876,8 @@
sectorData['sectorCode'].concat(sdata['Code (L3)'].to_s + ",")
end
query = "(" + sectorCode[0, sectorCode.length - 3] + ")"
puts query
filters = prepareFilters(query.to_s, 'S')
response = solrResponse(query, 'AND activity_status_code:(1 OR 2 OR 3)', 'S', 0, '', '')
response = solrResponse(query, 'AND activity_status_code:(2)', 'S', 0, '', '')
if(response['numFound'].to_i > 0)
response = addTotalBudgetWithCurrency(response)
end
Expand Down Expand Up @@ -904,7 +920,7 @@
sectorData['sectorName'] = sectorJsonData['Name']
query = "(" + sectorJsonData['Code (L3)'].to_s + ")"
filters = prepareFilters(query.to_s, 'S')
response = solrResponse(query, 'AND activity_status_code:(1 OR 2 OR 3)', 'S', 0, '', '')
response = solrResponse(query, 'AND activity_status_code:(2)', 'S', 0, '', '')
if(response['numFound'].to_i > 0)
response = addTotalBudgetWithCurrency(response)
end
Expand Down
7 changes: 3 additions & 4 deletions helpers/common_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ def generateReportingOrgList(apiLink)
def generateCountryData()
current_first_day_of_financial_year = first_day_of_financial_year(DateTime.now)
current_last_day_of_financial_year = last_day_of_financial_year(DateTime.now)
puts (settings.oipa_api_url + "budgets/aggregations/?reporting_organisation_identifier=#{settings.goverment_department_ids}&order_by=recipient_country&group_by=sector,recipient_country&aggregations=value&format=json&budget_period_start=#{current_first_day_of_financial_year}&budget_period_end=#{current_last_day_of_financial_year}")
sectorBudgets = Oj.load(RestClient.get api_simple_log(settings.oipa_api_url + "budgets/aggregations/?reporting_organisation_identifier=#{settings.goverment_department_ids}&order_by=recipient_country&group_by=sector,recipient_country&aggregations=value&format=json&budget_period_start=#{current_first_day_of_financial_year}&budget_period_end=#{current_last_day_of_financial_year}"))
sectorHierarchies = Oj.load(File.read('data/sectorHierarchies.json'))
sectorBudgets = sectorBudgets["results"]
Expand Down Expand Up @@ -674,13 +673,13 @@ def hash_to_csv(data)

def get_project_component_data(project)
components = Array.new
project['related_activities'].each do |component|
project['related_activity'].each do |component|
if(component['ref'].to_s.include? project['iati_identifier'].to_s)
begin
pullActivityData = get_h1_project_details(component['ref'])
componentData = {}
begin
componentData['title'] = pullActivityData['title']['narratives'][0]['text']
componentData['title'] = pullActivityData['title']['narrative'][0]['text']
rescue
componentData['title'] = 'N/A'
end
Expand All @@ -689,7 +688,7 @@ def get_project_component_data(project)
rescue
componentData['title'] = 'N/A'
end
dates = pullActivityData['activity_dates']
dates = pullActivityData['activity_date']
if (dates.length > 0)
begin
if(!dates.select{|activityDate| activityDate['type']['code'] == '2'}.first.nil?)
Expand Down
Loading

0 comments on commit 5e71b6b

Please sign in to comment.