Beispiel #1
0
        /// <summary>
        /// Process the row from the DB.  A row represents an ensemble.
        /// </summary>
        /// <param name="reader">Database connection data.</param>
        /// <param name="bin">Bin number.</param>
        /// <returns>Magnitude data for a row.</returns>
        private double ParseDirData(DbDataReader reader, int bin)
        {
            try
            {
                // Get the data
                DbDataHelper.VelocityMagDir velMagDir = DbDataHelper.CreateVelocityVectors(reader, _backupBtEast, _backupBtNorth, true, false);

                // Store the backup value
                if (velMagDir.IsBtVelGood)
                {
                    _backupBtEast  = velMagDir.BtEastVel;
                    _backupBtNorth = velMagDir.BtNorthVel;
                }

                if (bin < velMagDir.Magnitude.Length)
                {
                    if (Math.Round(velMagDir.DirectionYNorth[bin], 3) != DbDataHelper.BAD_VELOCITY)
                    {
                        return(velMagDir.DirectionYNorth[bin]);
                    }
                }

                return(0.0);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error parsing the Earth Velocity Direction data row", e);
                return(0.0);
            }
        }
        /// <summary>
        /// Process the row from the DB.  A row represents an ensemble.
        /// </summary>
        /// <param name="reader">Database connection data.</param>
        /// <returns>Direction data for a row.</returns>
        private double[] ParseDirData(DbDataReader reader)
        {
            try
            {
                // Get data
                DbDataHelper.VelocityMagDir velMagDir = DbDataHelper.CreateVelocityVectors(reader, _backupBtEast, _backupBtNorth, _IsRemoveShipSpeed, _IsMarkBadBelowBottom);

                // Store the backup value
                if (velMagDir.IsBtVelGood)
                {
                    _backupBtEast  = velMagDir.BtEastVel;
                    _backupBtNorth = velMagDir.BtNorthVel;
                }

                return(velMagDir.DirectionYNorth);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error parsing the Earth Velocity Direction data row", e);
                return(null);
            }
        }
        /// <summary>
        /// Query the data from the database.
        /// </summary>
        /// <param name="cnn">SQLite connection.</param>
        /// <param name="query">Query for the data.</param>
        /// <param name="magScale">Magnitude scale.</param>
        /// <param name="minIndex">Minimum index.</param>
        /// <param name="maxIndex">Maximum index.</param>
        /// <returns></returns>
        private List <ShipTrackData> QueryDataFromDb(SQLiteConnection cnn, string query, double magScale, int minIndex = 0, int maxIndex = 0)
        {
            // Init list
            double backupBtEast  = DbDataHelper.BAD_VELOCITY;
            double backupBtNorth = DbDataHelper.BAD_VELOCITY;

            // Init the new series data
            List <ShipTrackData> stDataList = new List <ShipTrackData>();

            //stData.MagScale = magScale;

            // Ensure a connection was made
            if (cnn == null)
            {
                return(null);
            }

            using (DbCommand cmd = cnn.CreateCommand())
            {
                cmd.CommandText = query;

                // Get Result
                DbDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    ShipTrackData stData = new ShipTrackData();

                    // Update the status
                    StatusProgress++;
                    StatusMsg = reader["EnsembleNum"].ToString();

                    // Get the Ensemble number and Date and time
                    stData.DateTime = reader["DateTime"].ToString();
                    stData.EnsNum   = reader["EnsembleNum"].ToString();

                    // Plot the lat/lon
                    stData.LatLon = reader["Position"].ToString();

                    // Heading
                    DbDataHelper.HPR hpr = DbDataHelper.GetHPR(reader);
                    stData.Heading = hpr.Heading;

                    //// Get the range bin
                    //int rangeBin = DbDataHelper.GetRangeBin(reader);

                    //// Get the magnitude data
                    //string jsonEarth = reader["EarthVelocityDS"].ToString();
                    //if (!string.IsNullOrEmpty(jsonEarth))
                    //{
                    //    // Convert to a JSON object
                    //    JObject ensEarth = JObject.Parse(jsonEarth);

                    //    // Average the data
                    //    avgMag = DbDataHelper.GetAvgMag(ensEarth, IsMarkBadBelowBottom, rangeBin, DbDataHelper.BAD_VELOCITY);
                    //    avgDir = DbDataHelper.GetAvgDir(ensEarth, IsMarkBadBelowBottom, rangeBin, DbDataHelper.BAD_VELOCITY);

                    //    //Debug.WriteLine(string.Format("Avg Dir: {0} Avg Mag: {1}", avgDir, avgMag));
                    //}

                    if (IsUseGpsSpeedBackup)
                    {
                        // Get the GPS data from the database
                        DbDataHelper.GpsData gpsData = DbDataHelper.GetGpsData(reader);

                        // Check for a backup value for BT East and North speed from the GPS if a Bottom Track value is never found
                        if (Math.Round(backupBtEast, 4) == BAD_VELOCITY && gpsData.IsBackShipSpeedGood)
                        {
                            backupBtEast  = gpsData.BackupShipEast;
                            backupBtNorth = gpsData.BackupShipNorth;
                        }
                    }

                    // Get the velocity
                    stData.VelMagDir = DbDataHelper.CreateVelocityVectors(reader, backupBtEast, backupBtNorth, true, true);

                    // Get the average range
                    stData.AvgRange = DbDataHelper.GetAverageRange(reader);

                    // Store the backup value
                    if (stData.VelMagDir.IsBtVelGood)
                    {
                        backupBtEast  = stData.VelMagDir.BtEastVel;
                        backupBtNorth = stData.VelMagDir.BtNorthVel;
                    }

                    // Add the data to the list
                    stDataList.Add(stData);
                }
            }

            return(stDataList);
        }