Ejemplo n.º 1
0
        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)));
        }
Ejemplo n.º 2
0
        public async Task CopyLogData_DepthIndexed()
        {
            var wellUid     = "W-5232880";
            var wellboreUid = "B-5232880";
            var job         = new CopyLogDataJob
            {
                LogCurvesReference = new LogCurvesReference
                {
                    LogReference = new LogReference
                    {
                        WellUid     = wellUid,
                        WellboreUid = wellboreUid,
                        LogUid      = "GM_Measured_Depth_GMDepth"
                    }
                },
                Target = new LogReference
                {
                    WellUid     = wellUid,
                    WellboreUid = wellboreUid,
                    LogUid      = "974f84b3-88da-4c5d-b318-b111c948dbc3"
                }
            };

            await worker.Execute(job);
        }
Ejemplo n.º 3
0
        public async Task CopyLogData_TimeIndexed_SelectedMnemonics()
        {
            var wellUid     = "W-5232880";
            var wellboreUid = "B-5232880";
            var job         = new CopyLogDataJob
            {
                LogCurvesReference = new LogCurvesReference
                {
                    LogReference = new LogReference
                    {
                        WellUid     = wellUid,
                        WellboreUid = wellboreUid,
                        LogUid      = "GM_Date_Time_GMTime"
                    },
                    Mnemonics = new List <string>
                    {
                        "Time",
                        "BLOCKPOS",
                        "DEPTH_BIT",
                        "DEPTH_HOLE"
                    }
                },
                Target = new LogReference
                {
                    WellUid     = wellUid,
                    WellboreUid = wellboreUid,
                    LogUid      = "8daba8bd-8d42-4fd0-80e4-b4d1a3a583e3"
                },
            };

            await worker.Execute(job);
        }
Ejemplo n.º 4
0
        public async Task CopyLogData_TimeIndexed()
        {
            var wellUid     = "W-5232880";
            var wellboreUid = "B-5232880";
            var job         = new CopyLogDataJob
            {
                LogCurvesReference = new LogCurvesReference
                {
                    LogReference = new LogReference
                    {
                        WellUid     = wellUid,
                        WellboreUid = wellboreUid,
                        LogUid      = "GM_Date_Time_GMTime"
                    }
                },
                Target = new LogReference
                {
                    WellUid     = wellUid,
                    WellboreUid = wellboreUid,
                    LogUid      = "230a60db-54e1-441d-afa6-0807ad308d7a"
                }
            };

            await worker.Execute(job);
        }
Ejemplo n.º 5
0
        public async Task <(WorkerResult, RefreshAction)> Execute(CopyLogDataJob job)
        {
            var(sourceLog, targetLog) = await GetLogs(job);

            var mnemonicsToCopy = job.LogCurvesReference.Mnemonics.Any()
                ? job.LogCurvesReference.Mnemonics.Distinct().ToList()
                : sourceLog.LogCurveInfo.Select(lci => lci.Mnemonic).ToList();

            var targetLogMnemonics        = targetLog.LogCurveInfo.Select(lci => lci.Mnemonic);
            var existingMnemonicsInTarget = mnemonicsToCopy.Where(mnemonic => targetLogMnemonics.Contains(mnemonic)).ToList();
            var newMnemonicsInTarget      = mnemonicsToCopy.Where(mnemonic => !targetLogMnemonics.Contains(mnemonic)).ToList();

            try
            {
                VerifyMatchingIndexTypes(sourceLog, targetLog);
                VerifyValidInterval(sourceLog);
                VerifyMatchingIndexCurves(sourceLog, targetLog);
                VerifyIndexCurveIsIncludedInMnemonics(sourceLog, newMnemonicsInTarget, existingMnemonicsInTarget);
            }
            catch (Exception e)
            {
                Log.Error("Failed to copy log data", e);
                return(new WorkerResult(witsmlClient.GetServerHostname(), false, "Failed to copy log data", e.Message), null);
            }

            var copyResultForExistingMnemonics = await CopyLogData(sourceLog, targetLog, job, existingMnemonicsInTarget);

            if (!copyResultForExistingMnemonics.Success)
            {
                var message = $"Failed to copy curves for existing mnemonics to log. Copied a total of {copyResultForExistingMnemonics.NumberOfRowsCopied} rows";
                return(LogAndReturnErrorResult(message));
            }

            var copyResultForNewMnemonics = await CopyLogData(sourceLog, targetLog, job, newMnemonicsInTarget);

            if (!copyResultForNewMnemonics.Success)
            {
                var message = $"Failed to copy curves for new mnemonics to log. Copied a total of {copyResultForNewMnemonics.NumberOfRowsCopied} rows";
                return(LogAndReturnErrorResult(message));
            }

            var totalRowsCopied = copyResultForExistingMnemonics.NumberOfRowsCopied + copyResultForNewMnemonics.NumberOfRowsCopied;

            Log.Information("{JobType} - Job successful. {Count} rows copied", GetType().Name, totalRowsCopied);
            var workerResult  = new WorkerResult(witsmlClient.GetServerHostname(), true, $"{totalRowsCopied} rows copied");
            var refreshAction = new RefreshLogObject(witsmlClient.GetServerHostname(), job.Target.WellUid, job.Target.WellboreUid, job.Target.LogUid, RefreshType.Update);

            return(workerResult, refreshAction);
        }
Ejemplo n.º 6
0
        private async Task <(WitsmlLog sourceLog, WitsmlLog targetLog)> GetLogs(CopyLogDataJob job)
        {
            var sourceLog = GetLog(witsmlSourceClient, job.LogCurvesReference.LogReference);
            var targetLog = GetLog(witsmlClient, job.Target);
            await Task.WhenAll(sourceLog, targetLog);

            if (sourceLog.Result == null)
            {
                throw new Exception($"Could not find source log object: UidWell: {job.LogCurvesReference.LogReference.WellUid}, " +
                                    $"UidWellbore: {job.LogCurvesReference.LogReference.WellboreUid}, Uid: {job.LogCurvesReference.LogReference.LogUid}");
            }
            if (targetLog.Result == null)
            {
                throw new Exception($"Could not find target log object: UidWell: {job.LogCurvesReference.LogReference.WellUid}, " +
                                    $"UidWellbore: {job.LogCurvesReference.LogReference.WellboreUid}, Uid: {job.LogCurvesReference.LogReference.LogUid}");
            }

            return(sourceLog.Result, targetLog.Result);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
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
            });
        }