Introducing three open source libraries for working with Ona and data
We are proud to announce preview releases for three Clojure/ClojureScript open source software libraries: Hatti, Milia, and Zebra Lite. We are actively working on and improving these libraries for use in our own software and by others. In alphabetical order the contributors to these libraries are geoffreymuchai, pld, prabhasp, royrutto, ukanga, and wilo99. We will followup on this post with additional tutorials and introductions to the individual libraries.
Hatti
Hatti is set of Om components for viewing structured data in tables, charts and — if it’s geocoded — maps. Hatti is a ClojureScript library built using Om, a ClojureScript interface to Facebook’s React. This example connects Hatti to an Ona dataset storing information on stolen Nepalese art. This snippet of code handles most of the functionality:
(go
(let [data-chan (raw-get (ona-urls/data-url "data" dataset-id))
form-chan (http/get (ona-urls/formjson-url dataset-id))
info-chan (http/get (ona-urls/data-url "forms" dataset-id))
data (-> (<! data-chan) :body json->cljs)
form (-> (<! form-chan) :body flatten-form)
info (-> (<! info-chan) :body)]
(shared/update-app-data! shared/app-state data :rerank? true)
(shared/transact-app-state! shared/app-state [:dataset-info] (fn [_] info))
(integrate-attachments! shared/app-state form)
(om/root views/tabbed-dataview
shared/app-state
{:target (. js/document (getElementById "map"))
:shared {:flat-form form
:map-config {:mapbox-tiles mapbox-tiles}}
:opts {:chart-get chart-getter}})))
You can see the complete code here. We use Hatti as the data visualization library in the new version of Ona, but it will work with any dataset and schema in a compatible format.
Milia
Milia is a Clojure and ClojureScript client for the Ona API. Milia uses the clj-http and cljs-http libraries to make both server-side and client-side requests to an Ona compatible application server. Milia is built using the specifications in the Ona API and will work with any server that is compatible with the Ona API.
Currently all API endpoints are accessible using Clojure, however only the dataset endpoints are available in ClojureScript. As of this writing we are using cljx, but we plan to transition to Reader Conditionals after Clojure 1.7 is released.
Zebra Lite
Zebra Lite is a light-weight version of Ona, that aims to replicate the core features necessary for a mobile data collection and analysis tool: a login/account, form listing, and a data view. It is built using Milia to fetch data from Ona (or any Ona compatible API) and Hatti to display data. It is written in both Clojure using the ring HTTP library and the Compojure routing library, as well as in ClojureScript using Om and Secretary.