Last active
January 25, 2017 21:41
-
-
Save rozap/e9a93ae11ab1598b5c1c1edfee0d3b73 to your computer and use it in GitHub Desktop.
elixir + socrata API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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