diff --git a/src/core.clj b/src/core.clj index 0250df6..2d78aa7 100644 --- a/src/core.clj +++ b/src/core.clj @@ -72,15 +72,24 @@ (add-observations birds now) {:status 200})) +(add-observations [{:bird "Botaurus stellaris" :certainty 0.9}] (now)) + (defn summarise-species [user-id s] - (let [bird (:bird (first s))] + (let [bird (:bird (first s)) + {first-seen :min last-seen :max} + (reduce (fn [l r] + (print l r) + {:max (max (:max l) r) :min (min (:min l) r)}) + {:min Integer/MAX_VALUE :max Integer/MIN_VALUE} + (map #(.toEpochSecond (.atZone (:time %) (java.time.ZoneId/of "Europe/Berlin"))) s))] {:bird bird :certainty (apply max (map :certainty s)) :count (count s) :nearby (get-nearby bird) :unseen (not (every? #(contains? (:seen-by %) user-id) s)) :rote-liste (get-in conservation-info [(:latin bird) :status]) - :first-seen (apply min (map #(.toEpochSecond (.atZone (:time %) (java.time.ZoneId/of "Europe/Berlin"))) s))})) + :first-seen first-seen + :last-seen last-seen})) (defn summarise-observations [observations user-id] (->> observations @@ -150,7 +159,9 @@ count :count nearby :nearby concern :rote-liste - unseen :unseen}] + unseen :unseen + last-seen :last-seen + :as observation}] (let [observation-count (:observation-count nearby)] [:li.closed {:onclick "onExpand(this)" @@ -175,7 +186,13 @@ " " (template-concern (if (contains? template-concern concern) concern (:iucn bird))) [:div.info {:style "display: none;font-size: 0.8em;"} - (str (or observation-count "no") " nearby observations")] + (str (or observation-count "no") " nearby observations") + [:br] + [:span.last-seen "Last seen: " (.format (.atZone (java.time.Instant/ofEpochSecond last-seen) + (java.time.ZoneId/of "Europe/Berlin")) + (.atZone (java.time.Instant/ofEpochSecond last-seen) + (java.time.ZoneId/of "Europe/Berlin")) + date-formatter)]] [:br] [:span.certainty {:style (str @@ -186,7 +203,9 @@ 0.8 (str "color:" (:orange colours) ";") 0.5 (str "color:" (:light-orange colours) ";") nil)} (double (/ (math/round (* 10000 certainty)) 100.0))] - " %"]])) + " %"] + [:br] + ])) (defn filter-outdated [since obs] (filter #(.isBefore since (:time %)) obs))