/** * Creates a new Compare model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreatedraw() { $model = new Compare(); if (Yii::$app->request->post()) { ini_set("memory_limit", "-1"); /*** * Langkah - langkah mengambil data kesesuaian lahan * 1. INTERSECTS (TRUE | FALSE) * 2. INTERSECTION (Kesesuain To Geom from draw) * * S = geom from draw * B = Hasil intersects **/ $get_intersection = "SELECT b.*, ST_AsGeojson(ST_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))) as geom from (select kesesuaian.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),kesesuaian.geom)as touch from kesesuaian where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),kesesuaian.geom) = true) as b;"; $value_intersections = Yii::$app->db->createCommand($get_intersection)->queryAll(); $area_of_interest = "SELECT ST_AsGeoJson(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))"; $aoi = Yii::$app->db->createCommand($area_of_interest)->queryAll(); /*** * Get Average Geometry Climate **/ $climate_ag = ClimateAG::find()->OrderBy('id DESC')->one(); $landnp_ag = LandnpeatAG::find()->OrderBy('id DESC')->one(); $landp_ag = LandpeatAG::find()->OrderBy('id DESC')->one(); $accessibility_ag = AccessibilityAG::find()->OrderBy('id DESC')->one(); /*** * Get Average Geometry Factor **/ $factors_ag = FactorsAG::find()->OrderBy('id DESC')->one(); /* Deklarasi variable result geojson */ $result_geojson = '{"type": "FeatureCollection","features": ['; if (isset($climate_ag)) { if (isset($landnp_ag)) { if (isset($landp_ag)) { if (isset($accessibility_ag)) { if (isset($factors_ag)) { for ($i = 0; $i < count($value_intersections); $i++) { $kesesuaian_climate = $value_intersections[$i]['scorech'] * ($climate_ag->bobot_ch * $factors_ag->bobot_climate) + $value_intersections[$i]['scoresuhu'] * ($climate_ag->boobt_temp * $factors_ag->bobot_climate) + $value_intersections[$i]['scoredry'] * ($climate_ag->bobot_dm * $factors_ag->bobot_climate); $status_climate = 'N'; if ($kesesuaian_climate >= 0 and $kesesuaian_climate <= 1) { $status_climate = 'N'; } elseif ($kesesuaian_climate > 1 and $kesesuaian_climate <= 2) { $status_climate = 'S3'; } elseif ($kesesuaian_climate > 2 and $kesesuaian_climate <= 3) { $status_climate = 'S2'; } elseif ($kesesuaian_climate > 3 and $kesesuaian_climate <= 4) { $status_climate = 'S1'; } else { $status_climate = 'S(alah)'; } $result_geojson .= "{\"type\": \"Feature\",\"properties\": {\"kesesuaian_climate\":\"" . $kesesuaian_climate . "\", \"status_climate\":\"" . $status_climate . "\"},\"geometry\": "; $result_geojson .= $value_intersections[$i]['geom']; $result_geojson .= "},"; } $result_geojson .= ']}'; $result_data = substr($result_geojson, 0, -3) . ' ]}'; /* Convert WKT to Geom */ $query_geom_from_wkt = "SELECT ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326), ST_Area(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))"; $result_geom_from_wkt = Yii::$app->db->createCommand($query_geom_from_wkt)->queryAll(); /* Climate Rainfall */ $get_rainfall = "SELECT b.scorech as scorech,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.scorech;"; $value_rainfall = Yii::$app->db->createCommand($get_rainfall)->queryAll(); $result_geojson_rain = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_rainfall); $i++) { $scorech = $value_rainfall[$i]['scorech']; $status_rainfall = ' '; if ($scorech <= 1) { $status_rainfall = '< 1250, > 4000'; } elseif ($scorech <= 2 and $scorech > 1) { $status_rainfall = '1250 - 1450, 3500 - 4000'; } elseif ($scorech <= 3 and $scorech > 2) { $status_rainfall = '1450 - 1700, 2500 - 3500'; } elseif ($scorech <= 4 and $scorech > 3) { $status_rainfall = '1700 - 2500'; } else { $status_rainfall = 'S(alah)'; } $result_geojson_rain .= "{\"type\": \"Feature\",\"properties\": {\"scorech\":\"" . $scorech . "\", \"status_rainfall\":\"" . $status_rainfall . "\"},\"geometry\": "; $result_geojson_rain .= $value_rainfall[$i]['geom']; $result_geojson_rain .= "},"; } $result_geojson_rain .= ']}'; $result_data_rain = substr($result_geojson_rain, 0, -3) . ' ]}'; /* Climate Temperature */ $get_temperature = "SELECT b.scoresuhu as scoresuhu, ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.scoresuhu;"; $value_temperature = Yii::$app->db->createCommand($get_temperature)->queryAll(); $result_geojson_temp = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_temperature); $i++) { $scoresuhu = $value_temperature[$i]['scoresuhu']; $status_temperature = ' '; if ($scoresuhu <= 1) { $status_temperature = '< 20, > 35'; } elseif ($scoresuhu <= 2 and $scoresuhu > 1) { $status_temperature = '20 - 22, 32 - 35 '; } elseif ($scoresuhu <= 3 and $scoresuhu > 2) { $status_temperature = '22 - 25, 28 - 32'; } elseif ($scoresuhu <= 4 and $scoresuhu > 3) { $status_temperature = '25 - 28'; } else { $status_temperature = 'S(alah)'; } $result_geojson_temp .= "{\"type\": \"Feature\",\"properties\": {\"scoresuhu\":\"" . $scoresuhu . "\", \"status_temperature\":\"" . $status_temperature . "\"},\"geometry\": "; $result_geojson_temp .= $value_temperature[$i]['geom']; $result_geojson_temp .= "},"; } $result_geojson_temp .= ']}'; $result_data_temp = substr($result_geojson_temp, 0, -3) . ' ]}'; /* Climate Dry Month */ $get_drymonth = "SELECT b.scoredry as scoredry ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.scoredry;"; $value_drymonth = Yii::$app->db->createCommand($get_drymonth)->queryAll(); $result_geojson_dm = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_drymonth); $i++) { $scoredry = $value_drymonth[$i]['scoredry']; $status_drymonth = '> 4'; if ($scoredry <= 1) { $status_drymonth = '> 4'; } elseif ($scoredry <= 2 and $scoredry > 1) { $status_drymonth = '3 – 4'; } elseif ($scoredry <= 3 and $scoredry > 2) { $status_drymonth = '3 – 2'; } elseif ($scoredry <= 4 and $scoredry > 3) { $status_drymonth = '< 2'; } else { $status_drymonth = 'S(alah)'; } $result_geojson_dm .= "{\"type\": \"Feature\",\"properties\": {\"scoredry\":\"" . $scoredry . "\", \"status_drymonth\":\"" . $status_drymonth . "\"},\"geometry\": "; $result_geojson_dm .= $value_drymonth[$i]['geom']; $result_geojson_dm .= "},"; } $result_geojson_dm .= ']}'; $result_data_dm = substr($result_geojson_dm, 0, -3) . ' ]}'; /* Land slope */ $get_slope = "SELECT b.score_lrg as score_lrg ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_lrg order by b.score_lrg asc;"; $value_slope = Yii::$app->db->createCommand($get_slope)->queryAll(); $result_geojson_slp = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_slope); $i++) { $score_lrg = $value_slope[$i]['score_lrg']; $status_slope = '>30'; if ($score_lrg <= 1) { $status_slope = '>30'; } elseif ($score_lrg <= 2 and $score_lrg > 1) { $status_slope = '16 - 30'; } elseif ($score_lrg <= 3 and $score_lrg > 2) { $status_slope = '8 - 16'; } elseif ($score_lrg <= 4 and $score_lrg > 3) { $status_slope = '<8'; } else { $status_slope = 'S(alah)'; } $result_geojson_slp .= "{\"type\": \"Feature\",\"properties\": {\"score_lrg\":\"" . $score_lrg . "\", \"status_slope\":\"" . $status_slope . "\"},\"geometry\": "; $result_geojson_slp .= $value_slope[$i]['geom']; $result_geojson_slp .= "},"; } $result_geojson_slp .= ']}'; $result_data_slp = substr($result_geojson_slp, 0, -3) . ' ]}'; /* Land Non Peat Texture */ $get_texture = "SELECT b.score_text as score_text ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_text;"; $value_texture = Yii::$app->db->createCommand($get_texture)->queryAll(); $result_geojson_txt = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_texture); $i++) { $score_text = $value_texture[$i]['score_text']; $status_texture = 'Peat Area'; if ($score_text <= 1) { $status_texture = 'Coarse'; } elseif ($score_text <= 2 and $score_text > 1) { $status_texture = 'Slightly Coarse'; } elseif ($score_text <= 3 and $score_text > 2) { $status_texture = '–'; } elseif ($score_text <= 4 and $score_text > 3) { $status_texture = 'Fine, Slightly fine, Medium'; } else { $status_texture = 'S(alah)'; } $result_geojson_txt .= "{\"type\": \"Feature\",\"properties\": {\"score_text\":\"" . $score_text . "\", \"status_texture\":\"" . $status_texture . "\"},\"geometry\": "; $result_geojson_txt .= $value_texture[$i]['geom']; $result_geojson_txt .= "},"; } $result_geojson_txt .= ']}'; $result_data_txt = substr($result_geojson_txt, 0, -3) . ' ]}'; /* Land Non Peat Elevation */ $get_elevation = "SELECT b.score_elev as score_elev ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_elev;"; $value_elevation = Yii::$app->db->createCommand($get_elevation)->queryAll(); $result_geojson_elev = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_elevation); $i++) { $score_elev = $value_elevation[$i]['score_elev']; $status_elevation = 'Peat Area'; if ($score_elev <= 1) { $status_elevation = '> 400'; } elseif ($score_elev <= 2 and $score_elev > 1) { $status_elevation = '300 - 400'; } elseif ($score_elev <= 3 and $score_elev > 2) { $status_elevation = '200 - 300'; } elseif ($score_elev <= 4 and $score_elev > 3) { $status_elevation = '0 - 200'; } else { $status_elevation = 'S(alah)'; } $result_geojson_elev .= "{\"type\": \"Feature\",\"properties\": {\"score_elev\":\"" . $score_elev . "\", \"status_elevation\":\"" . $status_elevation . "\"},\"geometry\": "; $result_geojson_elev .= $value_elevation[$i]['geom']; $result_geojson_elev .= "},"; // print_r($status_elevation); } // die; $result_geojson_elev .= ']}'; $result_data_elev = substr($result_geojson_elev, 0, -3) . ' ]}'; /* Land Peat Thickness */ $get_thickness = "SELECT b.scoredept as scoredept ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.scoredept;"; $value_thickness = Yii::$app->db->createCommand($get_thickness)->queryAll(); $result_geojson_thick = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_thickness); $i++) { $scoredept = $value_thickness[$i]['scoredept']; $status_thickness = 'Non Peat Area'; if ($scoredept <= 1 and $scoredept > 0) { $status_thickness = '< 140'; } elseif ($scoredept <= 2 and $scoredept > 1) { $status_thickness = '140 – 200'; } elseif ($scoredept <= 3 and $scoredept > 2) { $status_thickness = '200 – 400'; } elseif ($scoredept <= 4 and $scoredept > 3) { $status_thickness = '> 400'; } else { $status_thickness = 'S(alah)'; } $result_geojson_thick .= "{\"type\": \"Feature\",\"properties\": {\"scoredept\":\"" . $scoredept . "\", \"status_thickness\":\"" . $status_thickness . "\"},\"geometry\": "; $result_geojson_thick .= $value_thickness[$i]['geom']; $result_geojson_thick .= "},"; } $result_geojson_thick .= ']}'; $result_data_thick = substr($result_geojson_thick, 0, -3) . ' ]}'; /* Land Peat Ripe */ $get_ripening = "SELECT b.scoreripe as scoreripe ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.scoreripe;"; $value_ripening = Yii::$app->db->createCommand($get_ripening)->queryAll(); $result_geojson_ripe = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_ripening); $i++) { $scoreripe = $value_ripening[$i]['scoreripe']; $status_ripening = 'Non Peat Area'; if ($scoreripe <= 1 and $scoreripe > 0) { $status_ripening = 'Sapric*'; } elseif ($scoreripe <= 2 and $scoreripe > 1) { $status_ripening = 'Sapric, Hemic*'; } elseif ($scoreripe <= 3 and $scoreripe > 2) { $status_ripening = 'Hemic, Fibric*'; } elseif ($scoreripe <= 4 and $scoreripe > 3) { $status_ripening = 'Fibric'; } else { $status_ripening = 'S(alah)'; } $result_geojson_ripe .= "{\"type\": \"Feature\",\"properties\": {\"scoreripe\":\"" . $scoreripe . "\", \"status_ripening\":\"" . $status_ripening . "\"},\"geometry\": "; $result_geojson_ripe .= $value_ripening[$i]['geom']; $result_geojson_ripe .= "},"; } $result_geojson_ripe .= ']}'; $result_data_ripe = substr($result_geojson_ripe, 0, -3) . ' ]}'; /* Accessibility Distance From Road */ $get_road = "SELECT b.score_road as score_road ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_road;"; $value_road = Yii::$app->db->createCommand($get_road)->queryAll(); $result_geojson_rod = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_road); $i++) { $score_road = $value_road[$i]['score_road']; $status_road = '-'; if ($score_road <= 1 and $score_road > 0) { $status_road = '-'; } elseif ($score_road <= 2 and $score_road > 1) { $status_road = '> 10 Km'; } elseif ($score_road <= 3 and $score_road > 2) { $status_road = '5 - 10 Km'; } elseif ($score_road <= 4 and $score_road > 3) { $status_road = '0 - 5 Km'; } else { $status_road = 'S(alah)'; } $result_geojson_rod .= "{\"type\": \"Feature\",\"properties\": {\"score_road\":\"" . $score_road . "\", \"status_road\":\"" . $status_road . "\"},\"geometry\": "; $result_geojson_rod .= $value_road[$i]['geom']; $result_geojson_rod .= "},"; } $result_geojson_rod .= ']}'; $result_data_rod = substr($result_geojson_rod, 0, -3) . ' ]}'; /* Accessibility Distance From Mills */ $get_mills = "SELECT b.score_mill as score_mill ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_mill;"; $value_mills = Yii::$app->db->createCommand($get_mills)->queryAll(); $result_geojson_mls = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_mills); $i++) { $score_mill = $value_mills[$i]['score_mill']; $status_mills = '-'; if ($score_mill <= 1 and $score_mill > 0) { $status_mills = '-'; } elseif ($score_mill <= 2 and $score_mill > 1) { $status_mills = '> 10 Km'; } elseif ($score_mill <= 3 and $score_mill > 2) { $status_mills = '5 - 10 Km'; } elseif ($score_mill <= 4 and $score_mill > 3) { $status_mills = '0 - 5 Km'; } else { $status_mills = 'S(alah)'; } $result_geojson_mls .= "{\"type\": \"Feature\",\"properties\": {\"score_mill\":\"" . $score_mill . "\", \"status_mills\":\"" . $status_mills . "\"},\"geometry\": "; $result_geojson_mls .= $value_mills[$i]['geom']; $result_geojson_mls .= "},"; } $result_geojson_mls .= ']}'; $result_data_mls = substr($result_geojson_mls, 0, -3) . ' ]}'; /* Accessibility Distance From town */ $get_town = "SELECT b.score_town as score_town ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_town;"; $value_town = Yii::$app->db->createCommand($get_town)->queryAll(); $result_geojson_twn = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_town); $i++) { $score_town = $value_town[$i]['score_town']; $status_town = '-'; if ($score_town <= 1 and $score_town > 0) { $status_town = '-'; } elseif ($score_town <= 2 and $score_town > 1) { $status_town = '> 10 Km'; } elseif ($score_town <= 3 and $score_town > 2) { $status_town = '5 - 10 Km'; } elseif ($score_town <= 4 and $score_town > 3) { $status_town = '0 - 5 Km'; } else { $status_town = 'S(alah)'; } $result_geojson_twn .= "{\"type\": \"Feature\",\"properties\": {\"score_town\":\"" . $score_town . "\", \"status_town\":\"" . $status_town . "\"},\"geometry\": "; $result_geojson_twn .= $value_town[$i]['geom']; $result_geojson_twn .= "},"; } $result_geojson_twn .= ']}'; $result_data_twn = substr($result_geojson_twn, 0, -3) . ' ]}'; } else { return $this->redirect(['nodata', 'id' => $model->id]); } } else { return $this->redirect(['nodata', 'id' => $model->id]); } } else { return $this->redirect(['nodata', 'id' => $model->id]); } } else { return $this->redirect(['nodata', 'id' => $model->id]); } } else { return $this->redirect(['nodata', 'id' => $model->id]); } /* Convert m2 to Ha (Ha = m2 ÷ 10,000)*/ $data_st_area = $result_geom_from_wkt[0]['st_area']; /* Intervensi POST with result */ $_POST['Compare']['data'] = $result_data; $_POST['Compare']['geom'] = $result_geom_from_wkt[0]['st_geomfromtext']; $_POST['Compare']['st_area'] = $data_st_area; $_POST['Compare']['data_rain'] = $result_data_rain; $_POST['Compare']['data_temp'] = $result_data_temp; $_POST['Compare']['data_dm'] = $result_data_dm; $_POST['Compare']['data_slope'] = $result_data_slp; $_POST['Compare']['data_text'] = $result_data_txt; $_POST['Compare']['data_elev'] = $result_data_elev; $_POST['Compare']['data_thick'] = $result_data_thick; $_POST['Compare']['data_ripe'] = $result_data_ripe; $_POST['Compare']['data_road'] = $result_data_rod; $_POST['Compare']['data_mills'] = $result_data_mls; $_POST['Compare']['data_town'] = $result_data_twn; if (!Yii::$app->user->isGuest) { $_POST['Compare']['id_user'] = Yii::$app->user->identity->id; } if ($model->load($_POST) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { echo "error"; } } else { $get_geojson_kecamatan = "SELECT *, ST_AsGeoJson(geom), ST_X(ST_Centroid(geom)), ST_Y(ST_Centroid(geom)) FROM admin"; $data_admin = Yii::$app->db->createCommand($get_geojson_kecamatan)->queryAll(); $get_bbox = "SELECT ST_AsGeoJson(Box2D(ST_Union(geom))) FROM admin"; $bbox_geojsons = Yii::$app->db->createCommand($get_bbox)->queryColumn(); $bbox_geojson = $bbox_geojsons[0]; return $this->render('createdraw', ['model' => $model, 'data_admin' => $data_admin, 'bbox_geojson' => $bbox_geojson]); } }
/** * Creates a new Climate model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Climate(); if (Yii::$app->request->post()) { $ch_temp = $_POST['Climate']['ch_temp']; $temp_ch = 1 / $ch_temp; $ch_ch = 1; $temp_dm = $_POST['Climate']['temp_dm']; $dm_temp = 1 / $temp_dm; $temp_temp = 1; $ch_dm = $_POST['Climate']['ch_dm']; $dm_ch = 1 / $ch_dm; $dm_dm = 1; $sum_column_ch = $ch_ch + $temp_ch + $dm_ch; $sum_column_temp = $ch_temp + $temp_temp + $dm_temp; $sum_column_dm = $ch_dm + $temp_dm + $dm_dm; /* ---- */ $divided_sum_sum = $sum_column_ch / $sum_column_ch; $divided_ch_ch_sum = $ch_ch / $sum_column_ch; $divided_ch_temp_sum = $temp_ch / $sum_column_ch; $divided_ch_dm_sum = $dm_ch / $sum_column_ch; $divided_temp_ch_sum = $ch_temp / $sum_column_temp; $divided_temp_temp_sum = $temp_temp / $sum_column_temp; $divided_temp_dm_sum = $dm_temp / $sum_column_temp; $divided_dm_ch_sum = $ch_dm / $sum_column_dm; $divided_dm_temp_sum = $temp_dm / $sum_column_dm; $divided_dm_dm_sum = $dm_dm / $sum_column_dm; /* ---- */ $sum_ch = $divided_ch_ch_sum + $divided_temp_ch_sum + $divided_dm_ch_sum; $sum_temp = $divided_ch_temp_sum + $divided_temp_temp_sum + $divided_dm_temp_sum; $sum_dm = $divided_ch_dm_sum + $divided_temp_dm_sum + $divided_dm_dm_sum; $sum_divided = $divided_sum_sum + $divided_sum_sum + $divided_sum_sum; /* ---- */ $bobot_ch = $sum_ch / $sum_divided; $bobot_temp = $sum_temp / $sum_divided; $bobot_dm = $sum_dm / $sum_divided; /* ---- */ /* ---- */ $multiple_ch_ch_bobot = $ch_ch * $bobot_ch; $multiple_ch_temp_bobot = $temp_ch * $bobot_ch; $multiple_ch_dm_bobot = $dm_ch * $bobot_ch; $multiple_temp_ch_bobot = $ch_temp * $bobot_temp; $multiple_temp_temp_bobot = $temp_temp * $bobot_temp; $multiple_temp_dm_bobot = $dm_temp * $bobot_temp; $multiple_dm_ch_bobot = $ch_dm * $bobot_dm; $multiple_dm_temp_bobot = $temp_dm * $bobot_dm; $multiple_dm_dm_bobot = $dm_dm * $bobot_dm; /* ---- */ /* ---- */ $sum_bobot_ch = $multiple_ch_ch_bobot + $multiple_temp_ch_bobot + $multiple_dm_ch_bobot; $sum_bobot_temp = $multiple_ch_temp_bobot + $multiple_temp_temp_bobot + $multiple_dm_temp_bobot; $sum_bobot_dm = $multiple_ch_dm_bobot + $multiple_temp_dm_bobot + $multiple_dm_dm_bobot; /* ---- */ $divided_bobot_ch = $sum_bobot_ch / $bobot_ch; $divided_bobot_temp = $sum_bobot_temp / $bobot_temp; $divided_bobot_dm = $sum_bobot_dm / $bobot_dm; /* ---- */ $lamda_max = ($divided_bobot_ch + $divided_bobot_temp + $divided_bobot_dm) / $sum_divided; $jumlah_factor = $sum_divided; $consistensi_index = ($lamda_max - $jumlah_factor) / ($jumlah_factor - 1); $rasio_index = 0.58; $consistensi_rasio = $consistensi_index / $rasio_index; /* ---- */ if ($consistensi_rasio < 0.1) { $validation = TRUE; } else { $validation = FALSE; } if (Yii::$app->user->getId()) { $_POST['Climate']['ch_temp'] = $ch_temp; $_POST['Climate']['ch_dm'] = $ch_dm; $_POST['Climate']['temp_dm'] = $temp_dm; $_POST['Climate']['bobot_ch'] = $bobot_ch; $_POST['Climate']['boobt_temp'] = $bobot_temp; $_POST['Climate']['bobot_dm'] = $bobot_dm; $_POST['Climate']['cr'] = $consistensi_rasio; $_POST['Climate']['validation'] = $validation; $_POST['Climate']['id_user'] = Yii::$app->user->getId(); if ($model->load($_POST) && $model->save()) { $data_climates = Climate::find()->where(['validation' => TRUE])->AsArray()->All(); $ch_temp_ag_base = []; $ch_dm_ag_base = []; $temp_dm_ag_base = []; $bobot_ch_ag_base = []; $bobot_temp_ag_base = []; $bobot_dm_ag_base = []; $consistensi_rasio_ag_base = []; for ($i = 0; $i < count($data_climates); $i++) { $ch_temp_ag_base[$i] = $data_climates[$i]['ch_temp']; $ch_dm_ag_base[$i] = $data_climates[$i]['ch_dm']; $temp_dm_ag_base[$i] = $data_climates[$i]['temp_dm']; } $ch_temp_ag = pow(array_product($ch_temp_ag_base), 1 / count($data_climates)); $temp_ch_ag = 1 / $ch_temp_ag; $ch_ch_ag = 1; $ch_dm_ag = pow(array_product($ch_dm_ag_base), 1 / count($data_climates)); $dm_ch_ag = 1 / $ch_dm_ag; $dm_dm_ag = 1; $temp_dm_ag = pow(array_product($temp_dm_ag_base), 1 / count($data_climates)); $dm_temp_ag = 1 / $temp_dm_ag; $temp_temp_ag = 1; $sum_column_ch_ag = $ch_ch_ag + $temp_ch_ag + $dm_ch_ag; $sum_column_temp_ag = $ch_temp_ag + $temp_temp_ag + $dm_temp_ag; $sum_column_dm_ag = $ch_dm_ag + $temp_dm_ag + $dm_dm_ag; /* ---- */ $divided_sum_sum_ag = $sum_column_ch_ag / $sum_column_ch_ag; $divided_ch_ch_ag_sum = $ch_ch_ag / $sum_column_ch_ag; $divided_ch_temp_ag_sum = $temp_ch_ag / $sum_column_ch_ag; $divided_ch_dm_ag_sum = $dm_ch_ag / $sum_column_ch_ag; $divided_temp_ch_ag_sum = $ch_temp_ag / $sum_column_temp_ag; $divided_temp_temp_ag_sum = $temp_temp_ag / $sum_column_temp_ag; $divided_temp_dm_ag_sum = $dm_temp_ag / $sum_column_temp_ag; $divided_dm_ch_ag_sum = $ch_dm_ag / $sum_column_dm_ag; $divided_dm_temp_ag_sum = $temp_dm_ag / $sum_column_dm_ag; $divided_dm_dm_ag_sum = $dm_dm_ag / $sum_column_dm_ag; /* ---- */ $sum_ch_ag = $divided_ch_ch_ag_sum + $divided_temp_ch_ag_sum + $divided_dm_ch_ag_sum; $sum_temp_ag = $divided_ch_temp_ag_sum + $divided_temp_temp_ag_sum + $divided_dm_temp_ag_sum; $sum_dm_ag = $divided_ch_dm_ag_sum + $divided_temp_dm_ag_sum + $divided_dm_dm_ag_sum; $sum_divided_ag = $divided_sum_sum_ag + $divided_sum_sum_ag + $divided_sum_sum_ag; /* ---- */ $bobot_ch_ag = $sum_ch_ag / $sum_divided_ag; $bobot_temp_ag = $sum_temp_ag / $sum_divided_ag; $bobot_dm_ag = $sum_dm_ag / $sum_divided_ag; /* ---- */ /* ---- */ $multiple_ch_ch_ag_bobot = $ch_ch_ag * $bobot_ch_ag; $multiple_ch_temp_ag_bobot = $temp_ch_ag * $bobot_ch_ag; $multiple_ch_dm_ag_bobot = $dm_ch_ag * $bobot_ch_ag; $multiple_temp_ch_ag_bobot = $ch_temp_ag * $bobot_temp_ag; $multiple_temp_temp_ag_bobot = $temp_temp_ag * $bobot_temp_ag; $multiple_temp_dm_ag_bobot = $dm_temp_ag * $bobot_temp_ag; $multiple_dm_ch_ag_bobot = $ch_dm_ag * $bobot_dm_ag; $multiple_dm_temp_ag_bobot = $temp_dm_ag * $bobot_dm_ag; $multiple_dm_dm_ag_bobot = $dm_dm_ag * $bobot_dm_ag; /* ---- */ /* ---- */ $sum_bobot_ch_ag = $multiple_ch_ch_ag_bobot + $multiple_temp_ch_ag_bobot + $multiple_dm_ch_ag_bobot; $sum_bobot_temp_ag = $multiple_ch_temp_ag_bobot + $multiple_temp_temp_ag_bobot + $multiple_dm_temp_ag_bobot; $sum_bobot_dm_ag = $multiple_ch_dm_ag_bobot + $multiple_temp_dm_ag_bobot + $multiple_dm_dm_ag_bobot; /* ---- */ $divided_bobot_ch_ag = $sum_bobot_ch_ag / $bobot_ch_ag; $divided_bobot_temp_ag = $sum_bobot_temp_ag / $bobot_temp_ag; $divided_bobot_dm_ag = $sum_bobot_dm_ag / $bobot_dm_ag; /* ---- */ $lamda_max_ag = ($divided_bobot_ch_ag + $divided_bobot_temp_ag + $divided_bobot_dm_ag) / $sum_divided_ag; $jumlah_factor_ag = $sum_divided_ag; $consistensi_index_ag = ($lamda_max_ag - $jumlah_factor_ag) / ($jumlah_factor_ag - 1); $rasio_index_ag = 0.58; $consistensi_rasio_ag = $consistensi_index_ag / $rasio_index_ag; /* ---- */ $model_ag = new ClimateAG(); $_POSTAG['ClimateAG']['ch_temp'] = $ch_temp_ag; $_POSTAG['ClimateAG']['ch_dm'] = $ch_dm_ag; $_POSTAG['ClimateAG']['temp_dm'] = $temp_dm_ag; $_POSTAG['ClimateAG']['bobot_ch'] = $bobot_ch_ag; $_POSTAG['ClimateAG']['boobt_temp'] = $bobot_temp_ag; $_POSTAG['ClimateAG']['bobot_dm'] = $bobot_dm_ag; $_POSTAG['ClimateAG']['cr'] = $consistensi_rasio_ag; if ($model_ag->load($_POSTAG) && $model_ag->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } }