コード例 #1
0
ファイル: SelectData.cs プロジェクト: Rich1-King/grain
        /// <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     = 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);

            String[]      douTemp = grainTemp.ToArray();
            double[]      col0    = a.ToArray();
            DateTime[]    date    = dateTime.ToArray();
            double[]      water   = PeatsMiDu.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.InTemp       = douTemp[index];
                datapoint.PeatsMiDu    = 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);
        }
コード例 #2
0
ファイル: SelectData.cs プロジェクト: Rich1-King/grain
        /// <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);
        }
コード例 #3
0
ファイル: SelectData.cs プロジェクト: Rich1-King/grain
        /// <summary>
        /// 用MatrixEquation得到的预测值
        /// </summary>
        /// <param name="str">实验号</param>
        /// <returns>预测值</returns>
        public static List <DataValue> getAllPredictValue(String str)
        {
            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);

            string[]      douTemp   = grainTemp.ToArray();
            double[]      col0      = a.ToArray();
            DateTime[]    date      = dateTime.ToArray();
            double[]      peatsMiDu = PeatsMiDu.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 % 30 == 0)
                {
                    index++;
                }
                datapoint.InTemp       = douTemp[index];
                datapoint.PeatsMiDu    = peatsMiDu[index];
                datapoint.date         = dDay.AddDays(1);
                datapoint.CanShuNumber = canShuNumber;
                datapoint.yLable       = canShuName;
                dDay = datapoint.date;
                datapoint.ChaValue = ceshi[i] - y1;
                datapoint.Y        = ceshi[i];
                lists.Add(datapoint);
            }
            return(lists);
        }
コード例 #4
0
ファイル: SelectData.cs プロジェクト: Rich1-King/grain
        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> 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);


            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], DateTime.Compare(dateTime[1], dateTime[0]));
                }
                datapoint.High         = high;
                datapoint.Low          = low;
                datapoint.Media        = media;
                datapoint.Y            = col0[i];
                datapoint.yLable       = canShuName;
                datapoint.CanShuNumber = canShuNumber;
                datapoint.index        = i + 1;
                datapoint.InTemp       = douTemp[i];
                datapoint.PeatsMiDu    = peatsMiDu[i];
                lists.Add(datapoint);
            }
            return(lists);
        }