private async Task <WitsmlLog> GetLogData(WitsmlLog log, IEnumerable <string> mnemonics, Index startIndex, Index endIndex)
        {
            var query = LogQueries.QueryLogContent(
                log.UidWell,
                log.UidWellbore,
                log.Uid,
                log.IndexType,
                mnemonics,
                startIndex, endIndex);

            var data = await witsmlClient.GetFromStoreAsync(query, OptionsIn.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.QueryLogContent(wellUid, wellboreUid, logUid, log.IndexType, mnemonics, startIndex, endIndex);
            var witsmlLogs = await WitsmlClient.GetFromStoreAsync(query, OptionsIn.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)
            });
        }
Exemple #3
0
        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
            });
        }