public static function getGaugeData($gpr_id) { $db = ezcDbInstance::get(); $lang = R3Locale::getLanguageID(); $gpr_id = (int) $gpr_id; $sql = "SELECT gpr_gauge_type FROM ecogis.global_plain_row WHERE gpr_id={$gpr_id}"; $gaugeType = $db->query($sql)->FetchColumn(); switch ($gaugeType) { case 'P': // Percentuale $sql = "SELECT gpm_id, gpm_date, gpm_value_1, gpm_value_2\r\n FROM ecogis.global_plain_monitor gpm\r\n WHERE gpr_id={$gpr_id}\r\n ORDER BY gpm_date"; $result = array(); $result['P']['header'] = array('title' => _('% Completamento azione'), 'unit' => '%', 'unit_value' => 1); foreach ($db->query($sql, PDO::FETCH_ASSOC) as $row) { $result['P']['data'][$row['gpm_id']] = array('gpg_id' => null, 'date' => $row['gpm_date'], 'date_fmt' => SQLDateToStr($row['gpm_date'], 'd/m/Y'), 'value_1' => $row['gpm_value_1'], 'value_1_fmt' => R3NumberFormat($row['gpm_value_1'], 2), 'value_2' => $row['gpm_value_2'], 'value_2_fmt' => R3NumberFormat($row['gpm_value_2'], 2), 'tot_value' => $row['gpm_value_1'] * 1, 'tot_value_fmt' => R3NumberFormat($row['gpm_value_1'] * 1, 2)); } break; case 'G': // Indicatore $sql = "SELECT gpg.gpg_id, gpg_name_{$lang} AS gpg_name, gpgu_1.gpgu_name_{$lang} AS gpgu_name_1, \r\n gpgu_2.gpgu_name_{$lang} AS gpgu_name_2, gpg_value_1, gpg_value_2, gpg_value_3, gpm_id, gpm_date, \r\n gpm_value_1, gpm_value_2\r\n FROM ecogis.global_plain_gauge gpg\r\n LEFT JOIN ecogis.global_plain_gauge_udm gpgu_1 ON gpg.gpgu_id_1=gpgu_1.gpgu_id\r\n LEFT JOIN ecogis.global_plain_gauge_udm gpgu_2 ON gpg.gpgu_id_2=gpgu_2.gpgu_id\r\n LEFT JOIN ecogis.global_plain_monitor gpm ON gpg.gpg_id=gpm.gpg_id\r\n WHERE gpg.gpr_id={$gpr_id}\r\n ORDER BY gpg_name, gpm_date"; $sql = "SELECT gpg_id, gpg_name_{$lang} AS gpg_name, gpgu_name_1_{$lang} AS gpgu_name_1, \r\n gpgu_name_2_{$lang} AS gpgu_name_2, gpg_value_1, gpg_value_2, gpg_value_3, gpm_id, gpm_date, \r\n gpm_value_1, gpm_value_2\r\n FROM ecogis.global_plain_gauge_full_data\r\n WHERE gpr_id={$gpr_id}\r\n ORDER BY gpg_name, gpm_date"; $result = array(); foreach ($db->query($sql, PDO::FETCH_ASSOC) as $row) { $result[$row['gpg_id']]['header'] = array('title' => $row['gpg_name'], 'unit_1' => $row['gpgu_name_1'], 'unit_2' => $row['gpgu_name_2'], 'value_1' => $row['gpg_value_1'], 'value_2' => $row['gpg_value_2'], 'value_3' => $row['gpg_value_3']); $energyVariation = self::calculateEnergyVariation($row['gpg_value_1'], $row['gpg_value_2'], $row['gpm_value_2'], $row['gpm_value_1']); $emissionVariation = self::calculateEmissionVariation($energyVariation, $row['gpg_value_3']); $result[$row['gpg_id']]['data'][$row['gpm_id']] = array('gpg_id' => $row['gpg_id'], 'date' => $row['gpm_date'], 'date_fmt' => SQLDateToStr($row['gpm_date'], 'd/m/Y'), 'value_1' => $row['gpm_value_1'], 'value_1_fmt' => R3NumberFormat($row['gpm_value_1'], 2), 'value_2' => $row['gpm_value_2'], 'value_2_fmt' => R3NumberFormat($row['gpm_value_2'], 2), 'energy_variation' => $energyVariation, 'energy_variation_fmt' => R3NumberFormat($energyVariation, 2), 'emission_variation' => $emissionVariation, 'emission_variation_fmt' => R3NumberFormat($emissionVariation, 2)); } break; default: // No action return null; } return $result; }
public function convert2Locale($vlu) { if (!is_array($vlu)) { return $vlu; } setLangInfo(array('thousands_sep' => ".")); foreach ($this->fields as $key => $field) { if (isset($field['name'])) { $key = $field['name']; if (isset($field['dec']) && !isset($field['precision'])) { $field['precision'] = $field['dec']; } if (array_key_exists($key, $vlu)) { if ($vlu[$key] === null) { $vlu[$key] = ''; } else { $type = strToLower($field['type']); switch ($field['type']) { case 'real': case 'double': case 'number': case 'float': $vlu[$key] = R3NumberFormat($vlu[$key], isset($field['precision']) ? $field['precision'] : null, true); break; case 'integer': $vlu[$key] = R3NumberFormat($vlu[$key], isset($field['precision']) ? $field['precision'] : 0, true); break; case 'date': $vlu[$key] = SQLDateToStr($vlu[$key], R3Locale::getPhpDateFormat()); break; case 'datetime': case 'now': $vlu[$key] = SQLDateToStr($vlu[$key], R3Locale::getPhpDateTimeFormat()); break; case 'boolean': if ($vlu[$key] === true) { $vlu[$key] = 'T'; } else { if ($vlu[$key] === false) { $vlu[$key] = 'F'; } } } } } } } return $vlu; }
public function exportPAES($request) { require_once R3_CLASS_DIR . 'obj.global_result_table.php'; require_once R3_CLASS_DIR . 'obj.global_plain_table.php'; $id = empty($request['id']) ? $this->id : (int) $request['id']; set_time_limit(5 * 60); ini_set('memory_limit', '2G'); ignore_user_abort(true); $db = ezcDbInstance::get(); $driverInfo = $this->auth->getConfigValue('APPLICATION', 'EXPORT_PAES', array()); if (!isset($driverInfo[$request['driver']]['driver'])) { throw new Exception(_("Invalid driver \"{$request['driver']}\"")); } $exportDriverName = $driverInfo[$request['driver']]['driver']; $exportDriver = R3ExportPAES::factory($exportDriverName, $this->auth, isset($driverInfo[$request['driver']]['params']) ? $driverInfo[$request['driver']]['params'] : null); $q = $db->createSelectQuery(); $q->select('*')->from('global_strategy_data')->where("gst_id={$id}"); $globalStrategyData['general'] = $db->query($q)->fetch(PDO::FETCH_ASSOC); $globalStrategyData['general']['gst_reduction_target_text'] = $globalStrategyData['general']['gst_reduction_target_absolute'] ? _('Riduzione assoluta') : _('Riduzione "pro capite"'); $budgetEuro = $globalStrategyData['general']['gst_budget'] == '' ? '' : '€' . R3NumberFormat($globalStrategyData['general']['gst_budget'], 2, true); if ($globalStrategyData['general']['gst_budget_text_1'] != '' && $globalStrategyData['general']['gst_budget'] != '') { $globalStrategyData['general']['gst_budget_text_1'] = sprintf('%s - %s', $budgetEuro, $globalStrategyData['general']['gst_budget_text_1']); } else { $globalStrategyData['general']['gst_budget_text_1'] = $budgetEuro . $globalStrategyData['general']['gst_budget_text_1']; } if ($globalStrategyData['general']['gst_budget_text_2'] != '' && $globalStrategyData['general']['gst_budget'] != '') { $globalStrategyData['general']['gst_budget_text_2'] = sprintf('%s - %s', $budgetEuro, $globalStrategyData['general']['gst_budget_text_2']); } else { $globalStrategyData['general']['gst_budget_text_2'] = $budgetEuro . $globalStrategyData['general']['gst_budget_text_2']; } $q = $db->createSelectQuery(); $q->select('*')->from('global_plain_data')->where("gp_id=" . (int) $globalStrategyData['general']['gp_id']); $actionPlanData['general'] = $db->query($q)->fetch(PDO::FETCH_ASSOC); if (isset($actionPlanData['general']['gp_approval_date'])) { $actionPlanData['general']['gp_approval_date'] = ' ' . SQLDateToStr($actionPlanData['general']['gp_approval_date'], 'd/m/Y'); } // SHEET 2: EMISSION INVENTORY $udm_divider = 1000; // MWh (in db data are stored in kWh) $inventoryTableKinds = array('CONSUMPTION', 'EMISSION', 'ENERGY_PRODUCTION', 'HEATH_PRODUCTION'); $emissionInventoryData = array(); for ($i = 1; $i <= 2; $i++) { $ge_id = $i == 1 ? $globalStrategyData['general']['ge_id'] : $globalStrategyData['general']['ge_id_2']; if ($ge_id != '') { $q = $db->createSelectQuery(); $q->select('*, ge_green_electricity_purchase/1000 AS ge_green_electricity_purchase')->from('global_entry_data')->where('ge_id=' . (int) $ge_id); $emissionInventoryData[$i]['general'] = $db->query($q)->fetch(PDO::FETCH_ASSOC); $emissionInventoryData[$i]['general']['gst_emission_factor_text'] = $globalStrategyData['general']['gst_emission_factor_type_ipcc'] ? _('Fattori di emissione standard in linea con i principi IPCC') : _('Fattori LCA (valutazione del ciclo di vita)'); $emissionInventoryData[$i]['general']['gst_emission_unit_text'] = $globalStrategyData['general']['gst_emission_unit_co2'] ? _('Emissioni di CO2') : _('Emissioni equivalenti di CO2'); foreach ($inventoryTableKinds as $kind) { $emissionInventoryData[$i][$kind]['header'] = R3EcoGisGlobalTableHelper::getParameterList($kind, array('show_udm' => true)); $emissionInventoryData[$i][$kind]['rows'] = R3EcoGisGlobalTableHelper::getCategoriesData($ge_id, $kind, $udm_divider); } } } $ext = '.' . (isset($driverInfo[$request['driver']]['output_format']) ? $driverInfo[$request['driver']]['output_format'] : 'xlsx'); $fileName = R3_TMP_DIR . date('YmdHis') . '.' . md5(time()) . $ext; $opt = array('GENERAL' => $globalStrategyData, 'ACTION_PLAN' => $actionPlanData); for ($i = 1; $i <= 2; $i++) { if (isset($emissionInventoryData[$i])) { $opt["EMISSION_INVENTORY_{$i}"] = $emissionInventoryData[$i]; } } if ($globalStrategyData['general']['gp_id'] != '') { $opt['GLOBAL_PLAN'] = R3EcoGisGlobalPlainTableHelper::getData($this->do_id, $globalStrategyData['general']['gp_id']); } $opt['METADATA'] = array('creator' => $this->auth->getUserName(), 'title' => _('TEMPLATE') . ' - ' . _('POWER BY R3-EcoGIS 2')); $opt['SHEET-NAME'] = array('GENERAL' => _('Strategia generale'), 'EMISSION_INVENTORY_1' => _('Inventario base emissioni (1)'), 'EMISSION_INVENTORY_2' => _('Inventario base emissioni (2)'), 'ACTION_PLAN' => _("Piano d'azione SEAP")); $opt['logger'] = new R3ExportLogger(); // Close immediatly the session to allow concurrency session session_write_close(); $exportDriver->export($fileName, R3_SMARTY_TEMPLATE_DIR_DOC . $driverInfo[$request['driver']]['template'], $opt); $httpFileName = basename($fileName); $url = "getfile.php?type=tmp&file={$httpFileName}&disposition=download&name=PAES_" . date('Y-m-d') . $ext; return array('status' => R3_AJAX_NO_ERROR, 'url' => $url); }
/** * Return the data for a single customer */ public function getData($id = null) { $db = ezcDbInstance::get(); $id = (int) $id; $productMinEntry = 3; if ($this->act != 'add') { $q = $db->createSelectQuery(); $q->select('*')->from('utility_supplier')->where("us_id={$this->id}"); $vlu = $db->query($q)->fetch(PDO::FETCH_ASSOC); $vlu['municipality'] = R3EcoGisUtilityHelper::getSelectedMunicipalityList($this->id); $vlu['products'] = R3EcoGisUtilityHelper::getProductsList($this->id); foreach ($vlu['products'] as $key => $val) { $vlu['products'][$key]['esu_co2_factor'] = R3NumberFormat($val['esu_co2_factor'], null, true); } $tot = max($productMinEntry - 1, count($vlu['products'])) + 1; $key = 0; for ($i = count($vlu['products']); $i < $tot; $i++) { $vlu['products']["new_{$key}"] = array(); $key++; } $vlu = array_merge($vlu, R3EcoGisHelper::getChangeLogData('utility_supplier', $vlu['us_id'])); } else { $vlu = array(); $vlu['us_order'] = 0; $vlu['municipality'] = array(); for ($i = 0; $i < $productMinEntry; $i++) { $vlu['products']["new_{$i}"] = array(); } } $this->data = $vlu; return $vlu; }
public function performActionCatalogCalc($request) { setlocale(LC_ALL, 'C'); $energySavingData = R3EcoGisHelper::getEnergySourceUdmData($_SESSION['do_id'], $request['es_id_consumption'], $request['udm_id_consumption'], $request['mu_id']); $energyProductionData = R3EcoGisHelper::getEnergySourceUdmData($_SESSION['do_id'], $request['es_id_production'], $request['udm_id_production'], $request['mu_id']); $ac_expected_co2_reduction_total = 0; $ac_expected_co2_reduction = array(); $ac_expected_energy_saving_mwh = array(); foreach ($energySavingData as $i => $val) { $ac_expected_co2_reduction_total += $request['ac_expected_energy_saving'][$i] == '' ? null : $request['ac_expected_energy_saving'][$i] * $energySavingData[$i]['esu_co2_factor'] / 1000; $ac_expected_co2_reduction[$i] = R3NumberFormat($request['ac_expected_energy_saving'][$i] == '' ? null : $request['ac_expected_energy_saving'][$i] * $energySavingData[$i]['esu_co2_factor'] / 1000, 2, true); $ac_expected_energy_saving_mwh[$i] = R3NumberFormat($request['ac_expected_energy_saving'][$i] == '' ? null : $request['ac_expected_energy_saving'][$i] * $energySavingData[$i]['esu_kwh_factor'] / 1000, 2, true); } if ($energyProductionData === null) { $energyProductionMWh = null; } else { $energyProductionMWh = $request['ac_expected_renewable_energy_production'] == '' ? null : $request['ac_expected_renewable_energy_production'] * $energyProductionData[0]['esu_kwh_factor'] / 1000; } return array('status' => R3_AJAX_NO_ERROR, 'data' => array('ac_expected_co2_reduction_total' => R3NumberFormat($ac_expected_co2_reduction_total, null, true), 'ac_expected_co2_reduction' => $ac_expected_co2_reduction, 'ac_expected_energy_saving_mwh' => $ac_expected_energy_saving_mwh, 'ac_expected_renewable_energy_production_mwh' => R3NumberFormat($energyProductionMWh, null, true))); }
public function getListTableRowOperations(&$row) { $id = $row['doc_id']; $file_id = $row['doc_file_id']; $openExt = $this->auth->getConfigValue('APPLICATION', 'DOCUMENT_OPEN_EXT', array()); $name = $this->getDocFullName($row['doc_file'], $this->documentType, '', $file_id, false); $fileExists = file_exists($name); $ext = strtolower(substr(strrchr($row['doc_file'], '.'), 1)); $s = R3_WEB_IMAGES_DIR . "icons/ico_{$ext}.gif"; if (file_exists($s)) { $ico = R3_ICONS_URL . "ico_{$ext}.gif"; } else { $ico = R3_ICONS_URL . 'default.gif'; } if ($fileExists && in_array($ext, $openExt)) { $this->simpleTable->addCalcValue('doc_file', sprintf("<a href=\"javascript:openDocument('{$file_id}', '{$this->documentType}')\" class=\"document\"><img src=\"{$ico}\" border=\"0\"> %s</a>", $row['doc_file'])); } else { $this->simpleTable->addCalcValue('doc_file', sprintf("<img src=\"{$ico}\"> %s", $row['doc_file'])); } if ($fileExists) { $this->simpleTable->addCalcValue('doc_size', sprintf("%s KB", R3NumberFormat(ceil(filesize($name) / 1024), null, true))); } else { $this->simpleTable->addCalcValue('doc_size', '-'); } $links = array(); $canShow = false; $objName = strToUpper($this->baseName); $parent_act = $this->parent_act == 'show' ? $this->parent_act : 'mod'; foreach (array('show', 'mod', 'del') as $act) { if ($this->auth->hasPerm(strToUpper($act), $objName)) { switch ($act) { case 'show': if ($fileExists) { $links['SHOW'] = $this->simpleTable->AddLinkCell(_('Scarica'), "javascript:downloadDocument('{$file_id}', '{$this->documentType}')", "", "{$this->imagePath}ico_doc_download.gif"); } else { $links['SHOW'] = $this->simpleTable->AddLinkCell('', '', '', "{$this->imagePath}ico_spacer.gif"); } break; case 'mod': if ($this->parent_act != 'show') { if ($this->isDialog) { $links['MOD'] = $this->simpleTable->AddLinkCell(_('Modifica'), "javascript:modDocument('{$id}')", "", "{$this->imagePath}ico_{$act}.gif"); } else { $links['MOD'] = $this->simpleTable->AddLinkCell(_('Modifica'), "javascript:modObject('{$id}')", "", "{$this->imagePath}ico_{$act}.gif"); } } break; case 'del': if ($this->parent_act != 'show') { $links['DEL'] = $this->simpleTable->AddLinkCell(_('Cancella'), "javascript:askDelDocument('{$id}', '{$this->documentType}')", "", "{$this->imagePath}ico_{$act}.gif"); } break; } } else { $links[] = $this->simpleTable->AddLinkCell('', '', '', "{$this->imagePath}ico_spacer.gif"); } } return $links; }
private static function convertToLocale(&$data, $decimals) { // SOMME TABELLA (TOTALONE) $data['table_sum'] = R3NumberFormat($data['table_sum'], $decimals, true); // Somma tabella $data['sum']['total'] = R3NumberFormat($data['sum']['total'], $decimals, true); // Somma tabella // SOMME TABELLA (PER FONTE) if (!empty($data['sum']['source'])) { foreach ($data['sum']['source'] as $key => $dummy) { $data['sum']['source'][$key] = R3NumberFormat($data['sum']['source'][$key], $decimals, true); } } // Consumo + emissioni foreach ($data['data'] as $key1 => $dummy1) { // SOMME PARZIALI MACROCATEGORIA $data['data'][$key1]['sum']['total'] = R3NumberFormat($data['data'][$key1]['sum']['total'], $decimals, true); // Totale macrocategoria (Edifici, attrezzature/impianti e industrie) if (!empty($data['data'][$key1]['sum']['source'])) { foreach ($data['data'][$key1]['sum']['source'] as $key2 => $dummy2) { $data['data'][$key1]['sum']['source'][$key2] = R3NumberFormat($data['data'][$key1]['sum']['source'][$key2], $decimals, true); } } foreach ($data['data'][$key1]['categories'] as $catId => $dummy2) { // TOTALE RIGA PRINCIPALE (Edifici, attrezzature/impianti comunali) $data['data'][$key1]['categories'][$catId]['header']['sum'] = R3NumberFormat($data['data'][$key1]['categories'][$catId]['header']['sum'], $decimals, true); // TOTALE CELLE PRINCIPALI foreach ($data['data'][$key1]['categories'][$catId]['sum'] as $sourceId => $dummy3) { $data['data'][$key1]['categories'][$catId]['sum'][$sourceId] = R3NumberFormat($data['data'][$key1]['categories'][$catId]['sum'][$sourceId], $decimals, true); } // VALORI SOTTO-CATEGORIE (quelle inserite dagli utenti) if (!empty($data['data'][$key1]['categories'][$catId]['sub_categories'])) { foreach ($data['data'][$key1]['categories'][$catId]['sub_categories'] as $id => $dummy3) { $data['data'][$key1]['categories'][$catId]['sub_categories'][$id]['header']['sum'] = R3NumberFormat($data['data'][$key1]['categories'][$catId]['sub_categories'][$id]['header']['sum'], $decimals, true); $data['data'][$key1]['categories'][$catId]['sub_categories'][$id]['header']['co2_sum'] = R3NumberFormat($data['data'][$key1]['categories'][$catId]['sub_categories'][$id]['header']['co2_sum'], $decimals, true); foreach ($data['data'][$key1]['categories'][$catId]['sub_categories'][$id]['data'] as $key => $dummy4) { $data['data'][$key1]['categories'][$catId]['sub_categories'][$id]['data'][$key] = R3NumberFormat($data['data'][$key1]['categories'][$catId]['sub_categories'][$id]['data'][$key], $decimals, true); } } } } } // Produzione foreach ($data['production_data'] as $key1 => $dummy1) { foreach ($data['production_data'][$key1] as $id => $dummy2) { $data['production_data'][$key1][$id]['production'] = R3NumberFormat($data['production_data'][$key1][$id]['production'], $decimals, true); if (!empty($data['production_data'][$key1][$id]['production_emission'])) { $data['production_data'][$key1][$id]['production_emission'] = R3NumberFormat($data['production_data'][$key1][$id]['production_emission'], $decimals, true); } if (!empty($data['production_data'][$key1][$id]['production_emission_factor'])) { $data['production_data'][$key1][$id]['production_emission_factor'] = R3NumberFormat($data['production_data'][$key1][$id]['production_emission_factor'], $decimals, true); } } } // Somme produzione foreach (array('production_sum', 'production_emission_sum', 'production_emission_sum_factor') as $key0) { if (!empty($data[$key0]['tot'])) { $data[$key0]['tot'] = R3NumberFormat($data[$key0]['tot'], $decimals, true); } if (!empty($data[$key0]['category'])) { foreach ($data[$key0]['category'] as $key1 => $dummy2) { $data[$key0]['category'][$key1] = R3NumberFormat($data[$key0]['category'][$key1], $decimals, true); } } } }
public function convert2Locale(array $vlu) { // Change to locale $oldMessageLocale = setlocale(LC_MESSAGES, 0); $oldNumericLocale = setlocale(LC_NUMERIC, 0); setlocale(LC_NUMERIC, getLocaleInfo(R3Locale::getLanguageCode())); setLangInfo(array('thousands_sep' => ".")); foreach ($this->fields as $key => $field) { if (isset($field['name'])) { $key = $field['name']; if (isset($field['dec']) && !isset($field['precision'])) { $field['precision'] = $field['dec']; } if (isset($field['is_primary_key']) && $field['is_primary_key'] === true) { continue; } if (array_key_exists($key, $vlu)) { if ($vlu[$key] === null) { $vlu[$key] = ''; // IE Fix in json response } else { $type = strToLower($field['type']); switch ($field['type']) { case 'real': case 'double': case 'number': case 'float': $vlu[$key] = R3NumberFormat($vlu[$key], isset($field['precision']) ? $field['precision'] : null, true); break; case 'integer': $vlu[$key] = R3NumberFormat($vlu[$key], isset($field['precision']) ? $field['precision'] : 0, true); break; case 'date': $vlu[$key] = SQLDateToStr($vlu[$key], R3Locale::getPhpDateFormat()); break; case 'datetime': case 'now': $vlu[$key] = SQLDateToStr($vlu[$key], R3Locale::getPhpDateTimeFormat()); break; case 'boolean': if ($vlu[$key] === true) { $vlu[$key] = 'T'; } else { if ($vlu[$key] === false) { $vlu[$key] = 'F'; } } } } } } } setlocale(LC_MESSAGES, $oldMessageLocale); setlocale(LC_NUMERIC, $oldNumericLocale); return $vlu; }
/** * Return cost * * @see getNetEstimatedCost or getNetEffectiveCost */ private static function getNetCost(array $data, $returnAsLocale, $kind) { $result = null; if (array_key_exists("wo_{$kind}_cost", $data) && array_key_exists("wo_{$kind}_contribution", $data) && ($data["wo_{$kind}_cost"] != '' || $data["wo_{$kind}_contribution"] != '')) { $result = $data["wo_{$kind}_cost"] - $data["wo_{$kind}_contribution"]; } if ($returnAsLocale) { return $result == null ? '' : R3NumberFormat($result, 2, true); } return $result; }
public function calculateTotals($request) { $id = (int) $request['id']; $efe1 = null; $efe2 = null; $_SESSION = $this->closeSession(); R3EcoGisSimulationHelper::clearLog(); $data = R3EcoGisSimulationHelper::getSummaryTotals($id, explodeInt($request['ac_id_list']), explodeInt($request['ac_perc_list']), 1000, true, false, $efe1, $efe2); $log = R3EcoGisSimulationHelper::getLog(true); $message = ''; if (isset($data['simulation'][2]['efe']) && ($data['simulation'][2]['efe'] < 0.1 || $data['simulation'][2]['efe'] > 1)) { $message = _("ATTENZIONE! Il valore dell'EFE sembra essere fuori soglia. Verificare i parametri"); } if (isset($data['simulation'][1]['efe']) && ($data['simulation'][1]['efe'] < 0.1 || $data['simulation'][1]['efe'] > 1)) { $message = _("ATTENZIONE! Il valore dell'EFE sembra essere fuori soglia. Verificare i parametri"); } $result = array(); $this->adjSummaryData($data, $result); return array('status' => R3_AJAX_NO_ERROR, 'efe1' => isset($data['simulation'][1]['efe']) ? R3NumberFormat($data['simulation'][1]['efe'], 3) : '', 'efe2' => isset($data['simulation'][2]['efe']) ? R3NumberFormat($data['simulation'][2]['efe'], 3) : '', 'goal1_reached_total' => isset($data['simulation'][1]['goal_reached']['total']) ? $data['simulation'][1]['goal_reached']['total'] : false, 'goal2_reached_total' => isset($data['simulation'][2]['goal_reached']['total']) ? $data['simulation'][2]['goal_reached']['total'] : false, 'goal1_reached_per_capita' => isset($data['simulation'][1]['goal_reached']['per_capita']) ? $data['simulation'][1]['goal_reached']['per_capita'] : false, 'goal2_reached_per_capita' => isset($data['simulation'][2]['goal_reached']['per_capita']) ? $data['simulation'][2]['goal_reached']['per_capita'] : false, 'message' => $message, 'log' => $log, 'data' => $result); }
public function getData($factor = 1, $returnAsLocale = false) { $lastInventory = $this->data['inventory'][2]['present'] ? 2 : 1; $data = $this->data; // Apply factor for ($i = 1; $i <= 2; $i++) { $inventoryNo = min($i, $lastInventory); if ($this->data['inventory'][$i]['present'] == true) { $data['inventory'][$i]['consumption']['electricity'] = $data['inventory'][$inventoryNo]['consumption']['electricity'] / $factor; $data['inventory'][$i]['consumption']['per_capita'] = $data['inventory'][$inventoryNo]['consumption']['per_capita'] / $factor; $data['inventory'][$i]['emission']['total'] = $data['inventory'][$inventoryNo]['emission']['total'] / $factor; $data['inventory'][$i]['emission']['per_capita'] = $data['inventory'][$inventoryNo]['emission']['per_capita'] / $factor; $data['inventory'][$i]['production']['electricity'] = $data['inventory'][$inventoryNo]['production']['electricity'] / $factor; $data['inventory'][$i]['production']['production_emission'] = $data['inventory'][$inventoryNo]['production']['production_emission'] / $factor; $data['inventory'][$i]['green_energy']['consumption'] = $data['inventory'][$inventoryNo]['green_energy']['consumption'] / $factor; $data['inventory'][$i]['green_energy']['emission'] = $data['inventory'][$inventoryNo]['green_energy']['emission'] / $factor; $data['inventory'][$i]['green_energy']['production'] = $data['inventory'][$inventoryNo]['green_energy']['production'] / $factor; } if (isset($data['simulation'][$i]['emission'])) { $data['simulation'][$i]['emission']['total'] = $data['simulation'][$i]['emission']['total'] / $factor; $data['simulation'][$i]['emission']['per_capita'] = $data['simulation'][$i]['emission']['per_capita'] / $factor; $data['simulation'][$i]['target_emission']['total'] = $data['simulation'][$i]['target_emission']['total'] / $factor; $data['simulation'][$i]['target_emission']['per_capita'] = $data['simulation'][$i]['target_emission']['per_capita'] / $factor; $data['simulation'][$i]['target']['total'] = $data['simulation'][$i]['target']['total'] / $factor; $data['simulation'][$i]['simulation_reduction']['total'] = $data['simulation'][$i]['simulation_reduction']['total'] / $factor; $data['simulation'][$i]['simulation_emission']['total'] = $data['simulation'][$i]['simulation_emission']['total'] / $factor; $data['simulation'][$i]['simulation_emission']['per_capita'] = $data['simulation'][$i]['simulation_emission']['per_capita'] / $factor; $data['simulation'][$i]['renewal_production']['total'] = $data['simulation'][$i]['renewal_production']['total'] / $factor; } } if ($returnAsLocale) { for ($i = 1; $i <= 2; $i++) { $inventoryNo = max($i, $lastInventory); if ($this->data['inventory'][$i]['present'] == true) { $data['inventory'][$i]['population'] = R3NumberFormat($data['inventory'][$i]['population'], 0, true); $data['inventory'][$i]['consumption']['electricity'] = R3NumberFormat($data['inventory'][$i]['consumption']['electricity'], 2, true); $data['inventory'][$i]['consumption']['per_capita'] = R3NumberFormat($data['inventory'][$i]['consumption']['per_capita'], 2, true); $data['inventory'][$i]['emission']['total'] = R3NumberFormat($data['inventory'][$i]['emission']['total'], 2, true); $data['inventory'][$i]['emission']['per_capita'] = R3NumberFormat($data['inventory'][$i]['emission']['per_capita'], 2, true); $data['inventory'][$i]['production']['electricity'] = R3NumberFormat($data['inventory'][$i]['production']['electricity'], 2, true); $data['inventory'][$i]['production']['production_emission'] = R3NumberFormat($data['inventory'][$i]['production']['production_emission'], 2, true); $data['inventory'][$i]['green_energy']['consumption'] = R3NumberFormat($data['inventory'][$i]['green_energy']['consumption'], 2, true); $data['inventory'][$i]['green_energy']['emission'] = R3NumberFormat($data['inventory'][$i]['green_energy']['emission'], 2, true); $data['inventory'][$i]['green_energy']['production'] = R3NumberFormat($data['inventory'][$i]['green_energy']['production'], 2, true); $data['target'][$i]['population'] = R3NumberFormat($data['target'][$i]['population'], 0, true); } if (isset($data['simulation'][$i]['emission'])) { $data['simulation'][$i]['population'] = R3NumberFormat($data['simulation'][$i]['population'], 0, true); $data['simulation'][$i]['emission']['total'] = R3NumberFormat($data['simulation'][$i]['emission']['total'], 2, true); $data['simulation'][$i]['emission']['per_capita'] = R3NumberFormat($data['simulation'][$i]['emission']['per_capita'], 2, true); $data['simulation'][$i]['target_emission']['total'] = R3NumberFormat($data['simulation'][$i]['target_emission']['total'], 2, true); $data['simulation'][$i]['target_emission']['per_capita'] = R3NumberFormat($data['simulation'][$i]['target_emission']['per_capita'], 2, true); $data['simulation'][$i]['target']['total'] = R3NumberFormat($data['simulation'][$i]['target']['total'], 2, true); $data['simulation'][$i]['simulation_reduction']['total'] = R3NumberFormat($data['simulation'][$i]['simulation_reduction']['total'], 2, true); $data['simulation'][$i]['simulation_emission']['total'] = R3NumberFormat($data['simulation'][$i]['simulation_emission']['total'], 2, true); $data['simulation'][$i]['simulation_emission']['per_capita'] = R3NumberFormat($data['simulation'][$i]['simulation_emission']['per_capita'], 2, true); $data['simulation'][$i]['paes_target']['total'] = R3NumberFormat($data['simulation'][$i]['paes_target']['total'], 2, true); $data['simulation'][$i]['paes_target']['per_capita'] = R3NumberFormat($data['simulation'][$i]['paes_target']['per_capita'], 2, true); $data['simulation'][$i]['renewal_production']['total'] = R3NumberFormat($data['simulation'][$i]['renewal_production']['total'], 2, true); $data['simulation'][$i]['renewal_production']['total_perc'] = R3NumberFormat($data['simulation'][$i]['renewal_production']['total_perc'], 2, true); $data['simulation'][$i]['energy_saving']['total_perc'] = R3NumberFormat($data['simulation'][$i]['energy_saving']['total_perc'], 2, true); $data['simulation'][$i]['cost']['total'] = R3NumberFormat($data['simulation'][$i]['cost']['total'], 2, true); $data['simulation'][$i]['cost']['per_capita'] = R3NumberFormat($data['simulation'][$i]['cost']['per_capita'], 2, true); } } } return $data; }
public function generateStatisticClass($request) { $id = (int) $request['id']; if ($request['kind'] == 'absolute') { $field = 'sdt_absolute_value'; $prec = 'st_value_1_prec'; } else { if ($request['kind'] == 'relative') { $field = 'sdt_relative_value'; $prec = 'st_value_2_prec'; } else { throw new Exception("Invalid kind \"{$request['kind']}\""); } } require_once R3_LIB_DIR . 'eco_stat_utils.php'; require_once R3_LIB_DIR . 'stats_quantile_round.php'; $statData = R3EcoGisStatHelper::getStatTypeData($this->do_id, R3EcoGisStatHelper::getStatTypeCodeById($id)); $db = ezcDbInstance::get(); $sql = "SELECT {$field} \n FROM ecogis.stat_data_table sdt\n INNER JOIN ecogis.stat_data sd ON sd.sd_id=sdt.sd_id\n INNER JOIN ecogis.stat_type st ON sd.st_id=st.st_id\n INNER JOIN ecogis.stat_context sc ON sdt.sc_id=sc.sc_id\n WHERE st.do_id={$this->do_id} AND sd.st_id={$id} AND sc_code='MUNICIPALITY' AND gc_id IS NULL AND ges_id IS NULL AND sbpu_id IS NULL AND bby_id IS NULL"; $data = $db->query($sql)->fetchAll(PDO::FETCH_COLUMN); $capabilities = $this->getStatisticCapabilitiesByCode($statData['st_code']); if ($capabilities['is_value_stat']) { $limits = $capabilities['default_class_no']; $limits = getQuantileRoundLimits($data, $limits, $statData[$prec]); $result = array(); $i = 0; $oldValue = null; list($r, $g, $b) = $this->decodeRGB($capabilities['class_start_color']); list($rEnd, $gEnd, $bEnd) = $this->decodeRGB($capabilities['class_end_color']); $deltaR = ($rEnd - $r) / (count($limits) + 1); $deltaG = ($gEnd - $g) / (count($limits) + 1); $deltaB = ($bEnd - $b) / (count($limits) + 1); foreach ($limits as $limit) { $expr = $i == 0 ? "[{$field}]<{$limit}" : "[{$field}]>={$oldValue} AND [{$field}]<{$limit}"; $text1 = $i == 0 ? sprintf('fino a %s', R3NumberFormat($limit, $statData[$prec], true)) : sprintf('tra %s e %s', R3NumberFormat($oldValue, $statData[$prec], true), R3NumberFormat($limit, $statData[$prec], true)); $text2 = $i == 0 ? sprintf('bis %s', R3NumberFormat($limit, $statData[$prec], true)) : sprintf('von %s und %s', R3NumberFormat($oldValue, $statData[$prec], true), R3NumberFormat($limit, $statData[$prec], true)); $result[] = array('stc_color' => '#' . sprintf('%02X%02X%02X', $r, $g, $b), 'stc_outline_color' => '#000000', 'stc_text_1' => $text1, 'stc_text_2' => $text2, 'stc_value' => $limit, 'stc_order' => 10 + $i * 10, 'stc_expression' => $expr); $i++; $oldValue = $limit; $r += $deltaR; $g += $deltaG; $b += $deltaB; } $expr = "[{$field}]>={$oldValue}"; $result[] = array('stc_color' => '#' . sprintf('%02X%02X%02X', $r, $g, $b), 'stc_outline_color' => '#000000', 'stc_text_1' => sprintf('oltre %s', R3NumberFormat($oldValue, $statData[$prec], true)), 'stc_text_2' => sprintf('mehr als %s', R3NumberFormat($oldValue, $statData[$prec], true)), 'stc_value' => $oldValue, 'stc_order' => 10 + $i * 10, 'stc_expression' => $expr); } else { $classData = $this->generateClasses($statData['st_code']); if ($classData == null) { throw new Exception("Impossibile calcolare automaticamente le classi"); } $i = 0; foreach ($classData as $data) { $r = rand(0, 255); $g = rand(0, 255); $b = rand(0, 255); $expr = "[{$field}]={$data['id']}"; $result[] = array('stc_color' => '#' . sprintf('%02X%02X%02X', $r, $g, $b), 'stc_outline_color' => '#000000', 'stc_text_1' => $data['text_1'], 'stc_text_2' => $data['text_1'], 'stc_value' => $data['id'], 'stc_order' => 10 + $i * 10, 'stc_expression' => $expr); $i++; } } return array('status' => R3_AJAX_NO_ERROR, 'data' => $result); }