Пример #1
0
        /// <summary>
        /// Creates a new Lithologic Subinterval
        /// </summary>
        public LithologicSubinterval(int subID, LithologicDescription Description) : this()
        {
            _ = Description ?? throw new ArgumentNullException(nameof(Description));

            LithologicSubID = subID;
            SectionInfo     = Description.SectionInfo;
        }
Пример #2
0
        /// <summary>
        /// Returns a string ID based off the hierarchal information of a lithologic description
        /// </summary>
        /// <param name="description">The lithologic description to identify</param>
        /// <returns>A string representing a LithologicID</returns>
        public string GenerateID(LithologicDescription description)
        {

            try
            {
                string LithologicID = GenerateExpedition(description.SectionInfo.Expedition).ToString() +
                                    GenerateExpeditionModifier(description.SectionInfo.Expedition).ToString() +
                                    GenerateSite(description.SectionInfo.Site).ToString() +
                                    GenerateHole(description.SectionInfo.Hole).ToString() +
                                    GenerateCore(description.SectionInfo.Core).ToString() +
                                    GenerateType(description.SectionInfo.Type).ToString() +
                                    GenerateSection(description.SectionInfo.Section).ToString() +
                                    GenerateSectionHalf(description.SectionInfo.Half) +
                                    GenerateOffset(description.StartOffset.ToString()).ToString() +
                                    GenerateOffset(description.EndOffset.ToString()).ToString();

                description.LithologicID = LithologicID;
                return LithologicID;
            }
            catch (Exception)
            {

                throw;
           
            }

            


        }
Пример #3
0
        public static void CheckFile(IODPDataTable IODPDataTable)
        {
            int rowNumber = 1;

            foreach (DataRow row in IODPDataTable.DataTable.Rows)
            {
                if (!DataRowContainsDescription(row, IODPDataTable))
                {
                    throw new Exception(string.Format("Row {0}: Does not contain description", rowNumber));
                }

                if (!DataRowContainsSampleIDColumn(row, IODPDataTable))
                {
                    throw new Exception(string.Format("Row {0}: Does not contain SampleID column", rowNumber));
                }

                if (!DataRowContainsOffsetColumns(row, IODPDataTable))
                {
                    throw new Exception(string.Format("Row {0}: Data row does not contain Offset columns", rowNumber));
                }

                if (!StartOffsetValuesAreValid(row, IODPDataTable))
                {
                    throw new Exception(string.Format("Row {0}: Does not contain correct Start Offset values", rowNumber));
                }

                if (!EndOffsetValuesAreValid(row, IODPDataTable))
                {
                    throw new Exception(string.Format("Row {0}: Does not contain correct End Offset values", rowNumber));
                }

                LithologicDescription Description = new LithologicDescription();


                try
                {
                    Description = new LithologicDescription(row[IODPDataTable.SampleIDColumn].ToString());
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Row {0}: Could not parse SampleID. Error Message: {1}", rowNumber, ex.Message));
                }


                if (!DescriptionContainsSectionInfo(Description))
                {
                    throw new Exception(string.Format("Row {0}: Description does not contain section information", rowNumber));
                }

                rowNumber++;
            }
        }
