Skip to content

Commit

Permalink
Handle analysis/define datasets w/o collection summaries (#786)
Browse files Browse the repository at this point in the history
This aims to solve ticket
[here](#746)

Exploration and Analysis page seems like it already handles summaries
are not available
[here](https://github.com/NASA-IMPACT/veda-ui/pull/769/files) and
[here](https://github.com/NASA-IMPACT/veda-ui/pull/758/files#diff-cf038be4360f19e9ab0d1ea21567952a3c816545a0c23e57906e0f7223a5e769R61)

For Analysis/Results: We dont have to worry because users would not be
able to select the dataset without summaries any longer with this fix

Loom Local Validation: 
https://www.loom.com/share/d0b132ca88b242dc8014e277495d6746

**UPDATE TO FLAG COMMENT:**
![Screenshot 2024-01-04 at 12 34 47
PM](https://github.com/NASA-IMPACT/veda-ui/assets/30272083/6a96fd48-f12f-487d-99ae-4e92d422097b)
  • Loading branch information
sandrahoang686 authored Jan 10, 2024
2 parents 67b4436 + 6463ab5 commit 29cc038
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/scripts/components/analysis/define/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ export default function Analysis() {
</Overline>
{datasetLayer.name}
<DataPointsWarning>
<CollecticonSignDanger />~
{datasetLayer.numberOfItems} data points
<CollecticonSignDanger />
{'numberOfItems' in datasetLayer ? `${datasetLayer.numberOfItems} data points`: 'Data temporarily unavailable'}
</DataPointsWarning>
</FormCheckableUnselectable>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { areIntervalsOverlapping } from 'date-fns';
import { DatasetLayer } from 'veda';

import { MAX_QUERY_NUM } from '../constants';
import { TimeseriesDataResult } from '../results/timeseries-data';
import { TimeseriesMissingSummaries, TimeseriesDataResult } from '../results/timeseries-data';
import { getNumberOfItemsWithinTimeRange } from './utils';
import { allAvailableDatasetsLayers } from '.';

Expand All @@ -20,8 +20,10 @@ interface UseStacSearchProps {
aoi?: FeatureCollection<Polygon> | null;
}

export type DatasetWithTimeseriesData = TimeseriesDataResult &
DatasetLayer & { numberOfItems: number };
export type DatasetWithCollections = TimeseriesDataResult & DatasetLayer;
type DatasetMissingSummaries = TimeseriesMissingSummaries & DatasetLayer;
export type DatasetWithTimeseriesData = DatasetWithCollections & { numberOfItems: number };
export type InvalidDatasets = DatasetMissingSummaries | DatasetWithTimeseriesData;

const collectionEndpointSuffix = '/collections';

Expand Down Expand Up @@ -75,25 +77,33 @@ export function useStacCollectionSearch({
}
}, [result.data, aoi, start, end]);

const [datasetsWithSummaries, invalidDatasets]: [DatasetWithCollections[], DatasetMissingSummaries[]] = datasetLayersInRange.reduce((result: [DatasetWithCollections[], DatasetMissingSummaries[]], d) => {
/* eslint-disable-next-line fp/no-mutating-methods */
d.timeseries ? result[0].push(d as DatasetWithCollections) : result[1].push(d as DatasetMissingSummaries);
return result;
},[[], []]);

const datasetLayersInRangeWithNumberOfItems: DatasetWithTimeseriesData[] =
useMemo(() => {
return datasetLayersInRange.map((l) => {
return datasetsWithSummaries.map((l) => {
const numberOfItems = getNumberOfItemsWithinTimeRange(start, end, l);
return { ...l, numberOfItems };
});
}, [datasetLayersInRange, start, end]);
}, [datasetsWithSummaries, start, end]);

const selectableDatasetLayers = useMemo(() => {
return datasetLayersInRangeWithNumberOfItems.filter(
(l) => l.numberOfItems <= MAX_QUERY_NUM
);
}, [datasetLayersInRangeWithNumberOfItems]);

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

const unselectableDatasetLayers:InvalidDatasets[] = [...datasetsWithTooManyRequests, ...invalidDatasets];

return {
selectableDatasetLayers,
Expand Down Expand Up @@ -156,14 +166,15 @@ function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange) {
const collection = collectionData.find(
(c) => c.id === l.stacCol && stacApiEndpointUsed === c.stacApiEndpoint
);

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;
}
7 changes: 7 additions & 0 deletions app/scripts/components/analysis/results/timeseries-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ export interface TimeseriesDataResult {
timeseries: TimeseriesDataUnit[];
}

export interface TimeseriesMissingSummaries {
isPeriodic: boolean;
timeDensity: TimeDensity;
domain: string[];
timeseries?: unknown;
}

// Different options based on status.
export type TimeseriesData =
| {
Expand Down

0 comments on commit 29cc038

Please sign in to comment.