diff --git a/network/schemas/network_schemas.py b/network/schemas/network_schemas.py index 940214f..d3cf419 100644 --- a/network/schemas/network_schemas.py +++ b/network/schemas/network_schemas.py @@ -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', diff --git a/network/schemas/plotting_schemas.py b/network/schemas/plotting_schemas.py index 032fdb2..1e875cd 100644 --- a/network/schemas/plotting_schemas.py +++ b/network/schemas/plotting_schemas.py @@ -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 diff --git a/network/views/plotting.py b/network/views/plotting.py index 9068aee..11ec8f7 100644 --- a/network/views/plotting.py +++ b/network/views/plotting.py @@ -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])