From 9ae86a8fa3e2865df1105763658acfeee4b6440f Mon Sep 17 00:00:00 2001 From: Brandon Cohen Date: Sun, 21 Apr 2024 18:01:50 -0400 Subject: [PATCH 1/3] filter working --- data/src/data_utils/rco_geoms.py | 6 ++++-- src/components/PropertyMap.tsx | 16 +++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/data/src/data_utils/rco_geoms.py b/data/src/data_utils/rco_geoms.py index 5588ac0a..91d39602 100644 --- a/data/src/data_utils/rco_geoms.py +++ b/data/src/data_utils/rco_geoms.py @@ -1,4 +1,4 @@ -import numpy as np +import json from classes.featurelayer import FeatureLayer from constants.services import RCOS_LAYERS_TO_LOAD @@ -39,13 +39,15 @@ def rco_geoms(primary_featurelayer): .agg( { "rco_info": lambda x: "|".join(map(str, x)), - "rco_names": lambda x: "|".join(map(str, x)), + "rco_names": lambda x: list(map(str, x)), "geometry": "first", } ) .reset_index() ) + primary_featurelayer.gdf['rco_names'] = primary_featurelayer.gdf['rco_names'].apply(json.dumps) + primary_featurelayer.gdf.drop_duplicates(inplace=True) primary_featurelayer.rebuild_gdf() diff --git a/src/components/PropertyMap.tsx b/src/components/PropertyMap.tsx index 175f49b9..29d6ea4d 100644 --- a/src/components/PropertyMap.tsx +++ b/src/components/PropertyMap.tsx @@ -175,21 +175,23 @@ const PropertyMap: FC = ({ const mapFilter = Object.entries(appFilter).reduce( (acc, [property, filterItem]) => { if (filterItem.values.length) { - if (filterItem.useIndexOfFilter) { - const useIndexOfFilterFilter: any = ["any"]; - filterItem.values.map((item) => { + const useIndexOfFilterFilter: any = ["any"]; + filterItem.values.forEach((item) => { + if (filterItem.useIndexOfFilter) { useIndexOfFilterFilter.push([ ">=", ["index-of", item, ["get", property]], 0, ]); - }); + } else { + acc.push(["in", ["get", property], item]); + } + }); + + if (filterItem.useIndexOfFilter) { acc.push(useIndexOfFilterFilter); - } else { - acc.push(["in", property, ...filterItem.values]); } } - return acc; }, [] as any[] From b44b02428a75f27fda5339f3f00b56f0169e6369 Mon Sep 17 00:00:00 2001 From: Brandon Cohen Date: Sun, 21 Apr 2024 18:14:42 -0400 Subject: [PATCH 2/3] dont change source data --- data/src/data_utils/rco_geoms.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/data/src/data_utils/rco_geoms.py b/data/src/data_utils/rco_geoms.py index 91d39602..7dd02bc4 100644 --- a/data/src/data_utils/rco_geoms.py +++ b/data/src/data_utils/rco_geoms.py @@ -1,5 +1,3 @@ -import json - from classes.featurelayer import FeatureLayer from constants.services import RCOS_LAYERS_TO_LOAD @@ -39,15 +37,13 @@ def rco_geoms(primary_featurelayer): .agg( { "rco_info": lambda x: "|".join(map(str, x)), - "rco_names": lambda x: list(map(str, x)), + "rco_names": lambda x: "|".join(map(str, x)), "geometry": "first", } ) .reset_index() ) - primary_featurelayer.gdf['rco_names'] = primary_featurelayer.gdf['rco_names'].apply(json.dumps) - primary_featurelayer.gdf.drop_duplicates(inplace=True) primary_featurelayer.rebuild_gdf() From ae686bd11425abca8fea1cf2ce5b27191e4a018e Mon Sep 17 00:00:00 2001 From: Brandon Cohen Date: Sun, 21 Apr 2024 18:32:46 -0400 Subject: [PATCH 3/3] clean up logic --- src/components/PropertyMap.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/components/PropertyMap.tsx b/src/components/PropertyMap.tsx index 29d6ea4d..8c952d69 100644 --- a/src/components/PropertyMap.tsx +++ b/src/components/PropertyMap.tsx @@ -175,22 +175,20 @@ const PropertyMap: FC = ({ const mapFilter = Object.entries(appFilter).reduce( (acc, [property, filterItem]) => { if (filterItem.values.length) { - const useIndexOfFilterFilter: any = ["any"]; + const thisFilterGroup: any = ["any"]; filterItem.values.forEach((item) => { if (filterItem.useIndexOfFilter) { - useIndexOfFilterFilter.push([ + thisFilterGroup.push([ ">=", ["index-of", item, ["get", property]], 0, ]); } else { - acc.push(["in", ["get", property], item]); + thisFilterGroup.push(["in", ["get", property], item]); } }); - if (filterItem.useIndexOfFilter) { - acc.push(useIndexOfFilterFilter); - } + acc.push(thisFilterGroup); } return acc; },