<commit_before><?php

/*
 * This script combines various adaptation funding databases into one JSON file
 * see https://docs.google.com/document/d/1s0HVBtVG9ZVVFOhwS-n3PMdgzlwNTiMUyvrNYjGv8Mc/edit for more info
 * 
 * @todo, update sources
 * @todo, put amounts in same format (float vs int) + check whether they are adjusted for inflation etc
 * 
 * @author <NAME> <<EMAIL>>
 */

ini_set('memory_limit', '2G');
date_default_timezone_set('Europe/Amsterdam');
$datadir = "data";

$jsons = array();
load_databases();
print json_encode($jsons, JSON_PRETTY_PRINT);

function load_databases() {
    load_undp();
    load_ci_grasp();
    load_psi();
    load_climate_wise();
    load_oecd_riomarkers();
    load_climatefundsupdate();
    load_napa();
}

/*
 * UNDP adaptation learning mechanism (http://www.undp-alm.org/) 
 * 
 * methodology https://drive.google.com/?usp=folder&authuser=0#folders/0B3e-HpGNh9BwcVpPUHlJNkpnVWs
 * data file https://docs.google.com/file/d/0B3e-HpGNh9BwRnYzQVJpTE5HMjQ/edit
 * 
 * @todo: old source
 * 
 */

function load_undp() {
    global $jsons, $datadir;

    $inputfile = "undp.json";
    $file = file_get_contents($datadir . "/" . $inputfile);

    $data = json_decode($file);
    foreach ($data as $d) {
        $obj = new StdClass();
        $obj->source = "undp";
        $obj->year = "n/a";
        $obj->donor = "n/a";
        if (isset($d->data->partners)) {
            if (is_array($d->data->partners))
                $obj->donor = implode(",", $d->data->partners);
            else
                $obj->donor = $d->data->partners;
        }
        $obj->recipient = $d->location;
        $obj->purpose = "n/a";
        if (isset($d->data->{'climate-hazards'})) {
            if (is_array($d->data->{'climate-hazards'}))
                $obj->purpose = implode(",", $d->data->{'climate-hazards'});
            else
                $obj->purpose = $d->data->{'climate-hazards'};
        }
        $obj->amount = "n/a";
        if (isset($d->data->normalized_costs))
            $obj->amount = $d->data->normalized_costs;
        $obj->sector = $d->theme;
        $obj->projecttitle = $d->title;
        $jsons[] = $obj;
    }
}

/*
 * Ci-Grasp (http://www.pik-potsdam.de/~wrobel/ci_2/)
 * 
 * methodology https://drive.google.com/?usp=folder&authuser=0#folders/0B3e-HpGNh9BwcVpPUHlJNkpnVWs
 * json https://docs.google.com/file/d/0B3e-HpGNh9BwZzF0V2VnWmNrazA/edit
 * 
 * @todo: old source
 */

function load_ci_grasp() {
    global $jsons, $datadir;

    $inputfile = "cigrasp.json";
    $file = file_get_contents($datadir . "/" . $inputfile);

    $data = json_decode($file);
    foreach ($data as $d) {
        $obj = new StdClass();
        $obj->source = "cigrasp";
        $obj->year = "n/a";
        $obj->donor = "n/a";
        $obj->recipient = $d->country;
        $obj->purpose = "n/a";
        if (isset($d->overview->stimuli)) {
            if (is_array($d->overview->stimuli))
                $obj->purpose = implode(",", $d->overview->stimuli);
            else
                $obj->purpose = $d->overview->stimuli;
        }
        $obj->amount = $d->project_costs->normalized_costs;
        $obj->sector = $d->overview->sector;
        $obj->projecttitle = $d->title;
        $jsons[] = $obj;
    }
}

/*
 * UNFCCC Private Sector Initiative (http://unfccc.int/adaptation/workstreams/nairobi_work_programme/items/6547.php)
 */

function load_psi() {
    global $jsons, $datadir;

    $inputfile = "";
    $file = file($datadir . "/" . $inputfile);
}

/*
 * ClimateWise on insurance industry (http://www.climatewise.org.uk/)
 * 
 * methodology, https://docs.google.com/document/d/1aOIi0ofmjfl-haOt-hbHYGZjDnKBPxzxN6-5SpmuH-0/edit
 * json, https://docs.google.com/file/d/0B94tyKAcHuHBWnRscVUzWUpWTDg/edit, 
 * 
 * @todo: old source, add amount of money and year
 */

