Beispiel #1
0
        /// <summary>
        /// 根据已有数据预测后面时间的数据
        /// </summary>
        /// <param name="models">已有数据</param>
        /// <param name="time">要预测的时间长度</param>
        /// <param name="interval">时间间隔</param>
        /// <returns>返回预测数据加上已有数据</returns>
        public List <YuMiBaoZiModel> getPredictDataAfterTime(List <YuMiBaoZiModel> models, int time, int interval)
        {
            string xLabel = models[0].xLabel;
            string yLabel = models[0].canShuName;
            List <YuMiBaoZiModel> allModels = getAllData(models);

            double[]      douX     = new double[allModels.Count];
            List <double> predictX = new List <double>();

            double[] douY = new double[allModels.Count];
            for (int i = 0; i < allModels.Count; i++)
            {
                douX[i] = Convert.ToDouble(allModels[i].xData);
                douY[i] = Convert.ToDouble(allModels[i].yData);
            }
            int    count = time / interval;
            int    flag  = time % interval;
            double xLast = douX[douX.Length - 1];

            for (int i = 0; i < count; i++)
            {
                xLast = xLast + interval;
                predictX.Add(xLast);
            }
            if (flag != 0)
            {
                xLast = xLast + flag;
                predictX.Add(xLast);
            }
            Lagrange      lan      = new Lagrange(douX, douY);
            List <double> predictY = lan.InsertDatas(predictX);

            for (int i = 0; i < predictY.Count; i++)
            {
                YuMiBaoZiModel model = new YuMiBaoZiModel();
                model.xData = predictX[i].ToString();
                model.yData = predictY[i].ToString();
                allModels.Add(model);
            }
            for (int i = 0; i < models.Count; i++)
            {
                allModels[i].high       = getMax(convert(allModels));
                allModels[i].low        = getMin(convert(allModels));
                allModels[i].media      = getMedia(convert(allModels));
                allModels[i].xLabel     = xLabel;
                allModels[i].canShuName = yLabel;
            }
            List <YuMiBaoZiModel> predictModels = getAllData(allModels);

            return(predictModels);
        }
Beispiel #2
0
        public List <YuMiBaoZiModel> getLagPredictValue(List <YuMiBaoZiModel> models, int time)
        {
            string xLabel = models[0].xLabel;
            string yLabel = models[0].canShuName;
            List <YuMiBaoZiModel> allModels = getAllData(models);

            double[]      ownX = new double[time];
            double[]      ownY = new double[time];
            List <double> douX = new List <double>();
            List <double> douY;

            for (int i = 0; i < allModels.Count; i++)
            {
                if (i < time)
                {
                    ownX[i] = Convert.ToDouble(allModels[i].xData);
                    ownY[i] = Convert.ToDouble(allModels[i].yData);
                }
                douX.Add(Convert.ToDouble(allModels[i].xData));
            }

            Lagrange lan1 = new Lagrange(ownX, ownY);

            douY = lan1.InsertDatas(douX);
            List <YuMiBaoZiModel> predictAllModel = new List <YuMiBaoZiModel>();

            for (int i = 0; i < douY.Count; i++)
            {
                YuMiBaoZiModel model = new YuMiBaoZiModel();
                model.xData = douX[i].ToString();
                model.yData = douY[i].ToString();
                predictAllModel.Add(model);
            }
            for (int i = 0; i < predictAllModel.Count; i++)
            {
                predictAllModel[i].high            = getMax(convert(models));
                predictAllModel[i].low             = getMin(convert(models));
                predictAllModel[i].predictChaValue = Convert.ToDouble(allModels[i].yData) - Convert.ToDouble(predictAllModel[i].yData);
                predictAllModel[i].xLabel          = xLabel;
                predictAllModel[i].canShuName      = yLabel;
            }
            return(predictAllModel);
        }
Beispiel #3
0
        /// <summary>
        /// Lagrange得到的预测值
        /// </summary>
        /// <param name="str">实验号</param>
        /// <returns></returns>
        public static List <DataValue> getLagPredictValue(String str, int day)
        {
            List <DataValue> lists = new List <DataValue>();
            List <double>    a     = SqlData.sqlGetData("dbo.小麦质量特性参数数据表", "CanNumberValue", str);

            List <DateTime> dateTime = SqlData.sqlDataDate("dbo.小麦质量特性参数数据表", "Date", str);

            List <double> grainTemp    = SqlData.sqlDataDoubleValue("dbo.小麦质量特性参数数据表", "GrainTemp", str);
            List <double> WaterValue   = SqlData.sqlDataDoubleValue("dbo.小麦质量特性参数数据表", "Water", str);
            String        canShuNumber = SqlData.getCanShuNumber("dbo.小麦参数实验总概括表", "CanShuNumber", str);
            String        canShuName   = SqlData.getCanShuName("dbo.小麦参数名表", "CanShuName", canShuNumber);


            double[]      douTemp = grainTemp.ToArray();
            double[]      col0    = a.ToArray();
            DateTime[]    date    = dateTime.ToArray();
            double[]      water   = WaterValue.ToArray();
            List <double> dayDou  = new List <double>();//将有数据的日期转换为double类型

            for (int i = 0; i < date.Length; i++)
            {
                dayDou.Add(date[i].ToOADate());
            }

            List <double> doubleDay = new List <double>();

            for (double j = dayDou[0]; j <= dayDou[dayDou.Count - 1]; j++)
            {
                doubleDay.Add(j);
            }
            double[] ceshi = spline.setSplineData(dayDou.ToArray(), col0, doubleDay.ToArray());//实际值

            List <double> time1 = new List <double>();
            List <double> col1  = new List <double>();

            for (int i = 0; i < day; i++)
            {
                time1.Add(doubleDay[i]);
            }
            for (int i = 0; i < day; i++)
            {
                col1.Add(ceshi[i]);
            }

            Lagrange lan1 = new Lagrange(time1.ToArray(), col1.ToArray());

            List <double> jieguo1 = lan1.InsertDatas(doubleDay);//预测值


            DateTime dDay  = date[0];
            int      index = -1;

            for (int i = 0; i < doubleDay.Count; i++)
            {
                DataValue datapoint = new DataValue();
                datapoint.PredictData = jieguo1[i];
                if (i % 30 == 0)
                {
                    index++;
                }

                datapoint.GrainTemp    = douTemp[index];
                datapoint.Water        = water[index];
                datapoint.CanShuNumber = canShuNumber;
                datapoint.yLable       = canShuName;

                datapoint.date     = dDay.AddDays(1);
                dDay               = datapoint.date;
                datapoint.ChaValue = ceshi[i] - jieguo1[i];

                datapoint.Y = ceshi[i];


                lists.Add(datapoint);
            }
            return(lists);
        }
Beispiel #4
0
        /// <summary>
        /// 得到后几天的预测值
        /// </summary>
        /// <param name="str">实验号</param>
        /// <param name="day">天数</param>
        /// <returns>得到的预测值</returns>
        public static List <DataValue> getPredictData(String str, int day)
        {
            List <DataValue> lists = new List <DataValue>();
            List <double>    a     = new List <double>();

            List <DateTime> dateTime   = new List <DateTime>();
            List <double>   grainTemp  = new List <double>();
            List <double>   WaterValue = new List <double>();

            a = SqlData.sqlGetData("dbo.小麦质量特性参数数据表", "CanNumberValue", str);

            dateTime = SqlData.sqlDataDate("dbo.小麦质量特性参数数据表", "Date", str);

            grainTemp = SqlData.sqlDataDoubleValue("dbo.小麦质量特性参数数据表", "GrainTemp", str);

            WaterValue = SqlData.sqlDataDoubleValue("dbo.小麦质量特性参数数据表", "Water", str);
            String canShuNumber = SqlData.getCanShuNumber("dbo.小麦参数实验总概括表", "CanShuNumber", str);
            String canShuName   = SqlData.getCanShuName("dbo.小麦参数名表", "CanShuName", canShuNumber);

            double[]   col0    = a.ToArray();
            DateTime[] date    = dateTime.ToArray();
            double[]   douTemp = grainTemp.ToArray();
            double[]   water   = WaterValue.ToArray();

            double low   = getLow(col0);
            double high  = getHigh(col0);
            double media = getMedia(col0);

            DataValue datapoint = null;

            for (int i = 0; i < col0.Length; i++)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }
                datapoint = new DataValue();
                DateTime dYear = date[i];
                datapoint.date = dYear;

                if (i == 0)
                {
                    datapoint.SpeedData = 0;
                }
                else
                {
                    datapoint.SpeedData = getSpeedData(col0[i], col0[i - 1], 30);
                }
                datapoint.High         = high;
                datapoint.Low          = low;
                datapoint.Media        = media;
                datapoint.PredictData  = col0[i];
                datapoint.yLable       = canShuName;
                datapoint.CanShuNumber = canShuNumber;
                datapoint.index        = i + 1;
                datapoint.GrainTemp    = douTemp[i];
                datapoint.Water        = water[i];
                lists.Add(datapoint);
            }

            int      count  = day / 30;
            int      count1 = day % 30;
            int      index  = datapoint.index;
            DateTime d      = datapoint.date;
            double   d1     = datapoint.PredictData;

            List <double> dayDou = new List <double>();//将有数据的日期转换为double类型

            for (int i = 0; i < date.Length; i++)
            {
                dayDou.Add(date[i].ToOADate());
            }
            double[] dat;
            DateTime ti = date[date.Length - 1];

            if (count1 != 0)
            {
                dat = new double[count + 1];
                for (int i = 0; i < count; i++)
                {
                    ti     = ti.AddDays(30);
                    dat[i] = ti.ToOADate();
                }
                dat[count] = ti.AddDays(count1).ToOADate();
            }
            else
            {
                dat = new double[count];
                for (int i = 0; i < count; i++)
                {
                    ti     = ti.AddDays(7);
                    dat[i] = ti.ToOADate();
                }
            }
            Lagrange      lan    = new Lagrange(dayDou.ToArray(), col0);
            List <double> jieguo = lan.InsertDatas(dat.ToList <double>());

            double[] predictData = jieguo.ToArray();

            for (int i = 0; i < count; i++)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }

                datapoint             = new DataValue();
                datapoint.index       = index + 1;
                datapoint.PredictData = predictData[i];
                datapoint.date        = d.AddDays(30);

                datapoint.Water     = water[0];
                datapoint.yLable    = canShuName;
                datapoint.GrainTemp = douTemp[0];

                d     = datapoint.date;
                d1    = datapoint.PredictData;
                index = datapoint.index;
                lists.Add(datapoint);
            }
            if (count1 != 0)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }

                datapoint             = new DataValue();
                datapoint.PredictData = predictData[count];
                datapoint.date        = d.AddDays(count1);

                datapoint.Water     = water[0];
                datapoint.yLable    = canShuName;
                datapoint.GrainTemp = douTemp[0];


                d  = datapoint.date;
                d1 = datapoint.PredictData;

                datapoint.index = index + 1;
                lists.Add(datapoint);
            }
            return(lists);
        }
