Fixed bug where off-by-one was giving incorrect result of ChoD calculation
This commit is contained in:
parent
798bb4f403
commit
674f0447fc
1 changed files with 2 additions and 5 deletions
|
@ -38,10 +38,7 @@
|
||||||
:chod (* 100 (float (/ index threads-total)))}))))))
|
:chod (* 100 (float (/ index threads-total)))}))))))
|
||||||
|
|
||||||
(defn build-cache
|
(defn build-cache
|
||||||
"Build cache of near-death threads so the values don't have to be recalculated on each request.
|
"Build cache of near-death threads so the values don't have to be recalculated on each request."
|
||||||
|
|
||||||
Bugs: There is probably off-by-one somewhere in the calculation because thread at position 150 doesn't
|
|
||||||
have 100% chance of death which is weird, however, 99.333% is considered close enough for now"
|
|
||||||
[pages-to-index pages-total threads-per-page threads-total]
|
[pages-to-index pages-total threads-per-page threads-total]
|
||||||
(vec (flatten (map (fn [single-page]
|
(vec (flatten (map (fn [single-page]
|
||||||
;; We have to (dec page-number) bcs otherwise we would get the total number of threads
|
;; We have to (dec page-number) bcs otherwise we would get the total number of threads
|
||||||
|
@ -64,7 +61,7 @@
|
||||||
;; universal calculation for total number of threads:
|
;; universal calculation for total number of threads:
|
||||||
;; (pages-total-1) * threadsPerPage + threadsOnLastpage ;;accounts for boards which have stickied threads making them have 11pages
|
;; (pages-total-1) * threadsPerPage + threadsOnLastpage ;;accounts for boards which have stickied threads making them have 11pages
|
||||||
threads-per-page (count (:threads (first catalog)))
|
threads-per-page (count (:threads (first catalog)))
|
||||||
threads-total (+ (* threads-per-page (dec pages-total) (count (last catalog)))) ;; Todo: Yeah, maybe this calculation could be refactored into let
|
threads-total (+ (* threads-per-page (dec pages-total)) (count (:threads (last catalog)))) ;; Todo: Yeah, maybe this calculation could be refactored into let
|
||||||
to-index (filter (fn [item]
|
to-index (filter (fn [item]
|
||||||
(<= starting-page (:page item))) catalog)]
|
(<= starting-page (:page item))) catalog)]
|
||||||
(reset! chod-threads-cache (build-cache to-index pages-total threads-per-page threads-total))))
|
(reset! chod-threads-cache (build-cache to-index pages-total threads-per-page threads-total))))
|
||||||
|
|
Loading…
Reference in a new issue