Skip to content

Commit

Permalink
Merge pull request #2209 from eliasbruvik/FIX-2208
Browse files Browse the repository at this point in the history
FIX-2208 DeleteEmptyMnemonics - Delete curves without min or max index
  • Loading branch information
eliasbruvik authored Jan 18, 2024
2 parents d9a273e + 1aed2b7 commit 64a4a26
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 30 deletions.
1 change: 1 addition & 0 deletions Src/WitsmlExplorer.Api/Jobs/DeleteEmptyMnemonicsJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public record DeleteEmptyMnemonicsJob : Job
public ICollection<ObjectReference> Logs { get; init; } = new List<ObjectReference>();
public double NullDepthValue { get; init; }
public DateTime NullTimeValue { get; init; }
public bool DeleteNullIndex { get; init; }

public override string Description()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public DeleteEmptyMnemonicsWorker(

logCurvesCheckedCount += logCurves.Count;

var mnemonicsToDelete = FindNullMnemonics(job.NullDepthValue, job.NullTimeValue, logToCheck, logCurves);
var mnemonicsToDelete = FindNullMnemonics(job.NullDepthValue, job.NullTimeValue, job.DeleteNullIndex, logToCheck, logCurves);

foreach (var mnemonicToDelete in mnemonicsToDelete)
{
Expand Down Expand Up @@ -154,7 +154,7 @@ private async Task<QueryResult> DeleteMnemonic(string wellUid, string wellboreUi
return await _mnemonicService.DeleteMnemonic(wellUid, wellboreUid, logToCheckUid, mnemonicToDelete);
}

private ICollection<LogCurveInfo> FindNullMnemonics(double nullDepthValue, DateTime nullTimeValue, LogObject logToCheck, ICollection<LogCurveInfo> logCurves)
private ICollection<LogCurveInfo> FindNullMnemonics(double nullDepthValue, DateTime nullTimeValue, bool deleteNullIndex, LogObject logToCheck, ICollection<LogCurveInfo> logCurves)
{
var nullMnemonics = new List<LogCurveInfo>();

Expand All @@ -165,11 +165,17 @@ private ICollection<LogCurveInfo> FindNullMnemonics(double nullDepthValue, DateT
{
if (logToCheck.IndexType == WitsmlLog.WITSML_INDEX_TYPE_MD)
{
nullMnemonics.AddRange(logCurves.Where(logCurve => logCurve.MinDepthIndex == nullDepthValueString && logCurve.MaxDepthIndex == nullDepthValueString));
nullMnemonics.AddRange(logCurves.Where(logCurve =>
(logCurve.MinDepthIndex == nullDepthValueString || (deleteNullIndex && logCurve.MinDepthIndex == null)) &&
(logCurve.MaxDepthIndex == nullDepthValueString || (deleteNullIndex && logCurve.MaxDepthIndex == null))
));
}
else if (logToCheck.IndexType == WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME)
{
nullMnemonics.AddRange(logCurves.Where(logCurve => logCurve.MinDateTimeIndex == nullTimeValueString && logCurve.MaxDateTimeIndex == nullTimeValueString));
nullMnemonics.AddRange(logCurves.Where(logCurve =>
(logCurve.MinDateTimeIndex == nullTimeValueString || (deleteNullIndex && logCurve.MinDateTimeIndex == null)) &&
(logCurve.MaxDateTimeIndex == nullTimeValueString || (deleteNullIndex && logCurve.MaxDateTimeIndex == null))
));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Checkbox, Icon, Tooltip, Typography } from "@equinor/eds-core-react";
import { TextField } from "@material-ui/core";
import { DateTimeField } from "components/Modals/DateTimeField";
import ModalDialog from "components/Modals/ModalDialog";
Expand Down Expand Up @@ -25,12 +26,13 @@ const DeleteEmptyMnemonicsModal = (
const { wells, wellbores, logs } = props;
const {
dispatchOperation,
operationState: { timeZone }
operationState: { timeZone, colors }
} = useContext(OperationContext);
const [nullDepthValue, setNullDepthValue] = useState<number>(-999.25);
const [nullTimeValue, setNullTimeValue] = useState<string>(
"1900-01-01T00:00:00.000Z"
);
const [deleteNullIndex, setDeleteNullIndex] = useState<boolean>(false);
const [nullTimeValueValid, setNullTimeValueValid] = useState<boolean>(true);
const [isLoading, setIsLoading] = useState<boolean>(false);

Expand All @@ -52,7 +54,8 @@ const DeleteEmptyMnemonicsModal = (
}),
logs: logs?.map((log) => toObjectReference(log)),
nullDepthValue: nullDepthValue,
nullTimeValue: nullTimeValue
nullTimeValue: nullTimeValue,
deleteNullIndex: deleteNullIndex
};

const jobId = await JobService.orderJob(JobType.DeleteEmptyMnemonics, job);
Expand Down Expand Up @@ -90,6 +93,22 @@ const DeleteEmptyMnemonicsModal = (
value={nullDepthValue}
onChange={(e: any) => setNullDepthValue(+e.target.value)}
/>
<CheckboxLayout>
<Checkbox
checked={deleteNullIndex}
onChange={() => setDeleteNullIndex(!deleteNullIndex)}
/>
<Typography>
Delete mnemonics with missing minIndex and maxIndex
</Typography>
<Tooltip title="This will also delete mnemonics where the minIndex and maxIndex in LogCurveInfo are not returned from the server. These properties normally contains the null value.">
<Icon
name="infoCircle"
color={colors.interactive.primaryResting}
size={18}
/>
</Tooltip>
</CheckboxLayout>
</ContentLayout>
}
confirmDisabled={!nullTimeValueValid}
Expand All @@ -106,4 +125,11 @@ const ContentLayout = styled.div`
gap: 0.25rem;
`;

const CheckboxLayout = styled.div`
display: flex;
flex-direction: row;
gap: 0.25rem;
align-items: center;
`;

export default DeleteEmptyMnemonicsModal;
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface DeleteEmptyMnemonicsJob {
logs: ObjectReference[];
nullDepthValue: number;
nullTimeValue: string;
deleteNullIndex: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,34 @@ public async Task DeleteOneMnemonic()

Assert.NotNull(job.JobInfo?.Report);
Assert.Single(job.JobInfo.Report.ReportItems);
Assert.Equal("3 mnemonics were checked for NullDepthValue: \"0\" and NullTimeValue: \"" + dateTime.ToISODateTimeString() + "\". One empty mnemonic was found and deleted.",
Assert.Equal("4 mnemonics were checked for NullDepthValue: \"0\" and NullTimeValue: \"" + dateTime.ToISODateTimeString() + "\". One empty mnemonic was found and deleted.",
job.JobInfo.Report.Summary);

Assert.Equal("DeleteEmptyMnemonicsJob - WellUids: 111; WellboreUids: 112; LogUids: ;", job.JobInfo.Description);
Assert.Equal("Well111", job.JobInfo.WellName);
Assert.Equal("Wellbore112", job.JobInfo.WellboreName);
Assert.Equal("", job.JobInfo.ObjectName);
}

[Fact]
public async Task DeleteNullIndexMnemonic()
{
SetupDepthLogObject();

var dateTime = new DateTime(2023, 8, 20, 12, 0, 0);

var job = CreateJob(999, dateTime, testWellbores: true, deleteNullIndex: true);

(WorkerResult result, RefreshAction _) = await _worker.Execute(job);

_mnemonicService.Verify(s => s.DeleteMnemonic(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<LogCurveInfo>()),
Times.Once);

Assert.True(result.IsSuccess);

Assert.NotNull(job.JobInfo?.Report);
Assert.Single(job.JobInfo.Report.ReportItems);
Assert.Equal("4 mnemonics were checked for NullDepthValue: \"999\" and NullTimeValue: \"" + dateTime.ToISODateTimeString() + "\". One empty mnemonic was found and deleted.",
job.JobInfo.Report.Summary);

Assert.Equal("DeleteEmptyMnemonicsJob - WellUids: 111; WellboreUids: 112; LogUids: ;", job.JobInfo.Description);
Expand Down Expand Up @@ -150,7 +177,7 @@ public async Task DeleteWellMnemonics()

Assert.NotNull(job.JobInfo?.Report);
Assert.Single(job.JobInfo.Report.ReportItems);
Assert.Equal("3 mnemonics were checked for NullDepthValue: \"0\" and NullTimeValue: \"" + dateTime.ToISODateTimeString() + "\". One empty mnemonic was found and deleted.",
Assert.Equal("4 mnemonics were checked for NullDepthValue: \"0\" and NullTimeValue: \"" + dateTime.ToISODateTimeString() + "\". One empty mnemonic was found and deleted.",
job.JobInfo.Report.Summary);

Assert.Equal("DeleteEmptyMnemonicsJob - WellUids: 111; WellboreUids: ; LogUids: ;", job.JobInfo.Description);
Expand All @@ -177,7 +204,7 @@ public async Task DeleteLogMnemonics()

Assert.NotNull(job.JobInfo?.Report);
Assert.Single(job.JobInfo.Report.ReportItems);
Assert.Equal("3 mnemonics were checked for NullDepthValue: \"0\" and NullTimeValue: \"" + dateTime.ToISODateTimeString() + "\". One empty mnemonic was found and deleted.",
Assert.Equal("4 mnemonics were checked for NullDepthValue: \"0\" and NullTimeValue: \"" + dateTime.ToISODateTimeString() + "\". One empty mnemonic was found and deleted.",
job.JobInfo.Report.Summary);

Assert.Equal("DeleteEmptyMnemonicsJob - WellUids: 111; WellboreUids: 112; LogUids: 123;", job.JobInfo.Description);
Expand Down Expand Up @@ -234,40 +261,42 @@ private void SetupDepthLogObject()
.Setup(los => los.GetLog(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns(Task.Run(() => new LogObject() { Uid = "123", IndexType = WitsmlLog.WITSML_INDEX_TYPE_MD }));

var lcis = new List<LogCurveInfo>();

var lci = new LogCurveInfo
var lcis = new List<LogCurveInfo>
{
MinDepthIndex = "0",
MaxDepthIndex = "0"
new()
{
MinDepthIndex = "0",
MaxDepthIndex = "0"
},
new()
{
MinDepthIndex = "1",
MaxDepthIndex = "1"
},
new()
{
MinDepthIndex = "0",
MaxDepthIndex = "1"
},
new()
{
MinDepthIndex = null,
MaxDepthIndex = null
}
};
lcis.Add(lci);

lci = new LogCurveInfo
{
MinDepthIndex = "1",
MaxDepthIndex = "1"
};
lcis.Add(lci);

lci = new LogCurveInfo
{
MinDepthIndex = "0",
MaxDepthIndex = "1"
};
lcis.Add(lci);

_logObjectService
.Setup(los => los.GetLogCurveInfo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns(Task.Run(() => lcis.AsCollection()));
}

private DeleteEmptyMnemonicsJob CreateJob(double nullDepthValue, DateTime nullTimeValue, bool testWells = false, bool testWellbores = false, bool testLogs = false)
private DeleteEmptyMnemonicsJob CreateJob(double nullDepthValue, DateTime nullTimeValue, bool testWells = false, bool testWellbores = false, bool testLogs = false, bool deleteNullIndex = false)
{
return new DeleteEmptyMnemonicsJob()
{
NullDepthValue = nullDepthValue,
NullTimeValue = nullTimeValue,
DeleteNullIndex = deleteNullIndex,
Wells = testWells ? new List<WellReference> { new WellReference() { WellUid = "111", WellName = "Well111" } } : new List<WellReference>(),
Wellbores = testWellbores ? new List<WellboreReference> { new WellboreReference() { WellUid = "111", WellName = "Well111", WellboreUid = "112", WellboreName = "Wellbore112" } } : new List<WellboreReference>(),
Logs = testLogs ? new List<ObjectReference> { new ObjectReference() { WellUid = "111", WellName = "Well111", WellboreUid = "112", WellboreName = "Wellbore112", Uid = "123", Name = "Log123" } } : new List<ObjectReference>(),
Expand Down

0 comments on commit 64a4a26

Please sign in to comment.