function load_climate_wise() {
    global $jsons, $datadir;

    $inputfile = "adaptation_projects.json";
    $file = file_get_contents($datadir . "/" . $inputfile);
<commit_msg>added comment about undp ambiguity<commit_after><?php

/*
 * This script combines various adaptation funding databases into one JSON file
 * see https://docs.google.com/document/d/1s0HVBtVG9ZVVFOhwS-n3PMdgzlwNTiMUyvrNYjGv8Mc/edit for more info
 * 
 * @todo, update sources
 * @todo, put amounts in same format (float vs int) + check whether they are adjusted for inflation etc
 * 
 * @author <NAME> <<EMAIL>>
 */

ini_set('memory_limit', '2G');
date_default_timezone_set('Europe/Amsterdam');
$datadir = "data";

$jsons = array();
load_databases();
print json_encode($jsons, JSON_PRETTY_PRINT);

function load_databases() {
    load_undp();
    load_ci_grasp();
    load_psi();
    load_climate_wise();
    load_oecd_riomarkers();
    load_climatefundsupdate();
    load_napa();
}

/*
 * UNDP adaptation learning mechanism (http://www.undp-alm.org/) 
 * 
 * methodology https://drive.google.com/?usp=folder&authuser=0#folders/0B3e-HpGNh9BwcVpPUHlJNkpnVWs
 * json https://docs.google.com/file/d/0B3e-HpGNh9BwRnYzQVJpTE5HMjQ/edit
 * 
 * @todo: old source, there is also another source used in the combined file (adaptation_projects.json) and referenced from https://docs.google.com/document/d/1aOIi0ofmjfl-haOt-hbHYGZjDnKBPxzxN6-5SpmuH-0/edit# section IV
 * 
 */

function load_undp() {
    global $jsons, $datadir;

    $inputfile = "undp.json";
    $file = file_get_contents($datadir . "/" . $inputfile);

    $data = json_decode($file);
    foreach ($data as $d) {
        $obj = new StdClass();
        $obj->source = "undp";
        $obj->year = "n/a";
        $obj->donor = "n/a";
        if (isset($d->data->partners)) {
            if (is_array($d->data->partners))
                $obj->donor = implode(",", $d->data->partners);
            else
                $obj->donor = $d->data->partners;
        }
        $obj->recipient = $d->location;
        $obj->purpose = "n/a";
        if (isset($d->data->{'climate-hazards'})) {
            if (is_array($d->data->{'climate-hazards'}))
                $obj->purpose = implode(",", $d->data->{'climate-hazards'});
            else
                $obj->purpose = $d->data->{'climate-hazards'};
        }
        $obj->amount = "n/a";
        if (isset($d->data->normalized_costs))
            $obj->amount = $d->data->normalized_costs;
        $obj->sector = "n/a";
        if (!empty($d->theme))
            $obj->sector = $d->theme;
        $obj->projecttitle = $d->title;
        $jsons[] = $obj;
    }
}

/*
 * Ci-Grasp (http://www.pik-potsdam.de/~wrobel/ci_2/)
 * 
 * methodology https://drive.google.com/?usp=folder&authuser=0#folders/0B3e-HpGNh9BwcVpPUHlJNkpnVWs
 * json https://docs.google.com/file/d/0B3e-HpGNh9BwZzF0V2VnWmNrazA/edit
 * 
 * @todo: old source
 */

function load_ci_grasp() {
    global $jsons, $datadir;

    $inputfile = "cigrasp.json";
    $file = file_get_contents($datadir . "/" . $inputfile);

    $data = json_decode($file);
    foreach ($data as $d) {
        $obj = new StdClass();
        $obj->source = "cigrasp";
        $obj->year = "n/a";
        $obj->donor = "n/a";
        $obj->recipient = $d->country;
        $obj->purpose = "n/a";
        if (isset($d->overview->stimuli)) {
            if (is_array($d->overview->stimuli))
                $obj->purpose = implode(",", $d->overview->stimuli);
            else
                $obj->purpose = $d->overview->stimuli;
        }
        $obj->amount = $d->project_costs->normalized_costs;
        $obj->sector = $d->overview->sector;
        $obj->projecttitle = $d->title;
        $jsons[] = $obj;
    }
}

/*
 * UNFCCC Private Sector Initiative (http://unfccc.int/adaptation/workstreams/nairobi_work_programme/items/6547.php)
 * 
 * methodology, https://docs.google.com/document/d/1aOIi0ofmjfl-haOt-hbHYGZjDnKBPxzxN6-5SpmuH-0/edit
 * json, https://docs.google.com/file/d/0B94tyKAcHuHBWnRscVUzWUpWTDg/edit, 
 */

function load_psi() {
    global $jsons, $datadir;

    $inputfile = "adaptation_projects.json";
    $file = file_get_contents($datadir . "/" . $inputfile);

    $data = json_decode($file);
    foreach ($data as $d) {
        if ($d->source == "psi") {
            $obj = new StdClass();
            $obj->source = $d->source;
            $obj->year = "n/a";
            $obj->donor = "n/a";
            $obj->recipient = implode(",", $d->countries);
            $obj->purpose = implode(",", $d->{'climate-hazards'});
            $obj->amount = "n/a";
            $obj->sector = "n/a";
            if (!empty($d->themes))
                $obj->sector = implode(",", $d->themes);
            $obj->projecttitle = $d->name;
            $jsons[] = $obj;
        }
    }
}

/*
 * ClimateWise on insurance industry (http://www.climatewise.org.uk/)
 * 
 * methodology, https://docs.google.com/document/d/1aOIi0ofmjfl-haOt-hbHYGZjDnKBPxzxN6-5SpmuH-0/edit
 * json, https://docs.google.com/file/d/0B94tyKAcHuHBWnRscVUzWUpWTDg/edit, 
 * 
 * @todo: old source, add amount of money and year
 */

function load_climate_wise() {
    global $jsons, $datadir;

    $inputfile = "adaptation_projects.json";
    $file = file_get_contents($datadir . "/" . $inputfile);

{'fraction_non_alphanumeric': 0.17758753155526286, 'fraction_numerical': 0.009329382065634946, 'mean_word_length': 2.6173084557364032, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 147, 'https://': 17, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3513038', 'n_tokens_mistral': 3575, 'n_tokens_neox': 3406, 'n_words': 530}