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

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

            double[] douY = new double[models.Count];
            for (int i = 0; i < models.Count; i++)
            {
                douX[i] = Convert.ToDouble(models[i].xData);
                douY[i] = Convert.ToDouble(models[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++)
            {
                DaoGuZhiLiangTeXingModel model = new DaoGuZhiLiangTeXingModel();
                model.xData = predictX[i].ToString();
                model.yData = predictY[i].ToString();
                models.Add(model);
            }
            for (int i = 0; i < models.Count; i++)
            {
                models[i].high       = getMax(convert(models));
                models[i].low        = getMin(convert(models));
                models[i].media      = getMedia(convert(models));
                models[i].xLabel     = xLabel;
                models[i].canShuName = yLabel;
            }
            return(models);
        }
예제 #2
0
        public List <DaoGuZhiLiangTeXingModel> getAllPredictData(List <DaoGuZhiLiangTeXingModel> models)
        {
            string xLabel = models[0].xLabel;
            string yLabel = models[0].canShuName;
            List <DaoGuZhiLiangTeXingModel> allModels = getAllData(models);

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

            //double[] douAllY;

            for (int i = 0; i < allModels.Count; i++)
            {
                douX[i] = Convert.ToDouble(allModels[i].xData);
                douY[i] = Convert.ToDouble(allModels[i].yData);
            }
            for (double i = douX[0]; i <= douX[allModels.Count - 1]; i++)
            {
                douAllX.Add(i);
            }
            MatrixEquation mart = new MatrixEquation();

            double[] xiShu = mart.MultiLine(douX, douY, douY.Length, 3);

            List <DaoGuZhiLiangTeXingModel> allPredictModels = new List <DaoGuZhiLiangTeXingModel>();

            for (int i = 0; i < douAllX.Count; i++)
            {
                DaoGuZhiLiangTeXingModel model = new DaoGuZhiLiangTeXingModel();

                double y = xiShu[0] + xiShu[1] * douAllX[i] + xiShu[2] * douAllX[i] * douAllX[i] + xiShu[3] * douAllX[i] * douAllX[i] * douAllX[i];
                model.xData = douAllX[i].ToString();
                model.yData = y.ToString();
                allPredictModels.Add(model);
            }
            for (int i = 0; i < allPredictModels.Count; i++)
            {
                allPredictModels[i].high            = getMax(convert(allPredictModels));
                allPredictModels[i].low             = getMin(convert(allPredictModels));
                allPredictModels[i].predictChaValue = Convert.ToDouble(allModels[i].yData) - Convert.ToDouble(allPredictModels[i].yData);
                allPredictModels[i].xLabel          = xLabel;
                allPredictModels[i].canShuName      = yLabel;
            }
            return(allPredictModels);
        }
예제 #3
0
        public List <DaoGuZhiLiangTeXingModel> getLagPredictValue(List <DaoGuZhiLiangTeXingModel> models, int time)
        {
            string xLabel = models[0].xLabel;
            string yLabel = models[0].canShuName;
            List <DaoGuZhiLiangTeXingModel> 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 <DaoGuZhiLiangTeXingModel> predictModels = new List <DaoGuZhiLiangTeXingModel>();

            for (int i = 0; i < douY.Count; i++)
            {
                DaoGuZhiLiangTeXingModel model = new DaoGuZhiLiangTeXingModel();
                model.xData = douX[i].ToString();
                model.yData = douY[i].ToString();
                predictModels.Add(model);
            }
            for (int i = 0; i < predictModels.Count; i++)
            {
                predictModels[i].high            = getMax(convert(predictModels));
                predictModels[i].low             = getMin(convert(predictModels));
                predictModels[i].predictChaValue = Convert.ToDouble(allModels[i].yData) - Convert.ToDouble(predictModels[i].yData);
                predictModels[i].xLabel          = xLabel;
                predictModels[i].canShuName      = yLabel;
            }
            return(predictModels);
        }
예제 #4
0
        public List <DaoGuZhiLiangTeXingModel> getAllData(List <DaoGuZhiLiangTeXingModel> models)
        {
            string xLabel = models[0].xLabel;
            string yLabel = models[0].canShuName;

            double[]      douY    = new double[models.Count];
            double[]      douX    = new double[models.Count];
            List <double> douAllX = new List <double>();

            double[] douAllY;

            for (int i = 0; i < models.Count; i++)
            {
                douX[i] = Convert.ToDouble(models[i].xData);
                douY[i] = Convert.ToDouble(models[i].yData);
            }
            for (double i = douX[0]; i <= douX[models.Count - 1]; i++)
            {
                douAllX.Add(i);
            }
            douAllY = spline.setSplineData(douX, douY, douAllX.ToArray());

            List <DaoGuZhiLiangTeXingModel> allModels = new List <DaoGuZhiLiangTeXingModel>();

            for (int i = 0; i < douAllX.Count; i++)
            {
                DaoGuZhiLiangTeXingModel model = new DaoGuZhiLiangTeXingModel();
                model.xData = douAllX[i].ToString();
                model.yData = douAllY[i].ToString();
                allModels.Add(model);
            }
            for (int i = 0; i < allModels.Count; i++)
            {
                allModels[i].high       = getMax(convert(allModels));
                allModels[i].low        = getMin(convert(allModels));
                allModels[i].xLabel     = xLabel;
                allModels[i].canShuName = yLabel;
            }
            return(allModels);
        }
예제 #5
0
        public List <DaoGuZhiLiangTeXingModel> getDaoGuZhiLiangTeXingData(string shiYanHao)
        {
            List <DaoGuZhiLiangTeXingModel> daoGuModel = new List <DaoGuZhiLiangTeXingModel>();
            DaoGuZhiLiangTeXingModel        model      = new DaoGuZhiLiangTeXingModel();

            try
            {
                SqlConnection();
            }
            catch (Exception e)
            {
                throw e;
            }

            sqlStr = "select * from 稻谷质量特性参数实验信息表 where 实验号 = '" + shiYanHao + "'";
            try
            {
                dataControl = new DataControl();
                reader      = dataControl.controlSql(sqlCon, sqlStr);
            }
            catch (Exception e)
            {
                throw e;
            }

            reader.Read();

            model.shiYanHao = Convert.ToString(reader["实验号"]);

            model.canShuHao        = Convert.ToString(reader["参数号"]);
            model.startCanShuValue = Convert.ToString(reader["起始参数值"]);
            model.endCanShuValue   = Convert.ToString(reader["终点参数值"]);

            try
            {
                model.startTime = Convert.ToDateTime(reader["开始时间"]);
            }
            catch (Exception)
            {
            }

            try
            {
                model.endTime = Convert.ToDateTime(reader["结束时间"]);
            }
            catch (Exception)
            { }


            reader.Close();

            sqlStr = "select * from 稻谷质量特性参数信息表 where 参数号 = '" + model.canShuHao + "'";
            try
            {
                dataControl = new DataControl();
                reader      = dataControl.controlSql(sqlCon, sqlStr);
            }
            catch (Exception e)
            {
                throw e;
            }
            reader.Read();
            model.canShuName = Convert.ToString(reader["参数名"]);


            reader.Close();

            sqlStr = "select * from 稻谷质量特性参数实验数据表 where 实验号 = '" + shiYanHao + "'";

            try
            {
                dataControl = new DataControl();
                reader      = dataControl.controlSql(sqlCon, sqlStr);
            }
            catch (Exception e)
            {
                throw e;
            }

            while (reader.Read())
            {
                DaoGuZhiLiangTeXingModel model1 = new DaoGuZhiLiangTeXingModel();

                model1.shiYanHao = model.shiYanHao;

                model1.canShuHao        = model.canShuHao;
                model1.startCanShuValue = model.startCanShuValue;
                model1.endCanShuValue   = model.endCanShuValue;
                if (model.startTime != null && model.endTime != null)
                {
                    model1.startTime = model.startTime;
                    model1.endTime   = model.endTime;
                }
                model1.canShuName = model.canShuName;

                model1.xData  = Convert.ToString(reader["消耗时间(/d)"]);
                model1.xLabel = "消耗时间:";
                model1.yData  = Convert.ToString(reader["参数值"]);
                if (model1.rData < 5)
                {
                    model1.rData = 10;
                }
                try
                {
                    model1.checkTime = Convert.ToDateTime(reader["检测日期"]);
                }
                catch (Exception)
                { }
                model.tem   = Convert.ToString(reader["粮温"]);
                model.water = Convert.ToString(reader["水分"]);
                daoGuModel.Add(model1);
            }

            reader.Close();


            try
            {
                SqlClose();
            }
            catch (Exception e)
            {
                throw e;
            }

            for (int i = 0; i < daoGuModel.Count; i++)
            {
                if (i == 0)
                {
                    daoGuModel[i].addToSpeed = 0.0;
                }
                else
                {
                    daoGuModel[i].addToSpeed = ((Convert.ToDouble(daoGuModel[i].yData) - Convert.ToDouble(daoGuModel[i - 1].yData)) * 1.0 / (Convert.ToDouble(daoGuModel[i].xData) - Convert.ToDouble(daoGuModel[i - 1].xData)));
                }
            }
            for (int i = 0; i < daoGuModel.Count; i++)
            {
                daoGuModel[i].high           = getMax(convert(daoGuModel));
                daoGuModel[i].low            = getMin(convert(daoGuModel));
                daoGuModel[i].media          = getMedia(convert(daoGuModel));
                daoGuModel[i].addToSpeedHigh = getAddToSpeedMax(convert(daoGuModel));
                daoGuModel[i].addToSpeedLow  = getAddToSpeedMin(convert(daoGuModel));
            }
            return(daoGuModel);
        }