             [clj-time.core :as time]
             [clj-time.format :as timefmt]
             [clojure.java.jdbc :as jdbc]
+            [clojure.pprint :as pprint]
             [com.lemondronor.orbital-detector.planeplotter :as planeplotter]
             [com.lemonodor.gflags :as gflags]))
 

  (let [args (gflags/parse-flags (cons nil args))
        db (db-spec (first args))]
    (create-tables db)
    (add-records db (planeplotter/read-log (second args)))))

      (loop [records log
             previous-ping-time {}
             num-inserted 0
             num-skipped {:no-position 0
                             :non-monotonic-time 0
                             :rate-too-high 0}]
        (if (seq records)
          (let [r (first records)
                rstrecords (rest records)
                icao (:icao r)
                ping-ts (:timestamp r)
                previous-ping-ts (previous-ping-time icao)]
            (cond
              ;; No position, and position is required.
              (and position-only? (not (has-position? r)))
              (recur rstrecords
                     previous-ping-time
                     num-inserted
                     (update-in num-skipped [:no-position] inc))
              ;; Non-monotonic time.
              (and previous-ping-ts
                   (time/before? ping-ts previous-ping-ts))
              (recur rstrecords
                     previous-ping-time
                     num-inserted
                     (update-in num-skipped [:non-monotonic-time] inc))
              ;; Too soon since last ping.
              (and previous-ping-ts
                   (< (time/in-seconds (time/interval previous-ping-ts ping-ts))
                      ping-window))
              (recur rstrecords
                     previous-ping-time
                     num-inserted
                     (update-in num-skipped [:rate-too-high] inc))
              :else
              (do
                (jdbc/insert!
                 t-con