Beispiel #5
0
        /// <summary>
        /// Lagrange得到的预测值
        /// </summary>
        /// <param name="str">实验号</param>
        /// <returns></returns>
        public static List <DataValue> getLagPredictValue(String str, int day)
        {
            List <DataValue> lists = new List <DataValue>();
            List <DateTime>  dateTime;
            List <double>    a;
            List <string>    inTemp;
            List <double>    grainTemp;

            try
            {
                dateTime  = SqlData.sqlDataDate("dbo.小麦害虫种群变化数据表", "Date", str);
                a         = SqlData.sqlGetData("dbo.小麦害虫种群变化数据表", "CanShuValue", str);
                inTemp    = SqlData.sqlDataInTemp("dbo.小麦害虫种群变化数据表", "InTemp", str);
                grainTemp = SqlData.sqlDataGrainTemp("dbo.小麦害虫种群变化数据表", "GrainTemp", str);
            }
            catch (Exception e)
            {
                throw e;
            }

            string[]      strTemp = inTemp.ToArray();
            double[]      douTemp = grainTemp.ToArray();
            double[]      col0    = a.ToArray();
            DateTime[]    date    = dateTime.ToArray();
            List <double> dayDou  = new List <double>();//将有数据的日期转换为double类型

            for (int i = 0; i < date.Length; i++)
            {
                dayDou.Add(date[i].ToOADate());
            }

            List <double> doubleDay = new List <double>();

            for (double j = dayDou[0]; j <= dayDou[dayDou.Count - 1]; j++)
            {
                doubleDay.Add(j);
            }
            double[] ceshi = spline.setSplineData(dayDou.ToArray(), col0, doubleDay.ToArray());//实际值

            List <double> time1 = new List <double>();
            List <double> col1  = new List <double>();

            for (int i = 0; i < day; i++)
            {
                time1.Add(doubleDay[i]);
            }
            for (int i = 0; i < day; i++)
            {
                col1.Add(ceshi[i]);
            }

            Lagrange lan1 = new Lagrange(time1.ToArray(), col1.ToArray());

            List <double> jieguo1 = lan1.InsertDatas(doubleDay);//预测值


            DateTime dDay  = date[0];
            int      index = -1;

            for (int i = 0; i < doubleDay.Count; i++)
            {
                DataValue datapoint = new DataValue();
                datapoint.PredictData = jieguo1[i];
                if (i % 7 == 0)
                {
                    index++;
                }
                datapoint.InTemp    = strTemp[index];
                datapoint.GrainTemp = douTemp[index];

                datapoint.date     = dDay.AddDays(1);
                dDay               = datapoint.date;
                datapoint.ChaValue = ceshi[i] - jieguo1[i];
                if (str == "000051")
                {
                    datapoint.Y = ceshi[i];
                }
                else if (str == "000052")
                {
                    datapoint.Y = ceshi[i];
                }
                else if (str == "000053")
                {
                    datapoint.Y = ceshi[i];
                }
                else if (str == "000054")
                {
                    datapoint.Y = ceshi[i];
                }
                lists.Add(datapoint);
            }
            return(lists);
        }
