public DataSet GetResult1(DateTime time, string flightno, string depAir, string arrAir) { using (db = new Database()) { string sql = "select w.description from histweather_sample as w join (select TimeSeries,DepCity from flight_sample where flightno='" + flightno.Trim() + "' and timeseries='" + time.ToShortDateString() + "' and depairport='" + depAir.Trim() + "' and arrairport='" + arrAir.Trim() + "') as f" + " on w.date=f.TimeSeries and w.city=f.DepCity"; string des = db.ExecScalar(sql).ToString().Trim(); sql = "select count(*) from histweather_sample as w join (select TimeSeries,DepCity,delaytime from flight_sample where flightno='" + flightno.Trim() + "' and timeseries<='" + time.ToShortDateString() + "' and depairport='" + depAir.Trim() + "' and arrairport='" + arrAir.Trim() + "') as f" + " on w.date=f.TimeSeries and w.city=f.DepCity where w.description='" + des + "' and f.delaytime>=0 and f.delaytime<=120"; int counts = int.Parse(db.ExecScalar(sql).ToString()); if (counts > 0) { sql = "select sum(delaytime) from histweather_sample as w join (select TimeSeries,DepCity,delaytime from flight_sample where flightno='" + flightno.Trim() + "' and timeseries<='" + time.ToShortDateString() + "' and depairport='" + depAir.Trim() + "' and arrairport='" + arrAir.Trim() + "') as f" + " on w.date=f.TimeSeries and w.city=f.DepCity where w.description='" + des + "' and f.delaytime>=0 and f.delaytime<=120"; int sum = int.Parse(db.ExecScalar(sql).ToString()); return(ToDataSet(flightno, time, sum / counts)); } else { return(ToDataSet(flightno, time, 0)); } } }
/// <summary> /// 只考虑天气因数 /// </summary> /// <returns></returns> DataSet Fun1(DateTime time, string flightno, string depAir, string arrAir) { //查出预测当天起飞城市的天气情况 string sql = "select w.description from histweather_sample as w join (select TimeSeries,DepCity from flight_sample where flightno='" + flightno.Trim() + "' and timeseries='" + time.ToShortDateString() + "' and depairport='" + depAir.Trim() + "' and arrairport='" + arrAir.Trim() + "') as f" + " on w.date=f.TimeSeries and w.city=f.DepCity"; string yuceW = db.ExecScalar(sql).ToString(); //查出预测当天目的城市的天气情况 sql = "select w.description from histweather_sample as w join (select TimeSeries,ArrCity from flight_sample where flightno='" + flightno.Trim() + "' and timeseries='" + time.ToShortDateString() + "' and depairport='" + depAir.Trim() + "' and arrairport='" + arrAir.Trim() + "') as f" + " on w.date=f.TimeSeries and w.city=f.ArrCity"; string mudiW = db.ExecScalar(sql).ToString(); if (yuceW == "晴") { if (mudiW == "晴") { return(ToDataSet(flightno, time, 0)); } else { } sql = "select * from flight_sample as f left join histweather_sample as w on f.depcity=w.city and f.timeseries=w.date"; } else if (yuceW == "多云") { } //查询统计航班延误是各天气延误情况 sql = "select w.description,count(*) as counts from histweather_sample as w join (select TimeSeries,DepCity from flight_sample where flightno='" + flightno.Trim() + "' and timeseries<='2016/3/31' and depairport='" + depAir.Trim() + "' and arrairport='" + arrAir.Trim() + "' and isdelay=1) as f" + " on w.date=f.TimeSeries and w.city=f.DepCity group by w.description order by counts"; DataSet delayByW = db.GetDataSet(sql); //查看预测的当天天气是否在delayByW中 int counts = 0; foreach (DataRow item in delayByW.Tables[0].Rows) { if (item["description"].ToString() == yuceW) { counts = int.Parse(item["counts"].ToString()); break; } } if (counts > 0) { //counts大于1,认为非偶然,否则可认为为偶然 if (counts > 1) { } else { } } return(null); }