 (ns forma.hadoop.jobs.cdm
-  "Functions and Cascalog queries for converting data into map tile coordinates."
+  "Functions and Cascalog queries for converting data into map tile
+coordinates."
   (:use [cascalog.api]
-        [cartodb.playground :only (insert-rows delete-all)]
+        [cartodb.playground :only (insert-rows delete-all big-insert)]
         [forma.source.gadmiso :only (gadm->iso)]
         [forma.gfw.cdm :only (latlon->tile, read-latlon, latlon-valid?)]
         [forma.utils :only (positions)])

  [(reduce min (map first tuples))])

(defn first-hit
  "Returns the index of the first value in a vector of numbers that is greater
  than or equal to a threshold.

  Arguments:
    thresh - The threshold value.
    series - A vector of numbers.

  Example usage:
    (first-hit 5 [1 2 3 4 5 6 7 8 9 10]) => 4"

  (first (positions (partial <= thresh) series)))

(defn hansen->cdm
  "Returns a Cascalog query that transforms Hansen data into map tile
  coordinates. `src` - The source tap.  `zoom` - The map zoom level.
  `tres` - The temporal resolution."
  [src zoom tres]
  (let [epoch (date/datetime->period tres "2000-01-01")
        hansen (date/datetime->period tres "2010-12-31")
