 (ns polismath.poller
-  (:use polismath.named-matrix
+  (:use 
+        clojure.pprint
+        polismath.named-matrix
         polismath.utils
         polismath.pca)
   (:require [korma.db :as kdb]

               (conj (get conv-map conv-id []) vote))))
    {} votes))


(defn poll [db-spec last-timestanp]
  (kdb/with-db db-spec
    (ko/select "votes"
      (ko/where {:created [> last-timestanp]})
      (ko/order :created :asc))))



  (let [poll-interval 1000
        pg-spec         (heroku-db-spec (env/env :database-url))
        mg-db           (mongo-db env/env)
        last-timestamp  (atom 1388285552490)]
    (endlessly poll-interval
      (let [new-votes (poll pg-spec @last-timestamp)
            split-votes (split-by-conv new-votes)
            ; results (small-conv-update {
                      ; :conv conv 
                      ; :opts {}
                             ; :votes (get split-votes 451)})
            ]
        (println "polling:" split-votes)
        (swap! last-timestamp (fn [_] (:created (last new-votes))))
        ; want to upsert, using try-catch instead. try 
        (upsert-results pg-spec 1001 1 "foo")
        ))))


