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

Handle analysis/define datasets w/o collection summaries #786

Merged
merged 14 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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/analysis/define/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
const onDatasetLayerChange = useCallback(
(e) => {
const id = e.target.id;
let newDatasetsLayers = [...(datasetsLayers || [])];

Check warning on line 295 in app/scripts/components/analysis/define/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
if (e.target.checked) {
const newDatasetLayer = allAvailableDatasetsLayers.find(
(l) => l.id === id
Expand Down Expand Up @@ -333,7 +333,7 @@
setAnalysisParam('datasetsLayers', cleanedDatasetsLayers);
// Only update when stac search gets updated to avoid triggering an infinite
// read/set state loop
}, [selectableDatasetLayers, setAnalysisParam]);

Check warning on line 336 in app/scripts/components/analysis/define/index.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'datasetsLayers'. Either include it or remove the dependency array

const notReady = !readyToLoadDatasets || !datasetsLayers?.length;

Expand Down Expand Up @@ -517,7 +517,7 @@
{datasetLayer.name}
<DataPointsWarning>
<CollecticonSignDanger />~
{datasetLayer.numberOfItems} data points
{datasetLayer.numberOfItems ? `${datasetLayer.numberOfItems} data points`: "Data temporarily unavailable"}
</DataPointsWarning>
</FormCheckableUnselectable>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
aoi?: FeatureCollection<Polygon> | null;
}

export type DatasetWithTimeseriesData = TimeseriesDataResult &
DatasetLayer & { numberOfItems: number };
export type DatasetWithCollections = TimeseriesDataResult & DatasetLayer;

export type DatasetWithTimeseriesData = DatasetWithCollections & { numberOfItems: number };

const collectionEndpointSuffix = '/collections';

Expand Down Expand Up @@ -64,14 +65,15 @@
enabled: readyToLoadDatasets
});

const datasetLayersInRange = useMemo(() => {
const [datasetLayersInRange, invalidDatasets] = useMemo(() => {
try {
return getInTemporalAndSpatialExtent(result.data, aoi, {
const [datasetWithSummaries, datasetWithoutSummaries] = getInTemporalAndSpatialExtent(result.data, aoi, {
start,
end
});
return [datasetWithSummaries, datasetWithoutSummaries];
} catch (e) {
return [];
return [[], []];
}
}, [result.data, aoi, start, end]);

Expand All @@ -89,11 +91,13 @@
);
}, [datasetLayersInRangeWithNumberOfItems]);

const unselectableDatasetLayers = useMemo(() => {
let unselectableDatasetLayers: DatasetWithTimeseriesData[] = useMemo(() => {
return datasetLayersInRangeWithNumberOfItems.filter(
(l) => l.numberOfItems > MAX_QUERY_NUM
);
}, [datasetLayersInRangeWithNumberOfItems]);

unselectableDatasetLayers = [...unselectableDatasetLayers, ...(invalidDatasets as unknown) as DatasetWithTimeseriesData[]];

return {
selectableDatasetLayers,
Expand All @@ -103,7 +107,7 @@
};
}

function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange) {
function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange): [DatasetWithCollections[], DatasetLayer[]] {
const matchingCollectionIds = collectionData.reduce((acc, col) => {
const { id, stacApiEndpoint } = col;

Expand Down Expand Up @@ -156,14 +160,25 @@
const collection = collectionData.find(
(c) => c.id === l.stacCol && stacApiEndpointUsed === c.stacApiEndpoint
);

if(!collection.summaries || !!collection.summaries.length) {
// NOTE: Invalid data because collection does not include summaries
return l;
}

return {
...l,
isPeriodic: collection['dashboard:is_periodic'],
timeDensity: collection['dashboard:time_density'],
domain: collection.extent.temporal.interval[0],
timeseries: collection.summaries.datetime
timeseries: collection.summaries.datetime,
};
});

return filteredDatasetsWithCollections;

const [collectionsWithSummaries, collectionsWithoutSummaries]: [DatasetWithCollections[], DatasetLayer[]] = filteredDatasetsWithCollections.reduce((result: [DatasetWithCollections[], DatasetLayer[]], d: DatasetWithCollections) => {
sandrahoang686 marked this conversation as resolved.
Show resolved Hide resolved
/* eslint-disable-next-line fp/no-mutating-methods */
d.timeseries ? result[0].push(d) : result[1].push(d);

Check warning on line 180 in app/scripts/components/analysis/define/use-stac-collection-search.ts

View workflow job for this annotation

GitHub Actions / lint

Unnecessary conditional, value is always truthy
return result;
},[[], []]);
return [collectionsWithSummaries, collectionsWithoutSummaries];
}
2 changes: 1 addition & 1 deletion app/scripts/components/analysis/results/timeseries-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface TimeseriesDataResult {
isPeriodic: boolean;
timeDensity: TimeDensity;
domain: string[];
timeseries: TimeseriesDataUnit[];
timeseries: TimeseriesDataUnit[]; // NOTE: Summaries on collections will not always be available
sandrahoang686 marked this conversation as resolved.
Show resolved Hide resolved
}

// Different options based on status.
Expand Down
Loading