1.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2+++ b/examples/vegadat.lisp Sun Dec 24 19:24:39 2023 -0500
1.3@@ -0,0 +1,38 @@
1.4+;; from https://github.com/Lisp-Stat/plot/blob/master/src/vega/vega-datasets.lisp
1.5+(defpackage :examples/vegadat
1.6+ (:use :cl :std :net/fetch :dat)
1.7+ (:export
1.8+ :*vega-datasets* :*vega-dataset-base-url*
1.9+ :fetch-vega-dataset))
1.10+
1.11+(in-package :examples/vegadat)
1.12+
1.13+(defparameter *vega-dataset-base-url* "http://raw.githubusercontent.com/vega/vega-datasets/main/data/"
1.14+ "Base URL for datasets included in Vega")
1.15+
1.16+(defparameter *vega-dataset-stash* "vega/")
1.17+
1.18+
1.19+;; (gethash :airpots *vega-datasets*)
1.20+(defvar *vega-datasets* (make-hash-table :size 66 :test #'equal)
1.21+ "All Vega example data sets. k=symbol,v=url")
1.22+
1.23+(defun push-dataset (key)
1.24+ "Push a dataset to *VEGA-DATASETS* by filename."
1.25+ (let ((val (concatenate 'string *vega-dataset-base-url* key)))
1.26+ (setf (gethash key *vega-datasets*) val)))
1.27+
1.28+;; 66 files total, mostly json and csv. 1 tsv file, 1 arrow file.
1.29+(mapc #'push-dataset
1.30+ '("airports.csv" "annual-precip.json" "anscombe.json" "barley.json" "budget.json" "budgets.json" "burtin.json" "cars.json" "countries.json" "crimea.json" "driving.json" "earthquakes.json" "flare-dependencies.json" "flare.json" "flights-10k.json" "flights-200k.json" "flights-20k.json" "flights-2k.json" "flights-5k.json" "football.json" "gapminder.json" "income.json" "jobs.json" "londonBoroughs.json" "londonCentroids.json" "londonTubeLines.json" "miserables.json" "monarchs.json" "movies.json" "normal-2d.json" "obesity.json" "ohlc.json" "penguins.json" "points.json" "political-contributions.json" "population.json" "udistrict.json" "unemployment-across-industries.json" "uniform-2d.json" "us-10m.json" "us-state-capitals.json" "volcano.json" "weather.json" "wheat.json" "world-110m.json" "airports.csv" "birdstrikes.csv" "co2-concentration.csv" "disasters.csv" "flights-3m.csv" "flights-airport.csv" "gapminder-health-income.csv" "github.csv" "iowa-electricity.csv" "la-riots.csv" "lookup_groups.csv" "lookup_people.csv" "population_engineers_hurricanes.csv" "seattle-weather-hourly-normals.csv" "seattle-weather.csv" "sp500-2000.csv" "sp500.csv" "stocks.csv" "us-employment.csv" "weather.csv" "windvectors.csv" "zipcodes.csv" "unemployment.tsv" "flights-200k.arrow"))
1.31+
1.32+(defun fetch-vega-datasets ()
1.33+ (ensure-directories-exist *vega-dataset-stash*)
1.34+ (maphash-keys
1.35+ (lambda (x) (download (gethash x *vega-datasets*)
1.36+ (merge-pathnames x *vega-dataset-stash*)))
1.37+ *vega-datasets*))
1.38+
1.39+(defun purge-vega-datasets ()
1.40+ (std:when-let ((stash (probe-file *vega-dataset-stash*)))
1.41+ (sb-ext:delete-directory stash :recursive t)))