Skip to content

Commit d31f83f

Browse files
committed
fix: using altmetric for the ORCID integration
1 parent eaf28c0 commit d31f83f

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

server/workers/common/common/utils.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,21 @@ def push_metadata_to_queue(
128128
redis_store: redis.Redis,
129129
params: Dict[str, Union[str, List[str]]],
130130
metadata: pd.DataFrame,
131-
source: Literal["crossref", "altmetric"]
131+
source_list: List[str]
132132
) -> str:
133133
"""
134134
Sending metadata for processing into Redis queue and returning the request_id.
135135
136136
:param redis_store: Object of the Redis store.
137137
:param params: Request params.
138138
:param metadata: DataFrame with default metadata.
139-
:param source: define from which service additional metadata will be received.
139+
:param source_list: define from which service additional metadata will be received (available values: "crossref", "altmetric").
140140
:return: request_id for the receiving of the request result.
141141
"""
142+
check_metadata_enrichment_source(source_list)
142143

143144
request_id = str(uuid.uuid4())
144-
params["metrics_sources"] = [source]
145+
params["metrics_sources"] = source_list
145146
task_data = json.dumps({
146147
"id": request_id,
147148
"params": params,
@@ -152,6 +153,17 @@ def push_metadata_to_queue(
152153
return request_id
153154

154155

156+
def check_metadata_enrichment_source(source_list: List[str]) -> None:
157+
"""
158+
Checks that source for metadata enrichment contains correct values.
159+
160+
:param source_list: List of sources from where metadata will be enriched.
161+
:return: None.
162+
"""
163+
if not all(source in ("crossref", "altmetric") for source in source_list):
164+
raise ValueError("Source list must contain only 'crossref' or 'altmetric'")
165+
166+
155167
def fetch_enriched_metadata(redis_store: redis.Redis, request_id: str, timeout: int = 600) -> pd.DataFrame:
156168
"""
157169
Getting enriched metadata from Redis.
@@ -216,7 +228,7 @@ def enrich_metadata(
216228
redis: redis.Redis,
217229
params: Dict[str, Union[str, List[str]]],
218230
metadata: pd.DataFrame,
219-
source: Literal["crossref", "altmetric"],
231+
source_list: List[str],
220232
integration: Literal["pubmed", "orcid"]
221233
) -> pd.DataFrame:
222234
"""
@@ -225,13 +237,15 @@ def enrich_metadata(
225237
:param redis: store object of Redis.
226238
:param params: params of the request.
227239
:param metadata: DataFrame with default metadata.
228-
:param source: define from which service additional metadata will be received.
240+
:param source: define from which service additional metadata will be received (available values: "crossref", "altmetric").
229241
:return: Enriched DataFrame with metadata.
230242
"""
243+
# Checks that source list contains valid values
244+
check_metadata_enrichment_source(source_list)
231245

232246
# Creates a request to metrics for metadata enrichment
233247
# and returns request_id for receiving the result later
234-
request_id = push_metadata_to_queue(redis, params, metadata, source)
248+
request_id = push_metadata_to_queue(redis, params, metadata, source_list)
235249

236250
# Getting the result after metadata enrichment at metrics
237251
enriched_metadata = fetch_enriched_metadata(redis, request_id)

server/workers/orcid/src/orcid_service.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,11 @@ def _retrieve_author_info_and_metadata(self, orcid: Orcid) -> Tuple[AuthorInfo,
388388

389389
def _process_metadata(self, metadata: pd.DataFrame, author_info: AuthorInfo, params: Dict[str, str]) -> pd.DataFrame:
390390
metadata["authors"] = metadata["authors"].replace("", author_info.author_name)
391-
source_for_metadata_enrichment = "crossref"
391+
392392
integration = 'orcid'
393+
source_for_metadata_enrichment = ["crossref", "altmetric"]
393394
metadata = enrich_metadata(self.redis_store, params, metadata, source_for_metadata_enrichment, integration)
395+
394396
self.logger.debug(f'metadata shape after base enrichment: {metadata.shape}')
395397
author_info = self.enrich_author_info(author_info, metadata, params)
396398
self.logger.debug(f'metadata shape after enrichment: {metadata.shape}')

server/workers/pubmed/src/pubmed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def execute_search(self, params):
4141
return raw_metadata
4242

4343
metadata = pd.DataFrame(raw_metadata)
44-
source_for_metadata_enrichment = "crossref"
45-
integration = 'pubmed'
4644

45+
integration = 'pubmed'
46+
source_for_metadata_enrichment = ["crossref"]
4747
metadata = enrich_metadata(self.redis_store, params, metadata, source_for_metadata_enrichment, integration)
4848

4949
text = pd.DataFrame(raw_text)

0 commit comments

Comments
 (0)