-
Notifications
You must be signed in to change notification settings - Fork 27
Automatic Temporal Extent Calculation for Collections #999
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
Open
matthewhanson
wants to merge
4
commits into
main
Choose a base branch
from
mah/auto-temporal-extent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f60be36
Automatically populate a collections temporal extent when retrieving …
matthewhanson 1d6a3f3
remove weird and unncessary collectionId param to populateTemporalExt…
matthewhanson 877d69e
Update README.md
matthewhanson 7efa7dd
Update README.md
matthewhanson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| // @ts-nocheck | ||
|
|
||
| import test from 'ava' | ||
| import { deleteAllIndices, refreshIndices } from '../helpers/database.js' | ||
| import { ingestItem } from '../helpers/ingest.js' | ||
| import { randomId, loadFixture } from '../helpers/utils.js' | ||
| import { setup } from '../helpers/system-tests.js' | ||
|
|
||
| test.before(async (t) => { | ||
| await deleteAllIndices() | ||
| const standUpResult = await setup() | ||
|
|
||
| t.context = standUpResult | ||
| t.context.collectionId = randomId('collection') | ||
|
|
||
| const collection = await loadFixture( | ||
| 'landsat-8-l1-collection.json', | ||
| { id: t.context.collectionId } | ||
| ) | ||
|
|
||
| await ingestItem({ | ||
| ingestQueueUrl: t.context.ingestQueueUrl, | ||
| ingestTopicArn: t.context.ingestTopicArn, | ||
| item: collection | ||
| }) | ||
|
|
||
| // Ingest items with different dates | ||
| const item1 = await loadFixture('stac/LC80100102015002LGN00.json', { | ||
| collection: t.context.collectionId, | ||
| properties: { | ||
| datetime: '2015-01-02T15:49:05.000Z' | ||
| } | ||
| }) | ||
|
|
||
| const item2 = await loadFixture('stac/LC80100102015002LGN00.json', { | ||
| collection: t.context.collectionId, | ||
| id: 'item-2', | ||
| properties: { | ||
| datetime: '2020-06-15T10:30:00.000Z' | ||
| } | ||
| }) | ||
|
|
||
| const item3 = await loadFixture('stac/LC80100102015002LGN00.json', { | ||
| collection: t.context.collectionId, | ||
| id: 'item-3', | ||
| properties: { | ||
| datetime: '2018-03-20T08:15:00.000Z' | ||
| } | ||
| }) | ||
|
|
||
| await ingestItem({ | ||
| ingestQueueUrl: t.context.ingestQueueUrl, | ||
| ingestTopicArn: t.context.ingestTopicArn, | ||
| item: item1 | ||
| }) | ||
|
|
||
| await ingestItem({ | ||
| ingestQueueUrl: t.context.ingestQueueUrl, | ||
| ingestTopicArn: t.context.ingestTopicArn, | ||
| item: item2 | ||
| }) | ||
|
|
||
| await ingestItem({ | ||
| ingestQueueUrl: t.context.ingestQueueUrl, | ||
| ingestTopicArn: t.context.ingestTopicArn, | ||
| item: item3 | ||
| }) | ||
|
|
||
| await refreshIndices() | ||
| }) | ||
|
|
||
| test.after.always(async (t) => { | ||
| if (t.context.api) await t.context.api.close() | ||
| }) | ||
|
|
||
| test('GET /collections/:collectionId returns temporal extent from items', async (t) => { | ||
| const { collectionId } = t.context | ||
|
|
||
| const response = await t.context.api.client.get(`collections/${collectionId}`, | ||
| { resolveBodyOnly: false }) | ||
|
|
||
| t.is(response.statusCode, 200) | ||
| t.is(response.body.id, collectionId) | ||
|
|
||
| // Check that extent.temporal.interval exists and is populated | ||
| t.truthy(response.body.extent) | ||
| t.truthy(response.body.extent.temporal) | ||
| t.truthy(response.body.extent.temporal.interval) | ||
| t.is(response.body.extent.temporal.interval.length, 1) | ||
|
|
||
| const [startDate, endDate] = response.body.extent.temporal.interval[0] | ||
|
|
||
| // Verify the start date is the earliest item datetime (2015-01-02) | ||
| t.is(startDate, '2015-01-02T15:49:05.000Z') | ||
|
|
||
| // Verify the end date is the latest item datetime (2020-06-15) | ||
| t.is(endDate, '2020-06-15T10:30:00.000Z') | ||
| }) | ||
|
|
||
| test('GET /collections returns temporal extent for all collections', async (t) => { | ||
| const response = await t.context.api.client.get('collections', | ||
| { resolveBodyOnly: false }) | ||
|
|
||
| t.is(response.statusCode, 200) | ||
| t.truthy(response.body.collections) | ||
| t.true(response.body.collections.length > 0) | ||
|
|
||
| // Find our test collection | ||
| const collection = response.body.collections.find((c) => c.id === t.context.collectionId) | ||
| t.truthy(collection) | ||
|
|
||
| // Check that extent.temporal.interval exists and is populated | ||
| t.truthy(collection.extent) | ||
| t.truthy(collection.extent.temporal) | ||
| t.truthy(collection.extent.temporal.interval) | ||
| t.is(collection.extent.temporal.interval.length, 1) | ||
|
|
||
| const [startDate, endDate] = collection.extent.temporal.interval[0] | ||
|
|
||
| // Verify the dates match the items | ||
| t.is(startDate, '2015-01-02T15:49:05.000Z') | ||
| t.is(endDate, '2020-06-15T10:30:00.000Z') | ||
| }) | ||
|
|
||
| test('Collection with no items has null temporal extent', async (t) => { | ||
| // Create a new collection with no items | ||
| const emptyCollectionId = randomId('empty-collection') | ||
| const emptyCollection = await loadFixture( | ||
| 'landsat-8-l1-collection.json', | ||
| { id: emptyCollectionId } | ||
| ) | ||
|
|
||
| await ingestItem({ | ||
| ingestQueueUrl: t.context.ingestQueueUrl, | ||
| ingestTopicArn: t.context.ingestTopicArn, | ||
| item: emptyCollection | ||
| }) | ||
|
|
||
| await refreshIndices() | ||
|
|
||
| const response = await t.context.api.client.get(`collections/${emptyCollectionId}`, | ||
| { resolveBodyOnly: false }) | ||
|
|
||
| t.is(response.statusCode, 200) | ||
| t.is(response.body.id, emptyCollectionId) | ||
|
|
||
| // For a collection with no items, temporal extent should still exist from the original collection | ||
| // but our code should gracefully handle this (return null or keep original) | ||
| t.truthy(response.body.extent) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is insufficient to determine if temporal extent is defined. A collection with
extent.temporal.intervalset to[[null, null]]will fail this check (both values are not undefined), but this should be treated as missing temporal extent since null values indicate no data. The check should verify that at least one of the values is non-null:collection.extent?.temporal?.interval?.[0]?.[0] || collection.extent?.temporal?.interval?.[0]?.[1]