Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 用MatrixEquation得到的预测值
        /// </summary>
        /// <param name="str">实验号</param>
        /// <returns>预测值</returns>
        public static List <DataValue> getAllPredictValue(String str)
        {
            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());//实际值

            MatrixEquation mart = new MatrixEquation();

            double[] ceshi2 = mart.MultiLine(dayDou.ToArray(), col0, col0.Length, 3);
            int      index  = -1;
            DateTime dDay   = date[0];

            for (int i = 0; i < doubleDay.Count; i++)
            {
                DataValue datapoint = new DataValue();
                double    y1        = ceshi2[0] + ceshi2[1] * doubleDay[i] + ceshi2[2] * doubleDay[i] * doubleDay[i] + ceshi2[3] * doubleDay[i] * doubleDay[i] * doubleDay[i];
                datapoint.PredictData = y1;

                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] - y1;
                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);
        }
Ejemplo n.º 4
0
        public static List <DataValue> getData(String str)
        {
            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>();
            DateTime        endTime;
            DateTime        startTime;

            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);
                endTime   = SqlData.getInformationDate("dbo.小麦参数实验总概括表", "EndTime", str);
                startTime = SqlData.getInformationDate("dbo.小麦参数实验总概括表", "StartTime", 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);


            for (int i = 0; i < col0.Length; i++)
            {
                DataValue datapoint = new DataValue();;
                DateTime  dYear     = date[i];
                datapoint.date      = dYear;
                datapoint.StartTime = startTime;
                datapoint.EndTime   = endTime;
                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.Y     = 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.Y         = 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.Y         = 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.Y         = col0[i];
                    datapoint.yLable    = "赤拟谷盗";
                    datapoint.index     = i + 1;
                    datapoint.GrainTemp = douTemp[i];
                    datapoint.InTemp    = strTemp[i];
                    lists.Add(datapoint);
                }
            }
            return(lists);
        }