/// <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); }
public List <YuMiBaoZiModel> getAllPredictData(List <YuMiBaoZiModel> models) { string xLabel = models[0].xLabel; string yLabel = models[0].canShuName; List <YuMiBaoZiModel> 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 <YuMiBaoZiModel> predictAllModels = new List <YuMiBaoZiModel>(); for (int i = 0; i < douAllX.Count; i++) { YuMiBaoZiModel model = new YuMiBaoZiModel(); 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(); predictAllModels.Add(model); } for (int i = 0; i < predictAllModels.Count; i++) { predictAllModels[i].high = getMax(convert(predictAllModels)); predictAllModels[i].low = getMin(convert(predictAllModels)); predictAllModels[i].predictChaValue = Convert.ToDouble(allModels[i].yData) - Convert.ToDouble(predictAllModels[i].yData); predictAllModels[i].xLabel = xLabel; predictAllModels[i].canShuName = yLabel; } return(predictAllModels); }
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); }
public List <YuMiBaoZiModel> getAllData(List <YuMiBaoZiModel> 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 <YuMiBaoZiModel> allModels = new List <YuMiBaoZiModel>(); for (int i = 0; i < douAllX.Count; i++) { YuMiBaoZiModel model = new YuMiBaoZiModel(); 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); }
public List <YuMiBaoZiModel> getYuMiBaoZiData(string shiYanHao) { List <YuMiBaoZiModel> yuMiModel = new List <YuMiBaoZiModel>(); YuMiBaoZiModel model = new YuMiBaoZiModel(); 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["开始时间"]); 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()) { YuMiBaoZiModel model1 = new YuMiBaoZiModel(); model1.shiYanHao = model.shiYanHao; model1.canShuHao = model.canShuHao; model1.startCanShuValue = model.startCanShuValue; model1.endCanShuValue = model.endCanShuValue; model1.startTime = model.startTime; model1.endTime = model.endTime; model1.canShuName = model.canShuName; model1.water = Convert.ToString(reader["水分"]); model1.tem = Convert.ToString(reader["温度"]); model1.humidity = Convert.ToString(reader["湿度"]); model1.xData = Convert.ToString(reader["消耗时间(/h)"]); model1.xLabel = "时间(h)"; model1.yData = Convert.ToString(reader["孢子个数"]); model1.rData = Convert.ToDouble(model1.yData) * 0.1; try { model1.checkTime = Convert.ToDateTime(reader["检测日期"]); } catch (Exception) { } yuMiModel.Add(model1); } reader.Close(); try { SqlClose(); } catch (Exception e) { throw e; } for (int i = 0; i < yuMiModel.Count; i++) { if (i == 0) { yuMiModel[i].addToSpeed = 0.0; } else { yuMiModel[i].addToSpeed = ((Convert.ToDouble(yuMiModel[i].yData) - Convert.ToDouble(yuMiModel[i - 1].yData)) * 1.0 / (Convert.ToDouble(yuMiModel[i].xData) - Convert.ToDouble(yuMiModel[i - 1].xData))); } } for (int i = 0; i < yuMiModel.Count; i++) { yuMiModel[i].high = getMax(convert(yuMiModel)); yuMiModel[i].low = getMin(convert(yuMiModel)); yuMiModel[i].media = getMedia(convert(yuMiModel)); yuMiModel[i].addToSpeedHigh = getAddToSpeedMax(convert(yuMiModel)); yuMiModel[i].addToSpeedLow = getAddToSpeedMin(convert(yuMiModel)); } return(yuMiModel); }