 (defn decode-time [time-in-sec]
   (let [time (from-long (* 1000 time-in-sec))
         bucket (quot (to-long (date-time (year time) (month time) (day time))) 1000)
-        hitime (quot (- time-in-sec bucket) 3600)
-        lotime (rem (- time-in-sec bucket) 3600)]
-    [bucket hitime lotime]))
-
-(defn encode-time [bucket hitime lotime]
-  (+ bucket (* 3600 hitime) lotime))
+        slot (- time-in-sec bucket)]
+    [bucket slot]))
+
+(defn encode-time [bucket slot]
+  (+ bucket slot))
 
 (defn check-schema [cluster keyspace]
   (when-not (describe-keyspace cluster keyspace)

    (client/execute cluster (client/render-query query))))

(defn get-tattr [cluster k name time]
  (let [[bucket hitime] (take 2 (decode-time time))]
    (mapcat
     (fn [row]
       (map
        (fn [[lotime value]]
          [(encode-time bucket (:hitime row) lotime) (f/binary-to-bytes value)])
        (:data row)))
     (select cluster
             :t_attr
             (columns :hitime :data)
             (where :key k :name name :bucket bucket :hitime [:>= hitime])))))

(defn del-tattr [cluster attrs]
  (let [query (->> attrs

    (create-table
     cluster :t_attr
     (if-not-exists)
     (column-definitions {:key :uuid :name :varchar :bucket :bigint :slot :int :data :blob :primary-key [[:key :name :bucket] :slot]})
     (with {:compaction {:class "LeveledCompactionStrategy" :sstable_size_in_mb "128"}})))
  (when-not (describe-table cluster keyspace :k_attr)
    (warn "creating table k_attr")
