Exemplo n.º 1
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++;
            }
        }
Exemplo n.º 2
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);
        }