public static List<double[]> speedPowerTable(shipCoef seatrial, shipParticular shipParticular)
        {
            double[] seatrialCoef = new double[] { seatrial.seatrialSpeedToPowerCoef0_ballast, seatrial.seatrialSpeedToPowerCoef1_ballast, seatrial.seatrialSpeedToPowerCoef0_scant, seatrial.seatrialSpeedToPowerCoef1_scant };
            int mcrPower = Convert.ToInt16(shipParticular.MCR_POWER_ME);

            List<double[]> draftTable = new List<double[]> { };
            int numerOfDraft = (int)(shipParticular.draftForeAtScantling * 10);
            int numberOfPwer = (int)(shipParticular.MCR_POWER_ME / 200);
            double[] powerTable = new double[numberOfPwer];
            double[] speedPowerTable = new double[numberOfPwer];

            for (int i = 0; i < numerOfDraft; i++)
            {
                for (int j = 0; j < numberOfPwer; j++)
                {
                    powerTable[j] = (j + 1) * 50;
                    speedPowerTable[j] =
                    (seatrialCoef[1] * Math.Pow(j + 1, seatrialCoef[0]) - seatrialCoef[3] * Math.Pow(j + 1, seatrialCoef[2])) /
                    (shipParticular.draftForeAtScantling - shipParticular.draftForeAtBallast) *
                    ((i + 1) * 0.1 - shipParticular.draftForeAtBallast) + (seatrialCoef[1] * Math.Pow(j + 1, seatrialCoef[0]));
                }
                draftTable.Add(curveFitting.powerRegression(powerTable, speedPowerTable));
            }

            return draftTable;
        }
        public static double PVcalculator(shipCoef seatrial, double delPower, shipParticular shipParticular, double draft, double powerDel, double speedVs)
        {
            double PV = 0;
            double[] PowetToSpeed_Ballast = new double[30];
            double[] PowetToSpeed_Scant = new double[30];
            double[] seatrialCoef = new double[] { seatrial.seatrialSpeedToPowerCoef0_ballast, seatrial.seatrialSpeedToPowerCoef1_ballast, seatrial.seatrialSpeedToPowerCoef0_scant, seatrial.seatrialSpeedToPowerCoef1_scant };
            int mcrPower = Convert.ToInt16(shipParticular.MCR_POWER_ME);

            List<double> powerIndex = new List<double> { };
            //List<double> speedBallast = new List<double> { };
            //List<double> speedScant = new List<double> { };

            List<double> speedNow = new List<double> { };

            for (int i = 5000; i < mcrPower; i += 2000)
            {
                powerIndex.Add(i);
                //speedBallast.Add(seatrialCoef[1] * Math.Pow(i, seatrialCoef[0]));
                //speedScant.Add(seatrialCoef[3] * Math.Pow(i, seatrialCoef[2]));
                speedNow.Add(
                    (seatrialCoef[1] * Math.Pow(i, seatrialCoef[0]) - seatrialCoef[3] * Math.Pow(i, seatrialCoef[2])) /
                    (shipParticular.draftForeAtScantling - shipParticular.draftForeAtBallast) *
                    (draft - shipParticular.draftForeAtBallast) + (seatrialCoef[1] * Math.Pow(i, seatrialCoef[0]))

                    );
            }

            var powerIndex2 = powerIndex.ToArray();
            var speedNow2 = speedNow.ToArray();

            var cur = curveFitting.powerRegression(powerIndex2, speedNow2);

            var expectedSpeed = cur[1] * Math.Pow(powerDel, cur[2]);

            PV = 100 * (speedVs - expectedSpeed) / expectedSpeed;

            return PV;
        }
