Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions network/schemas/network_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@
name='l',
description='limit (concerning node retrieval)',
required=False,
type=OpenApiTypes.STR,
location=OpenApiParameter.INT,
type=OpenApiTypes.INT,
location=OpenApiParameter.QUERY,
),
OpenApiParameter(
name='s',
Expand Down
67 changes: 67 additions & 0 deletions network/schemas/plotting_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,73 @@
}
)

get_density_plot_schema = extend_schema(
summary="Returns gaussian kde density values for the variable x grouped by c (optional) to produce a "
"Density Plot",
description="""Returns gaussian kde density values for the given variable x (e.g. bmi) in JSON format
to produce a Density Plot. The optional parameter c (e.g. sex) allows for comparisons between different
groups such as males and females and the optional parameter bandwidth allows adjusting the smoothness of
the curves. If a sessionid and contextValue is provided, the data will be filtered by the respective
context.
""",
parameters=[
OpenApiParameter(
name='csrftoken',
description='The CSRF token provided in the request header.',
required=True,
type=OpenApiTypes.STR,
location=OpenApiParameter.COOKIE,
),
OpenApiParameter(
name="sessionid",
location=OpenApiParameter.COOKIE,
required=False,
description="Session cookie for authentication.",
type=OpenApiTypes.STR,
),
OpenApiParameter(
name='contextValue',
description='The value of the context which specifies at which tab it is supposed to be shown.',
required=False,
type=OpenApiTypes.INT,
location=OpenApiParameter.QUERY,
),
OpenApiParameter(
name='x',
description='variable x',
required=True,
type=OpenApiTypes.STR,
location=OpenApiParameter.QUERY,
),
OpenApiParameter(
name='c',
description='colour variable',
required=False,
type=OpenApiTypes.STR,
location=OpenApiParameter.QUERY,
),
OpenApiParameter(
name='bandwidth',
description='bandwidth is used to scale the standard deviation of the kernel, it expects a positive '
'float while a higher number results in a smoother curve',
required=False,
type=OpenApiTypes.FLOAT,
location=OpenApiParameter.QUERY,
),
],
responses={
200: OpenApiResponse(
description="Data returned successfully",
),
405: OpenApiResponse(
description="The data could not be returned, possible errors:\n"
"- No appropriate context found\n"
"- x is not valid\n"
"- c is not valid"
)
}
)

heatmap_schema = extend_schema(
summary="Returns contingency table for the given variables x and y for plotting a Heatmap",
description="""Returns contingency table for the given categorical variables x (e.g. sex) and y (e.g. desease
Expand Down
3 changes: 3 additions & 0 deletions network/views/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ def get(self, request):

if x_idx not in density_plot_df.columns:
return HttpResponseBadRequest('Variable x must be a valid variable of the data', status=405)
if pd.api.types.is_string_dtype(density_plot_df[x_idx]):
return HttpResponseBadRequest(
'x Variable is not numerical and can not be visualized in this plot.', status=405)

min_val, max_val = np.min(density_plot_df[x_idx]), np.max(density_plot_df[x_idx])

Expand Down