Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download memory issue #2640

Merged
merged 24 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Src/WitsmlExplorer.Api/Services/LogObjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,14 @@ private async Task<WitsmlLog> LoadDataRecursive(List<string> mnemonics, WitsmlLo
{
await using LogDataReader logDataReader = new(_witsmlClient, log, new List<string>(mnemonics), null, startIndex, endIndex);
WitsmlLogData logData = await logDataReader.GetNextBatch(cancellationToken);

if (!startIndex.GetValueAsString().Equals(log.StartDateTimeIndex))
{
log.StartDateTimeIndex = startIndex.GetValueAsString();
}
if (!endIndex.GetValueAsString().Equals(log.EndDateTimeIndex))
{
log.EndDateTimeIndex = endIndex.GetValueAsString();
}
eliasbruvik marked this conversation as resolved.
Show resolved Hide resolved
var allLogData = logData;
while (logData != null)
{
Expand Down
7 changes: 7 additions & 0 deletions Src/WitsmlExplorer.Api/Workers/DownloadLogDataWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public DownloadLogDataWorker(
}

var logData = await _logObjectService.ReadLogData(job.LogReference.WellUid, job.LogReference.WellboreUid, job.LogReference.Uid, job.Mnemonics.ToList(), job.StartIndexIsInclusive, job.LogReference.StartIndex, job.LogReference.EndIndex, true, cancellationToken, progressReporter);
if (logData.CurveSpecifications == null)
{
var message = "DownloadLogDataJob failed. Start or end indexes are out of range.";
eliasbruvik marked this conversation as resolved.
Show resolved Hide resolved
Logger.LogError(message);
return (new WorkerResult(GetTargetWitsmlClientOrThrow().GetServerHostname(), false, message, message), null);
eliasbruvik marked this conversation as resolved.
Show resolved Hide resolved
}

return (job.ExportToLas)
? await DownloadLogDataResultLasFile(job, logData.Data,
logData.CurveSpecifications)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ export const CurveValuesView = (): React.ReactElement => {
startIndex: startIndex,
endIndex: endIndex,
columns: columns,
curveValueRows: tableData,
autoRefresh: autoRefresh
};
const action: DisplayModalAction = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface ConfirmProps {
switchButtonPlaces?: boolean;
showCancelButton?: boolean;
cancelText?: string;
confirmDisabled?: boolean;
}

const ConfirmModal = (props: ConfirmProps): React.ReactElement => {
Expand All @@ -24,6 +25,7 @@ const ConfirmModal = (props: ConfirmProps): React.ReactElement => {
confirmColor={props.confirmColor}
switchButtonPlaces={props.switchButtonPlaces}
showCancelButton={props.showCancelButton}
confirmDisabled={props.confirmDisabled}
/>
);
};
Expand Down
eliasbruvik marked this conversation as resolved.
Show resolved Hide resolved
eliasbruvik marked this conversation as resolved.
Show resolved Hide resolved
eliasbruvik marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ import React, { CSSProperties, useCallback, useState } from "react";
import JobService, { JobType } from "services/jobService";
import ConfirmModal from "./ConfirmModal";
import { ReportModal } from "./ReportModal";
import { RouterLogType } from "routes/routerConstants";
import { useParams } from "react-router-dom";
import {
WITSML_INDEX_TYPE_DATE_TIME,
WITSML_LOG_ORDERTYPE_DECREASING
} from "components/Constants";
import AdjustDateTimeModal from "./TrimLogObject/AdjustDateTimeModal";
import WarningBar from "components/WarningBar";

export interface DownloadOptionsSelectionModalProps {
mnemonics: string[];
Expand All @@ -25,6 +33,7 @@ export interface DownloadOptionsSelectionModalProps {
startIndex: string;
endIndex: string;
columns: ExportableContentTableColumn<CurveSpecification>[];
curveValueRows: CurveValueRow[];
autoRefresh: boolean;
}

Expand All @@ -48,9 +57,41 @@ const DownloadOptionsSelectionModal = (

const [selectedDownloadFormat, setSelectedDownloadFormat] =
useState<DownloadFormat>(DownloadFormat.Csv);

const { exportData, exportOptions } = useExport();

const { logType } = useParams();

const { log, curveValueRows } = props;

const getStartIndex = (log: LogObject): string | number => {
const isTimeIndexed = log.indexType === WITSML_INDEX_TYPE_DATE_TIME;
if (selectedDownloadOption === DownloadOptions.All) {
return isTimeIndexed ? log.startIndex : indexToNumber(log.startIndex);
}
if (selectedDownloadOption === DownloadOptions.SelectedRange) {
return isTimeIndexed ? props.startIndex : indexToNumber(props.startIndex);
}
};

const getEndIndex = (log: LogObject): string | number => {
const isTimeIndexed = log.indexType === WITSML_INDEX_TYPE_DATE_TIME;
if (selectedDownloadOption === DownloadOptions.All) {
return isTimeIndexed ? log.endIndex : indexToNumber(log.endIndex);
}
if (selectedDownloadOption === DownloadOptions.SelectedRange) {
return isTimeIndexed ? props.endIndex : indexToNumber(props.endIndex);
}
};

const isTimeLog = logType === RouterLogType.TIME;

const [startIndex, setStartIndex] = useState<string | number>(
getStartIndex(log)
);
const [endIndex, setEndIndex] = useState<string | number>(getEndIndex(log));

const [isValidInterval, setIsValidInterval] = useState<boolean>(true);

const exportSelectedRange = async () => {
const logReference: LogObject = props.log;
const startIndexIsInclusive = !props.autoRefresh;
Expand All @@ -60,8 +101,8 @@ const DownloadOptionsSelectionModal = (
mnemonics: props.mnemonics,
startIndexIsInclusive,
exportToLas,
startIndex: props.startIndex,
endIndex: props.endIndex
startIndex: startIndex.toString(),
endIndex: endIndex.toString()
};
callExportJob(downloadLogDataJob);
};
Expand All @@ -70,13 +111,26 @@ const DownloadOptionsSelectionModal = (
const logReference: LogObject = props.log;
const startIndexIsInclusive = !props.autoRefresh;
const exportToLas = selectedDownloadFormat === DownloadFormat.Las;
const downloadLogDataJob: DownloadLogDataJob = {
logReference,
mnemonics: props.mnemonics,
startIndexIsInclusive,
exportToLas
};
callExportJob(downloadLogDataJob);
const isTimeIndexed = log.indexType === WITSML_INDEX_TYPE_DATE_TIME;
if (isTimeIndexed) {
const downloadLogDataJob: DownloadLogDataJob = {
logReference,
mnemonics: props.mnemonics,
startIndexIsInclusive,
exportToLas,
startIndex: startIndex.toString(),
endIndex: endIndex.toString()
};
callExportJob(downloadLogDataJob);
} else {
const downloadLogDataJob: DownloadLogDataJob = {
logReference,
mnemonics: props.mnemonics,
startIndexIsInclusive,
exportToLas
};
callExportJob(downloadLogDataJob);
}
};

const callExportJob = async (downloadLogDataJob: DownloadLogDataJob) => {
Expand Down Expand Up @@ -144,9 +198,32 @@ const DownloadOptionsSelectionModal = (
}
};

const step =
curveValueRows?.length > 1
? new Date(curveValueRows[1].id.toString()).getTime() -
new Date(curveValueRows[0].id.toString()).getTime()
: null;
const actualSize =
(new Date(endIndex).getTime() - new Date(startIndex).getTime()) /
60 /
60 /
24;
const maxSpan = (1290 * step) / props.mnemonics.length;
const tooBigInterval = actualSize > maxSpan;

const outOfRange =
new Date(startIndex).getTime() - new Date(log.startIndex).getTime() < 0 ||
new Date(endIndex).getTime() - new Date(log.endIndex).getTime() > 0
? true
: false;
eliasbruvik marked this conversation as resolved.
Show resolved Hide resolved
return (
<ConfirmModal
heading={`Download log data for ${props.mnemonics.length} mnemonics`}
confirmDisabled={
isTimeLog &&
(!isValidInterval || tooBigInterval) &&
selectedDownloadOption !== DownloadOptions.SelectedIndexValues
}
content={
<>
<span>
Expand Down Expand Up @@ -210,6 +287,49 @@ const DownloadOptionsSelectionModal = (
/>
<Typography>Las file</Typography>
</label>
{isTimeLog &&
tooBigInterval &&
(selectedDownloadOption === DownloadOptions.All ||
selectedDownloadOption === DownloadOptions.SelectedRange) && (
<WarningBar
message={`Selected range is too large. Reduce the end date to a maximum of ${new Date(
new Date(startIndex).getTime() + maxSpan * 60 * 60 * 24
eliasbruvik marked this conversation as resolved.
Show resolved Hide resolved
)} `}
/>
)}
{isTimeLog &&
outOfRange &&
(selectedDownloadOption === DownloadOptions.All ||
selectedDownloadOption === DownloadOptions.SelectedRange) && (
<WarningBar
message={`Selected start and end dates are out of log range. Available range is between ${startIndex} and ${startIndex}`}
eliasbruvik marked this conversation as resolved.
Show resolved Hide resolved
/>
)}
{isTimeLog && selectedDownloadOption === DownloadOptions.All && (
eliasbruvik marked this conversation as resolved.
Show resolved Hide resolved
<AdjustDateTimeModal
minDate={log.startIndex as string}
maxDate={log.endIndex as string}
isDescending={log.direction == WITSML_LOG_ORDERTYPE_DECREASING}
hideSetButtons={true}
onStartDateChanged={setStartIndex}
onEndDateChanged={setEndIndex}
onValidChange={(isValid: boolean) => setIsValidInterval(isValid)}
/>
)}
{isTimeLog &&
selectedDownloadOption === DownloadOptions.SelectedRange && (
<AdjustDateTimeModal
minDate={props.startIndex as string}
maxDate={props.endIndex as string}
isDescending={log.direction == WITSML_LOG_ORDERTYPE_DECREASING}
hideSetButtons={true}
onStartDateChanged={setStartIndex}
onEndDateChanged={setEndIndex}
onValidChange={(isValid: boolean) =>
setIsValidInterval(isValid)
}
/>
)}
</>
}
onConfirm={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface AdjustDateTimeModelProps {
minDate: string;
maxDate: string;
isDescending?: boolean;
hideSetButtons?: boolean;
onStartDateChanged: (value: string) => void;
onEndDateChanged: (value: string) => void;
onValidChange: (isValid: boolean) => void;
Expand All @@ -25,6 +26,7 @@ const AdjustDateTimeModal = (
minDate,
maxDate,
isDescending,
hideSetButtons,
onStartDateChanged,
onEndDateChanged,
onValidChange
Expand Down Expand Up @@ -93,25 +95,26 @@ const AdjustDateTimeModal = (
aria-label="set time range button group"
style={{ margin: ".5rem" }}
>
{setRangeButtons.map((buttonValue) => {
return (
totalTimeSpan > buttonValue.timeInMilliseconds && (
<Button
key={"last" + buttonValue.displayText}
onClick={() => {
const newStartIndex = addMilliseconds(
toDate(endIndex),
-buttonValue.timeInMilliseconds
);
setStartIndex(newStartIndex.toISOString());
setEndIndex(maxDate);
}}
>
{"Last " + buttonValue.displayText}
</Button>
)
);
})}
{!hideSetButtons &&
setRangeButtons.map((buttonValue) => {
return (
totalTimeSpan > buttonValue.timeInMilliseconds && (
<Button
key={"last" + buttonValue.displayText}
onClick={() => {
const newStartIndex = addMilliseconds(
toDate(endIndex),
-buttonValue.timeInMilliseconds
);
setStartIndex(newStartIndex.toISOString());
setEndIndex(maxDate);
}}
>
{"Last " + buttonValue.displayText}
</Button>
)
);
})}
<Button
key={"resetRangeValues"}
onClick={() => {
Expand Down
Loading