Пример #4
0
        /// <summary>
        /// Gets a collection of LithologicDescriptions from a corrected file.
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="columnIdentifiers"></param>
        /// <returns></returns>
        public static async Task <ICollection <LithologicDescription> > GetDescriptionsFromFileAsync(string filename, [Optional] IntervalHierarchyNames columnIdentifiers)
        {
            columnIdentifiers = columnIdentifiers ?? new IntervalHierarchyNames()
            {
                Expedition    = "Expedition_VP",
                Site          = "Site_VP",
                Hole          = "Hole_VP",
                Core          = "Core_VP",
                Type          = "Type_VP",
                Section       = "Section_VP",
                Half          = "SectionHalf_VP",
                TopOffset     = "TopOffset_VP",
                BottomOffset  = "BottomOffset_VP",
                ArchiveTextID = "ArchiveSectionTextID_VP",
                WorkingTextID = "WorkingSectionTextID_VP",
                ParentTextID  = "ParentSectionTextID_VP"
            };

            IODPDataTable iODPDataTable = Importer.ImportDataTableFromFile(filename, columnIdentifiers);

            ICollection <LithologicDescription> descriptions = new HashSet <LithologicDescription>();

            using (DescDBContext dbContext = new DescDBContext())
            {
                try
                {
                    foreach (DataRow row in iODPDataTable.DataTable.Rows)
                    {
                        SectionInfo           section     = new SectionInfo(Importer.GetHierarchyValuesFromDataRow(row, columnIdentifiers));
                        LithologicDescription description = new LithologicDescription();
                        // description.SectionInfo = section;
                        description.SectionInfo = await DatabaseWorkflowHandler.GetSectionInfoFromDatabaseForIntervalAsync(dbContext, section).ConfigureAwait(true);

                        description.LithologicID      = row["LithologicID_VP"].ToString();
                        description.DataRow           = row;
                        description.DescriptionReport = row["Filename_VP"].ToString();;
                        description.StartOffset       = double.TryParse(row[columnIdentifiers.TopOffset].ToString(), out double startOffset) ? startOffset : -1;
                        description.EndOffset         = double.TryParse(row[columnIdentifiers.BottomOffset].ToString(), out double endOffset) ? endOffset : -1;

                        descriptions.Add(description);
                    }
                }
                catch (Exception)
                {
                    throw new Exception("Error creating lithologic description from data row");
                }
            }

            return(descriptions);
        }
Пример #5
0
        private static void AddDataToHierarchyColumns(IODPDataTable IODPDataTable, string fileName, DataTable allSectionsDataTable)
        {
            int rowNumber = 1;

            IntervalHierarchyNames sectionTableColumnNames = new IntervalHierarchyNames()
            {
                Expedition = "Exp",
                Site       = "Site",
                Hole       = "Hole",
                Core       = "Core",
                Type       = "Type",
                Section    = "Sect"
            };

            foreach (DataRow row in IODPDataTable.DataTable.Rows)
            {
                LithologicDescription description = new LithologicDescription(row[IODPDataTable.SampleIDColumn].ToString());

                double parsedOffset = 0;

                Importer.StartOffsetValuesAreValid(row, IODPDataTable, ref parsedOffset);

                description.StartOffset = parsedOffset;

                Importer.EndOffsetValuesAreValid(row, IODPDataTable, ref parsedOffset);

                description.EndOffset = parsedOffset;

                LithologicIDGenerator idGenerator = new LithologicIDGenerator();

                var textids = GetSectionTextIDsForDescription(allSectionsDataTable, description, sectionTableColumnNames);

                try
                {
                    var descriptionID = idGenerator.GenerateID(description);

                    row.BeginEdit();
                    row["Filename_VP"]             = fileName;
                    row["LithologicID_VP"]         = descriptionID;
                    row["ArchiveSectionTextID_VP"] = textids.Archive;
                    row["WorkingSectionTextID_VP"] = textids.Working;
                    row["ParentSectionTextID_VP"]  = textids.Parent;
                    row["Expedition_VP"]           = description.SectionInfo.Expedition;
                    row["Site_VP"]         = description.SectionInfo.Site;
                    row["Hole_VP"]         = description.SectionInfo.Hole;
                    row["Core_VP"]         = description.SectionInfo.Core;
                    row["Type_VP"]         = description.SectionInfo.Type;
                    row["Section_VP"]      = description.SectionInfo.Section;
                    row["SectionHalf_VP"]  = description.SectionInfo.Half;
                    row["TopOffset_VP"]    = description.StartOffset.ToString();
                    row["BottomOffset_VP"] = description.EndOffset.ToString();
                    row.EndEdit();
                }
                catch (Exception)
                {
                    Log.Warning(string.Format("Row {0}: Unable to populate data for description", rowNumber.ToString()));
                }

                rowNumber++;
            }
        }
Пример #6
0
        private static (string Archive, string Working, string Parent) GetSectionTextIDsForDescription(DataTable allSections, LithologicDescription description, IntervalHierarchyNames columnNames)
        {
            var matchingTextID = allSections.AsEnumerable().Where(x => x.Field <string>(columnNames.Expedition) == description.SectionInfo.Expedition &&
                                                                  x.Field <string>(columnNames.Site) == description.SectionInfo.Site &&
                                                                  x.Field <string>(columnNames.Hole) == description.SectionInfo.Hole &&
                                                                  x.Field <string>(columnNames.Core) == description.SectionInfo.Core &&
                                                                  x.Field <string>(columnNames.Type) == description.SectionInfo.Type &&
                                                                  x.Field <string>(columnNames.Section) == description.SectionInfo.Section).FirstOrDefault();


            if (matchingTextID == null)
            {
                return(Archive : "-1", Working : "-1", Parent : "-1");
            }

            (string Archive, string Working, string Parent)textids = (matchingTextID["Text ID of archive half"].ToString(), matchingTextID["Text ID of working half"].ToString(), matchingTextID["Text ID of section"].ToString());
            return(textids);
        }
