fedbiomed.researcher.responses
Module:fedbiomed.researcher.responses
Classes
Responses
Responses(data)
Class parsing Nodes' responses Reconfigures input data into either a dictionary in a list (List[dict]), or a list with unique values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | Union[list, dict] | input response | required |
Source code in fedbiomed/researcher/responses.py
def __init__(self, data: Union[list, dict]):
"""Constructor of `Responses` class.
Args:
data: input response
"""
if isinstance(data, dict):
self._data = [data]
elif isinstance(data, list):
self._data = []
# create a list containing unique fields
for d in data:
if d not in self._data:
self._data.append(d)
Functions
append(response)
append(response)
Appends new responses to existing responses
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response | Union[List, Dict] | List of response as dict or single response as dict that will be appended | required |
Returns:
Type | Description |
---|---|
list | List of dict as responses |
Raises:
Type | Description |
---|---|
FedbiomedResponsesError | When |
Source code in fedbiomed/researcher/responses.py
def append(self, response: Union[List, Dict]) -> list:
""" Appends new responses to existing responses
Args:
response: List of response as dict or single response as dict that will be appended
Returns:
List of dict as responses
Raises:
FedbiomedResponsesError: When `response` argument is not in valid type
"""
if isinstance(response, List):
self._data = self._data + response
elif isinstance(response, Dict):
self._data = self._data + [response]
elif isinstance(response, self.__class__):
self._data = self._data + response.data()
else:
raise FedbiomedResponsesError(f'`The argument must be instance of List, '
f'Dict or Responses` not {type(response)}')
return self._data
data()
data()
Gets all responses that are received
Returns:
Type | Description |
---|---|
list | Data of the class |
Source code in fedbiomed/researcher/responses.py
def data(self) -> list:
"""Gets all responses that are received
Returns:
Data of the class `Responses`
"""
return self._data
dataframe()
dataframe()
This method converts the list that includes responses to pandas dataframe
Returns:
Type | Description |
---|---|
pd.DataFrame | Pandas DataFrame includes node responses. Each row of dataframe represent single response that comes from a node. |
Source code in fedbiomed/researcher/responses.py
def dataframe(self) -> pd.DataFrame:
""" This method converts the list that includes responses to pandas dataframe
Returns:
Pandas DataFrame includes node responses. Each row of dataframe represent single response that comes
from a node.
"""
return pd.DataFrame(self._data)
set_data(data)
set_data(data)
Setter for ._data attribute
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | List[Dict] | List of responses as python dictionary | required |
Returns:
Type | Description |
---|---|
List | List of responses as Dict |
Raises:
Type | Description |
---|---|
FedbiomedResponsesError | When |
Source code in fedbiomed/researcher/responses.py
def set_data(self, data: List[Dict]) -> List:
"""Setter for ._data attribute
Args:
data: List of responses as python dictionary
Returns:
List of responses as Dict
Raises:
FedbiomedResponsesError: When `data` argument is not in valid type
"""
# TODO: Check elements of list are Dict
if not isinstance(data, List):
raise FedbiomedResponsesError(f'`data` argument should instance of list not {type(data)}')
self._data = data
return self._data