Minor reduction in sql here:
WITH RECURSIVE dates(date) AS (
SELECT DISTINCT start FROM terms WHERE start >= "1975-01-01"
)
, members_gen as (
SELECT
members.*,
members.birthday < '1928-01-01' as other,
members.birthday between '1928-01-01' and '1945-12-31' as silent,
members.birthday between '1946-01-01' and '1964-12-31' as boomer,
members.birthday between '1965-01-01' and '1980-12-31' as x,
members.birthday between '1981-01-01' and '1996-12-31' as millenial
FROM members
)
SELECT
dates.date
, sum(other) as num_other
, sum(silent) as num_silent
, sum(boomer) as num_boomer
, sum(x) as num_x
, sum(millenial) as num_millenial
from terms
inner join dates
on terms.start <= dates.date
and terms.end > dates.date
left join members_gen on members_gen.bioguide = terms.member
where terms.type = 'rep'
group by dates.date
Love, love, love.
I just started playing with this, and installed Datasette in my Docker locally (because I would like to deploy the image to heroku later). The instructions in the Datasette docs worked great:
https://docs.datasette.io/en/stable/installation.html#using-docker
but in order to use localhost in my notebook, I had to of course insert --cors in the command line and also, because localhost didn't have an SSL cert, I couldn't have the https observable notebook fetch from the http localhost... so I had to use Chrome and allow the notebook sandbox to allow insecure content. I had to first find the domain for my user content by simply typing 'location.origin' in a cell to get the Observable worker's domain for my login, and then setting 'Insecure content: Allow' for that domain in Chrome.
That allowed me to then finally do
db = DatasetteClient("http://localhost:8001/fixtures")
and the rest was great.
Not sure if you want to perhaps explain some of these roadblocks to people who want to run their Datasette locally or in a local Docker.
Thanks again for a great notebook!!!!