Skip to content

Commit

Permalink
Correctly escape special chars in filtering by friendly name
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenwindflower committed Mar 17, 2024
1 parent 76b9623 commit 201af47
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 14 deletions.
9 changes: 9 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,30 @@ tasks:
- python3 -m pip install --upgrade pip
- source .venv/bin/activate && python3 -m pip install -r requirements.txt
- npm --prefix ./reports install

setup-uv:
# Requires uv https://astral.sh/uv
aliases: [suv]
cmds:
- uv venv
- source .venv/bin/activate && uv pip install -r requirements.txt
- npm --prefix ./reports install

build:
aliases: [b]
cmds:
- source .venv/bin/activate && dbt build

test:
aliases: [t]
cmds:
- source .venv/bin/activate && dbt test

bi:
cmds:
- npm --prefix ./reports run sources && npm --prefix ./reports run dev

bbi:
cmds:
- task: build
- task: bi
42 changes: 42 additions & 0 deletions data/neighborhoods.csv

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions data/nhoods.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
nhood
Western Addition
West of Twin Peaks
Visitacion Valley
Twin Peaks
South of Market
Treasure Island
Presidio Heights
Presidio
Potrero Hill
Portola
Pacific Heights
Outer Richmond
Outer Mission
Sunset/Parkside
Oceanview/Merced/Ingleside
North Beach
Noe Valley
Lone Mountain/USF
Lincoln Park
Seacliff
Nob Hill
Mission Bay
Mission
Russian Hill
Marina
Lakeshore
Tenderloin
McLaren Park
Japantown
Inner Sunset
Hayes Valley
Haight Ashbury
Golden Gate Park
Inner Richmond
Glen Park
Financial District/South Beach
Excelsior
Chinatown
Castro/Upper Market
Bernal Heights
Bayview Hunters Point
42 changes: 42 additions & 0 deletions data/test.csv

Large diffs are not rendered by default.

25 changes: 16 additions & 9 deletions models/marts/sf_trees.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@ clean_up_species as (

select
tree_id,
legal_status,
address,
site_order,
site_info,
plant_type,
site_order,
legal_status,
permit_notes,
caretaker,
care_assistant,
planted_at_date,
plot_size,
permit_notes,
address,
zip_codes,
neighborhood,
location,
x_coord,
y_coord,
latitude,
longitude,
location,
zip_codes,
neighborhood,
planted_at_date,
case
when plant_type = 'Tree' or plant_type = 'tree' then 'tree'
when plant_type = 'Landscaping' then 'landscaping'
else 'unknown'
end as plant_type,
case
when
(
Expand All @@ -37,6 +41,9 @@ clean_up_species as (
then 'Unknown'
else replace(species, ':: ', '')
end as species,
split_part(species, ':: ', 1) as scientific_name,
split_part(species, ':: ', 2) as friendly_name,


from sf_trees
)
Expand Down
2 changes: 1 addition & 1 deletion models/marts/species.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trees as (
species as (

select
species,
friendly_name,
count(*) as count_of_trees,

from trees
Expand Down
3 changes: 2 additions & 1 deletion models/staging/stg_sf_trees.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ staged as (
qcaretaker as caretaker,
qcareassistant as care_assistant,
plantdate as planted_at_date,
dbh,
dbh as depth_by_height,
plotsize as plot_size,
permitnotes as permit_notes,
xcoord as x_coord,
Expand All @@ -30,6 +30,7 @@ staged as (
"Fire Prevention Districts" as fire_prevention_districts,
"Zip Codes" as zip_codes,
"Analysis Neighborhoods" as neighborhood,

from source

)
Expand Down
7 changes: 4 additions & 3 deletions reports/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ select
from dbtree.trees

where
species = '${inputs.planted_at_species.value}' and
friendly_name = $$${inputs.planted_at_species.value}$$ and
planted_at_date
between
'${inputs.planted_at_dates.start}' and
Expand All @@ -116,6 +116,7 @@ group by 1, 2
```

```sql planted_at_species
select distinct species
from dbtree.trees
select friendly_name as species
from dbtree.species
order by count_of_trees desc
```

0 comments on commit 201af47

Please sign in to comment.