<commit_before>(ns rumahsewa141.views
  (:require [rumahsewa141.math :refer [abs]]))

(defn find-verb [a b c]
  (if (or (pos? a) (pos? b) (pos? c))
    "was billed"
    "paid"))

(defn describe-transaction [{:keys [username
                                    rent
                                    internet
                                    others
                                    transaction_timestamp]}]
  {:description (apply str (drop-last (str username
                                           " "
                                           (find-verb rent internet others)
                                           (when-not (zero? rent)
                                             (str " RM " (abs rent) " for rent,"))
                                           (when-not (zero? internet)
                                             (str " RM " (abs internet) " for internet,"))
                                           (when-not (zero? others)
                                             (str "  RM " (abs others) " for other bills,")))))
   :timestamp transaction_timestamp})

(defn history-view [page get-count-fn get-transactions-fn]
  #(let [max-items        10            ; max no of items displayed 
         prange           5             ; pagination range
         get-count-result (future (get-count-fn))
         {tcount :tcount} @get-count-result
         transactions     (future (get-transactions-fn
                                   {:max_items max-items
                                    :offset (* (dec page) max-items)}))
         first-page       (inc (* (quot (dec page) prange) prange))
         pages            (take prange (iterate inc first-page))
         total-pages      (if (zero? (mod tcount max-items))
                            (quot tcount max-items)
                            (inc (quot tcount max-items)))
         has-page?        (fn [page] (<= page total-pages))
         available-pages  (take-while has-page? pages)]
     {:transactions  (map describe-transaction @transactions)
      :current_page  page
      :prev_page     (dec first-page)
      :pages         available-pages
      :next_page     (inc (last pages))
      :no_next_page  (or (< (count available-pages) prange)
                         (= (last pages) total-pages))}))<commit_msg>Position future deref so that it won't blocking<commit_after>(ns rumahsewa141.views
  (:require [rumahsewa141.math :refer [abs]]))

(defn find-verb [a b c]
  (if (or (pos? a) (pos? b) (pos? c))
    "was billed"
    "paid"))

(defn describe-transaction [{:keys [username
                                    rent
                                    internet
                                    others
                                    transaction_timestamp]}]
  {:description (apply str (drop-last (str username
                                           " "
                                           (find-verb rent internet others)
                                           (when-not (zero? rent)
                                             (str " RM " (abs rent) " for rent,"))
                                           (when-not (zero? internet)
                                             (str " RM " (abs internet) " for internet,"))
                                           (when-not (zero? others)
                                             (str "  RM " (abs others) " for other bills,")))))
   :timestamp transaction_timestamp})

(defn history-view [page get-count-fn get-transactions-fn]
  #(let [max-items        10            ; max no of items displayed 
         prange           5             ; pagination range
         get-count-result (future (get-count-fn))
         transactions     (future (get-transactions-fn
                                   {:max_items max-items
                                    :offset (* (dec page) max-items)}))
         first-page       (inc (* (quot (dec page) prange) prange))
         pages            (take prange (iterate inc first-page))
         {tcount :tcount} @get-count-result
         total-pages      (if (zero? (mod tcount max-items))
                            (quot tcount max-items)
                            (inc (quot tcount max-items)))
         has-page?        (fn [page] (<= page total-pages))
         available-pages  (take-while has-page? pages)]
     {:transactions  (map describe-transaction @transactions)
      :current_page  page
      :prev_page     (dec first-page)
      :pages         available-pages
      :next_page     (inc (last pages))
      :no_next_page  (or (< (count available-pages) prange)
                         (= (last pages) total-pages))}))
{'fraction_non_alphanumeric': 0.10248181429182712, 'fraction_numerical': 0.0038510911424903724, 'mean_word_length': 1.1230699364214352, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 44, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6694779', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1117, 'n_words': 326}