some minor cleanups and a bit more commenting (incl. edge-case notes)

This commit is contained in:
Gered 2016-03-03 19:20:31 -05:00
parent 26a42a8d4b
commit 86986b553f

View file

@ -58,16 +58,17 @@
(if (and (= 0 (count deaths)) (if (and (= 0 (count deaths))
(= 0 (count resurrections))) (= 0 (count resurrections)))
(:duration encounter) (:duration encounter)
(let [segments (as-> (concat (let [segments (->> (concat
(map (fn [death] {:status :dead :at (:timestamp death)}) deaths) (map (fn [death] {:status :dead :at (:timestamp death)}) deaths)
(map (fn [resurrection] {:status :alive :at (:timestamp resurrection)}) resurrections) (map (fn [resurrection] {:status :alive :at (:timestamp resurrection)}) resurrections)
[{:status :end :at ended-at}]) x [{:status :end :at ended-at}])
(remove empty? x) (remove empty?)
(sort-by :at x))] (sort-by :at))]
(reduce (reduce
(fn [{:keys [total current-status from] :as result} {:keys [status at]}] (fn [{:keys [total current-status from] :as result} {:keys [status at]}]
(cond (cond
; is the first state change we find a resurrect? (e.g. they were dead when the fight began) ; is the first state change we find a resurrect? (that is, they were dead when the fight began)
; NOTE: technically this could also happen if for some reason the combat log missed a previous death event
(and (nil? current-status) (and (nil? current-status)
(= :alive status)) (= :alive status))
(assoc result (assoc result
@ -82,7 +83,7 @@
:from at :from at
:total (+ total (time-between from at))) :total (+ total (time-between from at)))
; resurrected after a death ; resurrected after a death during the encounter
(and (= :dead current-status) (and (= :dead current-status)
(= :alive status)) (= :alive status))
(assoc result (assoc result
@ -94,6 +95,8 @@
; available to us. so, we just tack on the time since the last death since at least one of the entities ; available to us. so, we just tack on the time since the last death since at least one of the entities
; was alive for that entire time period. in this way, the "entity alive time" for the entity with this ; was alive for that entire time period. in this way, the "entity alive time" for the entity with this
; name will just be a counter of "at least one entity with this name was alive" ; name will just be a counter of "at least one entity with this name was alive"
; NOTE: technically this "double death" thing could also happen for entities for which there really is
; only one if for some reason the combat log missed a previous resurrect event
(and (= :dead current-status) (and (= :dead current-status)
(= :dead status)) (= :dead status))
(assoc result (assoc result