diff --git a/uvdat/core/rest/chart.py b/uvdat/core/rest/chart.py index a7ec8700..55371d6a 100644 --- a/uvdat/core/rest/chart.py +++ b/uvdat/core/rest/chart.py @@ -12,8 +12,7 @@ class ChartViewSet(GenericViewSet, mixins.ListModelMixin): serializer_class = ChartSerializer def get_queryset(self, **kwargs): - request = self.request - context_id = request.query_params.get('context') + context_id = self.request.query_params.get('context') if context_id: return Chart.objects.filter(context__id=context_id) return Chart.objects.all() diff --git a/uvdat/core/rest/dataset.py b/uvdat/core/rest/dataset.py index 590639e3..9eaeb6ce 100644 --- a/uvdat/core/rest/dataset.py +++ b/uvdat/core/rest/dataset.py @@ -46,21 +46,21 @@ def convert(self, request, **kwargs): @action(detail=True, methods=['get']) def network(self, request, **kwargs): dataset = self.get_object() - return HttpResponse( - json.dumps( + networks = [] + for network in dataset.networks.all(): + networks.append([ { 'nodes': [ uvdat_serializers.NetworkNodeSerializer(n).data - for n in NetworkNode.objects.filter(network__dataset=dataset) + for n in NetworkNode.objects.filter(network=network) ], 'edges': [ uvdat_serializers.NetworkEdgeSerializer(e).data - for e in NetworkEdge.objects.filter(network__dataset=dataset) + for e in NetworkEdge.objects.filter(network=network) ], } - ), - status=200, - ) + ]) + return HttpResponse(json.dumps(networks), status=200) @action(detail=True, methods=['get']) def gcc(self, request, **kwargs): diff --git a/uvdat/core/tasks/chart.py b/uvdat/core/tasks/chart.py index 536c6292..62a5f511 100644 --- a/uvdat/core/tasks/chart.py +++ b/uvdat/core/tasks/chart.py @@ -4,7 +4,7 @@ import pandas from webcolors import name_to_hex -from uvdat.core.models import Chart, Context +from uvdat.core.models import Chart, Context, NetworkNode @shared_task @@ -45,9 +45,6 @@ def convert_chart(chart_id, conversion_options): def get_gcc_chart(dataset, context_id): chart_name = f'{dataset.name} Greatest Connected Component Sizes' - max_nodes = 0 - for network in dataset.networks.all(): - max_nodes += network.nodes.count() try: return Chart.objects.get(name=chart_name) except Chart.DoesNotExist: @@ -66,7 +63,7 @@ def get_gcc_chart(dataset, context_id): 'chart_title': 'Size of Greatest Connected Component over Period', 'x_title': 'Step when Excluded Nodes Changed', 'y_title': 'Number of Nodes', - 'y_range': [0, max_nodes], + 'y_range': [0, NetworkNode.objects.filter(network__dataset=dataset).count()], }, ) print('\t', f'Chart {chart.name} created.') diff --git a/uvdat/core/tests/test_load_roads.py b/uvdat/core/tests/test_load_roads.py index 572de76e..2fbaa6b4 100644 --- a/uvdat/core/tests/test_load_roads.py +++ b/uvdat/core/tests/test_load_roads.py @@ -7,7 +7,6 @@ @pytest.mark.django_db def test_load_roads(): - context = Context.objects.create( name='Road Test', default_map_zoom=10, default_map_center=Point(42, -71) )