private static void InsertHomewardTrip(DataTable tripsRawTable, DataTable tripsTable, InsertDatum datum, int i, InsertConfig.GpsCorrection correction) { int j = i; bool tripChangeFlag = false; // TripsRaw を結合して Trips を生成するループ while (j < tripsRawTable.Rows.Count && tripChangeFlag == false) { // YNU ⇒ 自宅 if (IsHome(tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLatitude), tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLongitude), tripsRawTable.Rows[j].Field <DateTime>(TripsRawDao.ColumnEndTime), datum)) { var row = tripsTable.NewRow(); row.SetField(TripsDao.ColumnTripId, GetMaxTripId(correction)); row.SetField(TripsDao.ColumnDriverId, tripsRawTable.Rows[i].Field <int>(TripsRawDao.ColumnDriverId)); row.SetField(TripsDao.ColumnCarId, tripsRawTable.Rows[i].Field <int>(TripsRawDao.ColumnCarId)); row.SetField(TripsDao.ColumnSensorId, tripsRawTable.Rows[i].Field <int>(TripsRawDao.ColumnSensorId)); row.SetField(TripsDao.ColumnStartTime, tripsRawTable.Rows[i].Field <DateTime>(TripsRawDao.ColumnStartTime)); row.SetField(TripsDao.ColumnEndTime, tripsRawTable.Rows[j].Field <DateTime>(TripsRawDao.ColumnEndTime)); row.SetField(TripsDao.ColumnStartLatitude, tripsRawTable.Rows[i].Field <double>(TripsRawDao.ColumnStartLatitude)); row.SetField(TripsDao.ColumnStartLongitude, tripsRawTable.Rows[i].Field <double>(TripsRawDao.ColumnStartLongitude)); row.SetField(TripsDao.ColumnEndLatitude, tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLatitude)); row.SetField(TripsDao.ColumnEndLongitude, tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLongitude)); row.SetField(TripsDao.ColumnTripDirection, "homeward"); TimeSpan span = tripsRawTable.Rows[j].Field <DateTime>(TripsRawDao.ColumnEndTime) - tripsRawTable.Rows[i].Field <DateTime>(TripsRawDao.ColumnStartTime); if (span.TotalHours > 12) { LogWritter.WriteLog(LogWritter.LogMode.Trip, "別々のトリップを結合する可能性があるので挿入しません " + ConvertRowToString(tripsRawTable.Rows[i], tripsRawTable.Rows[j])); break; } if (correction == InsertConfig.GpsCorrection.SpeedLPFMapMatching && !TripsSpeedLPF005MMDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else if (correction == InsertConfig.GpsCorrection.MapMatching && !TripsMMDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else if (correction == InsertConfig.GpsCorrection.Normal && !TripsDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else if (correction == InsertConfig.GpsCorrection.DopplerSpeed && !TripsDopplerDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else if (correction == InsertConfig.GpsCorrection.DopplerNotMM && !TripsDopplerNotMMDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else { LogWritter.WriteLog(LogWritter.LogMode.Trip, "既にこのトリップは挿入されているので挿入しません " + ConvertRowToString(tripsRawTable.Rows[i], tripsRawTable.Rows[j])); } tripChangeFlag = true; } // YNU ⇒ YNU else if (IsYnu(tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLatitude), tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLongitude))) { LogWritter.WriteLog(LogWritter.LogMode.Trip, "YNU⇒YNUトリップなので挿入しません " + ConvertRowToString(tripsRawTable.Rows[i], tripsRawTable.Rows[j])); // Trip の挿入は行わない // ループの初期化 tripChangeFlag = true; } j++; // YNU ⇒ ? if (j < tripsRawTable.Rows.Count && tripChangeFlag != true) { // 自宅にも、学校にも到着しないまま、開始地点が自宅か学校になった場合 if (IsHome(tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnStartLatitude), tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnStartLongitude), tripsRawTable.Rows[j].Field <DateTime>(TripsRawDao.ColumnStartTime), datum) || IsYnu(tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnStartLatitude), tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnStartLongitude))) { tripChangeFlag = true; LogWritter.WriteLog(LogWritter.LogMode.Trip, "YNU⇒?トリップなので挿入しません " + ConvertRowToString(tripsRawTable.Rows[i], tripsRawTable.Rows[j])); } } } }
/* * InsertSightSeeingTrip() * 観光用トリップを挿入するためのメソッド * YNU出発と観光地出発の2種類があることに注意が必要になる。 */ private static void InsertSightSeeingTrip(DataTable tripsRawTable, DataTable tripsTable, InsertDatum datum, int startIndex, InsertConfig.GpsCorrection correction) { // InsertHomewardTripと同じような処理を記述 // tripのスタートのtripsRawのインデックスをstartIndex // 現在注目しているtripsRawのインデックスをcurrentIndex int currentIndex = startIndex; // tripChangeFlagはループを抜けるためのフラグ // このフラグが立つと、異なるトリップに到達したことを示す bool tripChangeFlag = false; // TripsRawを結合してTripsを生成する。 while (currentIndex < tripsRawTable.Rows.Count && tripChangeFlag == false) { // スタートがynuか観光地 かつ ゴールがynuか観光地 // でもynuからynuのトリップは考えない // スタート,ゴールがynuであるか bool isStartYnu = IsYnu(tripsRawTable.Rows[startIndex].Field <double>(TripsRawDao.ColumnStartLatitude), tripsRawTable.Rows[startIndex].Field <double>(TripsRawDao.ColumnStartLongitude)); bool isEndYnu = IsYnu(tripsRawTable.Rows[currentIndex].Field <double>(TripsRawDao.ColumnEndLatitude), tripsRawTable.Rows[currentIndex].Field <double>(TripsRawDao.ColumnEndLongitude)); // スタートゴールが観光地であるか bool isStartSightseeingSpot = IsSightseeing(tripsRawTable.Rows[startIndex].Field <double>(TripsRawDao.ColumnStartLatitude), tripsRawTable.Rows[startIndex].Field <double>(TripsRawDao.ColumnStartLongitude)); bool isEndSightseeingSpot = IsSightseeing(tripsRawTable.Rows[currentIndex].Field <double>(TripsRawDao.ColumnEndLatitude), tripsRawTable.Rows[currentIndex].Field <double>(TripsRawDao.ColumnEndLongitude)); // スタートゴールが自宅であるか bool isStartHome = IsHome(tripsRawTable.Rows[startIndex].Field <double>(TripsRawDao.ColumnStartLatitude), tripsRawTable.Rows[startIndex].Field <double>(TripsRawDao.ColumnStartLongitude), tripsRawTable.Rows[startIndex].Field <DateTime>(TripsRawDao.ColumnStartTime), datum); bool isEndHome = IsHome(tripsRawTable.Rows[currentIndex].Field <double>(TripsRawDao.ColumnEndLatitude), tripsRawTable.Rows[currentIndex].Field <double>(TripsRawDao.ColumnEndLongitude), tripsRawTable.Rows[currentIndex].Field <DateTime>(TripsRawDao.ColumnEndTime), datum); // YNU to YNUは排除 if (isStartYnu && isEndYnu) { LogWritter.WriteLog(LogWritter.LogMode.Trip, "YNU⇒YNUトリップなので挿入しません。" + ConvertRowToString(tripsRawTable.Rows[startIndex], tripsRawTable.Rows[currentIndex])); tripChangeFlag = true; } // 自宅 to 自宅 も排除 else if (isStartHome && isEndHome) { LogWritter.WriteLog(LogWritter.LogMode.Trip, "Home⇒Homeトリップなので挿入しません。" + ConvertRowToString(tripsRawTable.Rows[startIndex], tripsRawTable.Rows[currentIndex])); tripChangeFlag = true; } // 候補地 to 候補地のトリップを挿入 else if ((isStartYnu || isStartSightseeingSpot || isStartHome) && (isEndYnu || isEndSightseeingSpot || isEndHome)) { var row = tripsTable.NewRow(); row.SetField(TripsDao.ColumnTripId, GetMaxTripId(correction)); row.SetField(TripsDao.ColumnDriverId, tripsRawTable.Rows[startIndex].Field <int>(TripsRawDao.ColumnDriverId)); row.SetField(TripsDao.ColumnCarId, tripsRawTable.Rows[startIndex].Field <int>(TripsRawDao.ColumnCarId)); row.SetField(TripsDao.ColumnSensorId, tripsRawTable.Rows[startIndex].Field <int>(TripsRawDao.ColumnSensorId)); row.SetField(TripsDao.ColumnStartTime, tripsRawTable.Rows[startIndex].Field <DateTime>(TripsRawDao.ColumnStartTime)); row.SetField(TripsDao.ColumnEndTime, tripsRawTable.Rows[currentIndex].Field <DateTime>(TripsRawDao.ColumnEndTime)); row.SetField(TripsDao.ColumnStartLatitude, tripsRawTable.Rows[startIndex].Field <double>(TripsRawDao.ColumnStartLatitude)); row.SetField(TripsDao.ColumnStartLongitude, tripsRawTable.Rows[startIndex].Field <double>(TripsRawDao.ColumnStartLongitude)); row.SetField(TripsDao.ColumnEndLatitude, tripsRawTable.Rows[currentIndex].Field <double>(TripsRawDao.ColumnEndLatitude)); row.SetField(TripsDao.ColumnEndLongitude, tripsRawTable.Rows[currentIndex].Field <double>(TripsRawDao.ColumnEndLongitude)); row.SetField(TripsDao.ColumnTripDirection, "tourism"); TimeSpan span = tripsRawTable.Rows[currentIndex].Field <DateTime>(TripsRawDao.ColumnEndTime) - tripsRawTable.Rows[startIndex].Field <DateTime>(TripsRawDao.ColumnStartTime); if (span.TotalHours > 12) { LogWritter.WriteLog(LogWritter.LogMode.Trip, "別々のトリップを結合する可能性があるので挿入しません " + ConvertRowToString(tripsRawTable.Rows[startIndex], tripsRawTable.Rows[currentIndex])); break; } if (correction == InsertConfig.GpsCorrection.SpeedLPFMapMatching && !TripsSpeedLPF005MMDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else if (correction == InsertConfig.GpsCorrection.MapMatching && !TripsMMDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else if (correction == InsertConfig.GpsCorrection.Normal && !TripsDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else if (correction == InsertConfig.GpsCorrection.DopplerSpeed && !TripsDopplerDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else if (correction == InsertConfig.GpsCorrection.DopplerNotMM && !TripsDopplerNotMMDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else { LogWritter.WriteLog(LogWritter.LogMode.Trip, "既にこのトリップは挿入されているので挿入しません " + ConvertRowToString(tripsRawTable.Rows[startIndex], tripsRawTable.Rows[currentIndex])); } tripChangeFlag = true; } currentIndex++; if (currentIndex == tripsRawTable.Rows.Count || tripChangeFlag) { break; } // YNUにも観光地にも自宅にも到着しないまま、開始地点がYNUか観光地か自宅になった場合 if (IsYnu(tripsRawTable.Rows[currentIndex].Field <double>(TripsRawDao.ColumnStartLatitude), tripsRawTable.Rows[currentIndex].Field <double>(TripsRawDao.ColumnStartLongitude)) || IsSightseeing(tripsRawTable.Rows[currentIndex].Field <double>(TripsRawDao.ColumnStartLongitude), tripsRawTable.Rows[currentIndex].Field <double>(TripsRawDao.ColumnStartLongitude)) || IsHome(tripsRawTable.Rows[currentIndex].Field <double>(TripsRawDao.ColumnStartLatitude), tripsRawTable.Rows[currentIndex].Field <double>(TripsRawDao.ColumnStartLongitude), tripsRawTable.Rows[currentIndex].Field <DateTime>(TripsRawDao.ColumnStartTime), datum) ) { tripChangeFlag = true; LogWritter.WriteLog(LogWritter.LogMode.Trip, "YNUor自宅or観光地⇒?トリップなので挿入しません " + ConvertRowToString(tripsRawTable.Rows[startIndex], tripsRawTable.Rows[currentIndex])); } } }
//TRIP_DIRECTION = 'other' のインサート private static void InsertOtherTrip(DataTable tripsRawTable, DataTable tripsTable, InsertDatum datum, int i, InsertConfig.GpsCorrection correction) { int j = i; bool tripChangeFlag = false; // TripsRaw を結合して Trips を生成するループ while (j < tripsRawTable.Rows.Count && tripChangeFlag == false) { // その他登録地点 ⇒ その他登録地点 if (IsOther(tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLatitude), tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLongitude))) { var row = tripsTable.NewRow(); if (correction == InsertConfig.GpsCorrection.SpeedLPFMapMatching) { row.SetField(TripsDao.ColumnTripId, TripsSpeedLPF005MMDao.GetMaxTripId() + 1); } else if (correction == InsertConfig.GpsCorrection.MapMatching) { row.SetField(TripsDao.ColumnTripId, TripsMMDao.GetMaxTripId() + 1); } else { row.SetField(TripsDao.ColumnTripId, TripsDao.GetMaxTripId() + 1); } row.SetField(TripsDao.ColumnDriverId, tripsRawTable.Rows[i].Field <int>(TripsRawDao.ColumnDriverId)); row.SetField(TripsDao.ColumnCarId, tripsRawTable.Rows[i].Field <int>(TripsRawDao.ColumnCarId)); row.SetField(TripsDao.ColumnSensorId, tripsRawTable.Rows[i].Field <int>(TripsRawDao.ColumnSensorId)); row.SetField(TripsDao.ColumnStartTime, tripsRawTable.Rows[i].Field <DateTime>(TripsRawDao.ColumnStartTime)); row.SetField(TripsDao.ColumnEndTime, tripsRawTable.Rows[j].Field <DateTime>(TripsRawDao.ColumnEndTime)); row.SetField(TripsDao.ColumnStartLatitude, tripsRawTable.Rows[i].Field <double>(TripsRawDao.ColumnStartLatitude)); row.SetField(TripsDao.ColumnStartLongitude, tripsRawTable.Rows[i].Field <double>(TripsRawDao.ColumnStartLongitude)); row.SetField(TripsDao.ColumnEndLatitude, tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLatitude)); row.SetField(TripsDao.ColumnEndLongitude, tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLongitude)); row.SetField(TripsDao.ColumnTripDirection, "other"); TimeSpan span = tripsRawTable.Rows[j].Field <DateTime>(TripsRawDao.ColumnEndTime) - tripsRawTable.Rows[i].Field <DateTime>(TripsRawDao.ColumnStartTime); if (span.TotalHours > 12) { LogWritter.WriteLog(LogWritter.LogMode.Trip, "別々のトリップを結合する可能性があるので挿入しません " + ConvertRowToString(tripsRawTable.Rows[i], tripsRawTable.Rows[j])); break; } if (correction == InsertConfig.GpsCorrection.SpeedLPFMapMatching && !TripsSpeedLPF005MMDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else if (correction == InsertConfig.GpsCorrection.MapMatching && !TripsMMDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else if (correction == InsertConfig.GpsCorrection.Normal && !TripsDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else { LogWritter.WriteLog(LogWritter.LogMode.Trip, "既にこのトリップは挿入されているので挿入しません " + ConvertRowToString(tripsRawTable.Rows[i], tripsRawTable.Rows[j])); } tripChangeFlag = true; } // その他登録地点 ⇒ YNU if (IsYnu(tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLatitude), tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLongitude))) { var row = tripsTable.NewRow(); if (correction == InsertConfig.GpsCorrection.SpeedLPFMapMatching) { row.SetField(TripsDao.ColumnTripId, TripsSpeedLPF005MMDao.GetMaxTripId() + 1); } else if (correction == InsertConfig.GpsCorrection.MapMatching) { row.SetField(TripsDao.ColumnTripId, TripsMMDao.GetMaxTripId() + 1); } else { row.SetField(TripsDao.ColumnTripId, TripsDao.GetMaxTripId() + 1); } row.SetField(TripsDao.ColumnDriverId, tripsRawTable.Rows[i].Field <int>(TripsRawDao.ColumnDriverId)); row.SetField(TripsDao.ColumnCarId, tripsRawTable.Rows[i].Field <int>(TripsRawDao.ColumnCarId)); row.SetField(TripsDao.ColumnSensorId, tripsRawTable.Rows[i].Field <int>(TripsRawDao.ColumnSensorId)); row.SetField(TripsDao.ColumnStartTime, tripsRawTable.Rows[i].Field <DateTime>(TripsRawDao.ColumnStartTime)); row.SetField(TripsDao.ColumnEndTime, tripsRawTable.Rows[j].Field <DateTime>(TripsRawDao.ColumnEndTime)); row.SetField(TripsDao.ColumnStartLatitude, tripsRawTable.Rows[i].Field <double>(TripsRawDao.ColumnStartLatitude)); row.SetField(TripsDao.ColumnStartLongitude, tripsRawTable.Rows[i].Field <double>(TripsRawDao.ColumnStartLongitude)); row.SetField(TripsDao.ColumnEndLatitude, tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLatitude)); row.SetField(TripsDao.ColumnEndLongitude, tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLongitude)); row.SetField(TripsDao.ColumnTripDirection, "other"); TimeSpan span = tripsRawTable.Rows[j].Field <DateTime>(TripsRawDao.ColumnEndTime) - tripsRawTable.Rows[i].Field <DateTime>(TripsRawDao.ColumnStartTime); if (span.TotalHours > 12) { LogWritter.WriteLog(LogWritter.LogMode.Trip, "別々のトリップを結合する可能性があるので挿入しません " + ConvertRowToString(tripsRawTable.Rows[i], tripsRawTable.Rows[j])); break; } if (correction == InsertConfig.GpsCorrection.SpeedLPFMapMatching && !TripsSpeedLPF005MMDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else if (correction == InsertConfig.GpsCorrection.MapMatching && !TripsMMDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else if (correction == InsertConfig.GpsCorrection.Normal && !TripsDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else { LogWritter.WriteLog(LogWritter.LogMode.Trip, "既にこのトリップは挿入されているので挿入しません " + ConvertRowToString(tripsRawTable.Rows[i], tripsRawTable.Rows[j])); } tripChangeFlag = true; } //その他登録地点 ⇒ 自宅 else if (IsHome(tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLatitude), tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLongitude), tripsRawTable.Rows[j].Field <DateTime>(TripsRawDao.ColumnEndTime), datum)) { var row = tripsTable.NewRow(); if (correction == InsertConfig.GpsCorrection.SpeedLPFMapMatching) { row.SetField(TripsDao.ColumnTripId, TripsSpeedLPF005MMDao.GetMaxTripId() + 1); } else if (correction == InsertConfig.GpsCorrection.MapMatching) { row.SetField(TripsDao.ColumnTripId, TripsMMDao.GetMaxTripId() + 1); } else { row.SetField(TripsDao.ColumnTripId, TripsDao.GetMaxTripId() + 1); } row.SetField(TripsDao.ColumnDriverId, tripsRawTable.Rows[i].Field <int>(TripsRawDao.ColumnDriverId)); row.SetField(TripsDao.ColumnCarId, tripsRawTable.Rows[i].Field <int>(TripsRawDao.ColumnCarId)); row.SetField(TripsDao.ColumnSensorId, tripsRawTable.Rows[i].Field <int>(TripsRawDao.ColumnSensorId)); row.SetField(TripsDao.ColumnStartTime, tripsRawTable.Rows[i].Field <DateTime>(TripsRawDao.ColumnStartTime)); row.SetField(TripsDao.ColumnEndTime, tripsRawTable.Rows[j].Field <DateTime>(TripsRawDao.ColumnEndTime)); row.SetField(TripsDao.ColumnStartLatitude, tripsRawTable.Rows[i].Field <double>(TripsRawDao.ColumnStartLatitude)); row.SetField(TripsDao.ColumnStartLongitude, tripsRawTable.Rows[i].Field <double>(TripsRawDao.ColumnStartLongitude)); row.SetField(TripsDao.ColumnEndLatitude, tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLatitude)); row.SetField(TripsDao.ColumnEndLongitude, tripsRawTable.Rows[j].Field <double>(TripsRawDao.ColumnEndLongitude)); row.SetField(TripsDao.ColumnTripDirection, "other"); TimeSpan span = tripsRawTable.Rows[j].Field <DateTime>(TripsRawDao.ColumnEndTime) - tripsRawTable.Rows[i].Field <DateTime>(TripsRawDao.ColumnStartTime); if (span.TotalHours > 12) { LogWritter.WriteLog(LogWritter.LogMode.Trip, "別々のトリップを結合する可能性があるので挿入しません " + ConvertRowToString(tripsRawTable.Rows[i], tripsRawTable.Rows[j])); break; } if (correction == InsertConfig.GpsCorrection.SpeedLPFMapMatching && !TripsSpeedLPF005MMDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else if (correction == InsertConfig.GpsCorrection.MapMatching && !TripsMMDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else if (correction == InsertConfig.GpsCorrection.Normal && !TripsDao.IsExsistsTrip(row)) { tripsTable.Rows.Add(row); } else { LogWritter.WriteLog(LogWritter.LogMode.Trip, "既にこのトリップは挿入されているので挿入しません " + ConvertRowToString(tripsRawTable.Rows[i], tripsRawTable.Rows[j])); } tripChangeFlag = true; } j++; } }