public async Task<IHttpActionResult> PutshipParticular(string callSign, shipParticular shipParticular)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (callSign != shipParticular.callSign)
            {
                return BadRequest();
            }

            db.Entry(shipParticular).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!shipParticularExists(callSign))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
        public static List<double[]> speedPowerTable(shipParticular shipParticular)
        {
            int mcrPower = Convert.ToInt16(shipParticular.MCR_POWER_ME);  //ME_POWER_MCr

            double seatrialdraftScantling = (shipParticular.draftForeAtScantling + shipParticular.draftAftAtScantling) * 0.5;  //Draft (Scantling) Fore , Draft (Scantling) Aft
            double seaTrialdraftBallast = (shipParticular.draftForeAtBallast + shipParticular.draftAftAtBallast) * 0.5;     //Draft (Ballast) Fore, Draft (Ballast) Aft

            List<double[]> draftTable = new List<double[]> { };
            double startDraft = Math.Truncate((seaTrialdraftBallast - 2) * 10);        // ref draft -2 부터 시작 (-2는 여유분)

            int numerOfDraft = (int)((Math.Truncate((seatrialdraftScantling + 2) * 10)) - (Math.Truncate((seaTrialdraftBallast - 2) * 10)));         // 스캔틀링까지 소수점 한자리 까지 검색, 기준 draft보다 -2 +2 만큼 큼
            int numberOfPwer = (int)(shipParticular.MCR_POWER_ME / 200);          //ME_POWER_MCr
            double[] powerTable = new double[numberOfPwer];         // 확인 완  200 씩 파워 간격을 띄움 --> 커브피팅 알고리즘으로 x 축 배열
            double[] speedTable = new double[numberOfPwer];         // 확인 완  파워 간격 만큼 스피드를 계산 --> 커브피팅 알고리즘으로 y 축 배열

            for (int i = 0; i < numerOfDraft; i++)          // 드라프트 간격 0.1 만큼 해상도의 커프피팅 테이블을 만듦
            {
                for (int j = 0; j < numberOfPwer; j++)
                {
                    powerTable[j] = (j + 1) * 200;
                    speedTable[j] =
                    ((shipParticular.seatrialPowerToSpeedCoef0_scant * Math.Pow(powerTable[j], shipParticular.seatrialPowerToSpeedCoef1_scant) - shipParticular.seatrialPowerToSpeedCoef0_ballast * Math.Pow(powerTable[j], shipParticular.seatrialPowerToSpeedCoef1_ballast)) /  // Seatrial PowerToSpeed(Scant')
                    (seatrialdraftScantling - seaTrialdraftBallast) *
                    ((i + startDraft) * 0.1 - seaTrialdraftBallast) + (shipParticular.seatrialPowerToSpeedCoef0_ballast * Math.Pow(powerTable[j], shipParticular.seatrialPowerToSpeedCoef1_ballast)));  // Seatrial PowerToSpeed(Ballast')
                }

                draftTable.Add(curveFitting.powerRegression(powerTable, speedTable));
            }

            return draftTable;
        }
        public static double makeFuelPower(double flowMeterMeHfo, shipParticular shipParticular, double shaftRev, double LCV = 9700)        // 연료사용량을 마력으로 환산 mass 연료사용량이 파라미터로 들어감.
        {
            double powerbyFoc = (flowMeterMeHfo * LCV / 10198.72) / (shipParticular.shopTestRpmToSfocCoef3 * Math.Pow(shaftRev, 3) + shipParticular.shopTestRpmToSfocCoef2 * Math.Pow(shaftRev, 2) + shipParticular.shopTestRpmToSfocCoef1 * shaftRev + shipParticular.shopTestRpmToSfocCoef0) * 1000;        // coef --> shoptest --> RPM to SFOC

            powerbyFoc = Math.Truncate(powerbyFoc);

            if (double.IsNaN(powerbyFoc))
            {
                powerbyFoc = 0;
            }

            return powerbyFoc;
        }
