Beispiel #1
0
        public static DataTable CalcEcologDoppler(DataRow tripRow, InsertDatum datum, InsertConfig.GpsCorrection correction)
        {
            var correctedGpsTable = new DataTable();

            if (correction == InsertConfig.GpsCorrection.DopplerSpeed) //補正GPS取得元変更
            {
                correctedGpsTable = CorrectedGPSDopplerDao.GetNormalized(tripRow.Field <DateTime>(TripsDao.ColumnStartTime),
                                                                         tripRow.Field <DateTime>(TripsDao.ColumnEndTime), datum);
            }
            else if (correction == InsertConfig.GpsCorrection.DopplerNotMM)
            {
                correctedGpsTable = CorrectedGpsDopplerNotMMDao.GetNormalized(tripRow.Field <DateTime>(TripsDao.ColumnStartTime),
                                                                              tripRow.Field <DateTime>(TripsDao.ColumnEndTime), datum);
            }


            var ecologTable = DataTableUtil.GetEcologTable();

            if (correctedGpsTable.Rows.Count == 0)
            {
                return(ecologTable);
            }
            var firstRow = GenerateFirstEcologDopplerRow(
                ecologTable.NewRow(), tripRow, correctedGpsTable.Rows[0], datum);

            ecologTable.Rows.Add(firstRow);

            var beforeRow = ecologTable.NewRow();

            beforeRow.ItemArray = firstRow.ItemArray;

            for (int i = 1; i < correctedGpsTable.Rows.Count; i++)
            {
                var row = GenerateEcologDopplerRow(
                    ecologTable.NewRow(), beforeRow, tripRow, correctedGpsTable.Rows[i], datum);

                ecologTable.Rows.Add(row);

                beforeRow.ItemArray = row.ItemArray;
            }

            return(ecologTable);
        }
        private static void MakeCorrectedGpsForDoppler(DataTable gpsRawTable, InsertConfig.GpsCorrection correction)
        {
            DataTable correctedGpsTable = DataTableUtil.GetCorrectedGpsDopplerTable();

            #region インデックスが 0 の場合
            DataRow firstRow = correctedGpsTable.NewRow();
            CopyRawDataDopplerToCorrectedRow(firstRow, gpsRawTable.Rows[0]);
            firstRow.SetField(CorrectedGpsDao.ColumnDistanceDifference, 0);
            //firstRow.SetField(CorrectedGpsDao.ColumnSpeed, 0);
            firstRow.SetField(CorrectedGpsDao.ColumnHeading, 0);
            var meshAndAltitude = AltitudeCalculator.GetInstance().CalcAltitude(
                gpsRawTable.Rows[0].Field <double>(CorrectedGpsDao.ColumnLatitude),
                gpsRawTable.Rows[0].Field <double>(CorrectedGpsDao.ColumnLongitude));

            firstRow.SetField(CorrectedGpsDao.ColumnTerrainAltitude, meshAndAltitude.Item2);



            var linkAndTheta = LinkMatcher.GetInstance().MatchLink(
                firstRow.Field <double>(CorrectedGpsDao.ColumnLatitude),
                firstRow.Field <double>(CorrectedGpsDao.ColumnLongitude),
                0f);

            firstRow.SetField(CorrectedGpsDao.ColumnLinkId, linkAndTheta.Item1);
            firstRow.SetField(CorrectedGpsDao.ColumnRoadTheta, linkAndTheta.Item2);

            correctedGpsTable.Rows.Add(firstRow);
            #endregion

            #region インデックスがiの場合
            for (int i = 1; i < gpsRawTable.Rows.Count - 1; i++)
            {
                DataRow row = correctedGpsTable.NewRow();

                CopyRawDataDopplerToCorrectedRow(row, gpsRawTable.Rows[i]);

                // 距離の算出
                row.SetField(CorrectedGpsDao.ColumnDistanceDifference, DistanceCalculator.CalcDistance(
                                 gpsRawTable.Rows[i - 1].Field <double>(AndroidGpsRawDao.ColumnLatitude),
                                 gpsRawTable.Rows[i - 1].Field <double>(AndroidGpsRawDao.ColumnLongitude),
                                 gpsRawTable.Rows[i].Field <double>(AndroidGpsRawDao.ColumnLatitude),
                                 gpsRawTable.Rows[i].Field <double>(AndroidGpsRawDao.ColumnLongitude)));

                meshAndAltitude = AltitudeCalculator.GetInstance().CalcAltitude(
                    gpsRawTable.Rows[i].Field <double>(CorrectedGpsDao.ColumnLatitude),
                    gpsRawTable.Rows[i].Field <double>(CorrectedGpsDao.ColumnLongitude));

                row.SetField(CorrectedGpsDao.ColumnTerrainAltitude, meshAndAltitude.Item2);



                // 速度の算出
                //row.SetField(CorrectedGpsDao.ColumnSpeed, SpeedCalculator.CalcSpeed(
                //    gpsRawTable.Rows[i - 1].Field<double>(AndroidGpsRawDao.ColumnLatitude),
                //    gpsRawTable.Rows[i - 1].Field<double>(AndroidGpsRawDao.ColumnLongitude),
                //    gpsRawTable.Rows[i - 1].Field<DateTime>(AndroidGpsRawDao.ColumnJst),
                //    gpsRawTable.Rows[i + 1].Field<double>(AndroidGpsRawDao.ColumnLatitude),
                //    gpsRawTable.Rows[i + 1].Field<double>(AndroidGpsRawDao.ColumnLongitude),
                //    gpsRawTable.Rows[i + 1].Field<DateTime>(AndroidGpsRawDao.ColumnJst),
                //    gpsRawTable.Rows[i].Field<double>(AndroidGpsRawDao.ColumnLatitude),
                //    gpsRawTable.Rows[i].Field<double>(AndroidGpsRawDao.ColumnLongitude)));

                //速度が1km以上になったらHEADINGを更新する(停止時に1つ1つ計算するとHEADINDが暴れるため)
                if (row.Field <Single?>(CorrectedGpsDao.ColumnSpeed) > 1.0)
                {
                    row.SetField(CorrectedGpsDao.ColumnHeading, HeadingCalculator.CalcHeading(
                                     gpsRawTable.Rows[i - 1].Field <double>(AndroidGpsRawDao.ColumnLatitude),
                                     gpsRawTable.Rows[i - 1].Field <double>(AndroidGpsRawDao.ColumnLongitude),
                                     gpsRawTable.Rows[i].Field <double>(AndroidGpsRawDao.ColumnLatitude),
                                     gpsRawTable.Rows[i].Field <double>(AndroidGpsRawDao.ColumnLongitude)));
                }
                else
                {
                    row.SetField(CorrectedGpsDao.ColumnHeading, correctedGpsTable.Rows[i - 1].Field <double>(CorrectedGpsDao.ColumnHeading));
                }

                linkAndTheta = LinkMatcher.GetInstance().MatchLink(
                    row.Field <double>(CorrectedGpsDao.ColumnLatitude),
                    row.Field <double>(CorrectedGpsDao.ColumnLongitude),
                    Convert.ToSingle(row.Field <double>(CorrectedGpsDao.ColumnHeading))
                    );

                row.SetField(CorrectedGpsDao.ColumnLinkId, linkAndTheta.Item1);
                row.SetField(CorrectedGpsDao.ColumnRoadTheta, linkAndTheta.Item2);
                correctedGpsTable.Rows.Add(row);
            }
            #endregion

            #region インデックスが最後の場合
            DataRow lastRow = correctedGpsTable.NewRow();
            CopyRawDataDopplerToCorrectedRow(lastRow, gpsRawTable.Rows[gpsRawTable.Rows.Count - 1]);
            lastRow.SetField(CorrectedGpsDao.ColumnDistanceDifference, 0);
            lastRow.SetField(CorrectedGpsDao.ColumnSpeed, 0);
            lastRow.SetField(CorrectedGpsDao.ColumnHeading, 0);

            meshAndAltitude = AltitudeCalculator.GetInstance().CalcAltitude(
                gpsRawTable.Rows[gpsRawTable.Rows.Count - 1].Field <double>(CorrectedGpsDao.ColumnLatitude),
                gpsRawTable.Rows[gpsRawTable.Rows.Count - 1].Field <double>(CorrectedGpsDao.ColumnLongitude));

            lastRow.SetField(CorrectedGpsDao.ColumnTerrainAltitude, meshAndAltitude.Item2);



            linkAndTheta = LinkMatcher.GetInstance().MatchLink(
                firstRow.Field <double>(CorrectedGpsDao.ColumnLatitude),
                firstRow.Field <double>(CorrectedGpsDao.ColumnLongitude),
                0f);

            lastRow.SetField(CorrectedGpsDao.ColumnLinkId, linkAndTheta.Item1);
            lastRow.SetField(CorrectedGpsDao.ColumnRoadTheta, linkAndTheta.Item2);

            correctedGpsTable.Rows.Add(lastRow);

            #endregion

            // ファイルごとの挿入なので主キー違反があっても挿入されないだけ
            if (correction == InsertConfig.GpsCorrection.DopplerSpeed)
            {
                CorrectedGPSDopplerDao.Insert(correctedGpsTable);
            }
            else if (correction == InsertConfig.GpsCorrection.DopplerNotMM)
            {
                CorrectedGpsDopplerNotMMDao.Insert(correctedGpsTable);
            }
        }
        public static void InsertTrip(InsertDatum datum, InsertConfig.GpsCorrection correction, bool isCheckedSightseeingInsert)
        {
            LogWritter.WriteLog(LogWritter.LogMode.Trip, $"TRIP挿入開始, DRIVER_ID: {datum.DriverId}, CAR_ID: {datum.CarId}, SENSOR_ID: {datum.SensorId}");
            var tripsRawTable = new DataTable();

            if (correction == InsertConfig.GpsCorrection.SpeedLPFMapMatching)
            {
                tripsRawTable = TripsRawSpeedLPF005MMDao.Get(datum);
                TripsSpeedLPF005MMDao.DeleteTrips(); //途中中断された際に作成したトリップを削除
            }
            else if (correction == InsertConfig.GpsCorrection.MapMatching)
            {
                tripsRawTable = TripsRawMMDao.Get(datum);
                TripsMMDao.DeleteTrips(); //途中中断された際に作成したトリップを削除
            }
            else if (correction == InsertConfig.GpsCorrection.Normal)
            {
                tripsRawTable = TripsRawDao.Get(datum);
                TripsDao.DeleteTrips(); //途中中断された際に作成したトリップを削除
            }
            else if (correction == InsertConfig.GpsCorrection.DopplerSpeed)
            {
                tripsRawTable = TripsRawDopplerDao.Get(datum);
                TripsDopplerDao.DeleteTrips(); //途中中断された際に作成したトリップを削除
            }
            else if (correction == InsertConfig.GpsCorrection.DopplerNotMM)
            {
                tripsRawTable = TripsRawDopplerNotMMDao.Get(datum);
                TripsDopplerNotMMDao.DeleteTrips();
            }


            LogWritter.WriteLog(LogWritter.LogMode.Trip, $"挿入対象のRAWデータ: {tripsRawTable.Rows.Count}");


            for (int i = 0; i < tripsRawTable.Rows.Count; i++)
            {
                DataTable tripsTable = DataTableUtil.GetTripsTable();


                // 観光オプションによるインサート処理はあらかじめ切り分ける。
                if (isCheckedSightseeingInsert)
                {
                    InsertSightSeeingTrip(tripsRawTable, tripsTable, datum, i, correction);
                }

                // 自宅出発
                else if (IsHome(tripsRawTable.Rows[i].Field <double>(TripsRawDao.ColumnStartLatitude),
                                tripsRawTable.Rows[i].Field <double>(TripsRawDao.ColumnStartLongitude),
                                tripsRawTable.Rows[i].Field <DateTime>(TripsRawDao.ColumnStartTime),
                                datum))
                {
                    InsertOutwardTrip(tripsRawTable, tripsTable, datum, i, correction);
                }
                // YNU出発
                else if (IsYnu(tripsRawTable.Rows[i].Field <double>(TripsRawDao.ColumnStartLatitude),
                               tripsRawTable.Rows[i].Field <double>(TripsRawDao.ColumnStartLongitude)))
                {
                    InsertHomewardTrip(tripsRawTable, tripsTable, datum, i, correction);
                }

                // 1トリップごとなので主キー違反があっても挿入されないだけ
                if (correction == InsertConfig.GpsCorrection.SpeedLPFMapMatching)
                {
                    TripsSpeedLPF005MMDao.Insert(tripsTable);
                }
                else if (correction == InsertConfig.GpsCorrection.MapMatching)
                {
                    TripsMMDao.Insert(tripsTable);
                }
                else if (correction == InsertConfig.GpsCorrection.Normal)
                {
                    TripsDao.Insert(tripsTable);
                }
                else if (correction == InsertConfig.GpsCorrection.DopplerSpeed)
                {
                    if (tripsTable.Rows.Count != 0)
                    {
                        var gpsCorrectedTable = CorrectedGPSDopplerDao.GetNormalized(
                            tripsTable.Rows[0].Field <DateTime>(TripsDopplerDao.ColumnStartTime),
                            tripsTable.Rows[0].Field <DateTime>(TripsDopplerDao.ColumnEndTime),
                            datum);
                        if (gpsCorrectedTable.Rows.Count != 0)
                        {
                            TripsDopplerDao.Insert(tripsTable);
                        }
                    }
                }
                else if (correction == InsertConfig.GpsCorrection.DopplerNotMM)
                {
                    if (tripsTable.Rows.Count != 0)
                    {
                        var gpsCorrectedTable = CorrectedGpsDopplerNotMMDao.GetNormalized(
                            tripsTable.Rows[0].Field <DateTime>(TripsDopplerDao.ColumnStartTime),
                            tripsTable.Rows[0].Field <DateTime>(TripsDopplerDao.ColumnEndTime),
                            datum);
                        if (gpsCorrectedTable.Rows.Count != 0)
                        {
                            TripsDopplerNotMMDao.Insert(tripsTable);
                        }
                    }
                }
            }
        }