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); }
public async Task <LogData> ReadLogData(string wellUid, string wellboreUid, string logUid, List <string> mnemonics, bool startIndexIsInclusive, string start, string end) { var log = await GetLogHeader(wellUid, wellboreUid, logUid); var startIndex = Index.Start(log, start); var endIndex = Index.End(log, end); if (!startIndexIsInclusive) { startIndex = startIndex.AddEpsilon(); } if (startIndex > endIndex) { return(new LogData()); } var indexMnemonic = log.IndexCurve.Value; if (!mnemonics.Contains(indexMnemonic)) { mnemonics.Insert(0, indexMnemonic); } var query = LogQueries.GetLogContent(wellUid, wellboreUid, logUid, log.IndexType, mnemonics, startIndex, endIndex); var witsmlLogs = await WitsmlClient.GetFromStoreAsync(query, new OptionsIn(ReturnElements.All)); if (!witsmlLogs.Logs.Any() || witsmlLogs.Logs.First().LogData == null) { return(new LogData()); } var witsmlLog = witsmlLogs.Logs.First(); var witsmlLogMnemonics = witsmlLog.LogData.MnemonicList.Split(","); var witsmlLogUnits = witsmlLog.LogData.UnitList.Split(","); return(new LogData { StartIndex = Index.Start(witsmlLog).GetValueAsString(), EndIndex = Index.End(witsmlLog).GetValueAsString(), CurveSpecifications = witsmlLogMnemonics.Zip(witsmlLogUnits, (mnemonic, unit) => new CurveSpecification { Mnemonic = mnemonic, Unit = unit }), Data = GetDataDictionary(witsmlLog.LogData) }); }
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.GetLogContent(job.SourceLogCurvesReference.LogReference.WellUid, job.SourceLogCurvesReference.LogReference.WellboreUid, job.SourceLogCurvesReference.LogReference.LogUid, sourceLog.IndexType, mnemonics, startIndex, endIndex); var sourceData = await witsmlSourceClient.GetFromStoreAsync(query, new OptionsIn(ReturnElements.DataOnly)); if (!sourceData.Logs.Any()) { break; } var sourceLogWithData = sourceData.Logs.First(); var copyNewCurvesQuery = CreateCopyQuery(targetLog, 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.SourceLogCurvesReference.LogReference.WellUid, job.SourceLogCurvesReference.LogReference.WellboreUid, job.SourceLogCurvesReference.LogReference.LogUid, job.TargetLogReference.WellUid, job.TargetLogReference.WellboreUid, job.TargetLogReference.LogUid, startIndex.GetValueAsString()); return(new CopyResult { Success = false, NumberOfRowsCopied = numberOfDataRowsCopied }); } } return(new CopyResult { Success = true, NumberOfRowsCopied = numberOfDataRowsCopied }); }