예제 #1
0
        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}");
            }
        }
        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)
            });
        }
        public override async Task <(WorkerResult, RefreshAction)> Execute(RenameMnemonicJob job)
        {
            Verify(job);

            var logHeader = await GetLog(job.LogReference);

            var mnemonics  = GetMnemonics(logHeader, job.Mnemonic);
            var startIndex = Index.Start(logHeader);
            var endIndex   = Index.End(logHeader);

            while (startIndex < endIndex)
            {
                var logData = await GetLogData(logHeader, mnemonics, startIndex, endIndex);

                if (logData == null)
                {
                    break;
                }

                var updatedWitsmlLog = CreateNewLogWithRenamedMnemonic(job, logHeader, mnemonics, logData);

                var result = await witsmlClient.UpdateInStoreAsync(updatedWitsmlLog);

                if (!result.IsSuccessful)
                {
                    Log.Error($"Failed to rename mnemonic from {job.Mnemonic} to {job.NewMnemonic} for " +
                              $"UidWell: {job.LogReference.WellUid}, UidWellbore: {job.LogReference.WellboreUid}, UidLog: {job.LogReference.LogUid}.");
                    return(new WorkerResult(witsmlClient.GetServerHostname(), false, $"Failed to rename Mnemonic from {job.Mnemonic} to {job.NewMnemonic}", result.Reason), null);
                }

                startIndex = Index.End(logData).AddEpsilon();
            }

            var resultDeleteOldMnemonic = await DeleteOldMnemonic(job.LogReference.WellUid, job.LogReference.WellboreUid, job.LogReference.LogUid, job.Mnemonic);

            if (!resultDeleteOldMnemonic.IsSuccess)
            {
                return(resultDeleteOldMnemonic, null);
            }

            Log.Information($"{GetType().Name} - Job successful. Mnemonic renamed from {job.Mnemonic} to {job.NewMnemonic}");
            return(
                new WorkerResult(witsmlClient.GetServerHostname(), true, $"Mnemonic renamed from {job.Mnemonic} to {job.NewMnemonic}"),
                new RefreshLogObject(witsmlClient.GetServerHostname(), job.LogReference.WellUid, job.LogReference.WellboreUid, job.LogReference.LogUid, RefreshType.Update));
        }
예제 #4
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
            });
        }
        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);
        }