private WitsmlLogs GetLogs(string indexType, Index startIndex, Index endIndex) { var witsmlLog = new WitsmlLog { UidWell = WellUid, UidWellbore = WellboreUid, Uid = LogUid, IndexType = indexType }; switch (indexType) { case WitsmlLog.WITSML_INDEX_TYPE_MD: witsmlLog.StartIndex = new WitsmlIndex((DepthIndex)startIndex); witsmlLog.EndIndex = new WitsmlIndex((DepthIndex)endIndex); break; case WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME: witsmlLog.StartDateTimeIndex = startIndex.GetValueAsString(); witsmlLog.EndDateTimeIndex = endIndex.GetValueAsString(); break; } return(new WitsmlLogs { Logs = new List <WitsmlLog> { witsmlLog } }); }
private static Stream CreateCopyLogDataJob(CopyLogJob job, WitsmlLog targetLog) { var sourceLogReference = new LogReference { WellUid = job.Source.LogReferenceList.FirstOrDefault()?.WellUid, WellboreUid = job.Source.LogReferenceList.FirstOrDefault()?.WellboreUid, LogUid = targetLog.Uid }; var targetLogReference = new LogReference { WellUid = job.Target.WellUid, WellboreUid = job.Target.WellboreUid, LogUid = targetLog.Uid }; var copyLogDataJob = new CopyLogDataJob { SourceLogCurvesReference = new LogCurvesReference { LogReference = sourceLogReference, Mnemonics = targetLog.LogData.MnemonicList.Split(",") }, TargetLogReference = targetLogReference }; var json = JsonSerializer.Serialize(copyLogDataJob, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); return(new MemoryStream(Encoding.UTF8.GetBytes(json))); }
private static void VerifyMatchingIndexTypes(WitsmlLog sourceLog, WitsmlLog targetLog) { if (sourceLog.IndexType != targetLog.IndexType) { throw new Exception($"{nameof(sourceLog)} and {nameof(targetLog)} has mismatching index types"); } }
private WitsmlLogs GetSourceLogs(string indexType, string startDateTimeIndex, string endDateTimeIndex) { var witsmlLog = new WitsmlLog { UidWell = WellUid, UidWellbore = SourceWellboreUid, Uid = LogUid, IndexType = indexType, IndexCurve = new WitsmlIndexCurve { Value = SourceMnemonics[indexType][0] }, StartDateTimeIndex = startDateTimeIndex, EndDateTimeIndex = endDateTimeIndex, CommonData = new WitsmlCommonData(), LogData = new WitsmlLogData { MnemonicList = SourceMnemonics[indexType].ToString() }, LogCurveInfo = SourceMnemonics[WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME].Select(mnemonic => new WitsmlLogCurveInfo { Uid = mnemonic, Mnemonic = mnemonic, MinDateTimeIndex = startDateTimeIndex, MaxDateTimeIndex = endDateTimeIndex }).ToList() }; return(new WitsmlLogs { Logs = new List <WitsmlLog> { witsmlLog } }); }
private WitsmlLogs GetSourceLogs(string indexType, double startIndex, double endIndex, string indexCurveValue = null) { var minIndex = new WitsmlIndex(new DepthIndex(startIndex)); var maxIndex = new WitsmlIndex(new DepthIndex(endIndex)); var witsmlLog = new WitsmlLog { UidWell = WellUid, UidWellbore = WellboreUid, Uid = SourceLogUid, IndexType = indexType, IndexCurve = new WitsmlIndexCurve { Value = indexCurveValue ?? SourceMnemonics[indexType][0] }, StartIndex = minIndex, EndIndex = maxIndex, LogCurveInfo = SourceMnemonics[WitsmlLog.WITSML_INDEX_TYPE_MD].Select(mnemonic => new WitsmlLogCurveInfo { Uid = mnemonic, Mnemonic = mnemonic.Equals(indexCurveValue, StringComparison.OrdinalIgnoreCase) ? indexCurveValue : mnemonic, MinIndex = minIndex, MaxIndex = maxIndex }).ToList() }; return(new WitsmlLogs { Logs = new List <WitsmlLog> { witsmlLog } }); }
private static WitsmlLogs CreateRequest(string wellUid, string wellboreUid, string logUid, string indexType, Index deleteTo = null, Index deleteFrom = null) { var witsmlLog = new WitsmlLog { UidWell = wellUid, UidWellbore = wellboreUid, Uid = logUid }; switch (indexType) { case WitsmlLog.WITSML_INDEX_TYPE_MD: witsmlLog.StartIndex = deleteFrom != null ? new WitsmlIndex((DepthIndex)deleteFrom) : null; witsmlLog.EndIndex = deleteTo != null ? new WitsmlIndex((DepthIndex)deleteTo) : null; break; case WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME: witsmlLog.StartDateTimeIndex = deleteFrom?.GetValueAsString(); witsmlLog.EndDateTimeIndex = deleteTo?.GetValueAsString(); break; } return(new WitsmlLogs { Logs = new List <WitsmlLog> { witsmlLog } }); }
private async Task VerifyTargetHasRequiredLogCurveInfos(WitsmlLog sourceLog, IEnumerable <string> sourceMnemonics, WitsmlLog targetLog) { var newLogCurveInfos = new List <WitsmlLogCurveInfo>(); foreach (var mnemonic in sourceMnemonics.Where(mnemonic => !string.Equals(targetLog.IndexCurve.Value, mnemonic, StringComparison.OrdinalIgnoreCase))) { if (targetLog.LogCurveInfo.All(lci => !string.Equals(lci.Mnemonic, mnemonic, StringComparison.OrdinalIgnoreCase))) { newLogCurveInfos.Add(sourceLog.LogCurveInfo.Find(lci => lci.Mnemonic == mnemonic)); } } if (newLogCurveInfos.Any()) { targetLog.LogCurveInfo.AddRange(newLogCurveInfos); var query = new WitsmlLogs { Logs = new List <WitsmlLog> { targetLog } }; var result = await witsmlClient.UpdateInStoreAsync(query); if (!result.IsSuccessful) { var newMnemonics = string.Join(",", newLogCurveInfos.Select(lci => lci.Mnemonic)); Log.Error("Failed to update LogCurveInfo for wellbore during copy data. Mnemonics: {Mnemonics}. " + "Target: UidWell: {TargetWellUid}, UidWellbore: {TargetWellboreUid}, Uid: {TargetLogUid}. ", newMnemonics, targetLog.UidWell, targetLog.UidWellbore, targetLog.Uid); } } }
public static string GetStartIndexAsString(this WitsmlLog witsmlLog) { if (witsmlLog.StartIndex == null && string.IsNullOrEmpty(witsmlLog.StartDateTimeIndex)) { return(null); } return(witsmlLog.IndexType.Equals(WitsmlLog.WITSML_INDEX_TYPE_MD) ? witsmlLog.StartIndex != null?witsmlLog.StartIndex.ToString() : "" : witsmlLog.StartDateTimeIndex); }
public static Index Start(WitsmlLog log, string customIndexValue = "") { return(log.IndexType switch { WitsmlLog.WITSML_INDEX_TYPE_MD => (Index) new DepthIndex(double.Parse(customIndexValue.NullIfEmpty() ?? log.StartIndex.Value), log.StartIndex.Uom), WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME => new DateTimeIndex(DateTime.Parse(customIndexValue.NullIfEmpty() ?? log.StartDateTimeIndex)), _ => throw new Exception($"Invalid index type: '{log.IndexType}'") });
private static IEnumerable <string> GetMnemonics(WitsmlLog log, string mnemonic) { return(new List <string> { log.IndexCurve.Value, mnemonic }); }
private static IReadOnlyCollection <string> GetMnemonics(WitsmlLog log, string mnemonic) { return(new List <string> { log.IndexCurve.Value, mnemonic }); }
public static EntityDescription GetDescription(this WitsmlLog witsmlLog) { return(new EntityDescription { WellName = witsmlLog.NameWell, WellboreName = witsmlLog.NameWellbore, ObjectName = witsmlLog.Name }); }
private static void VerifyValidInterval(WitsmlLog sourceLog) { var sourceStart = Index.Start(sourceLog); var sourceEnd = Index.End(sourceLog); if (sourceStart > sourceEnd) { throw new Exception($"Invalid interval. Start must be before End. Start: {sourceStart}, End: {sourceEnd}"); } }
private WitsmlLogs GetTargetLogs(string indexType) { var indexLogCurveInfo = indexType switch { WitsmlLog.WITSML_INDEX_TYPE_MD => new WitsmlLogCurveInfo { Uid = "Depth", Mnemonic = "Depth", MinIndex = new WitsmlIndex(new DepthIndex(-999.25)), MaxIndex = new WitsmlIndex(new DepthIndex(-999.25)) }, WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME => new WitsmlLogCurveInfo { Uid = "Time", Mnemonic = "Time", MinDateTimeIndex = "1900-01-01T00:00:00.000Z", MaxDateTimeIndex = "1900-01-01T00:00:00.000Z" }, _ => null }; var witsmlLog = new WitsmlLog { UidWell = WellUid, UidWellbore = WellboreUid, Uid = TargetLogUid, IndexType = indexType, IndexCurve = new WitsmlIndexCurve { Value = SourceMnemonics[indexType][0] }, LogCurveInfo = new List <WitsmlLogCurveInfo> { indexLogCurveInfo } }; switch (indexType) { case WitsmlLog.WITSML_INDEX_TYPE_MD: witsmlLog.StartIndex = new WitsmlIndex(new DepthIndex(DepthIndex.NullValue)); witsmlLog.EndIndex = new WitsmlIndex(new DepthIndex(DepthIndex.NullValue)); break; case WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME: witsmlLog.StartDateTimeIndex = DateTimeIndex.NullValue; witsmlLog.EndDateTimeIndex = DateTimeIndex.NullValue; break; } return(new WitsmlLogs { Logs = new List <WitsmlLog> { witsmlLog } }); }
private static void VerifyMatchingIndexCurves(WitsmlLog sourceLog, WitsmlLog targetLog) { var sourceIndexMnemonic = sourceLog.IndexCurve.Value; var targetIndexMnemonic = targetLog.IndexCurve.Value; if (sourceIndexMnemonic.Equals(targetIndexMnemonic, StringComparison.OrdinalIgnoreCase)) { return; } throw new Exception($"Source and Target has different index mnemonics. Source: {sourceIndexMnemonic}, Target: {targetIndexMnemonic}"); }
private static void VerifyIndexCurveIsIncludedInMnemonics(WitsmlLog log, IList <string> newMnemonics, IList <string> existingMnemonics) { var indexMnemonic = log.IndexCurve.Value; if (!newMnemonics.Contains(indexMnemonic, StringComparer.InvariantCultureIgnoreCase)) { newMnemonics.Insert(0, indexMnemonic); } if (!existingMnemonics.Contains(indexMnemonic, StringComparer.InvariantCultureIgnoreCase)) { existingMnemonics.Insert(0, indexMnemonic); } }
private static void VerifyIndexCurveIsIncludedInMnemonics(WitsmlLog log, List <string> newMnemonics, List <string> existingMnemonics) { var indexMnemonic = log.IndexCurve.Value; if (!newMnemonics.Contains(indexMnemonic)) { newMnemonics.Insert(0, indexMnemonic); } if (!existingMnemonics.Contains(indexMnemonic)) { existingMnemonics.Insert(0, indexMnemonic); } }
private async Task <WitsmlLog> GetLogData(WitsmlLog log, IEnumerable <string> mnemonics, Index startIndex, Index endIndex) { var query = LogQueries.GetLogContent( log.UidWell, log.UidWellbore, log.Uid, log.IndexType, mnemonics, startIndex, endIndex); var data = await witsmlClient.GetFromStoreAsync(query, new OptionsIn(ReturnElements.DataOnly)); return(data.Logs.Any() ? data.Logs.First() : null); }
private static WitsmlLogs CreateCopyQuery(WitsmlLog targetLog, WitsmlLog sourceLog, WitsmlLog sourceLogWithData) { var sourceMnemonics = sourceLogWithData.LogData.MnemonicList.Split(","); var updatedData = new WitsmlLog { UidWell = targetLog.UidWell, UidWellbore = targetLog.UidWellbore, Uid = targetLog.Uid, LogCurveInfo = sourceLog.LogCurveInfo .Where(LogCurveHasMnemonic(sourceMnemonics)) .Select(lci => new WitsmlLogCurveInfo { Uid = GetTargetUidForCurve(lci, targetLog), Mnemonic = GetTargetNameForCurve(lci, targetLog), ClassWitsml = lci.ClassWitsml.NullIfEmpty(), ClassIndex = lci.ClassIndex.NullIfEmpty(), Unit = lci.Unit.NullIfEmpty(), MnemAlias = lci.MnemAlias.NullIfEmpty(), NullValue = lci.NullValue.NullIfEmpty(), AlternateIndex = lci.AlternateIndex.NullIfEmpty(), WellDatum = lci.WellDatum.NullIfEmpty(), MinIndex = null, MaxIndex = null, MinDateTimeIndex = null, MaxDateTimeIndex = null, CurveDescription = lci.CurveDescription.NullIfEmpty(), SensorOffset = lci.SensorOffset.NullIfEmpty(), DataSource = lci.DataSource.NullIfEmpty(), DensData = lci.DensData.NullIfEmpty(), TraceState = lci.TraceState.NullIfEmpty(), TraceOrigin = lci.TraceOrigin.NullIfEmpty(), TypeLogData = lci.TypeLogData.NullIfEmpty(), AxisDefinition = lci.AxisDefinition, ExtensionNameValue = lci.ExtensionNameValue.NullIfEmpty() }).ToList(), LogData = sourceLogWithData.LogData }; var updatedWitsmlLog = new WitsmlLogs { Logs = new List <WitsmlLog> { updatedData } }; return(updatedWitsmlLog); }
private static WitsmlLogs CreateCopyLogQuery(WitsmlLog log, WitsmlWellbore targetWellbore) { log.UidWell = targetWellbore.UidWell; log.NameWell = targetWellbore.NameWell; log.UidWellbore = targetWellbore.Uid; log.NameWellbore = targetWellbore.Name; log.CommonData.ItemState = string.IsNullOrEmpty(log.CommonData.ItemState) ? null : log.CommonData.ItemState; log.CommonData.SourceName = string.IsNullOrEmpty(log.CommonData.SourceName) ? null : log.CommonData.SourceName; log.LogData.Data = new List <WitsmlData>(); var copyLogQuery = new WitsmlLogs { Logs = new List <WitsmlLog> { log } }; return(copyLogQuery); }
private async Task <CopyResult> CopyLogData(WitsmlLog sourceLog, WitsmlLog targetLog, CopyLogDataJob job, IReadOnlyCollection <string> mnemonics) { var startIndex = Index.Start(sourceLog); var endIndex = Index.End(sourceLog); var numberOfDataRowsCopied = 0; while (startIndex < endIndex) { var query = LogQueries.QueryLogContent(job.LogCurvesReference.LogReference.WellUid, job.LogCurvesReference.LogReference.WellboreUid, job.LogCurvesReference.LogReference.LogUid, sourceLog.IndexType, mnemonics, startIndex, endIndex); var sourceData = await witsmlSourceClient.GetFromStoreAsync(query, OptionsIn.DataOnly); if (!sourceData.Logs.Any()) { break; } var sourceLogWithData = sourceData.Logs.First(); var copyNewCurvesQuery = CreateCopyQuery(targetLog, sourceLog, sourceLogWithData); var result = await witsmlClient.UpdateInStoreAsync(copyNewCurvesQuery); if (result.IsSuccessful) { numberOfDataRowsCopied += copyNewCurvesQuery.Logs.First().LogData.Data.Count; startIndex = Index.End(sourceLogWithData).AddEpsilon(); } else { Log.Error( "Failed to copy log data. " + "Source: UidWell: {SourceWellUid}, UidWellbore: {SourceWellboreUid}, Uid: {SourceLogUid}. " + "Target: UidWell: {TargetWellUid}, UidWellbore: {TargetWellboreUid}, Uid: {TargetLogUid}. " + "Current index: {startIndex}", job.LogCurvesReference.LogReference.WellUid, job.LogCurvesReference.LogReference.WellboreUid, job.LogCurvesReference.LogReference.LogUid, job.Target.WellUid, job.Target.WellboreUid, job.Target.LogUid, startIndex); return(new CopyResult { Success = false, NumberOfRowsCopied = numberOfDataRowsCopied }); } } return(new CopyResult { Success = true, NumberOfRowsCopied = numberOfDataRowsCopied }); }
private static WitsmlLogs CreateCopyQuery(WitsmlLog targetLog, WitsmlLog sourceLogWithData) { var updatedData = new WitsmlLog { UidWell = targetLog.UidWell, UidWellbore = targetLog.UidWellbore, Uid = targetLog.Uid, LogData = sourceLogWithData.LogData }; var updatedWitsmlLog = new WitsmlLogs { Logs = new List <WitsmlLog> { updatedData } }; return(updatedWitsmlLog); }
public static WitsmlLogs GetLogContent( string wellUid, string wellboreUid, string logUid, string indexType, IEnumerable <string> mnemonics, Index startIndex, Index endIndex) { var queryLog = new WitsmlLog { Uid = logUid, UidWell = wellUid, UidWellbore = wellboreUid, IndexType = "", LogCurveInfo = new List <WitsmlLogCurveInfo>(), LogData = new WitsmlLogData { MnemonicList = string.Join(",", mnemonics) } }; switch (indexType) { case WitsmlLog.WITSML_INDEX_TYPE_MD: queryLog.StartIndex = new WitsmlIndex((DepthIndex)startIndex); queryLog.EndIndex = new WitsmlIndex((DepthIndex)endIndex); break; case WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME: queryLog.StartDateTimeIndex = startIndex.GetValueAsString(); queryLog.EndDateTimeIndex = endIndex.GetValueAsString(); break; } return(new WitsmlLogs { Logs = new List <WitsmlLog> { queryLog } }); }
private static CopyLogDataJob CreateCopyLogDataJob(CopyLogJob job, WitsmlLog log) { var referenceForNewLog = new LogReference { WellUid = job.Target.WellUid, WellboreUid = job.Target.WellboreUid, LogUid = job.Source.LogUid }; var copyLogDataJob = new CopyLogDataJob { LogCurvesReference = new LogCurvesReference { LogReference = job.Source, Mnemonics = log.LogData.MnemonicList.Split(",") }, Target = referenceForNewLog }; return(copyLogDataJob); }
public static WitsmlLogs DeleteLogCurveContent( string wellUid, string wellboreUid, string logUid, string indexType, List <WitsmlLogCurveInfo> logCurveInfos, Index startIndex, Index endIndex) { var queryLog = new WitsmlLog { Uid = logUid, UidWell = wellUid, UidWellbore = wellboreUid, LogCurveInfo = logCurveInfos.Select(lci => new WitsmlLogCurveInfo { Uid = lci.Uid, Mnemonic = lci.Mnemonic }).ToList() }; switch (indexType) { case WitsmlLog.WITSML_INDEX_TYPE_MD: queryLog.StartIndex = new WitsmlIndex((DepthIndex)startIndex); queryLog.EndIndex = new WitsmlIndex((DepthIndex)endIndex); break; case WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME: queryLog.StartDateTimeIndex = startIndex.GetValueAsString(); queryLog.EndDateTimeIndex = endIndex.GetValueAsString(); break; } return(new WitsmlLogs { Logs = new List <WitsmlLog> { queryLog } }); }
private static WitsmlLogs CreateNewLogWithRenamedMnemonic(RenameMnemonicJob job, WitsmlLog logHeader, IEnumerable <string> mnemonics, WitsmlLog logData) { var updatedData = new WitsmlLog { UidWell = logHeader.UidWell, UidWellbore = logHeader.UidWellbore, Uid = logHeader.Uid, LogCurveInfo = logHeader.LogCurveInfo.Where(lci => mnemonics.Contains(lci.Mnemonic, StringComparer.OrdinalIgnoreCase)).ToList(), LogData = logData.LogData }; updatedData.LogCurveInfo.Find(c => c.Mnemonic == job.Mnemonic) !.Mnemonic = job.NewMnemonic; updatedData.LogData.MnemonicList = string.Join(",", GetMnemonics(logHeader, job.NewMnemonic)); return(new WitsmlLogs { Logs = new List <WitsmlLog> { updatedData } }); }
private WitsmlLogs GetSourceLogs(string indexType, double startIndex, double endIndex) { var minIndex = new WitsmlIndex(new DepthIndex(startIndex)); var maxIndex = new WitsmlIndex(new DepthIndex(endIndex)); var witsmlLog = new WitsmlLog { UidWell = WellUid, UidWellbore = SourceWellboreUid, Uid = LogUid, IndexType = indexType, IndexCurve = new WitsmlIndexCurve { Value = SourceMnemonics[indexType][0] }, StartIndex = minIndex, EndIndex = maxIndex, CommonData = new WitsmlCommonData(), LogData = new WitsmlLogData { MnemonicList = SourceMnemonics[indexType].ToString() }, LogCurveInfo = SourceMnemonics[WitsmlLog.WITSML_INDEX_TYPE_MD].Select(mnemonic => new WitsmlLogCurveInfo { Uid = mnemonic, Mnemonic = mnemonic, MinIndex = minIndex, MaxIndex = maxIndex }).ToList() }; return(new WitsmlLogs { Logs = new List <WitsmlLog> { witsmlLog } }); }
private static WitsmlLogs CreateRequest(string wellUid, string wellboreUid, string logUid, WitsmlLog logObject) { return(new WitsmlLogs { Logs = new WitsmlLog { UidWell = wellUid, UidWellbore = wellboreUid, Uid = logUid, Name = logObject.Name, }.AsSingletonList() }); }
private static string GetTargetUidForCurve(WitsmlLogCurveInfo lci, WitsmlLog targetLog) { return(targetLog.LogCurveInfo.Find(GetTargetCurveIfExists(lci))?.Uid ?? lci.Uid); }
private static string GetTargetNameForCurve(WitsmlLogCurveInfo lci, WitsmlLog targetLog) { return(targetLog.LogCurveInfo.Find(GetTargetCurveIfExists(lci))?.Mnemonic ?? lci.Mnemonic); }