This repository has been archived by the owner on Jul 17, 2020. It is now read-only.
Useful Queries
James Hughes edited this page Jun 11, 2013
·
2 revisions
As you interact with the system there are a few things that you'll want to do - this page acts as a scratch pad for these queries.
If, for example, you have a few hundred IATI Activity sources selected on Production and are tracking down a bug and want to select the same sources you can run this query in the Developer Console in your browser (while navigated to the activity sources page on Production)
$(":checked").parent().next().map(function(){
return "$(\"td:contains('" + $(this).text() + "')\").prev().find(':checkbox').attr('checked', true)"
}).get().join("\n")
This will produce a list of JavaScript statements that you can run when navigated to the activity sources page of your development box. It will select all selected sources from production. You can also deselect all sources first to get an exact copy of production sources,
$(":checked").removeAttr('checked')
let $db := db:open('iati')
let $bd_activities := $db//iati-activity/recipient-country[@code='BD']/..
let $bd_projects := for $id in distinct-values($bd_activities/related-activity[@type='1']/data(@ref))
let $bd_project := $db//iati-activity/iati-identifier[text()=$id]/..
let $project_budget := <budgets>
{
for $component in $db//iati-activity[@hierarchy=2]
where $component/related-activity[@ref = $id]
return <budget>{ sum($component/budget/value) }</budget>
}
</budgets>
return <project>
{ $bd_project/title[1] }
{ $bd_project/description[1] }
{ $project_budget }
</project>
return $bd_projects