Using Datasette to map out charger locations
makes it easy to share
- tags
- datasette
- sqlite
- flyio
Contents
Datasette is a way to look through a sqlite3 database, and with sqlite-utils we can easily put a CSV into a database. This makes it easier, or at least easier, to see what there. Additionally, we can deploy the dataset on the web and make it accessable via JSON so we can quickly prototype or build something.
I watched the tutorial video on datasette homepage and got super excited.
Lets go through a real world dataset to see how it works.
Get some data
To go afdc.energy.gov and download the csv of alt fuel stations. I'm
saving it as alt_fuel_stations.csv
. We are going to explore what sort
of public changers are out there for electric vehicles.
Install datasette
and sqlite-utils
The tools are both in homebrew, and man does it take a long long while to install!
|
|
Once that's up we can test it with
|
|
datasette, version 0.64.6 sqlite-utils, version 3.36
Lets install the datasette-cluster-map
plug in so we can see where
these chargers actually are.
|
|
Import the csv file
With the file that we downloaded above, lets smash it into a sqlite database.
|
|
And check to see if it's been created.
|
|
-rw-r--r--@ 1 wschenk staff 27355616 Mar 5 11:34 alt_fuel_stations.csv -rw-r--r-- 1 wschenk staff 29429760 Mar 5 16:20 stations.db
Start datasette
|
|
Click through to stations
and start looking around. If we look at EV
Connector Types
as a facet, we can see what sort of weird values are
in there!
Looks like the connector types are in some weird format. Lets put it in to the CLI.
|
|
EV Connector Types "" J1772 J1772 NEMA520 J1772 NEMA515 J1772 TESLA CHADEMO J1772 J1772COMBO CHADEMO J1772 CHADEMO J1772 NEMA515 J1772 J1772COMBO CHADEMO J1772 NEMA1450 CHADEMO J1772COMBO NEMA520 TESLA TESLA J1772COMBO CHADEMO J1772 J1772COMBO TESLA J1772 NEMA1450 TESLA CHADEMO J1772 NEMA520 J1772COMBO TESLA CHADEMO J1772COMBO TESLA CHADEMO J1772 J1772COMBO NEMA515
Lets figure out which columns we need to add. This is SQL plus bash to get out the individual fields. In the database itself
|
|
CHADEMO J1772 J1772COMBO NEMA1450 NEMA515 NEMA520 TESLA
Lets extract those into their own columns
|
|
Adding CHADEMO Adding J1772 Adding J1772COMBO Adding NEMA1450 Adding NEMA515 Adding NEMA520 Adding TESLA
Now we can populate it
|
|
Speeding things up
We can pull out tables and add foriegn keys if you want to look at those directly
|
|
It's also possible to quickly add indexes
|
|
Publish to fly.io
This is fun to have locally, but it's interesting to share this with the team. We can use the datasette-publish-fly plugin to make this easier.
|
|
I've already have flyctl on my computer and am authenticated, so this is the one liner to publish it:
|
|
It will create the app, build it, embed the sqlite file in the Docker container, and put it on the internet!
Previously
Next