Beispiel #1
0
 public function editSaving(Request $request)
 {
     $postData = $request->all();
     $id = $postData['id'];
     $qltyDataEntry = QltyData::find($id);
     if ($qltyDataEntry) {
         $productType = $qltyDataEntry->PRODUCT_TYPE;
         switch ($productType) {
             case 1:
                 //oil
                 $attributes = ['QLTY_DATA_ID' => $id];
                 //    					$values = ['QLTY_DATA_ID'=>$id];
                 $oils = array_key_exists("oil", $postData) ? $postData['oil'] : null;
                 if ($oils && count($oils) > 0) {
                     foreach ($oils as $oil) {
                         /* if (array_key_exists("ID", $oil)) {
                         				unset($oil["ID"]);
                         			} */
                         $attributes['ELEMENT_TYPE'] = $oil['DT_RowId'];
                         $oil['QLTY_DATA_ID'] = $id;
                         $oil['ELEMENT_TYPE'] = $oil['DT_RowId'];
                         QltyDataDetail::updateOrCreate($attributes, $oil);
                     }
                 }
                 $gases = array_key_exists("gas", $postData) ? $postData['gas'] : null;
                 if ($gases && count($gases) > 0) {
                     foreach ($gases as $gas) {
                         /* if (array_key_exists("ID", $gas)) {
                         				unset($gas["ID"]);
                         			} */
                         $attributes['ELEMENT_TYPE'] = $gas['DT_RowId'];
                         $gas['QLTY_DATA_ID'] = $id;
                         $gas['ELEMENT_TYPE'] = $gas['DT_RowId'];
                         QltyDataDetail::updateOrCreate($attributes, $gas);
                     }
                 }
                 break;
             case 2:
                 //gas
                 $constantElementTypes = QltyProductElementType::where("PRODUCT_TYPE", '=', $productType)->select("MOL_WEIGHT", "CODE", "ID")->get();
                 $gases = array_key_exists("gas", $postData) ? $postData['gas'] : null;
                 if ($gases) {
                     $attributes = ['QLTY_DATA_ID' => $id];
                     $qltDetails = [];
                     foreach ($constantElementTypes as $constantElementType) {
                         // 	   					$entries[$eid] = [];
                         $attributes['ELEMENT_TYPE'] = $constantElementType->ID;
                         $aqltyDataDetail = QltyDataDetail::firstOrNew($attributes);
                         $aqltyDataDetail->fill($attributes);
                         $qltDetails[$constantElementType->ID] = $aqltyDataDetail;
                     }
                     if ($gases && count($gases) > 0) {
                         foreach ($gases as $gas) {
                             $qltd = $qltDetails[$gas['DT_RowId']];
                             $qltd->fill($gas);
                         }
                         $totalMole = 0;
                         foreach ($constantElementTypes as $constantElementType) {
                             $qltd = $qltDetails[$constantElementType->ID];
                             $qltd->{'calculated'} = $qltd->MOLE_FACTION * $constantElementType->MOL_WEIGHT;
                             $totalMole += $qltd->MOLE_FACTION * $constantElementType->MOL_WEIGHT;
                         }
                         if ($totalMole != 0) {
                             foreach ($qltDetails as $qltd) {
                                 $qltd->MASS_FRACTION = $qltd->calculated / $totalMole;
                                 unset($qltd->calculated);
                                 $qltd->save();
                             }
                         } else {
                             response()->json('total = 0');
                         }
                     } else {
                         response()->json('no change data detected');
                     }
                 } else {
                     response()->json('empty data');
                 }
         }
     }
     return response()->json('Edit Successfullly');
 }
