public static function printWD($wd) { if ($wd) { return Math::wd_round($wd) . ' ' . Yii::app()->params['water_demand_unit']; } return '0 ' . Yii::app()->params['water_demand_unit']; }
</thead> <tbody> <?php foreach ($geom->zones() as $zone) { ?> <tr> <td><?php echo CHtml::encode($zone->zoneDescription) . ' - ' . CHtml::encode($zone->zone_name); ?> </td> <td><?php echo CHtml::encode(Math::pe_round($zone->pe)); ?> </td> <td><?php echo CHtml::encode(Math::wd_round($zone->water_demand)) . ' ' . Yii::app()->params['water_demand_unit']; ?> </td> </tr> <?php } ?> </tbody> </table> </page> <?php } ?> </div> </page>
<?php $ret = array(); foreach ($model->zones() as $zone) { $z = array('wr_id' => $model->wr->id, 'geom_id' => $model->id, 'id' => $zone->id, 'zone' => $zone->zoneDescription, 'pe' => Math::pe_round($zone->pe), 'wd' => Math::wd_round($zone->water_demand) . ' ' . Yii::app()->params['water_demand_unit']); array_push($ret, $z); } echo htmlspecialchars(json_encode($ret), ENT_NOQUOTES);
?> :</b> <?php echo CHtml::encode(Math::wd_round($data->total_water_demand) . ' ' . Yii::app()->params['water_demand_unit']); ?> <br /> <?php if (Yii::app()->user->checkAccess('updateWaterDemandInWaterRequest')) { ?> <b><?php echo CHtml::encode($data->getAttributeLabel('effective_water_demand')); ?> :</b> <?php echo CHtml::encode(Math::wd_round($data->effective_water_demand) . ' ' . Yii::app()->params['water_demand_unit']); ?> <br /> <?php } ?> <?php if ($data->phase == 1 and ($data->status == WaterRequests::SW_NODE(WaterRequests::SUBMITTED_STATUS) and Yii::app()->user->isPlanner)) { echo CHtml::link(Yii::t('waterrequest', 'Move on Executive Phase'), array('waterRequests/create', 'phase' => 2, 'parent' => $data->id)); } ?> <div class="water_request_operation"> <?php
} ?> <div class="accordion" id="geom_<?php echo $geom->id; ?> "> <h6 class="<?php echo $class; ?> "> <?php echo $geom->name; ?> – <?php echo Math::wd_round($geom->geom_water_demand) . ' ' . Yii::app()->params['water_demand_unit']; ?> </h6> <span style="display: inline-block; text-align: right; float:right;"> <?php if (!$view) { /* echo CHtml::ajaxLink( ' ', array('waterRequestGeometryZones/popup', 'wr_id'=>$model->id,'type'=>'zone','geom_or_id'=>$geom->id), array( 'success'=>'function(html) { //$("#add_zone_popup").find(".overlayContent").html(html); $("#mycontent").html(html); doOverlayOpen("zone","'.$geom->id.'"); }'
public function updatePEAndWD($parameter = null, $value = null, $geom = null, &$info = null) { //retrieve city_state $g = isset($geom) ? $geom : $this->wr_geometry_id; $service_area = Geometry::Get_Service_Area_Detailed($g); $city_state = Geometry::Get_City_State($g); if ($city_state == null) { Yii::log('Comune non trovato. $g=' . $g, CLogger::LEVEL_INFO, 'updatePEAndWD'); // DEBUG if (isset($info)) { $info['city'] = '--'; $info['service_area'] = '--'; $info['water_demand'] = -1; $info['margin'] = -1; $info['maximum_water_supply'] = -1; $info['scenari'] = null; } return; } $water_supply = WaterSupply::model()->find('lower(city_state)=:city_state', array(':city_state' => strtolower($city_state))); if (!$water_supply) { Yii::log('Manca la WaterSupply. $city_state=' . $city_state, CLogger::LEVEL_INFO, 'updatePEAndWD'); // DEBUG return; } $dg = $water_supply->daily_maximum_water_supply; $da = $water_supply->yearly_average_water_supply; if (!isset($parameter) || !isset($value)) { $p = null; $v = null; foreach ($this->properties as $property) { if ($property->use4ae) { $p = $property->parameter; $v = $property->value; break; } } } else { $p = $parameter; $v = $value; } if ($p === null) { $this->pe = 0; } else { //calculate PE $zone = $this->zone_name; while ($zone != null) { $conversion_index = ZonesWaterRequestParameters::model()->active_parameters()->find('parameter=:parameter AND zone=:zone', array(':parameter' => $p, ':zone' => $zone)); if ($conversion_index) { break; } $zone = Zones::parentZone($zone); } if (strcmp($p, $conversion_index->parameter) == 0) { if (is_numeric($conversion_index->value)) { $val = $conversion_index->value; $this->pe = $v * $val; } else { $val = str_ireplace(array('dg', 'da'), array($dg, $da), $conversion_index->value); //TODO: mettere nel config il valore delle stringe dg e da try { $val = Math::safe_eval($val); $ret = $v * $val; if (is_numeric($ret)) { $this->pe = $ret; } else { $this->pe = -1; } } catch (Exception $e) { $this->pe = 0; Yii::log('PE Error. $conversion_index=' . $conversion_index->parameter . '|' . $conversion_index->value, CLogger::LEVEL_INFO, 'updatePEAndWD'); // DEBUG } } } else { $this->pe = 0; } } $formula = $this->zone->formula; $fformula = $formula->formula; /* if (stripos($formula->formula,Yii::app()->params['formulas']['pe'])!==false) { $fformula = str_ireplace(Yii::app()->params['formulas']['pe'],$this->pe,$fformula); } if (stripos($formula->formula,Yii::app()->params['formulas']['dg'])!==false) { $fformula = str_ireplace(Yii::app()->params['formulas']['dg'],$dg,$fformula); } if (stripos($formula->formula,Yii::app()->params['formulas']['da'])!==false) { $fformula = str_ireplace(Yii::app()->params['formulas']['da'],$da,$fformula); }*/ foreach ($this->properties() as $property) { if (stripos($formula->formula, $property->parameter) !== false) { $fformula = str_ireplace($property->parameter, $property->value, $fformula); } } if (stripos($formula->formula, Yii::app()->params['formulas']['da']) !== false) { $fformula = str_ireplace(Yii::app()->params['formulas']['da'], $da, $fformula); } if (stripos($formula->formula, Yii::app()->params['formulas']['dg']) !== false) { $fformula = str_ireplace(Yii::app()->params['formulas']['dg'], $dg, $fformula); } $fformula_with_pe = null; if (stripos($formula->formula, Yii::app()->params['formulas']['pe']) !== false) { $fformula_with_pe = $fformula; $fformula = str_ireplace(Yii::app()->params['formulas']['pe'], $this->pe, $fformula); } try { $ret = Math::safe_eval($fformula); if (is_numeric($ret)) { $this->water_demand = $ret; } else { $this->water_demand = -1; } } catch (Exception $e) { $this->water_demand = 0; Yii::log('WD Error. $fformula=' . $fformula, CLogger::LEVEL_INFO, 'updatePEAndWD'); // DEBUG } if (isset($info)) { $info['city'] = ucwords(strtolower($city_state)); $info['water_demand'] = Math::wd_round($this->water_demand) . ' ' . Yii::app()->params['water_demand_unit']; if ($service_area == null) { $info['service_area'] = '--'; $operative_margin = DummyOperativeMargin::model()->findAll('lower(area)=:area', array(':area' => strtolower($city_state))); if (count($operative_margin) == 0) { Yii::log('Manca il margine operativo del comune. area=' . $city_state, CLogger::LEVEL_INFO, 'updatePEAndWD'); // DEBUG return; } } else { //var_dump($service_area); $info['service_area'] = ucwords(strtolower($service_area['desc_area'])); /*TODO: cambiare il $service_area*/ $operative_margin = DummySAOperativeMargin::model()->findAll('lower(area)=:area', array(':area' => strtolower($service_area['area']))); if (count($operative_margin) == 0) { Yii::log('Manca il margine operativo dell\'area di servizio. area=' . $city_state, CLogger::LEVEL_INFO, 'updatePEAndWD'); // DEBUG return; } } $actual_margin = null; foreach ($operative_margin as $op) { if ($op->scenario == null) { $actual_margin = Math::margin_round($op->margin); break; } } if ($actual_margin == null) { Yii::log('Manca il margine operativo attuale. area=' . $city_state, CLogger::LEVEL_INFO, 'updatePEAndWD'); // DEBUG $actual_margin = 0; } if ($this->water_demand > $actual_margin) { $info['margin'] = -1; } else { if ($this->water_demand > $actual_margin - $actual_margin * (int) Yii::app()->params['water_demand_range'] / 100) { $info['margin'] = 0; } else { $info['margin'] = 1; } } $info['maximum_water_supply'] = Math::margin_round($actual_margin) . ' ' . Yii::app()->params['water_demand_unit']; if ($fformula_with_pe != null) { $info['max_parameter'] = array(); $info['max_parameter']['name'] = $p; $fformula_with_pe = str_ireplace(Yii::app()->params['formulas']['pe'], 1 / $actual_margin, $fformula_with_pe); try { $ret = Math::safe_eval($fformula_with_pe); if (is_numeric($ret)) { $max_pe = 1 / $ret; } else { $max_pe = -1; } } catch (Exception $e) { $max_pe = -1; Yii::log('MAX PE Error. $fformula_with_pe=' . $fformula_with_pe, CLogger::LEVEL_INFO, 'updatePEAndWD'); // DEBUG } if ($max_pe > 0) { $info['max_parameter']['value'] = $max_pe / $val; } else { $info['max_parameter']['value'] = -1; } } $info['scenari'] = array(); foreach ($operative_margin as $op) { if ($op->scenario == null) { continue; } $item = array(); $item['scenario'] = $op->scenario; $item['maximum_water_supply'] = Math::margin_round($op->margin) . ' ' . Yii::app()->params['water_demand_unit']; if ($this->water_demand > $op->margin) { $item['margin'] = -1; } else { if ($this->water_demand > $op->margin - $op->margin * (int) Yii::app()->params['water_demand_range'] / 100) { $item['margin'] = 0; } else { $item['margin'] = 1; } } array_push($info['scenari'], $item); } } return; }
/** * */ public function getRounded_water_demand() { return Math::wd_round($this->total_water_demand); }
public static function feasibilityCheck($geom_id, $wd) { //Yii::log('geom_id= '.print_r($geom_id, true).' wd= '.print_r($wd, true), CLogger::LEVEL_INFO, 'feasibilitycheck()'); // DEBUG $ret = array(); $service_area = Geometry::Get_Service_Area_Detailed($geom_id); $city_state = Geometry::Get_City_State($geom_id); //Yii::log('city_state= '.print_r($city_state, true).' wd= '.print_r($wd, true), CLogger::LEVEL_INFO, 'feasibilitycheck()'); // DEBUG if ($city_state == null || $wd == null) { $ret['sarea'] = null; $ret['city'] = '--'; $ret['scenari'] = null; $ret['margin'] = -1; $ret['maximum_water_supply'] = -1; return $ret; } $ret['city'] = ucwords(strtolower($city_state)); // uso city_state ma potrei usare service_area->desc_area se Get_Service_Area ritornasse un array if (!$service_area) { $ret['sarea'] = null; $water_supply = DummyOperativeMargin::model()->findAll('lower(area)=:area', array(':area' => strtolower($city_state)), array('limit' => 3)); if (!$water_supply) { Yii::log('Cannot find Operative Margin for $city_state=' . $city_state, CLogger::LEVEL_INFO, 'feasibilityCheck'); // DEBUG $ret['scenari'] = null; $ret['margin'] = -1; $ret['maximum_water_supply'] = -1; return $ret; } } else { $ret['sarea'] = $service_area['desc_area']; $water_supply = DummySAOperativeMargin::model()->findAll('lower(area)=:area', array(':area' => strtolower($service_area['area'])), array('limit' => 3)); } $ret['scenari'] = array(); foreach ($water_supply as $ws) { //Yii::log(print_r($ws->attributes, true), CLogger::LEVEL_INFO, 'foreach'); // DEBUG $operative_margin = $ws->margin; if ($ws->scenario == null) { $ret['maximum_water_supply'] = Math::wd_round($operative_margin); if ($wd > $operative_margin) { $ret['margin'] = -1; } else { if ($wd > $operative_margin - (int) Yii::app()->params['water_demand_range']) { $ret['margin'] = 0; } else { $ret['margin'] = 1; } } } else { $item = array(); $item['scenario'] = $ws->scenario; $item['maximum_water_supply'] = Math::wd_round($operative_margin); if ($wd > $operative_margin) { $item['margin'] = -1; } else { if ($wd > $operative_margin - (int) Yii::app()->params['water_demand_range']) { $item['margin'] = 0; } else { $item['margin'] = 1; } } array_push($ret['scenari'], $item); } } return $ret; }
$attr = array('label' => $model->getAttributeLabel('parent_water_demand_usage'), 'value' => Math::wd_percentage_round($model->total_water_demand / $model->parent_wr->total_water_demand * 100) . ' %'); array_push($attributes, $attr); } if ($model->phase == 2) { $attr = array('label' => $model->getAttributeLabel('expiration_date'), 'value' => $model->expiration_date); array_push($attributes, $attr); } // TODO: Perche' solo i WRU possono vedere il costo? Il costo viene assegnato da WRU quando approva una richiesta. if (Yii::app()->user->isWRU) { $attr = array('label' => $model->getAttributeLabel('cost'), 'value' => $model->cost . ' ' . Yii::app()->params['currency']); array_push($attributes, $attr); $attr = array('label' => $model->getAttributeLabel('file_link'), 'type' => 'raw', 'value' => CHtml::link($model->file_link, Yii::app()->params['transition']['upload_dir'] . '/' . $model->file_link)); array_push($attributes, $attr); } if (Yii::app()->user->checkAccess('updateWaterDemandInWaterRequest')) { $attr = array('label' => $model->getAttributeLabel('effective_water_demand'), 'value' => Math::wd_round($model->effective_water_demand)); array_push($attributes, $attr); } $this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => $attributes)); ?> <script type="text/javascript"> /* <![CDATA[ */ function infoHistory(elem, wr_id) { $('.info_history').remove(); var url = <?php echo CJSON::encode(CController::createUrl('waterRequests/infoHistory')); ?> ; $.ajax({ url: url, cache: false,
<div id="parent_percent"> <?php $usage = $model->getParentWDUsage(); if ($model->parent_wr->total_water_demand <= 0) { $percentage = 100; } else { $percentage = Math::wd_percentage_round($usage / $model->parent_wr->total_water_demand * 100); } $amount = Math::wd_round($usage) . ' ' . Yii::app()->params['water_demand_unit'] . ' / ' . Math::wd_percentage_round($model->parent_wr->total_water_demand) . ' ' . Yii::app()->params['water_demand_unit'] . ' ( ' . $percentage . '%)'; if ($percentage < 35) { $pb_class = 'pb_ok'; } else { if ($percentage < 70) { $pb_class = 'pb_notice'; } else { $pb_class = 'pb_ko'; } } $this->widget('zii.widgets.jui.CJuiProgressBar', array('id' => 'progress', 'value' => $percentage, 'htmlOptions' => array('style' => 'height:22px;width:300px;float:left; margin-right: 10px;', 'class' => $pb_class))); echo '<div id="amount" style="padding:3px;">' . $amount . '</div>'; ?> </div>