Skip to content

Instantly share code, notes, and snippets.

@rozap
Last active January 25, 2017 21:41
Show Gist options
  • Save rozap/e9a93ae11ab1598b5c1c1edfee0d3b73 to your computer and use it in GitHub Desktop.
Save rozap/e9a93ae11ab1598b5c1c1edfee0d3b73 to your computer and use it in GitHub Desktop.
elixir + socrata API
import Exsoda.Reader
with {:ok, rows} <- query("6zsd-86xi", domain: "data.cityofchicago.org")
|> select(["date_trunc_ym(date) as month", "count(*)"])
|> where("primary_type = 'HOMICIDE' AND month = '2001-01-01T00:00:00.000'")
|> group("month")
|> order("month")
|> run do
rows
|> Stream.map(&Enum.into(&1, %{}))
|> Enum.filter(fn row -> String.contains?(row["month"], "01-01")
|> Enum.map(fn row -> String.to_integer(row["count"]) end)
|> IO.inspect
|> Sparkel.sparkline
# These are counts of homicides each january
# [42, 45, 39, 29, 20, 29, 26, 34, 25, 22, 28, 39, 41, 20, 30, 53, 27]
# "▅▆▅▂▁▂▂▃▂▁▂▅▅▁▃█▂"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment