virelay.server
Represents the server of ViRelAy, which serves the website and contains the RESTful API.
Functions
Formats the specified exception as a string so that it can be logged. |
|
Generates an HTTP 400 Bad request response. |
|
Generates an HTTP 404 Not Found response. |
|
Generates an HTTP 200 OK response. |
|
Converts the image to a JPEG image and generates a response which sends the image to the client. |
Classes
Represents the server of ViRelAy, which encapsulates the website and the RESTful API. |
- class virelay.server.Server(workspace, is_in_debug_mode=False)[source]
Bases:
object
Represents the server of ViRelAy, which encapsulates the website and the RESTful API.
- get_analysis(project_id, analysis_method_name)[source]
Retrieves the analysis from the specified project with the specified analysis method. Besides the project ID and the analysis method name, the name of the category, clustering, and embedding have to be specified as URL parameters.
- Parameters
project_id (int) – The ID of the project from which the analysis is to be retrieved.
analysis_method_name (str) – The name of the analysis method from which the analysis is to be retrieved.
- Returns
Returns an HTTP 200 OK response with a JSON string as content, which contains the data of the analysis. If the specified project does not exist, then an HTTP 404 Not Found response is returned. If the specified analysis method does not exist, then an HTTP 404 Not Found response is returned. If the analysis does not exist, then an HTTP 404 Not Found response is returned. If no category name, clustering name, or embedding name were specified in the URL parameters, then an HTTP 400 Bad Request response is returned.
- Return type
flask.Response
- get_attribution(project_id, attribution_index)[source]
Retrieves the attribution with the specified index from the specified project.
- Parameters
project_id (int) – The ID of the project from which the attribution is to be retrieved.
attribution_index (int) – The index of the attribution that is to be retrieved.
- Returns
Returns an HTTP 200 OK response with a JSON string as content, which contains the data of the attribution. If the specified project does not exist, then an HTTP 404 Not Found response is returned. If the specified attribution does not exist, then an HTTP 404 Not Found response is returned.
- Return type
flask.Response
- get_attribution_heatmap(project_id, attribution_index)[source]
Renders a heatmap from the attribution with the specified index from the specified project.
- Parameters
project_id (int) – The ID of the project from which the attribution is to be retrieved.
attribution_index (int) – The index of the attribution for which the heatmap is to be rendered.
- Returns
Returns an HTTP 200 OK response with the rendered heatmap image. If the specified project does not exist, then an HTTP 404 Not Found response is returned. If the specified attribution does not exist, then an HTTP 404 Not Found response is returned.
- Return type
flask.Response
- get_color_map_preview(color_map)[source]
Renders a preview of a color map with a value gradient. Using the URL parameters “width” and “height”, the size of the preview can be specified. The size defaults to 200x20.
- Parameters
color_map (str) – The name of the color map for which the preview is to be rendered.
- Returns
Returns an HTTP 200 OK response with the rendered heatmap preview. If the specified color map is unknown, then an HTTP 400 Bad Request response is returned.
- Return type
flask.Response
- get_color_maps()[source]
Retrieves the names of all the color maps that are supported.
- Returns
Returns an HTTP 200 OK response with a list of all the supported color maps as content.
- Return type
flask.Response
- get_project(project_id)[source]
Retrieves the project with the specified ID.
- Parameters
project_id (int) – The ID of the project that is to be retrieved.
- Returns
Returns an HTTP 200 OK response with a JSON string as content, which contains the project information. If the specified project could not be found, then an HTTP 404 Not Found response is returned.
- Return type
flask.Response
- get_projects()[source]
Retrieves all the projects and their respective information from the workspace.
- Returns
Returns an HTTP 200 OK response with a JSON string as content that contains the projects of the workspace as well as their information.
- Return type
flask.Response
- get_sample(project_id, sample_index)[source]
Retrieves the dataset sample with the specified index from the specified project.
- Parameters
project_id (int) – The ID of the project from which the dataset sample is to be retrieved.
sample_index (int) – The index of the dataset sample that is to be retrieved.
- Returns
Returns an HTTP 200 OK response with a JSON string as content, which contains the data of the dataset sample. If the specified project does not exist, then an HTTP 404 Not Found response is returned. If the specified dataset sample does not exist, then an HTTP 404 Not Found response is returned.
- Return type
flask.Response
- get_sample_image(project_id, sample_index)[source]
Retrieves the image of the dataset with the specified index from the specified project.
- Parameters
project_id (int) – The ID of the project from which the dataset sample is to be retrieved.
sample_index (int) – The index of the dataset sample for which the image is to be retrieved.
- Returns
Returns an HTTP 200 OK response with the image of the specified dataset sample as content. If the specified project does not exist, then an HTTP 404 Not Found response is returned. If the specified dataset sample does not exist, then an HTTP 404 Not Found response is returned.
- Return type
flask.Response
- virelay.server.format_exception(exception, add_debug_information)[source]
Formats the specified exception as a string so that it can be logged.
- Parameters
exception (BaseException) – The exception that is to be formatted.
add_debug_information (bool) – Determines whether debug information is added to the string representation of the exception.
- Returns
Returns a string, which contains the error message of the exception. If the server is being run in debug mode, then the traceback is also included in the string that is returned.
- Return type
str
- virelay.server.http_bad_request(error, add_debug_information)[source]
Generates an HTTP 400 Bad request response.
- Parameters
error (str or BaseException) – The error that is to be returned in the body of the response.
add_debug_information (bool) – Determines whether debug information is added to the error message.
- Returns
Returns an HTTP 400 Bad Request response.
- Return type
flask.Response
- virelay.server.http_not_found(error, add_debug_information)[source]
Generates an HTTP 404 Not Found response.
- Parameters
error (str or BaseException) – The error that is to be returned in the body of the response.
add_debug_information (bool) – Determines whether debug information is added to the error message.
- Returns
Returns an HTTP 404 Not found response.
- Return type
flask.Response
- virelay.server.http_ok(content)[source]
Generates an HTTP 200 OK response.
- Parameters
content – The content that is to be converted into JSON and returned in the body of the response.
- Returns
Returns an HTTP 200 OK response.
- Return type
flask.Response
- virelay.server.send_image_file(image)[source]
Converts the image to a JPEG image and generates a response which sends the image to the client.
- Parameters
image (numpy.ndarray | PIL.Image) – The image as a NumPy array that is to be send to the client.
- Returns
Returns a response, which contains the specified image as a JPEG encoded image file.
- Return type
flask.Response