Пример #7
0
 public static bool DescriptionContainsSectionInfo(LithologicDescription description)
 {
     return(description.SectionInfo.Section != null ? true : false);
 }
Пример #8
0
 public static void PrintDescriptionToConsole(LithologicDescription description)
 {
     Console.WriteLine(string.Format("ID:{0}, LithologicSubID:{1}, StartOffset:{2}, EndOffset:{3}", description.ID, description.LithologicID, description.StartOffset, description.EndOffset));
 }
Пример #9
0
        public static async Task <bool> CheckForDescriptionAsync(DescDBContext dBContext, LithologicDescription description)
        {
            bool recordExists = await dBContext.LithologicDescriptions
                                .Where(x => x.SectionInfo.ID == description.SectionInfo.ID)
                                .Where(x => x.DescriptionReport == description.DescriptionReport) //Report names may change depending on how we name the files,
                                .Where(x => x.StartOffset == description.StartOffset && x.EndOffset == description.EndOffset)
                                .AnyAsync().ConfigureAwait(true);

            return(recordExists);
        }
Пример #10
0
        /// <summary>
        /// Converts an IODPDataTable object into a collection of Lithologic Descriptions
        /// </summary>
        /// <param name="dataTable">The datatable to convert</param>
        /// <returns></returns>
        public static Dictionary <string, LithologicDescription> ConvertDatatableToDictionary(IODPDataTable dataTable, SectionInfoCollection SectionCollection)
        {
            _ = SectionCollection ?? throw new ArgumentNullException(nameof(SectionCollection));


            var LithologyCache = new Dictionary <string, LithologicDescription>();


            if (dataTable == null)
            {
                return(LithologyCache);
            }
            //Add a column in the datatable to ensure consistency between files with and without descriptions:
            dataTable.DataTable.Columns.Add("LithologicID_VP", typeof(string)).SetOrdinal(0);


            foreach (DataRow dataTableRow in dataTable.DataTable.Rows)
            {
                dataTableRow["LithologicID_VP"] = "-1";

                if (!Importer.DataRowContainsDescription(dataTableRow, dataTable))
                {
                    return(LithologyCache);
                }

                if (!Importer.DataRowContainsSampleIDColumn(dataTableRow, dataTable))
                {
                    return(LithologyCache);
                }

                LithologicDescription description = new LithologicDescription(dataTableRow[dataTable.SampleIDColumn].ToString());

                description.SectionInfo = SectionCollection.GetExistingElseAddAndGetCurrentSection(description.SectionInfo);

                if (!Importer.DescriptionContainsSectionInfo(description))
                {
                    return(LithologyCache);
                }

                description.DataRow = dataTableRow;

                double parsedOffset = 0;

                if (!Importer.DataRowContainsOffsetColumns(dataTableRow, dataTable))
                {
                    return(LithologyCache);
                }

                if (!Importer.StartOffsetValuesAreValid(dataTableRow, dataTable, ref parsedOffset))
                {
                    return(LithologyCache);
                }

                description.StartOffset = parsedOffset;

                if (!Importer.EndOffsetValuesAreValid(dataTableRow, dataTable, ref parsedOffset))
                {
                    return(LithologyCache);
                }

                description.EndOffset = parsedOffset;

                LithologicIDGenerator IDGenerator = new LithologicIDGenerator();
                IDGenerator.GenerateID(description);

                if (description.OffsetsSet())
                {
                    description.GenerateSubintervals();
                }

                description.DataRow["LithologicID_VP"] = description.LithologicID;

                //Some descriptions are split in two rows. It's very uncommon, but throws an error
                //Only selecting the first row, despite the loss of data
                if (!LithologyCache.ContainsKey(description.LithologicID))
                {
                    LithologyCache.Add(description.LithologicID, description);
                }
            }

            return(LithologyCache);
        }