This repository was archived by the owner on Sep 25, 2023. It is now read-only.
generated from linz/template-python-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 1
feat(validate): validate STAC Collection (TDE-170) #416
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d8ee4be
WIP
paulfouquet 484db4f
Merge branch 'master' of https://github.com/linz/topo-processor into …
paulfouquet 8d00810
feat(validate): validate STAC Collections
paulfouquet dac0dd5
merge
paulfouquet 27b29a6
WIP
paulfouquet 51f8f87
Merge branch 'master' of https://github.com/linz/topo-processor into …
paulfouquet 6c4c935
chores
paulfouquet 7922823
merge
paulfouquet a7c0bf3
format
paulfouquet d414eb1
refactor(validate): improve validate_report implementation readability
paulfouquet 9f3d33f
chore: fix formatting
paulfouquet 4bab777
chore: add type hint
paulfouquet 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
File renamed without changes.
File renamed without changes.
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
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,19 @@ | ||
| import os | ||
| from logging import error | ||
|
|
||
| import pytest | ||
|
|
||
| from topo_processor.stac.validate_report import ValidateReport | ||
|
|
||
|
|
||
| def test_increment_error(): | ||
| """""" | ||
| error_report: ValidateReport = ValidateReport() | ||
| error_report.increment_error("schema_a", "error_1") | ||
| assert error_report.report_per_error_type["schema_a"]["error_1"] == 1 | ||
| error_report.increment_error("schema_a", "error_1") | ||
| assert error_report.report_per_error_type["schema_a"]["error_1"] == 2 | ||
| error_report.increment_error("schema_b", "error_1") | ||
| assert error_report.report_per_error_type["schema_b"]["error_1"] == 1 | ||
| error_report.increment_error("schema_a", "error_2") | ||
| assert error_report.report_per_error_type["schema_a"]["error_2"] == 1 |
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,22 @@ | ||
| from typing import Dict, List | ||
|
|
||
|
|
||
| class ValidateReport: | ||
| total: int | ||
| report_per_error_type: Dict[str, Dict[str, int]] | ||
|
|
||
| def __init__(self): | ||
| self.total = 0 | ||
| self.report_per_error_type = {} | ||
|
|
||
| def add_errors(self, errors_per_schema: Dict[str, List[str]]) -> None: | ||
| for schema_uri in errors_per_schema: | ||
| for error in errors_per_schema[schema_uri]: | ||
| self.increment_error(schema_uri, error) | ||
| self.total = self.total + 1 | ||
|
|
||
| def increment_error(self, schema, error) -> None: | ||
| existing = self.report_per_error_type.get(schema) | ||
| if existing is None: | ||
| self.report_per_error_type[schema] = existing = {} | ||
| existing[error] = existing.get(error, 0) + 1 | ||
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,49 @@ | ||
| from typing import Any, Dict, List, Tuple, Union | ||
|
|
||
| from linz_logger import get_log | ||
|
|
||
| from topo_processor.metadata.metadata_loaders import metadata_loader_imagery_historic | ||
| from topo_processor.metadata.metadata_validators import metadata_validator_stac | ||
| from topo_processor.stac.validate_report import ValidateReport | ||
| from topo_processor.util import time_in_ms | ||
|
|
||
| from .collection import Collection | ||
| from .item import Item | ||
| from .store import collection_store, item_store | ||
|
|
||
|
|
||
| def validate_stac(metadata_file: str, validate_item: bool = True, validate_collection: bool = True) -> None: | ||
| start_time = time_in_ms() | ||
| item_report: ValidateReport = ValidateReport() | ||
| collection_report: ValidateReport = ValidateReport() | ||
|
|
||
| # Load metadata from metadata csv file | ||
| metadata_loader_imagery_historic.load_all_metadata(metadata_file) | ||
| get_log().debug("Metadata Loaded", metadata_file=metadata_file, duration=time_in_ms() - start_time) | ||
|
|
||
| # Validate metadata from stored STAC objects | ||
| if validate_item: | ||
| item_report = validate_store(item_store) | ||
| if validate_collection: | ||
| collection_report = validate_store(collection_store) | ||
|
|
||
| # Print report | ||
| get_log().info( | ||
| "Metadata Validated", | ||
| metadata_file=metadata_file, | ||
| nbItemsValidated=item_report.total, | ||
| nbCollectionsValidated=collection_report.total, | ||
| duration=time_in_ms() - start_time, | ||
| itemErrors=item_report.report_per_error_type, | ||
| collectionErrors=collection_report.report_per_error_type, | ||
| ) | ||
|
|
||
|
|
||
| def validate_store(store: List[Union[Item, Collection]]) -> ValidateReport: | ||
| validate_report: ValidateReport = ValidateReport() | ||
|
|
||
| for stac_object in store.values(): | ||
| if stac_object.is_valid(): | ||
| validate_report.add_errors(metadata_validator_stac.validate_metadata_with_report(stac_object)) | ||
|
|
||
| return validate_report |
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| from topo_processor.cli import main | ||
| from topo_processor.cli import upload | ||
|
|
||
| main.main() | ||
| upload.main() |
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.
Uh oh!
There was an error while loading. Please reload this page.