示例#1
0
 static function getInventoryTotals($ge_id, array $opt = array(), array $type = array('EMISSION'), $divider = 1000)
 {
     //$ge_id_2=null, array $type=array('EMISSION'), $divider=1000) {
     $result = array();
     R3EcoGisHelper::includeHelperClass('obj.global_result_table.php');
     foreach ($type as $t) {
         $result[$t] = R3EcoGisGlobalTableHelper::getCategoriesData($ge_id, $t, $divider);
         // Remove unused data
         if (isset($result[$t]['data'])) {
             unset($result[$t]['data']);
         }
         if (isset($result[$t]['sum']['source'])) {
             unset($result[$t]['sum']['source']);
         }
         // Calcolo pro capite
         if (isset($opt['citizen']) && $opt['citizen'] > 0) {
             $result[$t]['sum']['total_citizen'] = $result[$t]['sum']['total'] / $opt['citizen'];
         }
     }
     return $result;
 }
示例#2
0
 public function getEnergyUDM($request)
 {
     R3EcoGisHelper::includeHelperClass('obj.global_consumption_row.php');
     if ($request['type'] == 'CONSUMPTION') {
         $data = R3EcoGisGlobalConsumptionHelper::getEnergySourceList($_SESSION['do_id'], $request['type'], array('order' => 'ges_name, gest_order, ges_order, ges.ges_id, es_order, es_name, es.es_id, udm_order, udm_name, udm.udm_id'));
     } else {
         $data = R3EcoGisActionCatalogHelper::getProductionEnergySourceList($_SESSION['do_id']);
     }
     $result = array();
     if (isset($data[$request['ges_id']]['source'][$request['es_id']]['udm'])) {
         foreach ($data[$request['ges_id']]['source'][$request['es_id']]['udm'] as $key => $val) {
             $result[$key] = $val['name'];
         }
     }
     $result = R3Opt::addChooseItem($result, array('allow_empty' => count($result) != 1));
     return array('status' => R3_AJAX_NO_ERROR, 'data' => R3EcoGisHelper::forceJSonArray($result));
 }
示例#3
0
 public function loadEmissionDataFrominventory($ge_id)
 {
     $db = ezcDbInstance::get();
     R3EcoGisHelper::includeHelperClass('obj.global_result_table.php');
     // Emissioni
     $data = R3EcoGisGlobalTableHelper::getCategoriesData($ge_id, 'EMISSION', 1);
     $result['emission']['total'] = $data['table_sum'];
     // Consumi
     $consumptionData = R3EcoGisGlobalTableHelper::getCategoriesData($ge_id, 'CONSUMPTION', 1);
     // Ricavo ID PAES Elettricità (dovrebbe essere 1 nei db standard)
     $sql = "SELECT ges_id\r\n                FROM global_energy_source ges\r\n                INNER JOIN global_energy_type get ON ges.get_id=get.get_id WHERE get_code='ELECTRICITY'";
     $electricityGesId = $db->query($sql)->fetchColumn();
     if (!isset($data['sum']['source'][$electricityGesId])) {
         $result['consumption']['electricity'] = null;
     } else {
         $result['consumption']['electricity'] = isset($consumptionData['sum']['source'][$electricityGesId]) ? $consumptionData['sum']['source'][$electricityGesId] : 0;
     }
     $result['consumption']['total'] = $consumptionData['sum']['total'];
     // Produzione
     $productionData = R3EcoGisGlobalTableHelper::getCategoriesData($ge_id, 'ENERGY_PRODUCTION', 1);
     $result['production']['electricity'] = $productionData['production_sum']['tot'];
     $result['production']['production_emission'] = $productionData['production_emission_sum']['tot'];
     // Energia verde
     $sql = "SELECT ge_green_electricity_purchase, ge_green_electricity_co2_factor\r\n                FROM global_entry\r\n                WHERE ge_id=?";
     $stmt = $db->prepare($sql);
     $stmt->execute(array($ge_id));
     $data = $stmt->fetch(PDO::FETCH_ASSOC);
     $result['green_energy']['consumption'] = $data['ge_green_electricity_purchase'];
     $result['green_energy']['factor'] = $data['ge_green_electricity_co2_factor'];
     $result['green_energy']['emission'] = $result['green_energy']['consumption'] * $result['green_energy']['factor'];
     // Energia rinnovabile
     $sql = "SELECT ges.ges_id, ges_name_1 AS ges_name\r\nFROM global_energy_source ges\r\nINNER JOIN global_energy_type get ON ges.get_id=get.get_id\r\nINNER JOIN global_energy_source_type gest ON ges.ges_id=gest.ges_id\r\nINNER JOIN global_type gt ON gt.gt_id=gest.gt_id\r\nWHERE get_code='RENEWABLE' AND gt_code='CONSUMPTION'\r\nORDER BY gest_order";
     $renewableConsumption = 0;
     foreach ($db->query($sql, PDO::FETCH_ASSOC) as $row) {
         $tot = 0;
         foreach ($consumptionData['data'] as $data) {
             if (isset($data['sum']['source'][$row['ges_id']])) {
                 $tot += $data['sum']['source'][$row['ges_id']];
             }
         }
         $gesIds[$row['ges_id']] = array('id' => $row['ges_id'], 'name' => $row['ges_name'], 'tot' => $tot);
         $renewableConsumption += $tot;
     }
     $result['green_energy']['production'] = $renewableConsumption;
     return $result;
 }