Ejemplo n.º 1
0
 public static function Calculate($json)
 {
     $counts = array();
     $community_arrayx = array();
     //non-functional water points
     $community_array = array();
     //water points per community
     $ranking_array = array();
     //ranking  by percentage
     $counter = 0;
     foreach ($json as $data => $value) {
         if (isset($value['water_functioning'])) {
             $stat = $value['water_functioning'];
             $community = $value['communities_villages'];
             if (!in_array($community_arrayx, $community)) {
                 array_push($community, $community_arrayx);
             }
             if (strcasecmp($stat, "yes") == 0) {
                 ++$counter;
             }
         }
     }
     $cc_arr = array();
     for ($y = 0; $y < count($community_arrayx); ++$y) {
         $comm = $community_arrayx[$y];
         $community_array[$comm] = calc::getWaterPointsToTal($json, $comm);
         $cc_arr[$comm] = calc::getBrokenWaterPointsToTal($json, $comm);
         $ranking_array = $cc_arr;
     }
     $counts['functional_water_points'] = $counter;
     $counts['number_of_water_points'] = json_encode($community_array);
     $counts['community_ranking'] = calc::getRanking($ranking_array);
     return $counts;
 }