         [ring.adapter.jetty :only (run-jetty)]
         [ring.util.codec :only (url-encode url-decode)]
         [hiccup.core :only (html escape-html)]
-        [hiccup.page-helpers :only (doctype link-to)])
+        [hiccup.page-helpers :only (doctype link-to)]
+        [demogorgon.nh :only (parse-bitfield conducts)])
   (:require [compojure.route :as route]
             [clojure.contrib.sql :as sql]))
 

                    :subname "/tmp/nh.db"
                    :create true})

(defn layout [content]
  (html
   (doctype :html5)
   [:html

    [:th "death"]]
   (map #'rs-row-to-tr rs)])

(defn rs-to-table-ascension [rs]
  [:table
   [:tr
    [:th "game"]
    [:th "name"]
    [:th "points"]
    [:th "turns"]
    [:th "deathdate"]
    [:th "conducts"]]
   (map #'rs-row-to-tr-ascension rs)])

(defn ascensions []
  (sql/with-connection db
     (let [rows
           (map #(assoc %1 :conducts (parse-bitfield conducts (:conduct %1)))
                (sql/with-query-results rs
                  ["select * from xlogfile where death = 'ascended' order by points desc"]
                  (doall rs)))
           points-table (rs-to-table-ascension (take 10 rows))
           conducts-table (rs-to-table-ascension
                           (take 10
                                 (sort-by #(* (count (:conducts %1)) -1) rows)))]
       (layout
        [:h2 "by points"]
        points-table
        [:h2 "by conducts"]
        conducts-table))))

(defn game [id]
  (sql/with-connection db
    (sql/with-query-results
