Skip to content

Instantly share code, notes, and snippets.

@gloriouslyawkwardlife
Last active September 9, 2024 15:56
Show Gist options
  • Save gloriouslyawkwardlife/e25eb0b96ca05c6da300d4d08f0fc071 to your computer and use it in GitHub Desktop.
Save gloriouslyawkwardlife/e25eb0b96ca05c6da300d4d08f0fc071 to your computer and use it in GitHub Desktop.
Wolfram Language: Create a daily map from Bouncie API webhook data
(*
Requires creation of a webhook on https://bouncie.dev to post to an Apache CouchDB database exposed to the Internet.
Substitute '6984' as the port number if you prefer a secure connection after setting up SSL according to the Apache
CouchDB Instructions.
The 'tripData' view used here to retrieve just tripData entries is as follows in CouchDB:
function (doc) {
if (doc.eventType == 'tripData')
emit(doc.data, null);
}
The variables 'Yesterday' and 'Today' are built into the Wolfram Language and do not need to be defined elsewhere;
but to avoid an error with conflicting date/time granularities, the 'Instant' option *must* be specified.
*)
data = Import["http://<your server name>:5984/bouncie/_design/tripData/_view/tripData?include_docs=true", "RawJSON"][["rows", All, "doc", "data"]] // Flatten //
Select[DateObject[#timestamp] >=
DateObject[Yesterday, "Instant"] &&
DateObject[#timestamp] < DateObject[Today, "Instant"] &] //
SortBy[#timestamp &];
tb = Table[
GeoPosition[{data[[i, "gps", "lat"]],
data[[i, "gps", "lon"]]}], {i, Length[data]}];
tb = DeleteCases[tb, GeoPosition[{_Missing, _Missing}]];
tb = DeleteCases[tb, GeoPosition[{0, 0}]];
img = GeoListPlot[
tb,
Joined -> True,
PlotMarkers -> None,
PlotStyle -> Thin,
ImageSize -> Large,
GeoBackground -> "StreetMap",
PlotLabel ->
"Bouncie App Vehicle Locator \[Bullet] " <>
DateString[Yesterday, "Date"]
];
Export["~/Downloads/bouncie.png", img, "PNG"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment