Example #1
0
        public static IntervalHierarchyValues GetHierarchyValuesFromDataRow(DataRow dataRow, IntervalHierarchyNames columnNames)
        {
            IntervalHierarchyValues result = new IntervalHierarchyValues();

            try
            {
                result.SampleID      = DataRowContainsColumn(columnNames.SampleID, dataRow) ? dataRow[columnNames.SampleID].ToString() : result.SampleID;
                result.Expedition    = DataRowContainsColumn(columnNames.Expedition, dataRow) ? dataRow[columnNames.Expedition].ToString() : result.Expedition;
                result.Site          = DataRowContainsColumn(columnNames.Site, dataRow) ? dataRow[columnNames.Site].ToString() : result.Site;
                result.Hole          = DataRowContainsColumn(columnNames.Hole, dataRow) ? dataRow[columnNames.Hole].ToString() : result.Hole;
                result.Core          = DataRowContainsColumn(columnNames.Core, dataRow) ? dataRow[columnNames.Core].ToString() : result.Core;
                result.Type          = DataRowContainsColumn(columnNames.Type, dataRow) ? dataRow[columnNames.Type].ToString() : result.Type;
                result.Section       = DataRowContainsColumn(columnNames.Section, dataRow) ? dataRow[columnNames.Section].ToString() : result.Section;
                result.Half          = DataRowContainsColumn(columnNames.Half, dataRow) ? dataRow[columnNames.Half].ToString() : result.Half;
                result.Offset        = DataRowContainsColumn(columnNames.Offset, dataRow) ? dataRow[columnNames.Offset].ToString() : result.Offset;
                result.TopOffset     = DataRowContainsColumn(columnNames.TopOffset, dataRow) ? dataRow[columnNames.TopOffset].ToString() : result.TopOffset;
                result.BottomOffset  = DataRowContainsColumn(columnNames.BottomOffset, dataRow) ? dataRow[columnNames.BottomOffset].ToString() : result.BottomOffset;
                result.ArchiveTextID = DataRowContainsColumn(columnNames.ArchiveTextID, dataRow) ? dataRow[columnNames.ArchiveTextID].ToString() : result.ArchiveTextID;
                result.WorkingTextID = DataRowContainsColumn(columnNames.WorkingTextID, dataRow) ? dataRow[columnNames.WorkingTextID].ToString() : result.WorkingTextID;
                result.ParentTextID  = DataRowContainsColumn(columnNames.ParentTextID, dataRow) ? dataRow[columnNames.ParentTextID].ToString() : result.ParentTextID;
                result.TextID        = DataRowContainsColumn(columnNames.TextID, dataRow) ? dataRow[columnNames.TextID].ToString() : result.TextID;
                result.TestNumber    = DataRowContainsColumn(columnNames.TestNumber, dataRow) ? dataRow[columnNames.TestNumber].ToString() : result.TestNumber;
                return(result);
            }
            catch (Exception)
            {
                throw new Exception("Error trying to get hierarchy values from data row");
            }
        }
Example #2
0
 public void GetPropertiesFromSampleHierarchy(IntervalHierarchyValues hierarchy)
 {
     SampleID      = hierarchy.SampleID;
     Expedition    = hierarchy.Expedition;
     Site          = hierarchy.Site;
     Hole          = hierarchy.Hole;
     Core          = hierarchy.Core;
     Type          = hierarchy.Type;
     Section       = hierarchy.Section;
     Half          = hierarchy.Half;
     ParentTextID  = hierarchy.ParentTextID;
     WorkingTextID = hierarchy.WorkingTextID;
     ArchiveTextID = hierarchy.ArchiveTextID;
 }
Example #3
0
 public void ParseSectionInfoFromDataTable(DataTable sectionsDatatable, IntervalHierarchyNames hierarchyNames)
 {
     foreach (DataRow row in sectionsDatatable.Rows)
     {
         try
         {
             IntervalHierarchyValues values  = Importer.GetHierarchyValuesFromDataRow(row, hierarchyNames);
             SectionInfo             section = new SectionInfo(values);
             Sections.Add(section);
         }
         catch (Exception)
         {
             throw new Exception("Error parsing SectionInfo from data row");
         }
     }
 }
