-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature use db inst for cmr matching #525
Open
CarsonDavis
wants to merge
5
commits into
feature-check_for_deleted_objects_in_doi_matcher
Choose a base branch
from
feature-use_db_inst_for_cmr_matching
base: feature-check_for_deleted_objects_in_doi_matcher
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
5 commits
Select commit
Hold shift + click to select a range
40ac746
update doi_matching to use actual database data for merging
CarsonDavis 366cfba
correct import path for DOI
CarsonDavis 1e317be
Update cmr/doi_matching.py
praveenphatate 70cbaa7
Update Doi on concept_id or DOI
a328c19
Fix code style issues with Black
lint-action 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 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 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,90 @@ | ||
import requests | ||
|
||
from cmr.doi_matching import DoiMatcher | ||
from cmr.process_metadata import process_data_product | ||
from data_models.models import DOI | ||
|
||
|
||
def query_cmr_for_concept_id(concept_id): | ||
"""Returns the cmr response given a concept_id | ||
|
||
Args: | ||
concept_id (string): concept_id | ||
|
||
Returns: | ||
cmr_data: Json containing the cmr response | ||
hits: Number of hits in the cmr page | ||
""" | ||
base_url = "https://cmr.earthdata.nasa.gov/search/collections.umm_json?echo_collection_id=" | ||
cmr_url = base_url + concept_id | ||
query_response = requests.get(cmr_url) | ||
cmr_data = query_response.json()["items"] | ||
hits = query_response.json()["hits"] | ||
query_response.close() | ||
|
||
return cmr_data, hits | ||
|
||
|
||
def query_cmr_for_doi(doi): | ||
"""Returns the cmr response given a doi | ||
|
||
Args: | ||
doi (string): doi | ||
|
||
Returns: | ||
cmr_data: Json containing the cmr response | ||
hits: Number of hits in the cmr page | ||
""" | ||
base_url = "https://cmr.earthdata.nasa.gov/search/collections.umm_json?doi=" | ||
cmr_url = base_url + doi | ||
query_response = requests.get(cmr_url) | ||
cmr_data = query_response.json()["items"] | ||
hits = query_response.json()["hits"] | ||
query_response.close() | ||
|
||
return cmr_data, hits | ||
|
||
|
||
def convert_cmr_data_to_doi_recommendation(cmr_data): | ||
return process_data_product(cmr_data) | ||
|
||
|
||
def update_entire_database(): | ||
matcher = DoiMatcher() | ||
missing_dois = [] | ||
for doi in DOI.objects.all(): | ||
print(doi) | ||
cmr_data, hits = query_cmr_for_concept_id(doi.concept_id) | ||
if not cmr_data: | ||
cmr_data, hits = query_cmr_for_doi(doi.doi) | ||
# Check the number of hits | ||
if hits == 1: | ||
doi_recommendation = convert_cmr_data_to_doi_recommendation(cmr_data[0]) | ||
matcher.add_to_db(doi_recommendation) | ||
|
||
else: | ||
missing_dois.append(doi) | ||
# If there are any DOI's which are not updated | ||
if missing_dois: | ||
with open("dois_not_updated.txt", "w") as file: | ||
for doi in missing_dois: | ||
file.write(f"{doi}\n") | ||
|
||
|
||
# def get_published_uuid(recent_draft): | ||
# if recent_draft.action == Change.Actions.UPDATE: | ||
# return recent_draft.model_instance_uuid | ||
# else: | ||
# # this must be a published create draft, who's uuid will match the published uuid | ||
# return recent_draft.uuid | ||
|
||
# def make_update_draft(merged_draft, linked_object): | ||
# doi_obj = Change.objects.create( | ||
# content_type=ContentType.objects.get(model="doi"), | ||
# model_instance_uuid=linked_object, | ||
# update=merged_draft, | ||
# status=Change.Statuses.CREATED, | ||
# action=Change.Actions.UPDATE, | ||
# ) | ||
# doi_obj = Change.objects.get(uuid=doi_obj.uuid) | ||
# return doi_obj |
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.