Skip to content

Commit

Permalink
refactor: apply suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
annehaley committed Aug 20, 2024
1 parent bfd69c2 commit f50de69
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
3 changes: 1 addition & 2 deletions uvdat/core/rest/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 7 additions & 7 deletions uvdat/core/rest/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 2 additions & 5 deletions uvdat/core/tasks/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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.')
Expand Down
1 change: 0 additions & 1 deletion uvdat/core/tests/test_load_roads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down

0 comments on commit f50de69

Please sign in to comment.