Example #4
0
        public static IntervalHierarchyValues ParseSampleID(string sampleID)
        {
            _ = sampleID ?? throw new ArgumentNullException(nameof(sampleID));

            IntervalHierarchyValues hierarchy = new IntervalHierarchyValues();


            string[] sampleIDComponents = sampleID.Split("-");
            try
            {
                switch (sampleIDComponents.Length)
                {
                case 0:
                    hierarchy.SampleID   = sampleID;
                    hierarchy.Expedition = null;
                    hierarchy.Site       = null;
                    hierarchy.Hole       = null;
                    hierarchy.Core       = null;
                    hierarchy.Type       = null;
                    hierarchy.Section    = null;
                    hierarchy.Half       = null;
                    break;

                case 1:
                    hierarchy.SampleID   = sampleID;
                    hierarchy.Expedition = sampleIDComponents[0];     //I may want to change in the iteration because I keep getting "No Sample" in the Exedition Column
                    hierarchy.Site       = null;
                    hierarchy.Hole       = null;
                    hierarchy.Core       = null;
                    hierarchy.Type       = null;
                    hierarchy.Section    = null;
                    hierarchy.Half       = null;
                    break;

                case 2:
                    hierarchy.SampleID   = sampleID;
                    hierarchy.Expedition = sampleIDComponents[0];
                    hierarchy.Site       = sampleIDComponents[1].Substring(0, sampleIDComponents[1].Length - 1);
                    hierarchy.Hole       = sampleIDComponents[1].Substring(sampleIDComponents[1].Length - 1, 1);
                    hierarchy.Core       = null;
                    hierarchy.Type       = null;
                    hierarchy.Section    = null;
                    hierarchy.Half       = null;
                    break;

                case 3:
                    hierarchy.SampleID   = sampleID;
                    hierarchy.Expedition = sampleIDComponents[0];
                    hierarchy.Site       = sampleIDComponents[1].Substring(0, sampleIDComponents[1].Length - 1);
                    hierarchy.Hole       = sampleIDComponents[1].Substring(sampleIDComponents[1].Length - 1, 1);
                    hierarchy.Core       = sampleIDComponents[2].Substring(0, sampleIDComponents[2].Length - 1);
                    hierarchy.Type       = sampleIDComponents[2].Substring(sampleIDComponents[2].Length - 1, 1);
                    hierarchy.Section    = null;
                    hierarchy.Half       = null;
                    break;

                case 4:
                    hierarchy.SampleID   = sampleID;
                    hierarchy.Expedition = sampleIDComponents[0];
                    hierarchy.Site       = sampleIDComponents[1].Substring(0, sampleIDComponents[1].Length - 1);
                    hierarchy.Hole       = sampleIDComponents[1].Substring(sampleIDComponents[1].Length - 1, 1);
                    hierarchy.Core       = sampleIDComponents[2].Substring(0, sampleIDComponents[2].Length - 1);
                    hierarchy.Type       = sampleIDComponents[2].Substring(sampleIDComponents[2].Length - 1, 1);
                    hierarchy.Section    = sampleIDComponents[3];
                    hierarchy.Half       = null;
                    break;

                case 5:
                    hierarchy.SampleID   = sampleID;
                    hierarchy.Expedition = sampleIDComponents[0];
                    hierarchy.Site       = sampleIDComponents[1].Substring(0, sampleIDComponents[1].Length - 1);
                    hierarchy.Hole       = sampleIDComponents[1].Substring(sampleIDComponents[1].Length - 1, 1);
                    hierarchy.Core       = sampleIDComponents[2].Substring(0, sampleIDComponents[2].Length - 1);
                    hierarchy.Type       = sampleIDComponents[2].Substring(sampleIDComponents[2].Length - 1, 1);
                    hierarchy.Section    = sampleIDComponents[3];
                    hierarchy.Half       = CleanUpSectionHalf(sampleIDComponents[4].Split(" ")[0]);
                    break;

                default:
                    hierarchy.SampleID   = sampleID;
                    hierarchy.Expedition = sampleIDComponents[0];
                    hierarchy.Site       = sampleIDComponents[1].Substring(0, sampleIDComponents[1].Length - 1);
                    hierarchy.Hole       = sampleIDComponents[1].Substring(sampleIDComponents[1].Length - 1, 1);
                    hierarchy.Core       = sampleIDComponents[2].Substring(0, sampleIDComponents[2].Length - 1);
                    hierarchy.Type       = sampleIDComponents[2].Substring(sampleIDComponents[2].Length - 1, 1);
                    hierarchy.Section    = sampleIDComponents[3];
                    hierarchy.Half       = CleanUpSectionHalf(sampleIDComponents[4].Split(" ")[0]);
                    break;
                }
                return(hierarchy);
            }
            catch (Exception)
            {
                throw new Exception("Error Parsing SampleID");
            }
        }
