public async Task CopyLogData_DepthIndexed_SelectedMnemonics() { var job = CreateJobTemplate(); job.SourceLogCurvesReference.Mnemonics = new[] { "Depth", "DepthBit" }; SetupSourceLog(WitsmlLog.WITSML_INDEX_TYPE_MD); SetupTargetLog(WitsmlLog.WITSML_INDEX_TYPE_MD); WitsmlLogs query = null; witsmlClient.Setup(client => client.GetFromStoreAsync(It.IsAny <WitsmlLogs>(), new OptionsIn(ReturnElements.DataOnly, null))) .Callback <WitsmlLogs, OptionsIn>((logs, _) => query = logs) .ReturnsAsync(() => { var startIndex = double.Parse(query.Logs.First().StartIndex.Value); var endIndex = double.Parse(query.Logs.First().EndIndex.Value); return(GetSourceLogData(startIndex, endIndex, job.SourceLogCurvesReference.Mnemonics)); }); var updatedLogs = SetupUpdateInStoreAsync(); await worker.Execute(job); Assert.NotNull(query); var queriedMnemonics = query.Logs.First().LogData.MnemonicList.Split(","); var copiedMnemonics = updatedLogs.Last().Logs.First().LogData.MnemonicList.Split(","); Assert.Equal(job.SourceLogCurvesReference.Mnemonics, queriedMnemonics); Assert.Equal(job.SourceLogCurvesReference.Mnemonics, copiedMnemonics); }
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 async Task CopyLogData_DepthIndexed_AllowIndexCurveNamesThatOnlyDifferInCasing() { var sourceIndexCurve = "DEPTH"; var targetIndexCurve = "Depth"; var mnemonics = new[] { sourceIndexCurve, "DepthBit", "DepthHole" }; var job = CreateJobTemplate(); job.SourceLogCurvesReference.Mnemonics = mnemonics; var sourceLogs = GetSourceLogs(WitsmlLog.WITSML_INDEX_TYPE_MD, DepthStart, DepthEnd, sourceIndexCurve); SetupSourceLog(WitsmlLog.WITSML_INDEX_TYPE_MD, sourceLogs); SetupTargetLog(WitsmlLog.WITSML_INDEX_TYPE_MD); WitsmlLogs query = null; witsmlClient.Setup(client => client.GetFromStoreAsync(It.IsAny <WitsmlLogs>(), new OptionsIn(ReturnElements.DataOnly, null))) .Callback <WitsmlLogs, OptionsIn>((logs, _) => query = logs) .ReturnsAsync(() => { var startIndex = double.Parse(query.Logs.First().StartIndex.Value); var endIndex = double.Parse(query.Logs.First().EndIndex.Value); return(GetSourceLogData(startIndex, endIndex, job.SourceLogCurvesReference.Mnemonics)); }); var updatedLogs = SetupUpdateInStoreAsync(); var(result, _) = await worker.Execute(job); Assert.True(result.IsSuccess); Assert.Equal(3, updatedLogs.First().Logs.First().LogCurveInfo.Count); Assert.Equal(targetIndexCurve, updatedLogs.First().Logs.First().LogCurveInfo.First().Mnemonic); }
public async Task CopyLogData_DepthIndexed_ShouldUseTargetLogUidIfSourceHasDifferent() { var job = CreateJobTemplate(); job.LogCurvesReference.Mnemonics = new[] { "Depth", "DepthBit" }; var sourceLogs = GetSourceLogs(WitsmlLog.WITSML_INDEX_TYPE_MD, DepthStart, DepthEnd - 1); var targetLogs = GetSourceLogs(WitsmlLog.WITSML_INDEX_TYPE_MD, DepthEnd, DepthEnd + 2); targetLogs.Logs[0].LogCurveInfo[1].Uid = "SomethingElse"; SetupSourceLog(WitsmlLog.WITSML_INDEX_TYPE_MD, sourceLogs); SetupTargetLog(WitsmlLog.WITSML_INDEX_TYPE_MD, targetLogs); SetupGetDepthIndexed(); var expectedQuery = GetSourceLogs(WitsmlLog.WITSML_INDEX_TYPE_MD, DepthStart, DepthEnd - 1); expectedQuery.Logs[0].LogData = GetSourceLogData(double.Parse(expectedQuery.Logs[0].StartIndex.Value), double.Parse(expectedQuery.Logs[0].EndIndex.Value), job.LogCurvesReference.Mnemonics).Logs[0].LogData; WitsmlLogs actual = null; witsmlClient.Setup(client => client.UpdateInStoreAsync(It.IsAny <WitsmlLogs>())) .Callback <WitsmlLogs>(witsmlLogs => actual = witsmlLogs) .ReturnsAsync(new QueryResult(true)); await worker.Execute(job); Assert.NotNull(actual); Assert.Equal("SomethingElse", actual.Logs[0].LogCurveInfo[1].Uid); }
private void SetupGetDepthIndexed(WitsmlLogs query = null) { witsmlClient.Setup(client => client.GetFromStoreAsync(It.IsAny <WitsmlLogs>(), It.IsAny <OptionsIn>())) .Callback <WitsmlLogs, OptionsIn>((logs, _) => query = logs) .ReturnsAsync(() => { var startIndex = double.Parse(query.Logs.First().StartIndex.Value); var endIndex = double.Parse(query.Logs.First().EndIndex.Value); return(GetSourceLogData(startIndex, endIndex)); }); }
private async Task <IList <WitsmlLog> > GetLogs(string wellUid, string wellboreUid) { var query = new WitsmlLogs { Logs = new WitsmlLog { UidWell = wellUid, UidWellbore = wellboreUid }.AsSingletonList() }; var result = await witsmlClient.GetFromStoreAsync(query, new OptionsIn(ReturnElements.HeaderOnly)); return(result?.Logs); }
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 void SetupSourceLog(string indexType, WitsmlLogs sourceLogs = null) { switch (indexType) { case WitsmlLog.WITSML_INDEX_TYPE_MD: witsmlClient.Setup(client => client.GetFromStoreAsync(It.Is <WitsmlLogs>(witsmlLogs => witsmlLogs.Logs.First().Uid == LogUid), OptionsIn.All)) .ReturnsAsync(sourceLogs ?? GetSourceLogs(WitsmlLog.WITSML_INDEX_TYPE_MD, DepthStart, DepthEnd)); break; case WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME: witsmlClient.Setup(client => client.GetFromStoreAsync(It.Is <WitsmlLogs>(witsmlLogs => witsmlLogs.Logs.First().Uid == LogUid), OptionsIn.All)) .ReturnsAsync(sourceLogs ?? GetSourceLogs(WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME, TimeStart, TimeEnd)); break; } }
private void SetupTargetLog(string indexType, WitsmlLogs targetLogs = null) { switch (indexType) { case WitsmlLog.WITSML_INDEX_TYPE_MD: witsmlClient.Setup(client => client.GetFromStoreAsync(It.Is <WitsmlLogs>(witsmlLogs => witsmlLogs.Logs.First().Uid == TargetLogUid), new OptionsIn(ReturnElements.HeaderOnly, null))) .ReturnsAsync(targetLogs ?? GetTargetLogs(WitsmlLog.WITSML_INDEX_TYPE_MD)); break; case WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME: witsmlClient.Setup(client => client.GetFromStoreAsync(It.Is <WitsmlLogs>(witsmlLogs => witsmlLogs.Logs.First().Uid == TargetLogUid), new OptionsIn(ReturnElements.HeaderOnly, null))) .ReturnsAsync(targetLogs ?? GetTargetLogs(WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME)); break; } }
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); }
public async Task CopyLogData_TimeIndexed() { var job = CreateJobTemplate(); SetupSourceLog(WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME); SetupTargetLog(WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME); var updatedLogs = SetupUpdateInStoreAsync(); WitsmlLogs query = null; witsmlClient.Setup(client => client.GetFromStoreAsync(It.IsAny <WitsmlLogs>(), new OptionsIn(ReturnElements.DataOnly, null))) .Callback <WitsmlLogs, OptionsIn>((logs, _) => query = logs) .ReturnsAsync(() => GetSourceLogData(query.Logs.First().StartDateTimeIndex, query.Logs.First().EndDateTimeIndex)); await worker.Execute(job); Assert.Equal(string.Join(",", SourceMnemonics[WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME]), updatedLogs.First().Logs.First().LogData.MnemonicList); Assert.Equal(5, updatedLogs.First().Logs.First().LogData.Data.Count); }
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 async Task ImportTimeLogData() { var timeJob = CreateTimeJobTemplate(); var returnedWitsmlLog = new WitsmlLogs { Logs = new List <WitsmlLog> { new WitsmlLog { UidWell = WellUid, UidWellbore = WellboreUid, Uid = LogUid, LogCurveInfo = new List <WitsmlLogCurveInfo> { new WitsmlLogCurveInfo { Mnemonic = "Time", Unit = "date time" }, new WitsmlLogCurveInfo { Mnemonic = "mnemo1", Unit = "unitless" }, new WitsmlLogCurveInfo { Mnemonic = "mnemo2", Unit = "unitless" } } } } }; witsmlClient.Setup(client => client.GetFromStoreAsync(It.IsAny <WitsmlLogs>(), new OptionsIn(ReturnElements.HeaderOnly, null))).ReturnsAsync(returnedWitsmlLog); witsmlClient.Setup(client => client.UpdateInStoreAsync(It.IsAny <WitsmlLogs>())).ReturnsAsync(new QueryResult(true)); var timeJobResult = await worker.Execute(timeJob); Assert.True(timeJobResult.Item1.IsSuccess); }
private async IAsyncEnumerable <WitsmlWellbore> GetActiveWellbores() { var liveLogsQuery = new WitsmlLogs { Logs = new WitsmlLog { Uid = "", UidWell = "", UidWellbore = "", Name = "", NameWell = "", NameWellbore = "", ObjectGrowing = "true" }.AsSingletonList() }; var result = await witsmlClient.GetFromStoreAsync(liveLogsQuery, new OptionsIn(ReturnElements.Requested)); var groupedResults = result.Logs .OrderBy(x => x.NameWell) .GroupBy(x => new { x.UidWell, x.UidWellbore }) .Select(x => new { x.Key.UidWell, x.Key.UidWellbore, Logs = x }); foreach (var groupedResult in groupedResults) { yield return(new WitsmlWellbore { UidWell = groupedResult.UidWell, Uid = groupedResult.UidWellbore, NameWell = groupedResult.Logs.First().NameWell, Name = groupedResult.Logs.First().NameWellbore }); } }