Skip to content

Commit

Permalink
Build out reports and improve species data model
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenwindflower committed Mar 16, 2024
1 parent a99d3bf commit 5dc0c0e
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 13 deletions.
37 changes: 36 additions & 1 deletion models/marts/sf_trees.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,41 @@ sf_trees as (

select *, from {{ ref('stg_sf_trees') }}

),

clean_up_species as (

select
tree_id,
legal_status,
address,
site_order,
site_info,
plant_type,
caretaker,
care_assistant,
planted_at_date,
plot_size,
permit_notes,
x_coord,
y_coord,
latitude,
longitude,
location,
zip_codes,
neighborhood,
case
when
(
species is null
or species = ''
or species = 'Tree(s) ::'
)
then 'Unknown'
else replace(species, ':: ', '')
end as species,

from sf_trees
)

select *, from sf_trees
select *, from clean_up_species
6 changes: 1 addition & 5 deletions models/marts/species.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ with

trees as (

select *, from {{ ref('stg_sf_trees') }}
select *, from {{ ref('sf_trees') }}

),

Expand All @@ -14,10 +14,6 @@ species as (

from trees

where
species is not null
and species != 'Tree(s) ::'

group by 1

)
Expand Down
2 changes: 1 addition & 1 deletion profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ dbtree:
prod:
type: duckdb
path: md:dbtree
targt: dev
target: dev
2 changes: 1 addition & 1 deletion reports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@evidence-dev/core-components": "^3.5.1",
"@evidence-dev/csv": "^1.0.7",
"@evidence-dev/databricks": "^1.0.3",
"@evidence-dev/duckdb": "^1.0.4",
"@evidence-dev/duckdb": "^1.0.7",
"@evidence-dev/evidence": "^29.0.2",
"@evidence-dev/mssql": "^1.0.5",
"@evidence-dev/mysql": "^1.1.0",
Expand Down
75 changes: 70 additions & 5 deletions reports/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,89 @@ from dbtree.species
where count_of_trees > 3000
```

### Trees planted by year

<Dropdown
name="trees_planted_years"
data={trees_planted_years}
value="year"
/>
<CalendarHeatmap
data={trees_planted_2023}
data={trees_planted_dynamic}
date="planted_at_date"
value=count_of_trees
title="Trees Planted"
subtitle="Heatmap of trees planted in 2023"
yearLabel=false
subtitle="Heatmap of trees planted in selected year"
yearLabel=true
colorPalette={myColors}
/>

```sql trees_planted_2023
```sql trees_planted_dynamic
select
planted_at_date,
count(*) as count_of_trees,

from dbtree.trees

where planted_at_date between '2023-01-01' and '2023-12-31'
where
planted_at_date
between
'${inputs.trees_planted_years.value}-01-01' and
'${inputs.trees_planted_years.value}-12-31'

group by 1
```

```sql trees_planted_years
select
distinct date_part('year', planted_at_date) as year

from dbtree.trees

where year is not null

order by 1 desc
```

<DateRange
name="planted_at_dates"
title="Planted between dates"
dates=planted_at_month
/>
<Dropdown
name="planted_at_species"
data={planted_at_species}
value="species"
title="Filter by species"
/>
<BarChart
data={trees_planted}
x="planted_at_month"
y="count_of_trees"
title="Trees Planted"
subtitle="Trees planted per month"
colorPalette={myColors}
/>

```sql trees_planted
select
date_trunc('month', planted_at_date) as planted_at_month,
species,
count(*) as count_of_trees

from dbtree.trees

where
species = '${inputs.planted_at_species.value}' and
planted_at_date
between
'${inputs.planted_at_dates.start}' and
'${inputs.planted_at_dates.end}'

group by 1, 2
```

```sql planted_at_species
select distinct species
from dbtree.trees
```
34 changes: 34 additions & 0 deletions reports/pages/trees_planted_history.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: History of Trees Planted
---

<script>
let myColors = [
"#D7E4C0",
"#C6DCBA",
"#BBC3A4",
"#B3A398",
"#638889"
]
</script>

<CalendarHeatmap
data={trees_planted_all_time}
date="planted_at_date"
value=count_of_trees
title="Trees Planted"
subtitle="Heatmap of trees planted all time"
yearLabel=true
colorPalette={myColors}
/>

```sql trees_planted_all_time
select
planted_at_date,
count(*) as count_of_trees,

from dbtree.trees

group by 1
order by 1 desc
```

0 comments on commit 5dc0c0e

Please sign in to comment.