/// <summary>
        ///     Recursive function that will cycle through the readings, starting at
        ///     indexToUpdate until it reaches the end of the readings list, updating
        ///     the trustworthiness as it goes along.
        /// </summary>
        /// <param name="readings"></param>
        /// <param name="indexToUpdate"></param>
        /// <param name="config">If left null, will use config from database - optional for unit testing purposes</param>
        public static void UpdateReadingsTrustworthiness(List <DepthReadingModel> readings, int indexToUpdate, DrillConfigModel config = null)
        {
            if (indexToUpdate >= readings.Count)
            {
                return; // end of list
            }
            if (config == null)
            {
                config = Config ?? (Config = DrillConfigService.GetInstance().DrillConfigModel);
            }

            var azimuthRecordsToQuery =
                RetrieveXRecordsBefore(readings, indexToUpdate, config.NumberOfRecordsToQueryAzimuth).ToList();
            var dipRecordsToQuery = config.NumberOfRecordsToQueryAzimuth == config.NumberOfRecordsToQueryDip
                ? azimuthRecordsToQuery // no need to calculate new list, if they're both going to be the same
                : RetrieveXRecordsBefore(readings, indexToUpdate, config.NumberOfRecordsToQueryDip).ToList();

            CalculateTrustWorthiness(config, readings[indexToUpdate], dipRecordsToQuery, azimuthRecordsToQuery);
            UpdateReadingsTrustworthiness(readings, indexToUpdate + 1, config);
        }
        /// <summary>
        /// Retrieve singleton instance of config service - on first call
        /// GetInstance will attempt to retrieve config from database, if
        /// config does not exist in database, an instance is created and
        /// inserted into the database.
        /// </summary>
        /// <returns>Database config service instance</returns>
        public static DrillConfigService GetInstance()
        {
            if (_instance != null)
            {
                return(_instance); // already instantiated
            }
            // create default instance
            _instance = new DrillConfigService();

            // attempt to read config from database
            try
            {
                using (var db = new DsmContext())
                {
                    var config = db.Config.FirstOrDefaultAsync().Result;
                    if (config == null) // no config exists in database
                    {
                        // insert default instance
                        db.Config.Add(_instance.DrillConfigModel);
                        db.SaveChanges();
                    }
                    else
                    {
                        // config exists, create service instance using config data
                        _instance = new DrillConfigService(config);
                    }
                }
            }
            catch (SqliteException ex)
            {
                Console.WriteLine("Failed to retrieve or write config to database", ex);
            }
            catch (AggregateException ex)
            {
                Console.WriteLine("Failed to retrieve or write config to database", ex);
            }

            return(_instance);
        }