Пример #3
0
        private void ReadCsv()
        {
            List<shipSailingData> shipdata = new List<shipSailingData>();

            // open the file "data.csv" which is a CSV file with headers
            using (CsvReader csv = new CsvReader(
                   new StreamReader("c:\\total.csv"), false))
            {
                int d_count = 0;
                //   string[] headers = csv.GetFieldHeaders();
                while (csv.ReadNextRecord())
                {
                    d_count++;

                    shipdata.Add(new shipSailingData
                    {
                        Id = d_count,
                        date = Convert.ToDateTime(csv[0]),
                        speedVs = Convert.ToDouble(csv[1]),
                        powerDel = Convert.ToDouble(csv[2]),
                        shaftRev = Convert.ToDouble(csv[3]),
                        relWindSpd = Convert.ToDouble(csv[4]) * 0.5144,
                        relWindDir = Convert.ToDouble(csv[5]),
                        airTemp = Convert.ToDouble(csv[6]),
                        speedVg = Convert.ToDouble(csv[7]),
                        headingGps = Convert.ToDouble(csv[8]),
                        rudderAngle = Convert.ToDouble(csv[9]),
                        waterDepth = Convert.ToDouble(csv[10]),
                        draughtFore = Convert.ToDouble(csv[11]),
                        draughtAft = Convert.ToDouble(csv[12]),
                        seawaterTemp = Convert.ToDouble(csv[14]),
                        flowMeterMeHfo = 0,
                        powerbyFoc = 0,
                        windResistance = 0,
                        correctPow = 0,
                        slip = 0,
                        PV = 0,
                        validByChauvent = true,
                        validByvalidation = true,
                        validByRefCondition = true
                    });
                }

                shipCoef shipCoef =
                    new shipCoef
                    {
                        airDenR2 = 0.9997,
                        airDenCoef0 = 1.29199697,
                        airDenCoef1 = -0.003711898,
                        airDenCoef2 = -0.000219621,
                        airDenCoef3 = 0.0000163010101010094,
                        airDenCoef4 = -3.42424E-07,

                        windResR2 = 0.995778277,
                        windResCoef0 = -0.520407804,
                        windResCoef1 = -0.06484229,
                        windResCoef2 = 0.00297724,
                        windResCoef3 = -5.90255E-05,
                        windResCoef4 = 6.00689E-07,
                        windResCoef5 = -2.87174E-09,
                        windResCoef6 = 5.07895E-12,

                        seatrialSpeedToPowerR2_ballast = 0.99917,
                        seatrialSpeedToPowerCoef0_ballast = 0.261812317,
                        seatrialSpeedToPowerCoef1_ballast = 1.343659789,

                        seatrialSpeedToPowerR2_scant = 0.99954,
                        seatrialSpeedToPowerCoef0_scant = 0.292102996,
                        seatrialSpeedToPowerCoef1_scant = 0.910963221
                    };

                shipParticular shipParticular =
                    new shipParticular
                    {
                        shipName = "PAN BONA",
                        shipOwner = "Pan Ocean Co., Ltd.",
                        shipType = "BULKER",
                        yard = "NEW TIMES SHIPYARD",
                        telNo = "773110197",
                        faxNo = "783110516",
                        emailAddress = "*****@*****.**",
                        dateDelivery = new DateTime(2011, 01, 07),
                        resister = "KR",
                        IMO_Number = "9510527",
                        flag = "PANAMA",
                        LOA = 291.8,
                        LBP = 282.2,
                        breadth = 45.0,
                        depthToUpperdeck = 24.75,
                        deadWeight = 0,
                        displacement = 0,
                        draft_ref = 18.2,
                        draftForeAtBallast = 7.91,
                        draftAftAtBallast = 7.91,
                        draftForeAtScantling = 18.25,
                        draftAftAtScantling = 18.25,
                        draftForeAtDesign = 14.2,
                        draftAftAtDesign = 13.3,
                        ME_type = "ME50",
                        MCR_POWER_ME = 23232,
                        ME_RPM_ME = 86.2,
                        propellerPitch = 6084,
                        blockCoeffDesign = 0.7,
                        blockCoeffBallast = 0.67,
                        blockCoeffLaden = 0.56,
                        WSE_Design = 45.5,
                        WSE_Ballast = 56.4,
                        WSE_Scantling = 54.3,
                        AT_Design = 1500,
                        AT_Ballast = 1800,
                        AT_Scantling = 1200
                    };

                var shipdatabox = Spms_Library.iso19030Method.preProcessData(shipdata, shipCoef, shipParticular);

                var tt = 0;
            }
        }
        static public IEnumerable<List<shipSailingData>> preProcessData(List<shipSailingData> rawShipdata, shipCoef shipCoef, shipParticular shipParticular, DateTime? startDateTime = null, DateTime? endDateTime = null)
        {
            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 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<shipSailingData> afterValid_shipdata = new List<shipSailingData> { };
            List<shipSailingData> afterRef_shipdata = new List<shipSailingData> { };

            double[] airDenCoef = new double[] { shipCoef.airDenR2, shipCoef.airDenCoef0, shipCoef.airDenCoef1, shipCoef.airDenCoef2, shipCoef.airDenCoef3, shipCoef.airDenCoef4 };
            double[] windResCoef = new double[] { shipCoef.windResR2, shipCoef.windResCoef0, shipCoef.windResCoef1, shipCoef.windResCoef2, shipCoef.windResCoef3, shipCoef.windResCoef4, shipCoef.windResCoef5, shipCoef.windResCoef6 };
            double AT_ballast = shipParticular.AT_Ballast;
            double breadth = shipParticular.breadth;
            double draft_ref = shipParticular.draft_ref;

            if (startDateTime == null)
            {
                startDateTime = new DateTime(2015, 05, 06, 03, 50, 00);
            }

            if (endDateTime == null)
            {
                endDateTime = new DateTime(2100, 01, 01, 00, 00, 00);
            }

            IOrderedEnumerable<shipSailingData> shipdata =
            from s in rawShipdata
            where s.date >= startDateTime && s.date <= endDateTime
            orderby s.date ascending
            select s;
            shipDataPreprocessor.speedPowerTable(shipCoef, 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);

                //  item.PV = shipDataPreprocessor.PVcalculator(shipCoef, item.powerDel, shipParticular, item.draughtFore, item.powerDel, item.speedVs);
            }

            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));

                int temp_i = 0;

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

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

                    temp_i++;
                    total_count++;

                    if (item2.validByChauvent == true)
                    {
                        count_chauvent_count++;
                        afterChauvent_shipdata.Add(item2);
                    }
                }
            }

            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++; }

                    if (item2.validByvalidation == true)
                    {
                        count_valid_count++;
                        afterValid_shipdata.Add(item2);
                    }
                }
            }

            foreach (var item in afterValid_shipdata)
            {
                if ((item.seawaterTemp < 2) || (item.relWindSpd < 0) || (item.relWindSpd > 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;
                }

                if (item.validByRefCondition == true)
                {
                    count_ref_count++;
                    afterRef_shipdata.Add(item);
                }
            }

            return shipdataout;
        }