Skip to content

Commit

Permalink
Look at decreasing logs #1975 (#2003)
Browse files Browse the repository at this point in the history
  • Loading branch information
petrlicman authored Sep 5, 2023
1 parent 14934b7 commit 6f0f1d9
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 24 deletions.
20 changes: 20 additions & 0 deletions Src/Witsml/Data/Curves/DateTimeIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,25 @@ public override string ToString()
{
return GetValueAsString();
}

public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}

if (obj is DateTimeIndex dateTimeIndex)
{
return this.Value == dateTimeIndex.Value;
}

return obj is null ? false : throw new NotImplementedException();
}

public override int GetHashCode()
{
return this.Value.GetHashCode();
}
}
}
17 changes: 10 additions & 7 deletions Src/Witsml/Data/Curves/DepthIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@ public override bool IsNullValue()
public override bool Equals(object that)
{
if (this == that) return true;
if (that == null || GetType() != that.GetType()) return false;

var depth = (DepthIndex)that;

if (depth.Value.CompareTo(Value) != 0) return false;
return Uom?.Equals(depth.Uom) ?? depth.Uom == null;
switch (that)
{
case null:
case DepthIndex depthIndex when depthIndex.Value.CompareTo(Value) != 0:
return false;
case DepthIndex depthIndex:
return Uom?.Equals(depthIndex.Uom) ?? depthIndex.Uom == null;
default:
return false;
}
}