Example #5
0
        /// <summary>
        /// Asynchronously gets a collection of IODP measurements from a .csv file.
        /// </summary>
        /// <param name="filename">The .csv file location</param>
        /// <param name="columnIdentifiers">Optional parameter which specifies the file's column names</param>
        /// <returns>A collection of measurements</returns>
        public static async Task <ICollection <Measurement> > GetMeasurementsFromFileAsync(string filename, [Optional] IntervalHierarchyNames columnIdentifiers)
        {
            columnIdentifiers = columnIdentifiers ?? new IntervalHierarchyNames()
            {
                Expedition    = "Exp",
                Site          = "Site",
                Hole          = "Hole",
                Core          = "Core",
                Type          = "Type",
                Section       = "Sect",
                Half          = "A/W",
                TopOffset     = "Offset (cm)",
                BottomOffset  = "Offset (cm)",
                ArchiveTextID = "ArchiveSectionTextID_VP",
                WorkingTextID = "WorkingSectionTextID_VP",
                ParentTextID  = "ParentSectionTextID_VP",
                SampleID      = "Sample",
                TextID        = "Text ID",
                TestNumber    = "Test No.",
            };

            //TODO: need to get this some other way
            string InstrumentSystem = Importer.GetFileNameWithoutExtension(filename);

            if (InstrumentSystem == "CARB" || InstrumentSystem == "ICP")
            {
                columnIdentifiers.TopOffset    = "Top offset on section (cm)";
                columnIdentifiers.BottomOffset = "Bot offset on section (cm)";
            }

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

            ICollection <Measurement> measurements = new HashSet <Measurement>();

            try
            {
                foreach (DataRow row in iODPDataTable.DataTable.Rows)
                {
                    IntervalHierarchyValues parsedValues = Importer.GetHierarchyValuesFromDataRow(row, columnIdentifiers);

                    Measurement measurement = new Measurement();
                    measurement.SectionInfo      = new SectionInfo(parsedValues); //Creating a SectionInfo here that will be used to find the one stored in the DB.
                    measurement.DataRow          = row;
                    measurement.InstrumentReport = "";
                    measurement.InstrumentSystem = InstrumentSystem;
                    measurement.TextID           = parsedValues.TextID;
                    measurement.TestNumber       = parsedValues.TestNumber;
                    measurement.StartOffset      = double.TryParse(row[columnIdentifiers.TopOffset].ToString(), out double startOffset) ? startOffset : -1;
                    measurement.EndOffset        = double.TryParse(row[columnIdentifiers.BottomOffset].ToString(), out double endOffset) ? endOffset : -1;

                    measurements.Add(measurement);
                }
            }
            catch (Exception)
            {
                throw new Exception("Error creating measurement from data row");
            }

            using (DescDBContext dbContext = new DescDBContext())
            {
                string[] expeditions = measurements.Select(x => x.SectionInfo.Expedition).Distinct().ToArray();

                ICollection <SectionInfo> sections;
                try
                {
                    sections = await DatabaseWorkflowHandler.GetAllSectionsFromDatabaseForExpeditionAsync(dbContext, expeditions).ConfigureAwait(false);
                }
                catch (Exception)
                {
                    throw new Exception("Could not get sections from the database");
                }


                foreach (var measurement in measurements)
                {
                    measurement.SectionInfo = DatabaseWorkflowHandler.GetSectionInfoFromCollection(sections, measurement.SectionInfo);
                }

                return(measurements);
            }
        }
Example #6
0
 public SectionInfo(IntervalHierarchyValues sampleHierarchy)
 {
     GetPropertiesFromSampleHierarchy(sampleHierarchy);
 }