Beispiel #6
0
        /// <summary>
        /// 得到后几天的预测值
        /// </summary>
        /// <param name="str">实验号</param>
        /// <param name="day">天数</param>
        /// <returns>得到的预测值</returns>
        public static List <DataValue> getPredictData(String str, int day)
        {
            List <DataValue> lists = new List <DataValue>();
            List <double>    a     = new List <double>();

            List <DateTime> dateTime  = new List <DateTime>();
            List <string>   inTemp    = new List <string>();
            List <double>   grainTemp = new List <double>();

            try
            {
                a = SqlData.sqlGetData("dbo.小麦害虫种群变化数据表", "CanShuValue", str);

                dateTime  = SqlData.sqlDataDate("dbo.小麦害虫种群变化数据表", "Date", str);
                inTemp    = SqlData.sqlDataInTemp("dbo.小麦害虫种群变化数据表", "InTemp", str);
                grainTemp = SqlData.sqlDataGrainTemp("dbo.小麦害虫种群变化数据表", "GrainTemp", str);
            }
            catch (Exception e)
            {
                throw e;
            }

            double[]   col0    = a.ToArray();
            DateTime[] date    = dateTime.ToArray();
            string[]   strTemp = inTemp.ToArray();
            double[]   douTemp = grainTemp.ToArray();

            double low   = getLow(col0);
            double high  = getHigh(col0);
            double media = getMedia(col0);



            DataValue datapoint = null;

            for (int i = 0; i < col0.Length; i++)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }
                datapoint = new DataValue();
                DateTime dYear = date[i];
                datapoint.date = dYear;


                if (i == 0)
                {
                    datapoint.SpeedData = 0;
                }
                else
                {
                    datapoint.SpeedData = getSpeedData(col0[i], col0[i - 1], 7);
                }

                if (str == "000051")
                {
                    datapoint.High        = high;
                    datapoint.Low         = low;
                    datapoint.Media       = media;
                    datapoint.PredictData = col0[i];

                    datapoint.yLable    = "玉米象";
                    datapoint.index     = i + 1;
                    datapoint.GrainTemp = douTemp[i];
                    datapoint.InTemp    = strTemp[i];
                    lists.Add(datapoint);
                }
                else if (str == "000052")
                {
                    datapoint.High        = high;
                    datapoint.Low         = low;
                    datapoint.Media       = media;
                    datapoint.PredictData = col0[i];
                    datapoint.yLable      = "谷蠹";
                    datapoint.index       = i + 1;
                    datapoint.GrainTemp   = douTemp[i];
                    datapoint.InTemp      = strTemp[i];
                    lists.Add(datapoint);
                }
                else if (str == "000053")
                {
                    datapoint.High        = high;
                    datapoint.Low         = low;
                    datapoint.Media       = media;
                    datapoint.PredictData = col0[i];
                    datapoint.yLable      = "米象";
                    datapoint.index       = i + 1;
                    datapoint.GrainTemp   = douTemp[i];
                    datapoint.InTemp      = strTemp[i];
                    lists.Add(datapoint);
                }
                else if (str == "000054")
                {
                    datapoint.High        = high;
                    datapoint.Low         = low;
                    datapoint.Media       = media;
                    datapoint.PredictData = col0[i];
                    datapoint.yLable      = "米象";
                    datapoint.index       = i + 1;
                    datapoint.GrainTemp   = douTemp[i];
                    datapoint.InTemp      = strTemp[i];
                    lists.Add(datapoint);
                }
            }
            double firstdata;
            double speed;

            try
            {
                firstdata = SqlData.getInformationData("dbo.小麦参数实验总概括表", "StartCanShuValue", str);//起始数据
                speed     = SqlData.getInformationData("dbo.小麦参数实验总概括表", "CanShuChangeSpeed", str);
            }
            catch (Exception e)
            {
                throw e;
            }
            int count  = day / 7;
            int count1 = day % 7;
            int index  = datapoint.index;

            DateTime d  = datapoint.date;
            double   d1 = datapoint.PredictData;

            List <double> dayDou = new List <double>();//将有数据的日期转换为double类型

            for (int i = 0; i < date.Length; i++)
            {
                dayDou.Add(date[i].ToOADate());
            }
            double[] dat;
            DateTime ti = date[date.Length - 1];

            if (count1 != 0)
            {
                dat = new double[count + 1];
                for (int i = 0; i < count; i++)
                {
                    ti     = ti.AddDays(7);
                    dat[i] = ti.ToOADate();
                }
                dat[count] = ti.AddDays(count1).ToOADate();
            }
            else
            {
                dat = new double[count];
                for (int i = 0; i < count; i++)
                {
                    ti     = ti.AddDays(7);
                    dat[i] = ti.ToOADate();
                }
            }
            Lagrange      lan    = new Lagrange(dayDou.ToArray(), col0);
            List <double> jieguo = lan.InsertDatas(dat.ToList <double>());

            double[] predictData = jieguo.ToArray();

            for (int i = 0; i < count; i++)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }

                datapoint             = new DataValue();
                datapoint.index       = index + 1;
                datapoint.PredictData = predictData[i];
                datapoint.date        = d.AddDays(7);
                d     = datapoint.date;
                d1    = datapoint.PredictData;
                index = datapoint.index;
                lists.Add(datapoint);
            }
            if (count1 != 0)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }

                datapoint             = new DataValue();
                datapoint.PredictData = predictData[count];
                datapoint.date        = d.AddDays(count1);
                d  = datapoint.date;
                d1 = datapoint.PredictData;
                datapoint.index = index + 1;
                lists.Add(datapoint);
            }
            return(lists);
        }
