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

Integrates STAC metadata request #645

Merged
merged 7 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion app/scripts/components/exploration/atoms/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function useTimelineDatasetsDomain() {

return useMemo(() => {
const successDatasets = datasets.filter(
(d) => d.status === TimelineDatasetStatus.SUCCEEDED
(d) => d.status === TimelineDatasetStatus.SUCCESS
);
if (!successDatasets.length) return undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,16 @@ export function DatasetListItem(props: DatasetListItemProps) {
data: dataPoint
});

const isDatasetError = dataset.status === TimelineDatasetStatus.ERRORED;
const isDatasetError = dataset.status === TimelineDatasetStatus.ERROR;
const isDatasetLoading = dataset.status === TimelineDatasetStatus.LOADING;
const isDatasetSucceeded = dataset.status === TimelineDatasetStatus.SUCCEEDED;
const isDatasetSuccess = dataset.status === TimelineDatasetStatus.SUCCESS;

const isAnalysisAndError =
isAnalysis && dataset.analysis.status === TimelineDatasetStatus.ERRORED;
isAnalysis && dataset.analysis.status === TimelineDatasetStatus.ERROR;
const isAnalysisAndLoading =
isAnalysis && dataset.analysis.status === TimelineDatasetStatus.LOADING;
const isAnalysisAndSucceeded =
isAnalysis && dataset.analysis.status === TimelineDatasetStatus.SUCCEEDED;
const isAnalysisAndSuccess =
isAnalysis && dataset.analysis.status === TimelineDatasetStatus.SUCCESS;

const datasetLegend = dataset.data.legend;

Expand Down Expand Up @@ -270,7 +270,7 @@ export function DatasetListItem(props: DatasetListItemProps) {
/>
)}

{isDatasetSucceeded && (
{isDatasetSuccess && (
<>
{isAnalysisAndLoading && (
<DatasetTrackLoading
Expand All @@ -286,7 +286,7 @@ export function DatasetListItem(props: DatasetListItemProps) {
}}
/>
)}
{isAnalysisAndSucceeded && (
{isAnalysisAndSuccess && (
<DatasetChart
xScaled={xScaled!}
width={width}
Expand All @@ -299,7 +299,7 @@ export function DatasetListItem(props: DatasetListItemProps) {
</>
)}

{isDatasetSucceeded && !isAnalysis && (
{isDatasetSuccess && !isAnalysis && (
<DatasetTrack
width={width}
xScaled={xScaled!}
Expand All @@ -308,7 +308,7 @@ export function DatasetListItem(props: DatasetListItemProps) {
/>
)}

{isVisible && isPopoverVisible && dataPoint && (
{isDatasetSuccess && isVisible && isPopoverVisible && dataPoint && (
<DatasetPopover
ref={popoverRefs.setFloating}
style={floatingStyles}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export default function Timeline(props: TimelineProps) {
);

const successDatasets = datasets.filter(
(d) => d.status === TimelineDatasetStatus.SUCCEEDED
(d) => d.status === TimelineDatasetStatus.SUCCESS
);

// When a loaded dataset is added from an empty state, compute the correct
Expand Down
54 changes: 52 additions & 2 deletions app/scripts/components/exploration/data-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import {
eachDayOfInterval,
eachMonthOfInterval,
eachYearOfInterval
} from 'date-fns';
import { DatasetLayer, datasets } from 'veda';
import { TimelineDataset, TimelineDatasetStatus } from './types.d.ts';
import {
StacDatasetData,
TimeDensity,
TimelineDataset,
TimelineDatasetStatus
} from './types.d.ts';

import { utcString2userTzDate } from '$utils/date';

export const findParentDataset = (layerId: string) => {
const parentDataset = Object.values(datasets).find((dataset) =>
Expand All @@ -24,7 +36,7 @@ export function reconcileDatasets(
ids: string[],
datasetsList: DatasetLayer[],
reconciledDatasets: TimelineDataset[]
) {
): TimelineDataset[] {
return ids.map((id) => {
const alreadyReconciled = reconciledDatasets.find((d) => d.data.id === id);

Expand All @@ -34,6 +46,10 @@ export function reconcileDatasets(

const dataset = datasetsList.find((d) => d.id === id);

if (!dataset) {
throw new Error(`Dataset [${id}] not found`);
}

return {
status: TimelineDatasetStatus.IDLE,
data: dataset,
Expand All @@ -51,3 +67,37 @@ export function reconcileDatasets(
};
});
}

export function resolveLayerTemporalExtent(
datasetId: string,
datasetData: StacDatasetData
): Date[] {
const { domain, isPeriodic, timeDensity } = datasetData;

if (!domain || domain.length === 0) {
throw new Error(`Invalid domain on dataset [${datasetId}]`);
}

if (!isPeriodic) return domain.map((d) => utcString2userTzDate(d));

if (timeDensity === TimeDensity.YEAR) {
return eachYearOfInterval({
start: utcString2userTzDate(domain[0]),
end: utcString2userTzDate(domain.last)
});
} else if (timeDensity === TimeDensity.MONTH) {
return eachMonthOfInterval({
start: utcString2userTzDate(domain[0]),
end: utcString2userTzDate(domain.last)
});
} else if (timeDensity === TimeDensity.DAY) {
return eachDayOfInterval({
start: utcString2userTzDate(domain[0]),
end: utcString2userTzDate(domain.last)
});
}

throw new Error(
`Invalid time density [${timeDensity}] on dataset [${datasetId}]`
);
}
24 changes: 12 additions & 12 deletions app/scripts/components/exploration/datasets-mock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from './types.d.ts';

const chartData = {
status: 'succeeded',
status: 'success',
meta: {
total: 9,
loaded: 9
Expand Down Expand Up @@ -105,7 +105,7 @@ const chartData = {
};

const chartData2 = {
status: 'succeeded',
status: 'success',
meta: {
total: 15,
loaded: 15
Expand Down Expand Up @@ -368,7 +368,7 @@ function makeAnalysis(

function makeDataset(
data,
status = TimelineDatasetStatus.SUCCEEDED,
status = TimelineDatasetStatus.SUCCESS,
settings: Record<string, any> = {},
analysis = makeAnalysis({}, {})
): TimelineDataset {
Expand Down Expand Up @@ -445,10 +445,10 @@ export function MockControls() {
toggleDataset(
makeDataset(
{
id: 'errored',
id: 'error',
name: 'Error dataset'
},
TimelineDatasetStatus.ERRORED
TimelineDatasetStatus.ERROR
)
)
);
Expand Down Expand Up @@ -479,12 +479,12 @@ export function MockControls() {
toggleDataset(
makeDataset(
datasetSingle,
TimelineDatasetStatus.SUCCEEDED,
TimelineDatasetStatus.SUCCESS,
{},
makeAnalysis(
chartData2.data,
chartData2.meta,
TimelineDatasetStatus.SUCCEEDED
TimelineDatasetStatus.SUCCESS
)
)
)
Expand All @@ -500,12 +500,12 @@ export function MockControls() {
toggleDataset(
makeDataset(
dataset2020,
TimelineDatasetStatus.SUCCEEDED,
TimelineDatasetStatus.SUCCESS,
{},
makeAnalysis(
chartData.data,
chartData.meta,
TimelineDatasetStatus.SUCCEEDED
TimelineDatasetStatus.SUCCESS
)
)
)
Expand All @@ -525,7 +525,7 @@ export function MockControls() {
id: 'analysis-loading',
name: 'Analysis loading'
},
TimelineDatasetStatus.SUCCEEDED,
TimelineDatasetStatus.SUCCESS,
{},
makeAnalysis(
{},
Expand All @@ -550,12 +550,12 @@ export function MockControls() {
id: 'analysis-error',
name: 'Analysis Error'
},
TimelineDatasetStatus.SUCCEEDED,
TimelineDatasetStatus.SUCCESS,
{},
makeAnalysis(
{},
{ loaded: 34, total: 100 },
TimelineDatasetStatus.ERRORED
TimelineDatasetStatus.ERROR
)
)
)
Expand Down
Loading