Beispiel #4
0
        static public List<shipSailingData> ReadCsv(string fileSavePath, shipParticular shipParticularInput)
        {
            List<shipSailingData> shipdata = new List<shipSailingData>();
            var fs = new FileStream(fileSavePath, FileMode.Open, FileAccess.Read, FileShare.Delete);
            // open the file "data.csv" which is a CSV file with headers
            using (CsvReader csv = new CsvReader(
                   new StreamReader(fs), false))
            {

                csv.ReadNextRecord();
                csv.ReadNextRecord();

                int d_count = 0;
                csv.ReadNextRecord();
                //   string[] headers = csv.GetFieldHeaders();
                while (csv.ReadNextRecord())
                {
                    shipdata.Add(new shipSailingData
                    {
                        Id = d_count,
                        callSign = shipParticularInput.callSign,
                        date = Convert.ToDateTime(csv[0]),
                        speedVs = Convert.ToDouble(csv[1]),     // SPEED_LW
                        powerDel = Convert.ToDouble(csv[2]),       // SHAFT_POWER
                        shaftRev = Convert.ToDouble(csv[3]),        // SHAFT_REV
                        relWindSpd = Convert.ToDouble(csv[4]) * 0.5144,     // REL_WIND_SPEED  "knot -> m/s 0.5144"
                        relWindDir = Convert.ToDouble(csv[5]),      // REL_WIND_DIR
                        airTemp = 25,     // AIR_TEMP
                        speedVg = Convert.ToDouble(csv[6]),     // SPEED_VG
                        headingGps = Convert.ToDouble(csv[7]),      // SHIP_HEADING
                        rudderAngle = Convert.ToDouble(csv[8]),     // RUDDER_ANGLE
                        waterDepth = Convert.ToDouble(csv[9]),     // WATER_DEPTH
                        draughtFore = Convert.ToDouble(csv[10]),        // DRAUGHT_FORE
                        draughtAft = Convert.ToDouble(csv[11]),     // DRAUGHT_AFT
                        seawaterTemp = Convert.ToDouble(csv[12]),       // SW_TEMP
                        flowMeterMeHfo = Convert.ToDouble(csv[13]),     // ME_TTL_FOC
                        absWindDir = 0,     // ABS_WIND_DIR
                        absWindSpd = 0,     // ABS_WIND_SPEED
                        powerbyFoc = 0,     // SHAFT_POWER_FOC
                        windResistance = 0,     //WINDRESISTANCE
                        correctPow = 0,     // CORRECTPOW
                        correctPow_foc = 0,     // CORRECTPOW_FOC
                        slip = 0,       // SLIP
                        PV = 0,         //PV
                        PV_foc = 0,     //PV_FOC
                        PPV = 0,        //PPV
                        PPV_foc = 0,        //PPV_FOC

                        validByChauvent = true,     //valid_CHAUVENT
                        validByvalidation = true,       //valid_validation
                        validByRefCondition = true      //valid_refcondition
                    });
                    d_count++;
                }

                File.Delete(fileSavePath);

                var shipdatabox = iso19030Method.preProcessData(shipdata, shipParticularInput);

                return shipdatabox;
            }
        }
        static public List<shipSailingData> preProcessData(List<shipSailingData> rawShipdata, shipParticular shipParticular)
        {
            int speedVs_Chau_Count = 0;
            int speedVg_Chau_Count = 0;
            int powerDel_Chau_Count = 0;
            int shaftRev_Chau_Count = 0;
            int relWindDir_Chau_Count = 0;
            int relWindSpeed_Chau_Count = 0;
            int headingGps_Chau_Count = 0;
            int draughtFore_Chau_Count = 0;
            int draughtAft_Chau_Count = 0;
            int rudderAngle_Chau_Count = 0;
            int seawaterTemp_Chau_Count = 0;
            int airTemp_Chau_Count = 0;
            int waterDepth_Chau_Count = 0;

            int shaftRev_Valid_Count = 0;
            int speedVg_Valid_Count = 0;
            int speedVs_Valid_Count = 0;
            int Rudder_Valid_Count = 0;

            int ice_Valid_Count = 0;
            int wind_Valid_Count = 0;
            int depth_Valid_Count = 0;

            int total_count = 0;
            int count_chauvent_count = 0;
            int count_valid_count = 0;
            int count_ref_count = 0;

            List<shipSailingData> afterChauvent_shipdata = new List<shipSailingData> { };       //인수로 넣은 List 와 동일한 자료형으로 만들 것
            List<shipSailingData> afterValid_shipdata = new List<shipSailingData> { };
            List<shipSailingData> afterRef_shipdata = new List<shipSailingData> { };
            List<shipSailingData> insert_DB_shipdata = new List<shipSailingData> { };
            List<shipSailingData> insert_DB_shipdata2 = new List<shipSailingData> { };
            List<shipSailingData_AvgDay> insert_DB_shipdataAvgDay = new List<shipSailingData_AvgDay> { };

            double[] airDenCoef = new double[] { shipParticular.airDenR2, shipParticular.airDenCoef0, shipParticular.airDenCoef1, shipParticular.airDenCoef2, shipParticular.airDenCoef3, shipParticular.airDenCoef4 };         // Envir   pA
            double[] windResCoef = new double[] { shipParticular.windResR2, shipParticular.windResCoef0, shipParticular.windResCoef1, shipParticular.windResCoef2, shipParticular.windResCoef3, shipParticular.windResCoef4, shipParticular.windResCoef5, shipParticular.windResCoef6 };        // Wind-coef Cx[-]
            double AT_ballast = shipParticular.AT_Ballast;      // AT(Ballast)
            double breadth = shipParticular.breadth;        // Breadth
            double draft_ref = shipParticular.draft_ref;        // (Draft(Ballast) Fore + Draft(Ballast) Aft) / 2

            IOrderedEnumerable<shipSailingData> shipdata =
            from s in rawShipdata
            orderby s.date ascending
            select s;

            List<double[]> speedPowerTable = shipDataPreprocessor.speedPowerTable(shipParticular);

            foreach (var item in shipdata)
            {
                item.windResistance = shipDataPreprocessor.resistanceWind(airDenCoef, windResCoef, draft_ref, AT_ballast, breadth, item.draughtAft, item.airTemp, item.relWindSpd, item.relWindDir, item.speedVg);
                item.slip = shipDataPreprocessor.slip(item.shaftRev, item.speedVg, shipParticular.propellerPitch);          // PROPELLER_PITCH
                item.powerbyFoc = shipDataPreprocessor.makeFuelPower(item.flowMeterMeHfo, shipParticular, item.shaftRev);
                item.correctPow = item.powerDel + item.windResistance;
                item.correctPow_foc = item.powerbyFoc + item.windResistance;
                //item.correctPow = item.powerbyFoc + item.windResistance;

                var absWind = shipDataPreprocessor.windRelToAbs(item.relWindSpd, item.relWindDir, item.speedVg, item.headingGps);

                item.absWindSpd = absWind[0];
                item.absWindDir = absWind[1];

                //var ttss = (int)((Math.Truncate(((item.draughtFore + item.draughtAft) * 0.5 + 2) * 10)) - Math.Truncate((shipParticular.draftForeAtBallast + shipParticular.draftAftAtBallast) * 0.5 * 10));

                if ((int)((Math.Truncate(((item.draughtFore + item.draughtAft) * 0.5 + 2) * 10)) - Math.Truncate((shipParticular.draftForeAtBallast + shipParticular.draftAftAtBallast) * 0.5 * 10)) > 0)  //  Draft (Ballast) Fore, Draft (Ballast) Aft
                {
                    var speedPowerEquation = speedPowerTable[(int)((Math.Truncate(((item.draughtFore + item.draughtAft) * 0.5 + 2) * 10)) - Math.Truncate((shipParticular.draftForeAtBallast + shipParticular.draftAftAtBallast) * 0.5 * 10))]; //  Draft (Ballast) Fore, Draft (Ballast) Aft
                    item.PV = shipDataPreprocessor.PVcalculator(speedPowerEquation, item.correctPow, item.speedVs);
                    item.PV_foc = shipDataPreprocessor.PVcalculator(speedPowerEquation, item.correctPow_foc, item.speedVs);
                    item.PPV = shipDataPreprocessor.PPVcalculator(speedPowerEquation, item.correctPow, item.speedVs);
                    item.PPV_foc = shipDataPreprocessor.PPVcalculator(speedPowerEquation, item.correctPow_foc, item.speedVs);
                }
                else
                {
                    item.PV = 0;
                }
            }

            foreach (var item in shipdata)
            {
                insert_DB_shipdata.Add(item);
            }

            IEnumerable<List<shipSailingData>> shipdataout =
            from s in shipdata
            group s by new
            {
                s.date.Year,
                s.date.Month,
                s.date.Day,
                s.date.Hour,
                Minute = s.date.Minute / 10
            } into groupShipdata
            orderby groupShipdata.Key.Year, groupShipdata.Key.Month, groupShipdata.Key.Day, groupShipdata.Key.Hour, groupShipdata.Key.Minute ascending

            select
            groupShipdata.ToList();

            foreach (var item in shipdataout)
            {
                var speedVs = Chauvent(item.Select(d => d.speedVs));
                var relWindDir = Chauvent_angle(item.Select(d => d.relWindDir));
                var powerDel = Chauvent(item.Select(d => d.powerDel));
                var rudderAngle = Chauvent_angle(item.Select(d => d.rudderAngle));
                var shaftRev = Chauvent(item.Select(d => d.shaftRev));
                var relWindSpeed = Chauvent(item.Select(d => d.powerDel));
                var speedVg = Chauvent(item.Select(d => d.speedVg));
                var headingGps = Chauvent_angle(item.Select(d => d.headingGps));
                var draghtFore = Chauvent(item.Select(d => d.draughtFore));
                var draghtAft = Chauvent(item.Select(d => d.draughtAft));
                var waterDepth = Chauvent(item.Select(d => d.waterDepth));
                var seawaterTemp = Chauvent(item.Select(d => d.seawaterTemp));
                var airTemp = Chauvent(item.Select(d => d.airTemp));
                var powerByFoc = Chauvent(item.Select(d => d.powerbyFoc));

                int temp_cha = 0;

                foreach (var item2 in item)
                {
                    item2.validByChauvent = speedVs[temp_cha] && powerByFoc[temp_cha] && relWindDir[temp_cha] && relWindSpeed[temp_cha] && speedVg[temp_cha] && shaftRev[temp_cha] &&
                                            headingGps[temp_cha] && draghtFore[temp_cha] && draghtAft[temp_cha] && waterDepth[temp_cha] && rudderAngle[temp_cha] &&
                                            seawaterTemp[temp_cha] && airTemp[temp_cha];

                    if (speedVs[temp_cha] == false) { speedVs_Chau_Count++; }
                    if (shaftRev[temp_cha] == false) { shaftRev_Chau_Count++; }
                    if (speedVg[temp_cha] == false) { speedVg_Chau_Count++; }
                    if (powerDel[temp_cha] == false) { powerDel_Chau_Count++; }
                    if (relWindDir[temp_cha] == false) { relWindDir_Chau_Count++; }
                    if (relWindSpeed[temp_cha] == false) { relWindSpeed_Chau_Count++; }
                    if (headingGps[temp_cha] == false) { headingGps_Chau_Count++; }
                    if (draghtFore[temp_cha] == false) { draughtFore_Chau_Count++; }
                    if (draghtAft[temp_cha] == false) { draughtAft_Chau_Count++; }
                    if (rudderAngle[temp_cha] == false) { rudderAngle_Chau_Count++; }
                    if (seawaterTemp[temp_cha] == false) { seawaterTemp_Chau_Count++; }
                    if (airTemp[temp_cha] == false) { airTemp_Chau_Count++; }
                    if (waterDepth[temp_cha] == false) { waterDepth_Chau_Count++; }

                    if (item2.validByChauvent == true)
                    {
                        afterChauvent_shipdata.Add(item2);
                    }
                    else
                    {
                        insert_DB_shipdata.ElementAt(total_count).validByChauvent = false;
                        insert_DB_shipdata.ElementAt(total_count).validByvalidation = false;
                        insert_DB_shipdata.ElementAt(total_count).validByRefCondition = false;
                        count_chauvent_count++;
                    }

                    temp_cha++;
                    total_count++;
                }
            }

            IEnumerable<List<shipSailingData>> afterChauvent_shipdataout =
            from s in afterChauvent_shipdata
            group s by new
            {
                s.date.Year,
                s.date.Month,
                s.date.Day,
                s.date.Hour,
                Minute = s.date.Minute / 10
            } into groupShipdata
            orderby groupShipdata.Key.Year, groupShipdata.Key.Month, groupShipdata.Key.Day, groupShipdata.Key.Hour, groupShipdata.Key.Minute ascending

            select
            groupShipdata.ToList();

            foreach (var item in afterChauvent_shipdataout)
            {
                var rudderAngleValidation = standardError_angle(item.Select(d => d.rudderAngle), 1);
                var shaftrevValidation = standardError(item.Select(d => d.shaftRev), 3);
                var speedVsValidation = standardError(item.Select(d => d.speedVs), 0.5);
                var speedVgValidation = standardError(item.Select(d => d.speedVg), 0.5);

                int temp_i = 0;

                foreach (var item2 in item)
                {
                    item2.validByvalidation = shaftrevValidation[temp_i] && speedVsValidation[temp_i] && speedVgValidation[temp_i]
                   && rudderAngleValidation[temp_i];

                    if (shaftrevValidation[temp_i] == false) { shaftRev_Valid_Count++; }
                    if (speedVsValidation[temp_i] == false) { speedVs_Valid_Count++; }
                    if (speedVgValidation[temp_i] == false) { speedVg_Valid_Count++; }
                    if (rudderAngleValidation[temp_i] == false) { Rudder_Valid_Count++; }

                    count_valid_count++;
                    if (item2.validByvalidation == true)
                    {
                        afterValid_shipdata.Add(item2);
                    }
                    else
                    {
                        insert_DB_shipdata.ElementAt(item2.Id).validByvalidation = false;
                        insert_DB_shipdata.ElementAt(item2.Id).validByRefCondition = false;
                    }
                }
            }

            foreach (var item in afterValid_shipdata)
            {
                if ((item.seawaterTemp < 2) || (item.absWindSpd < 0) || (item.absWindSpd > 7.9))
                //|| (item.waterDepth < 3*Math.Sqrt(shipParticular.breadth* (item.draughtFore *item.draughtAft)/2) || (item.waterDepth < (2.75* Math.Pow(item.speedVs,2) / 9.80665))) )
                {
                    item.validByRefCondition = false;
                    insert_DB_shipdata.ElementAt(item.Id).validByRefCondition = false;
                }

                if (item.validByRefCondition == true)
                {
                    count_ref_count++;
                    afterRef_shipdata.Add(item);
                }
                if (item.seawaterTemp < 2) { ice_Valid_Count++; }
                if (item.absWindSpd < 0) { wind_Valid_Count++; }
                if (item.absWindSpd > 7.9) { wind_Valid_Count++; }

                //if ((item.waterDepth < 3 * Math.Sqrt(shipParticular.breadth * (item.draughtFore * item.draughtAft) / 2) || (item.waterDepth < (2.75 * Math.Pow(item.speedVs, 2) / 9.80665)))) { depth_Valid_Count++; }
            }

            return insert_DB_shipdata;
        }
        public async Task<IHttpActionResult> PostshipParticular(string callSign, shipParticular shipParticular)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.shipParticulars.Add(shipParticular);
            await db.SaveChangesAsync();

            return StatusCode(HttpStatusCode.NoContent);
        }