Beispiel #7
0
        /// <summary>
        /// 得到后几天的预测值
        /// </summary>
        /// <param name="str">实验号</param>
        /// <param name="day">天数</param>
        /// <returns>得到的预测值</returns>
        public static List <DataValue> getPredictData(String str, int day)
        {
            List <DataValue> lists = new List <DataValue>();
            List <double>    a     = new List <double>();

            List <DateTime> dateTime  = new List <DateTime>();
            List <string>   grainTemp = new List <string>();
            List <double>   PeatsMiDu = new List <double>();

            a = SqlData.sqlGetData("dbo.害虫对小麦参数的影响数据表", "CanShuValue", str);

            dateTime = SqlData.sqlDataDate("dbo.害虫对小麦参数的影响数据表", "CheckDate", str);

            grainTemp = SqlData.sqlDataStringValue("dbo.害虫对小麦参数的影响数据表", "GrainTemp", str);
            PeatsMiDu = SqlData.sqlDataDoubleValue("dbo.害虫对小麦参数的影响数据表", "PeatsMiDu", str);

            DateTime endTime      = SqlData.getInformationDate("dbo.小麦参数实验总概括表", "EndTime", str);
            DateTime startTime    = SqlData.getInformationDate("dbo.小麦参数实验总概括表", "StartTime", str);
            String   canShuNumber = SqlData.getCanShuNumber("dbo.小麦参数实验总概括表", "CanShuNumber", str);
            String   canShuName   = SqlData.getCanShuName("dbo.小麦参数名表", "CanShuName", canShuNumber);

            double[]   col0      = a.ToArray();
            DateTime[] date      = dateTime.ToArray();
            string[]   douTemp   = grainTemp.ToArray();
            double[]   peatsMiDu = PeatsMiDu.ToArray();

            double low   = getLow(col0);
            double high  = getHigh(col0);
            double media = getMedia(col0);

            DataValue datapoint = null;

            for (int i = 0; i < col0.Length; i++)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }
                datapoint = new DataValue();
                DateTime dYear = date[i];
                datapoint.date = dYear;

                if (i == 0)
                {
                    datapoint.SpeedData = 0;
                }
                else
                {
                    datapoint.SpeedData = getSpeedData(col0[i], col0[i - 1], DateTime.Compare(dateTime[1], dateTime[0]));
                }
                datapoint.High         = high;
                datapoint.Low          = low;
                datapoint.Media        = media;
                datapoint.PredictData  = col0[i];
                datapoint.yLable       = canShuName;
                datapoint.CanShuNumber = canShuNumber;
                datapoint.index        = i + 1;
                datapoint.InTemp       = douTemp[i];
                datapoint.PeatsMiDu    = peatsMiDu[i];
                lists.Add(datapoint);
            }

            int      count  = day / DateTime.Compare(dateTime[1], dateTime[0]);
            int      count1 = day % DateTime.Compare(dateTime[1], dateTime[0]);
            int      index  = datapoint.index;
            DateTime d      = datapoint.date;
            double   d1     = datapoint.PredictData;

            List <double> dayDou = new List <double>();//将有数据的日期转换为double类型

            for (int i = 0; i < date.Length; i++)
            {
                dayDou.Add(date[i].ToOADate());
            }
            double[] dat;
            DateTime ti = date[date.Length - 1];

            if (count1 != 0)
            {
                dat = new double[count + 1];
                for (int i = 0; i < count; i++)
                {
                    ti     = ti.AddDays(DateTime.Compare(dateTime[1], dateTime[0]));
                    dat[i] = ti.ToOADate();
                }
                dat[count] = ti.AddDays(count1).ToOADate();
            }
            else
            {
                dat = new double[count];
                for (int i = 0; i < count; i++)
                {
                    ti     = ti.AddDays(DateTime.Compare(dateTime[1], dateTime[0]));
                    dat[i] = ti.ToOADate();
                }
            }
            Lagrange      lan    = new Lagrange(dayDou.ToArray(), col0);
            List <double> jieguo = lan.InsertDatas(dat.ToList <double>());

            double[] predictData = jieguo.ToArray();

            for (int i = 0; i < count; i++)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }

                datapoint              = new DataValue();
                datapoint.index        = index + 1;
                datapoint.PredictData  = predictData[i];
                datapoint.PeatsMiDu    = peatsMiDu[0];
                datapoint.yLable       = canShuName;
                datapoint.InTemp       = douTemp[0];
                datapoint.CanShuNumber = canShuNumber;
                datapoint.date         = d.AddDays(DateTime.Compare(dateTime[1], dateTime[0]));
                d     = datapoint.date;
                d1    = datapoint.PredictData;
                index = datapoint.index;
                lists.Add(datapoint);
            }
            if (count1 != 0)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }

                datapoint             = new DataValue();
                datapoint.PredictData = predictData[count];
                datapoint.date        = d.AddDays(count1);
                d  = datapoint.date;
                d1 = datapoint.PredictData;
                datapoint.index = index + 1;
                lists.Add(datapoint);
            }
            return(lists);
        }