   (let [parsed-dates (map #(tc/from-date (:timestamp %)) measurements)]
     (reduce (fn [{:keys [min-date max-date]} timestamp]
               {:min-date (if (t/before? timestamp min-date) timestamp min-date)
-               :max-date (if (t/after? timestamp max-date) timestamp max-date)}) 
+               :max-date (if (t/after? timestamp max-date) timestamp max-date)})
             {:min-date (first parsed-dates)
              :max-date (last parsed-dates)} parsed-dates)))
 

  [store]
  (db/with-session [session (:hecuba-session store)]
    (let [all-sensors-metadata (db/execute session (hayt/select :sensor_metadata))]
      (map #(merge (first (db/execute session 
                                      (hayt/select :sensors
                                                   (hayt/where [[= :device_id (:device_id %)] [= :type (:type %)]]))))
                   %) all-sensors-metadata))))

(defn metadata-is-spike? [{:keys [reading_metadata] :as m}]
  (truthy? (get reading_metadata "median-spike")))

(defn where-from
  "Takes measurement or sensor and returns where clause"
  [m]
  [[= :device_id (:device_id m)] [= :type (:type m)]])