public override int GetHashCode()
{
return Value.GetHashCode() ^ Uom.GetHashCode();
Expand Down
1 change: 1 addition & 0 deletions Src/WitsmlExplorer.Api/Models/LogData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class LogData
{
public string StartIndex { get; init; }
public string EndIndex { get; init; }
public string Direction { get; set; }
public IEnumerable<CurveSpecification> CurveSpecifications { get; init; }
public IEnumerable<Dictionary<string, LogDataValue>> Data { get; init; }
}
Expand Down
8 changes: 8 additions & 0 deletions Src/WitsmlExplorer.Api/Models/LogObject.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Witsml.Data;

namespace WitsmlExplorer.Api.Models
{
public class LogObject : ObjectOnWellbore
Expand All @@ -11,5 +13,11 @@ public class LogObject : ObjectOnWellbore
public string IndexCurve { get; init; }
public int Mnemonics { get; init; }
public CommonData CommonData { get; init; }
public string Direction { get; init; }

public static string ConvertDirection(WitsmlLog witsmlLog)
{
return witsmlLog?.Direction?.ToLowerInvariant() ?? WitsmlLog.WITSML_DIRECTION_INCREASING;
}
}
}
3 changes: 2 additions & 1 deletion Src/WitsmlExplorer.Api/Services/LogObjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public async Task<IEnumerable<LogObject>> GetLogs(string wellUid, string wellbor
StartIndex = log.GetStartIndexAsString(),
EndIndex = log.GetEndIndexAsString(),
IndexCurve = log.IndexCurve.Value,
Direction = LogObject.ConvertDirection(log),
Mnemonics = log.LogCurveInfo.Count,
CommonData = new CommonData()
{
Expand Down Expand Up @@ -146,7 +147,7 @@ public async Task<LogData> ReadLogData(string wellUid, string wellboreUid, strin
Index startIndex = Index.Start(log, start);
Index endIndex = Index.End(log, end);

if (startIndex > endIndex)
if ((!log.IsDecreasing() && startIndex > endIndex) || (log.IsDecreasing() && startIndex < endIndex))
{
return new LogData();
}
Expand Down
31 changes: 27 additions & 4 deletions Src/WitsmlExplorer.Api/Workers/TrimLogObjectWorker.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -16,6 +17,8 @@
using WitsmlExplorer.Api.Query;
using WitsmlExplorer.Api.Services;

using Index = Witsml.Data.Curves.Index;

namespace WitsmlExplorer.Api.Workers
{
public class TrimLogObjectWorker : BaseWorker<TrimLogDataJob>, IWorker
Expand All @@ -34,16 +37,36 @@ public TrimLogObjectWorker(ILogger<TrimLogDataJob> logger, IWitsmlClientProvider
Index newStartIndex = Index.Start(witsmlLog, job.StartIndex);
Index currentEndIndex = Index.End(witsmlLog);
Index newEndIndex = Index.End(witsmlLog, job.EndIndex);
bool isDescending = string.Equals(witsmlLog.Direction, WitsmlLog.WITSML_DIRECTION_DECREASING, StringComparison.InvariantCultureIgnoreCase);

// Added because of issue reported by Jan Burak, see #1975, pull request #2003
if (isDescending)
{
return (new WorkerResult(GetTargetWitsmlClientOrThrow().GetServerHostname(), false, "Trimming of decreasing log temporarily disabled because of potential server issue", string.Empty, witsmlLog.GetDescription()), null);
}


if ((currentStartIndex == newStartIndex) && (newEndIndex == currentEndIndex))
{
return (new WorkerResult(GetTargetWitsmlClientOrThrow().GetServerHostname(), true, "No update needed", string.Empty, witsmlLog.GetDescription()), null);
}

bool trimStart = isDescending
? currentStartIndex > newStartIndex && newStartIndex > currentEndIndex
: currentStartIndex < newStartIndex && newStartIndex < currentEndIndex;
bool trimEnd = isDescending
? currentEndIndex < newEndIndex && newEndIndex < currentStartIndex
: currentEndIndex > newEndIndex && newEndIndex > currentStartIndex;

bool trimmedStartOfLog = false;
if (currentStartIndex < newStartIndex && newStartIndex < currentEndIndex)
if (trimStart)
{
WitsmlLogs trimLogObjectStartQuery = CreateRequest(
job.LogObject.WellUid,
job.LogObject.WellboreUid,
job.LogObject.Uid,
witsmlLog.IndexType,
deleteTo: newStartIndex);
deleteTo: isDescending ? newEndIndex : newStartIndex);

QueryResult result = await GetTargetWitsmlClientOrThrow().DeleteFromStoreAsync(trimLogObjectStartQuery);
if (result.IsSuccessful)
Expand All @@ -58,14 +81,14 @@ public TrimLogObjectWorker(ILogger<TrimLogDataJob> logger, IWitsmlClientProvider
}

bool trimmedEndOfLog = false;
if (currentEndIndex > newEndIndex && newEndIndex > currentStartIndex)
if (trimEnd)
{
WitsmlLogs trimLogObjectEndQuery = CreateRequest(
job.LogObject.WellUid,
job.LogObject.WellboreUid,
job.LogObject.Uid,
witsmlLog.IndexType,
deleteFrom: newEndIndex);
deleteFrom: isDescending ? newStartIndex : newEndIndex);

QueryResult result = await GetTargetWitsmlClientOrThrow().DeleteFromStoreAsync(trimLogObjectEndQuery);
if (result.IsSuccessful)
Expand Down
1 change: 1 addition & 0 deletions Src/WitsmlExplorer.Frontend/components/Constants.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const WITSML_INDEX_TYPE_MD = "measured depth";
export const WITSML_INDEX_TYPE_DATE_TIME = "date time";
export const WITSML_LOG_ORDERTYPE_DECREASING = "decreasing";

export const DateFormat = {
DATE: "DD.MM.YYYY",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import OperationType from "../../contexts/operationType";
import { ComponentType } from "../../models/componentType";
import { CopyRangeClipboard, createComponentReferences } from "../../models/jobs/componentReferences";
import LogObject, { indexToNumber } from "../../models/logObject";
import { WITSML_INDEX_TYPE_DATE_TIME, WITSML_INDEX_TYPE_MD } from "../Constants";
import { WITSML_INDEX_TYPE_DATE_TIME, WITSML_INDEX_TYPE_MD, WITSML_LOG_ORDERTYPE_DECREASING } from "../Constants";
import ModalDialog from "./ModalDialog";
import AdjustDateTimeModal from "./TrimLogObject/AdjustDateTimeModal";
import AdjustNumberRangeModal from "./TrimLogObject/AdjustNumberRangeModal";
Expand Down Expand Up @@ -45,6 +45,7 @@ const CopyRangeModal = (props: CopyRangeModalProps): React.ReactElement => {
<AdjustDateTimeModal
minDate={selectedLog.startIndex}
maxDate={selectedLog.endIndex}
isDescending={selectedLog.direction == WITSML_LOG_ORDERTYPE_DECREASING}
onStartDateChanged={setStartIndex}
onEndDateChanged={setEndIndex}
onValidChange={toggleConfirmDisabled}
Expand All @@ -54,6 +55,7 @@ const CopyRangeModal = (props: CopyRangeModalProps): React.ReactElement => {
<AdjustNumberRangeModal
minValue={indexToNumber(selectedLog.startIndex)}
maxValue={indexToNumber(selectedLog.endIndex)}
isDescending={selectedLog.direction == WITSML_LOG_ORDERTYPE_DECREASING}
onStartValueChanged={setStartIndex}
onEndValueChanged={setEndIndex}
onValidChange={toggleConfirmDisabled}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import NavigationType from "../../contexts/navigationType";
import { HideModalAction } from "../../contexts/operationStateReducer";
import OperationType from "../../contexts/operationType";
import LogObject from "../../models/logObject";
import { WITSML_INDEX_TYPE_DATE_TIME } from "../Constants";
import { WITSML_INDEX_TYPE_DATE_TIME, WITSML_LOG_ORDERTYPE_DECREASING } from "../Constants";
import { LogCurveInfoRow } from "../ContentViews/LogCurveInfoListView";
import ModalDialog from "./ModalDialog";
import AdjustDateTimeModal from "./TrimLogObject/AdjustDateTimeModal";
Expand Down Expand Up @@ -62,6 +62,7 @@ const SelectIndexToDisplayModal = (props: SelectIndexToDisplayModalProps): React
<AdjustDateTimeModal
minDate={log.startIndex}
maxDate={log.endIndex}
isDescending={log.direction == WITSML_LOG_ORDERTYPE_DECREASING}
onStartDateChanged={setStartIndex}
onEndDateChanged={setEndIndex}
onValidChange={toggleConfirmDisabled}
Expand All @@ -71,6 +72,7 @@ const SelectIndexToDisplayModal = (props: SelectIndexToDisplayModalProps): React
<AdjustNumberRangeModal
minValue={indexToNumber(log.startIndex)}
maxValue={indexToNumber(log.endIndex)}
isDescending={log.direction == WITSML_LOG_ORDERTYPE_DECREASING}
onStartValueChanged={setStartIndex}
onEndValueChanged={setEndIndex}
onValidChange={toggleConfirmDisabled}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { LogHeaderDateTimeField } from "../LogHeaderDateTimeField";
export interface AdjustDateTimeModelProps {
minDate: string;
maxDate: string;
isDescending?: boolean;
onStartDateChanged: (value: string) => void;
onEndDateChanged: (value: string) => void;
onValidChange: (isValid: boolean) => void;
Expand All @@ -19,7 +20,7 @@ interface SetRangeButton {
}

const AdjustDateTimeModal = (props: AdjustDateTimeModelProps): React.ReactElement => {
const { minDate, maxDate, onStartDateChanged, onEndDateChanged, onValidChange } = props;
const { minDate, maxDate, isDescending, onStartDateChanged, onEndDateChanged, onValidChange } = props;
const [startIndexIsValid, setStartIndexIsValid] = useState<boolean>(true);
const [endIndexIsValid, setEndIndexIsValid] = useState<boolean>(true);
const [startOffset] = useState<string>(getOffset(minDate));
Expand All @@ -40,7 +41,7 @@ const AdjustDateTimeModal = (props: AdjustDateTimeModelProps): React.ReactElemen
}, [startIndex, endIndex]);

useEffect(() => {
onValidChange(startIndexIsValid && endIndexIsValid && startIndex < endIndex);
onValidChange(startIndexIsValid && endIndexIsValid && (isDescending ? startIndex > endIndex : startIndex < endIndex));
}, [startIndexIsValid, endIndexIsValid, startIndex, endIndex]);

return (
Expand Down Expand Up @@ -81,7 +82,8 @@ const AdjustDateTimeModal = (props: AdjustDateTimeModelProps): React.ReactElemen
setEndIndexIsValid(valid);
}}
offset={startOffset}
maxValue={endIndex}
minValue={isDescending ? endIndex : null}
maxValue={isDescending ? null : endIndex}
/>
<LogHeaderDateTimeField
value={endIndex ?? ""}
Expand All @@ -91,7 +93,8 @@ const AdjustDateTimeModal = (props: AdjustDateTimeModelProps): React.ReactElemen
setStartIndexIsValid(valid);
}}
offset={endOffset}
minValue={startIndex}
minValue={isDescending ? null : startIndex}
maxValue={isDescending ? startIndex : null}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import React, { useEffect, useState } from "react";
export interface AdjustNumberRangeModalProps {
minValue: number;
maxValue: number;
isDescending?: boolean;
onStartValueChanged: (value: number) => void;
onEndValueChanged: (value: number) => void;
onValidChange: (isValid: boolean) => void;
}

const AdjustNumberRangeModal = (props: AdjustNumberRangeModalProps): React.ReactElement => {
const { minValue, maxValue, onStartValueChanged, onEndValueChanged, onValidChange } = props;
const { minValue, maxValue, isDescending, onStartValueChanged, onEndValueChanged, onValidChange } = props;
const [startValue, setStartIndex] = useState<number>(minValue);
const [endValue, setEndIndex] = useState<number>(maxValue);
const [startIndexIsValid, setStartIndexIsValid] = useState<boolean>();
Expand All @@ -24,8 +25,8 @@ const AdjustNumberRangeModal = (props: AdjustNumberRangeModalProps): React.React
}, [startValue, endValue]);

useEffect(() => {
setStartIndexIsValid(startValue < endValue);
setEndIndexIsValid(endValue > startValue);
setStartIndexIsValid(isDescending ? startValue > endValue : endValue > startValue);
setEndIndexIsValid(isDescending ? startValue > endValue : endValue > startValue);
}, [startValue, endValue]);

useEffect(() => {
Expand Down Expand Up @@ -78,7 +79,7 @@ const AdjustNumberRangeModal = (props: AdjustNumberRangeModalProps): React.React
value={startValue ?? ""}
type={"number"}
error={!startIndexIsValid}
helperText={startIndexIsValid ? "" : `Must be lower than ${endValue}`}
helperText={startIndexIsValid ? "" : isDescending ? `Must be higher than ${endValue}` : `Must be lower than ${endValue}`}
onChange={handleStartIndexChanged}
style={{ paddingBottom: startIndexIsValid ? "23px" : 0 }}
/>
Expand All @@ -88,7 +89,7 @@ const AdjustNumberRangeModal = (props: AdjustNumberRangeModalProps): React.React
value={endValue ?? ""}
type={"number"}
error={!endIndexIsValid}
helperText={endIndexIsValid ? "" : `Must be higher than ${maxValue}`}
helperText={endIndexIsValid ? "" : isDescending ? `Must be lower than ${startValue}` : `Must be higher than ${startValue}`}
onChange={handleEndIndexChanged}
style={{ paddingBottom: endIndexIsValid ? "23px" : 0 }}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { truncateAbortHandler } from "../../../services/apiClient";
import JobService, { JobType } from "../../../services/jobService";
import ObjectService from "../../../services/objectService";
import { colors } from "../../../styles/Colors";
import { WITSML_INDEX_TYPE_DATE_TIME, WITSML_INDEX_TYPE_MD } from "../../Constants";
import { WITSML_INDEX_TYPE_DATE_TIME, WITSML_INDEX_TYPE_MD, WITSML_LOG_ORDERTYPE_DECREASING } from "../../Constants";
import ModalDialog from "../ModalDialog";
import AdjustDateTimeModal from "./AdjustDateTimeModal";
import AdjustNumberRangeModal from "./AdjustNumberRangeModal";
Expand Down Expand Up @@ -70,6 +70,7 @@ const TrimLogObjectModal = (props: TrimLogObjectModalProps): React.ReactElement
<AdjustDateTimeModal
minDate={log.startIndex}
maxDate={log.endIndex}
isDescending={log.direction == WITSML_LOG_ORDERTYPE_DECREASING}
onStartDateChanged={setStartIndex}
onEndDateChanged={setEndIndex}
onValidChange={toggleConfirmDisabled}
Expand All @@ -79,6 +80,7 @@ const TrimLogObjectModal = (props: TrimLogObjectModalProps): React.ReactElement
<AdjustNumberRangeModal
minValue={indexToNumber(logObject.startIndex)}
maxValue={indexToNumber(logObject.endIndex)}
isDescending={log.direction == WITSML_LOG_ORDERTYPE_DECREASING}
onStartValueChanged={setStartIndex}
onEndValueChanged={setEndIndex}
onValidChange={toggleConfirmDisabled}
Expand Down
1 change: 1 addition & 0 deletions Src/WitsmlExplorer.Frontend/models/logObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default interface LogObject extends ObjectOnWellbore {
serviceCompany?: string;
runNumber?: string;
indexCurve?: string;
direction?: string;
mnemonics?: string;
commonData?: CommonData;
}
Expand Down
2 changes: 2 additions & 0 deletions witsml-explorer.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Northing/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Southing/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tubulars/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=wellbores/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=witsml/@EntryIndexedValue">True</s:Boolean>
Expand Down

0 comments on commit 6f0f1d9

Please sign in to comment.