public void LogExtensions_141_IsValidDataDelimiter_Validation_Fail_Tests() { var log = new Witsml141.Log { DataDelimiter = "long" }; Assert.IsFalse(log.IsValidDataDelimiter()); // Validate that all digits are invalid for (int i = 0; i < 10; i++) { log.DataDelimiter = i.ToString(); Assert.IsFalse(log.IsValidDataDelimiter()); } // A space in the delimiter is not allowed log.DataDelimiter = "# "; Assert.IsFalse(log.IsValidDataDelimiter()); // A decimal in the delimiter is not allowed log.DataDelimiter = "."; Assert.IsFalse(log.IsValidDataDelimiter()); // A "+" in the delimiter is not allowed log.DataDelimiter = "+"; Assert.IsFalse(log.IsValidDataDelimiter()); // A "-" in the delimiter is not allowed log.DataDelimiter = "-"; Assert.IsFalse(log.IsValidDataDelimiter()); }
public void LogExtensions_141_GetNullValues_Can_Return_Null_Values_In_The_Order_Of_Mnemonics() { var log = new Witsml141.Log { LogCurveInfo = new List <Witsml141.ComponentSchemas.LogCurveInfo>() }; var lci0 = _log141Generator.CreateDoubleLogCurveInfo("DEPTH", "m"); lci0.NullValue = "-1000.00"; log.LogCurveInfo.Add(lci0); var lci1 = _log141Generator.CreateDoubleLogCurveInfo("CH1", "m/h"); lci1.NullValue = "-1111.11"; log.LogCurveInfo.Add(lci1); var lci2 = _log141Generator.CreateDoubleLogCurveInfo("CH2", "gAPI"); lci2.NullValue = "-2222.22"; log.LogCurveInfo.Add(lci2); var lci3 = _log141Generator.CreateDoubleLogCurveInfo("CH3", "gAPI"); lci3.NullValue = "-3333.33"; log.LogCurveInfo.Add(lci3); var lci4 = _log141Generator.CreateDoubleLogCurveInfo("CH4", "gAPI"); log.LogCurveInfo.Add(lci4); string[] mnemonic = new string[] { "CH3", "CH4", "CH1" }; var nullValueList = log.GetNullValues(mnemonic).ToArray(); Assert.AreEqual(3, nullValueList.Length); Assert.AreEqual("-3333.33", nullValueList[0]); Assert.AreEqual("null", nullValueList[1]); Assert.AreEqual("-1111.11", nullValueList[2]); }
public void LogExtensions_GetByMnemonic_Returns_141_LogCurveInfo_By_Mnemonic() { var log = new Witsml141.Log(); var logCurveInfo = log.LogCurveInfo.GetByMnemonic("depth"); Assert.IsNull(logCurveInfo); log.LogCurveInfo = new List <Witsml141.ComponentSchemas.LogCurveInfo>(); logCurveInfo = log.LogCurveInfo.GetByMnemonic("depth"); Assert.IsNull(logCurveInfo); // Add curves log.LogCurveInfo = new List <Witsml141.ComponentSchemas.LogCurveInfo>(); var lci0 = _log141Generator.CreateDoubleLogCurveInfo("DEPTH", "m"); lci0.NullValue = "-1000.00"; log.LogCurveInfo.Add(lci0); var lci1 = _log141Generator.CreateDoubleLogCurveInfo("CH1", "m/h"); lci1.NullValue = "-1111.11"; log.LogCurveInfo.Add(lci1); logCurveInfo = log.LogCurveInfo.GetByMnemonic("depth"); Assert.IsNotNull(logCurveInfo); Assert.AreEqual(lci0, logCurveInfo); }
public void LogExtensions_GetIndexRange_Returns_Range_From_141_DepthLog() { double start, end; InitDepthIndexes(out start, out end); var log = new Witsml141.Log { LogCurveInfo = new List <Witsml141.ComponentSchemas.LogCurveInfo>() }; var result = new Witsml141.ComponentSchemas.LogCurveInfo().GetIndexRange(); Assert.IsNull(result.Start); Assert.IsNull(result.End); // Add logCurveInfo with just start index var lci0 = _log141Generator.CreateDoubleLogCurveInfo("DEPTH", "m"); lci0.NullValue = "-1000.00"; lci0.MinIndex = new Witsml141.ComponentSchemas.GenericMeasure(start, "m"); log.LogCurveInfo.Add(lci0); result = log.LogCurveInfo[0].GetIndexRange(); Assert.IsNotNull(result); Assert.IsTrue(result.Start.HasValue); Assert.IsFalse(result.End.HasValue); Assert.AreEqual(start, result.Start.Value); // Decreasing log result = log.LogCurveInfo[0].GetIndexRange(false); Assert.IsNotNull(result); Assert.IsTrue(result.End.HasValue); Assert.IsFalse(result.Start.HasValue); Assert.AreEqual(start, result.End.Value); // Update end index lci0.MaxIndex = new Witsml141.ComponentSchemas.GenericMeasure(end, "m"); result = log.LogCurveInfo[0].GetIndexRange(); Assert.IsNotNull(result); Assert.IsTrue(result.Start.HasValue); Assert.IsTrue(result.End.HasValue); Assert.AreEqual(start, result.Start.Value); Assert.AreEqual(end, result.End.Value); // Decreasing with end index result = log.LogCurveInfo[0].GetIndexRange(false); Assert.IsNotNull(result); Assert.IsTrue(result.Start.HasValue); Assert.IsTrue(result.End.HasValue); Assert.AreEqual(start, result.End.Value); Assert.AreEqual(end, result.Start.Value); }
public void LogExtensions_IsIncreasing_Returns_Bool_If_141_Log_Is_Timelog() { var log = new Witsml141.Log { IndexType = Witsml141.ReferenceData.LogIndexType.datetime }; Assert.IsTrue(log.IsTimeLog()); log.IndexType = Witsml141.ReferenceData.LogIndexType.elapsedtime; Assert.IsTrue(log.IsTimeLog(true)); log.IndexType = Witsml141.ReferenceData.LogIndexType.measureddepth; Assert.IsFalse(log.IsTimeLog()); log.IndexType = null; Assert.IsTrue(log.IsTimeLog()); log.LogData = new List <Witsml141.ComponentSchemas.LogData>() { new Witsml141.ComponentSchemas.LogData { MnemonicList = "TIME,A,B,C", } }; Assert.IsTrue(log.IsTimeLog()); log.LogData = new List <Witsml141.ComponentSchemas.LogData>() { new Witsml141.ComponentSchemas.LogData { Data = new List <string>() { "2016-01-01T00:00:00.001Z,1,2,3" }, MnemonicList = "TIME,A,B,C", UnitList = "unitless,m,m,m" } }; log.LogData = new List <Witsml141.ComponentSchemas.LogData>() { new Witsml141.ComponentSchemas.LogData { Data = new List <string>() { "1023.1,1,2,3" }, MnemonicList = "DEPTH,A,B,C", UnitList = "m,m,m,m" } }; Assert.IsFalse(log.IsTimeLog()); }
public void LogExtensions_141_GetDataDelimiterOrDefault_When_Log_Is_Null() { var log = new Witsml141.Log(); log = null; var result = log.GetDataDelimiterOrDefault(); Assert.AreEqual(",", result); }
public void LogExtensions_IsIncreasing_Returns_Bool_For_141_Log_Direction() { var log = new Witsml141.Log { Direction = Witsml141.ReferenceData.LogIndexDirection.increasing }; Assert.IsTrue(log.IsIncreasing()); log.Direction = Witsml141.ReferenceData.LogIndexDirection.decreasing; Assert.IsFalse(log.IsIncreasing()); }
public void EtpUris_GetUri_Can_Get_Log_141_Uri() { var log = new Witsml141.Log { Uid = _data.Uid(), UidWell = _data.Uid(), UidWellbore = _data.Uid() }; var uri = log.GetUri(); Assert.IsTrue($"eml://witsml14/well({ log.UidWell })/wellbore({ log.UidWellbore })/log({ log.Uid })".EqualsIgnoreCase(uri.ToString())); Assert.AreEqual("log", uri.ObjectType); Assert.AreEqual(log.Uid, uri.ObjectId); Assert.AreEqual(uri, ((IDataObject)log).GetUri()); Assert.AreEqual(uri, ((IWellObject)log).GetUri()); }
/// <summary> /// Sets the log data. /// </summary> /// <param name="log">The log.</param> /// <param name="keepGridData">True if not clearing data when querying partial results</param> /// <param name="errorHandler">The error handler.</param> private void SetLogData(Witsml141.Log log, bool keepGridData, Action <WitsmlException> errorHandler) { ClearDataTable(log.GetUri(), keepGridData); Task.Run(() => { try { log.GetReaders().ForEach(SetChannelData); } catch (WitsmlException ex) { _log.WarnFormat("Error setting log data: {0}", ex); errorHandler(ex); } }); }
/// <summary> /// Determines whether the specified log's data delimiter is valid. /// </summary> /// <param name="log">The log.</param> /// <returns>true if the log's data delimiter is valid, false otherwise.</returns> public static bool IsValidDataDelimiter(this Witsml141.Log log) { // null or empty string will use default data delimiter if (string.IsNullOrWhiteSpace(log.DataDelimiter)) { return(true); } // check delimiter length if (log.DataDelimiter.Length > _maxDataDelimiterLength) { return(false); } // check for invalid characters return(!_dataDelimterExclusionsRegex.IsMatch(log.DataDelimiter)); }
/// <summary> /// Determines whether the <see cref="Witsml141.Log"/> is a time log. /// </summary> /// <param name="log">The log.</param> /// <param name="includeElapsedTime">if set to <c>true</c>, include elapsed time.</param> /// <returns> /// <c>true</c> if the <see cref="Witsml141.Log"/> is a time log; otherwise, false. /// </returns> public static bool IsTimeLog(this Witsml141.Log log, bool includeElapsedTime = false) { if (log.IndexType.HasValue) { return(log.IndexType.Value == Witsml141.ReferenceData.LogIndexType.datetime || (log.IndexType.Value == Witsml141.ReferenceData.LogIndexType.elapsedtime && includeElapsedTime)); } // Use LogIndexType default if logData not available if (log.LogData == null) { return(true); } var data = log.LogData.SelectMany(x => x.Data ?? new List <string>(0)).FirstOrDefault(); return(data.IsFirstValueDateTime(log.GetDataDelimiterOrDefault())); }
/// <summary> /// Gets multiple readers for each LogData from a <see cref="Witsml141.Log"/> instance. /// </summary> /// <param name="log">The log.</param> /// <returns>An <see cref="IEnumerable{ChannelDataReader}"/>.</returns> public static IEnumerable <ChannelDataReader> GetReaders(this Witsml141.Log log) { if (log?.LogData == null) { yield break; } _log.DebugFormat("Creating ChannelDataReaders for {0}", log.GetType().FullName); var isTimeIndex = log.IsTimeLog(); var increasing = log.IsIncreasing(); foreach (var logData in log.LogData) { if (logData?.Data == null || !logData.Data.Any()) { continue; } var mnemonics = ChannelDataReader.Split(logData.MnemonicList); var units = ChannelDataReader.Split(logData.UnitList); var dataTypes = log.LogCurveInfo.Select(x => x.TypeLogData?.ToString()).ToArray(); var nullValues = log.GetNullValues(mnemonics).ToArray(); // Split index curve from other value curves var indexCurve = log.LogCurveInfo.GetByMnemonic(log.IndexCurve) ?? new Witsml141.ComponentSchemas.LogCurveInfo { Mnemonic = new Witsml141.ComponentSchemas.ShortNameStruct(mnemonics.FirstOrDefault()), Unit = units.FirstOrDefault() }; // Skip index curve when passing mnemonics to reader mnemonics = mnemonics.Skip(1).ToArray(); units = units.Skip(1).ToArray(); dataTypes = dataTypes.Skip(1).ToArray(); nullValues = nullValues.Skip(1).ToArray(); yield return(new ChannelDataReader(logData.Data, mnemonics.Length + 1, mnemonics, units, dataTypes, nullValues, log.GetUri(), dataDelimiter: log.GetDataDelimiterOrDefault()) // Add index curve to separate collection .WithIndex(indexCurve.Mnemonic.Value, indexCurve.Unit, increasing, isTimeIndex)); } }
public void EtpUris_GetUri_Can_Get_LogCurveInfo_141_Uri() { var logCurve = new Witsml141.ComponentSchemas.LogCurveInfo { Mnemonic = new Witsml141.ComponentSchemas.ShortNameStruct("ROP") }; var log = new Witsml141.Log { Uid = _data.Uid(), UidWell = _data.Uid(), UidWellbore = _data.Uid(), LogCurveInfo = new List <Witsml141.ComponentSchemas.LogCurveInfo> { logCurve } }; var uri = logCurve.GetUri(log); Assert.IsTrue($"eml://witsml14/well({log.UidWell})/wellbore({log.UidWellbore})/log({log.Uid})/logCurveInfo({logCurve.Mnemonic})".EqualsIgnoreCase(uri.ToString())); Assert.AreEqual(ObjectTypes.LogCurveInfo, uri.ObjectType); Assert.AreEqual(logCurve.Mnemonic.Value, uri.ObjectId); }
public void LogExtensions_141_IsValidDataDelimiter_Data_Delimiter_Validation_Pass_Tests() { var log = new Witsml141.Log(); Assert.IsTrue(log.IsValidDataDelimiter()); // Test symbols that should pass validation log.DataDelimiter = "#"; Assert.IsTrue(log.IsValidDataDelimiter()); log.DataDelimiter = "*"; Assert.IsTrue(log.IsValidDataDelimiter()); log.DataDelimiter = "~"; Assert.IsTrue(log.IsValidDataDelimiter()); log.DataDelimiter = "^"; Assert.IsTrue(log.IsValidDataDelimiter()); log.DataDelimiter = "$"; Assert.IsTrue(log.IsValidDataDelimiter()); log.DataDelimiter = "("; Assert.IsTrue(log.IsValidDataDelimiter()); log.DataDelimiter = ")"; Assert.IsTrue(log.IsValidDataDelimiter()); log.DataDelimiter = "@"; Assert.IsTrue(log.IsValidDataDelimiter()); log.DataDelimiter = "!"; Assert.IsTrue(log.IsValidDataDelimiter()); log.DataDelimiter = "|"; Assert.IsTrue(log.IsValidDataDelimiter()); }
/// <summary> /// Gets the data delimiter for the log or the default data delimiter. /// </summary> /// <param name="log">The log.</param> /// <returns>The data delimiter.</returns> public static string GetDataDelimiterOrDefault(this Witsml141.Log log) { return(ChannelDataExtensions.GetDataDelimiterOrDefault(log?.DataDelimiter)); }
/// <summary> /// Gets the <see cref="EtpUri"/> for a given <see cref="Energistics.DataAccess.WITSML131.ComponentSchemas.LogCurveInfo"/> /// </summary> /// <param name="entity">The entity.</param> /// <param name="log">The log.</param> /// <returns>An <see cref="EtpUri"/> instance.</returns> public static EtpUri GetUri(this Witsml141.ComponentSchemas.LogCurveInfo entity, Witsml141.Log log) { return(log.GetUri() .Append(ObjectTypes.LogCurveInfo, entity.Mnemonic.Value, true)); }
public void LogExtensions_GetIndexRange_Returns_Range_From_141_TimeLog() { Timestamp start, end; InitTimeIndexes(out start, out end); var startAsLong = start.ToUnixTimeMicroseconds(); var endAsLong = end.ToUnixTimeMicroseconds(); var log = new Witsml141.Log { LogCurveInfo = new List <Witsml141.ComponentSchemas.LogCurveInfo>() }; var logCurveInfo = new Witsml141.ComponentSchemas.LogCurveInfo(); logCurveInfo = null; var result = logCurveInfo.GetIndexRange(); Assert.IsNull(result.Start); Assert.IsNull(result.End); // Add logCurveInfo with just start index var lci0 = _log141Generator.CreateDoubleLogCurveInfo("DEPTH", "m"); lci0.NullValue = "-1000.00"; lci0.MinDateTimeIndex = start; log.LogCurveInfo.Add(lci0); result = log.LogCurveInfo[0].GetIndexRange(true, true); Assert.IsNotNull(result); Assert.IsTrue(result.Start.HasValue); Assert.IsFalse(result.End.HasValue); Assert.AreEqual(startAsLong, result.Start.Value); // Decreasing log result = log.LogCurveInfo[0].GetIndexRange(false, true); Assert.IsNotNull(result); Assert.IsTrue(result.End.HasValue); Assert.IsFalse(result.Start.HasValue); Assert.AreEqual(startAsLong, result.End.Value); // Update end index lci0.MaxDateTimeIndex = end; result = log.LogCurveInfo[0].GetIndexRange(true, true); Assert.IsNotNull(result); Assert.IsTrue(result.Start.HasValue); Assert.IsTrue(result.End.HasValue); Assert.AreEqual(startAsLong, result.Start.Value); Assert.AreEqual(endAsLong, result.End.Value); // Decreasing with end index result = log.LogCurveInfo[0].GetIndexRange(false, true); Assert.IsNotNull(result); Assert.IsTrue(result.Start.HasValue); Assert.IsTrue(result.End.HasValue); Assert.AreEqual(startAsLong, result.End.Value); Assert.AreEqual(endAsLong, result.Start.Value); }
/// <summary> /// Gets the null values with the column index /// </summary> /// <param name="log">The log.</param> /// <param name="mnemonics">The mnemonics.</param> /// <returns> /// A <see cref="IDictionary{TKey, TValue}" /> with the column index as key and the log curve null value as the value. /// </returns> public static IEnumerable <string> GetNullValues(this Witsml141.Log log, string[] mnemonics) { return(mnemonics .Select(x => log.LogCurveInfo.GetByMnemonic(x)) .Select(n => GetNullValue(log.NullValue, n?.NullValue))); }
/// <summary> /// Determines whether the <see cref="Witsml141.Log"/> is increasing. /// </summary> /// <param name="log">The log.</param> /// <returns> /// <c>true</c> if the <see cref="Witsml141.Log"/> is increasing; otherwise, false. /// </returns> public static bool IsIncreasing(this Witsml141.Log log) { return(log.Direction.GetValueOrDefault(Witsml141.ReferenceData.LogIndexDirection.increasing) == Witsml141.ReferenceData.LogIndexDirection.increasing); }
public void ChannelDataExtensions_GetReader_Returns_ChannelDataReader_For_141_Log() { var log = new Witsml141.Log(); log = null; var readers = log.GetReaders(); Assert.AreEqual(0, readers.Count()); log = new Witsml141.Log(); readers = log.GetReaders(); Assert.AreEqual(0, readers.Count()); log.IndexType = Witsml141.ReferenceData.LogIndexType.measureddepth; log.Direction = Witsml141.ReferenceData.LogIndexDirection.increasing; log.LogCurveInfo = new List <Witsml141.ComponentSchemas.LogCurveInfo> { new Witsml141.ComponentSchemas.LogCurveInfo { Mnemonic = new Witsml141.ComponentSchemas.ShortNameStruct("MD"), Unit = "m", }, new Witsml141.ComponentSchemas.LogCurveInfo { Mnemonic = new Witsml141.ComponentSchemas.ShortNameStruct("A"), Unit = "ft", TypeLogData = new Witsml141.ReferenceData.LogDataType?(Witsml141.ReferenceData.LogDataType.@double) }, new Witsml141.ComponentSchemas.LogCurveInfo { Mnemonic = new Witsml141.ComponentSchemas.ShortNameStruct("B"), Unit = "m/hr", }, }; log.LogData = new List <Witsml141.ComponentSchemas.LogData>() { new Witsml141.ComponentSchemas.LogData() { Data = new List <string>() { "10,1,2", "11,3,4" }, MnemonicList = "DEPTH,A,B", UnitList = "m,ft,m/h" }, new Witsml141.ComponentSchemas.LogData() { MnemonicList = "DEPTH,A,B", UnitList = "m,ft,m/h" }, new Witsml141.ComponentSchemas.LogData() { Data = new List <string>(), MnemonicList = "DEPTH,A,B", UnitList = "m,ft,m/h" } }; readers = log.GetReaders(); var listOfReaders = readers.ToList(); Assert.AreEqual(1, listOfReaders.Count); AssertReaderAndData(listOfReaders); }