Beispiel #2
0
 public function getInputDataSet($postData, $occur_date)
 {
     $phase_type = $postData['ExtensionPhaseType'];
     $value_type = $postData['ExtensionValueType'];
     $data_source = $postData['ExtensionDataSource'];
     $objs = $this->getPostObjects($postData);
     $objdata = array();
     $objinfo = [];
     foreach ($objs as $obj) {
         if ($obj) {
             $ss = explode(":", $obj);
             $obj_id = $ss[1];
             $src = $ss[0];
             $obj_name = $ss[2];
             $pre = $src;
             $pvalue = $src;
             $ele = $this->getElement($obj_name);
             $where = ["OCCUR_DATE" => $occur_date];
             if ($src == "ENERGY_UNIT") {
                 $pre = "EU";
                 $pvalue = $pre;
                 $where['FLOW_PHASE'] = $phase_type;
             } else {
                 if ($src == "FLOW") {
                     $pvalue = "FL";
                 }
             }
             $where["{$pre}" . "_ID"] = $obj_id;
             $qlty_src_type = CodeQltySrcType::where('CODE', '=', $src)->first();
             $mdl = $this->getObjectTable($src, $data_source);
             $objectData = $mdl::where($where)->select("OBS_TEMP", "OBS_PRESS", "{$pvalue}" . "_DATA_{$value_type} as OBJ_VALUE")->orderBy('OCCUR_DATE')->first();
             $qltyData = QltyData::getTableName();
             $qltyProductElementType = QltyProductElementType::getTableName();
             $qltyDataDetail = QltyDataDetail::getTableName();
             $qlty_datas = QltyData::join($qltyDataDetail, "{$qltyData}.ID", '=', "{$qltyDataDetail}.QLTY_DATA_ID")->join($qltyProductElementType, function ($query) use($qltyDataDetail, $phase_type, $qltyProductElementType) {
                 $query->on("{$qltyDataDetail}.ELEMENT_TYPE", '=', "{$qltyProductElementType}.ID")->where("{$qltyProductElementType}.PRODUCT_TYPE", '=', $phase_type);
             })->whereHas('CodeQltySrcType', function ($query) use($src) {
                 $query->where("CODE", $src)->skip(0)->take(1);
             })->where("{$qltyData}.SRC_ID", $obj_id)->where("{$qltyData}.PRODUCT_TYPE", $phase_type)->where('EFFECTIVE_DATE', '=', $occur_date)->select("{$qltyProductElementType}.NAME", "{$qltyDataDetail}.MOLE_FACTION")->get();
             // 				foreach($workingDataSet as $objectData){
             if ($objectData) {
                 foreach ($qlty_datas as $qlty) {
                     if (array_key_exists($qlty->NAME, $ele)) {
                         $ele[$qlty->NAME] = $qlty->MOLE_FACTION ? $qlty->MOLE_FACTION : 0;
                     }
                 }
                 $ele["Pressure"] = \Helper::getRoundValue($objectData->OBS_PRESS);
                 $ele["Temperature"] = \Helper::getRoundValue($objectData->OBS_TEMP);
                 $ele["Volume"] = \Helper::getRoundValue($objectData->OBJ_VALUE);
                 $objdata["{$src}" . "_{$obj_id}"] = $ele;
                 $objinfo[] = array("src" => $src, "pre" => $pre, "obj_id" => $obj_id);
             }
             // 				}
         }
     }
     return ['data' => $objdata, 'info' => $objinfo];
 }
