Skip to content

Commit

Permalink
Select layer to visualise
Browse files Browse the repository at this point in the history
  • Loading branch information
ev-sc committed Dec 11, 2024
1 parent 4ab5543 commit 82765b5
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 16 deletions.
3 changes: 2 additions & 1 deletion hub/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ def imported_data_count_by_area(
self,
postcode_io_key: str = None,
gss: str = None,
layer_ids: List[str] = None,
) -> QuerySet[AreaCount]:
qs = self.get_analytics_queryset()
qs = self.get_analytics_queryset(layer_ids=layer_ids)
if postcode_io_key is None:
return []

Expand Down
7 changes: 5 additions & 2 deletions hub/graphql/types/model_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,10 +701,13 @@ class Analytics:

@strawberry_django.field
def imported_data_count_by_area(
self, analytical_area_type: AnalyticalAreaType
self,
analytical_area_type: AnalyticalAreaType,
layer_ids: Optional[List[str]],
) -> List[GroupedDataCount]:
data = self.imported_data_count_by_area(
postcode_io_key=analytical_area_type.value
postcode_io_key=analytical_area_type.value,
layer_ids=layer_ids,
)
area_key = postcodeIOKeyAreaTypeLookup[analytical_area_type]
return [GroupedDataCount(**datum, area_type=area_key) for datum in data]
Expand Down
17 changes: 13 additions & 4 deletions hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4183,9 +4183,18 @@ class MapLayer(TypedDict):
def get_layers(self) -> list[MapLayer]:
return self.layers or []

def get_import_data(self):
def get_import_data(self, layer_ids=None):
filtered_layers = (
self.get_layers()
if layer_ids is None
else [layer for layer in self.get_layers() if layer["id"] in layer_ids]
)

if not filtered_layers:
return GenericData.objects.none()

visible_layer_ids = [
layer["source"] for layer in self.get_layers() if layer.get("visible", True)
layer["source"] for layer in filtered_layers if layer.get("visible", True)
]
return GenericData.objects.filter(
models.Q(data_type__data_set__external_data_source_id__in=visible_layer_ids)
Expand All @@ -4201,8 +4210,8 @@ def get_import_data(self):
)
)

def get_analytics_queryset(self):
return self.get_import_data()
def get_analytics_queryset(self, layer_ids=None):
return self.get_import_data(layer_ids=layer_ids)


def generate_puck_json_content():
Expand Down
8 changes: 4 additions & 4 deletions nextjs/src/__generated__/gql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 82765b5

Please sign in to comment.