Skip to content

Commit

Permalink
include organisations' country
Browse files Browse the repository at this point in the history
  • Loading branch information
JHogenboom committed Jun 5, 2024
1 parent ec30fd6 commit 591a585
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions triplestore-collaboration-descriptives/partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import sys

import numpy as np
import pandas as pd

from .post_query import post_sparql_query
Expand All @@ -25,18 +26,20 @@ def partial(client: AlgorithmClient, df1: pd.DataFrame) -> Any:
"""
Executes the decentralised part of the algorithm for the collaboration descriptives.
This function retrieves the organisation name, reads a SPARQL query from a file, posts the query to an endpoint,
and processes the results. The results are then returned in a dictionary format.
This function retrieves the organisation name ad country,
reads a SPARQL query from a file, posts the query to an endpoint, and processes the results.
The results are then returned in a dictionary format.
Args:
client (AlgorithmClient): The client instance for the algorithm.
df1 (pd.DataFrame): The input data frame.
Returns:
dict: A dictionary containing the organisation name, sample size, and variable info.
dict: A dictionary containing the organisation name, country, sample size, and variable info.
"""
# Get the name of the organisation
organisation_name = client.organization.get(client.organization_id).get("name")
organisation_country = client.organization.get(client.organization_id).get("country")

try:
# The 'r' argument means the file will be opened in read mode
Expand All @@ -55,11 +58,10 @@ def partial(client: AlgorithmClient, df1: pd.DataFrame) -> Any:
error(f"Unexpected error occurred whilst posting SPARQL query, error: {e}")
sys.exit(1)

# If the result is empty (i.e. the query returned no results)
# If the result is empty (i.e. the query returned no results) it is likely the data is not available
if not result:
# Log an error and return a dictionary with an error message
error("No results were returned from the SPARQL query.")
sys.exit(1)
return {"organisation": organisation_name, "country": organisation_country,
"sample_size": np.nan, "variable_info": []}

try:
# Convert main_class_count to int for all items in the list
Expand All @@ -76,5 +78,6 @@ def partial(client: AlgorithmClient, df1: pd.DataFrame) -> Any:
error(f"Unexpected error processing results, error: {e}")
sys.exit(1)

# Return a dictionary with the organisation name, sample size, and variable info
return {"organisation": organisation_name, "sample_size": sample_size, "variable_info": result}
# Return a dictionary with the organisation name, country, sample size, and variable info
return {"organisation": organisation_name, "country": organisation_country,
"sample_size": sample_size, "variable_info": result}

0 comments on commit 591a585

Please sign in to comment.