Beispiel #3
0
 public static function calculateBg($flow_phase, $T_obs, $P_obs, $API_obs, $occur_date, $object_id, $object_type_code)
 {
     $_Bg = null;
     set_error_handler("evalErrorHandler");
     if ($flow_phase == 1) {
         try {
             if ($T_obs && $P_obs && $API_obs) {
                 $_Bg = self::calculateCrudeOil($T_obs, $P_obs, $API_obs);
             }
         } catch (Exception $e) {
             \Log::info($e->getTraceAsString());
         }
     } else {
         if ($flow_phase == 2 || $flow_phase == 21) {
             $cqst = CodeQltySrcType::getTableName();
             $qdata = QltyData::getTableName();
             $row = QltyData::getQualityRow($object_id, $object_type_code, $occur_date);
             /* $row= QltyData::with(['CodeQltySrcType' => function ($query) use ($object_type_code) {
             										    $query->where('CODE', '=', $object_type_code);
             										
             										}])
              					->where('SRC_ID',$object_id)
              					->whereDate("$qdata.EFFECTIVE_DATE", '<=', $occur_date)
             	     	->select("$qdata.ID")
             	     	->orderBy("$qdata.EFFECTIVE_DATE",'desc')
             			->first(); */
             //Find composition %Mol
             //     		$sSQL="select a.ID from qlty_data a, code_qlty_src_type b where a.SRC_ID='$object_id' and a.SRC_TYPE=b.ID and b.CODE='$object_type_code' and a.EFFECTIVE_DATE<=STR_TO_DATE('$occur_date', '%m/%d/%Y') order by a.EFFECTIVE_DATE desc limit 1";
             if ($row) {
                 $dataID = $row->ID;
                 //     			\DB::enableQueryLog();
                 $querys = ['C1' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) {
                     $query->where("CODE", 'C1');
                 })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C2' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) {
                     $query->where("CODE", 'C2');
                 })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C3' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) {
                     $query->where("CODE", 'C3');
                 })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C4I' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) {
                     $query->where("CODE", 'IC4');
                 })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C4N' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) {
                     $query->where("CODE", 'NC4');
                 })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C5I' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) {
                     $query->where("CODE", 'IC5');
                 })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C5N' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) {
                     $query->where("CODE", 'NC5');
                 })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C6' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) {
                     $query->where("CODE", 'C6');
                 })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C7' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) {
                     $query->where("CODE", 'C7+');
                 })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'H2S' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) {
                     $query->where("CODE", 'H2S');
                 })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'CO2' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) {
                     $query->where("CODE", 'CO2');
                 })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'N2' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) {
                     $query->where("CODE", 'N2');
                 })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'M_C7' => QltyProductElementType::where('CODE', 'C7+')->select(\DB::raw("max(MOL_WEIGHT)")), 'G_C7' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) {
                     $query->where("CODE", 'C7+');
                 })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(GAMMA_C7)"))];
                 $qr = \DB::table(null);
                 foreach ($querys as $key => $query) {
                     $qr = $qr->selectSub($query->getQuery(), $key);
                 }
                 $qdltDatas = $qr->first();
                 //      			\Log::info("qdltDatas C1 ".$qdltDatas->C1);
                 // 				\Log::info(\DB::getQueryLog());
                 if ($qdltDatas) {
                     $MolWt_C7 = $qdltDatas->M_C7;
                     $gamma_C7 = $qdltDatas->G_C7;
                     $M_C1 = $qdltDatas->C1;
                     $M_C2 = $qdltDatas->C2;
                     $M_C3 = $qdltDatas->C3;
                     $M_C4n = $qdltDatas->C4N;
                     $M_C4i = $qdltDatas->C4I;
                     $M_C5n = $qdltDatas->C5N;
                     $M_C5i = $qdltDatas->C5I;
                     $M_C6n = $qdltDatas->C6;
                     $M_C7 = $qdltDatas->C7;
                     $M_H2S = $qdltDatas->H2S;
                     $M_CO2 = $qdltDatas->CO2;
                     $M_N2 = $qdltDatas->N2;
                     if ($T_obs && $P_obs) {
                         try {
                             $_Bg = self::calculateGas($T_obs, $P_obs, $MolWt_C7, $gamma_C7, $M_C1, $M_C2, $M_C3, $M_C4n, $M_C4i, $M_C5n, $M_C5i, $M_C6n, $M_C7, $M_H2S, $M_CO2, $M_N2);
                         } catch (Exception $e) {
                             \Log::info($e->getTraceAsString());
                         }
                     }
                 }
             }
         }
     }
     restore_error_handler();
     return $_Bg;
 }