Пример #1
0
        // Update the species detected against the threshold in both the database and the file table
        private void UpdateSpeciesDetected(double threshold)
        {
            FileTable fileTable = this.fileDatabase.FileTable;
            // We now have an unselected temporary data table
            // Get the original value of each, and update each date by the corrected amount if possible
            List <ImageRow> filesToAdjust = new List <ImageRow>();
            List <ColumnTuplesWithWhere> filesToUpdate = new List <ColumnTuplesWithWhere>();

            for (int row = 0; row < fileTable.RowCount; row++)
            {
                ImageRow imageRow = this.fileDatabase.FileTable[row];
                bool?    newSpeciesDetectedValue = null;
                bool     forceUpdate             = false;
                // Get the current SpeciesDetected value
                if (bool.TryParse(imageRow.GetValueDisplayString(Constant.Recognition.SpeciesDetectedDataLabel), out bool currentSpeciesDetectedValue) == false)
                {
                    forceUpdate = true;
                }
                if (double.TryParse(imageRow.GetValueDisplayString(Constant.Recognition.DataLabelMaxConfidence), out double maxConfidence) == false)
                {
                    // If there is no confidence level, then the detector is likely not working so we always set the new Species detected value to false
                    forceUpdate             = true;
                    newSpeciesDetectedValue = false;
                }
                else
                {
                    newSpeciesDetectedValue = (maxConfidence >= threshold) ? true : false;
                }
                if (forceUpdate == true || newSpeciesDetectedValue != currentSpeciesDetectedValue)
                {
                    // System.Diagnostics.Debug.Print(newSpeciesDetectedValue.ToString());
                    string newSpeciesDetectedValueAsString = (newSpeciesDetectedValue == true)
                        ? Constant.BooleanValue.True
                        : Constant.BooleanValue.False;
                    imageRow.SetValueFromDatabaseString(Constant.Recognition.SpeciesDetectedDataLabel, newSpeciesDetectedValueAsString);
                    filesToAdjust.Add(imageRow);
                    filesToUpdate.Add(new ColumnTuplesWithWhere(new List <ColumnTuple>
                    {
                        new ColumnTuple(Constant.Recognition.SpeciesDetectedDataLabel, newSpeciesDetectedValueAsString)
                    }, imageRow.ID));
                }
            }
            // update the database with the new values
            this.fileDatabase.UpdateFiles(filesToUpdate);
        }