<commit_before>(ns relevance.order
  (:require [relevance.utils :refer [on-channel url-key host-key hostname is-http? ms-day]]))


;;;;------------------------------------
;;;; Settings
;;;;------------------------------------

(def non-http-penalty 0.01)
(def sound-extra-score 9888777666)


;;;;------------------------------------
;;;; Functions
;;;;------------------------------------

(defn time-score
  "Returns a score for a tab based on the total time spent at both URLs and sites"
  [tab url-times site-times settings]
  (let [url           (:url tab)
        idx           (:index tab)
        url-time      (or (:time (get url-times (url-key url)))
                          0)
        is-priority?  (and (:sound-to-left? settings)
                           (:audible tab))
        is-penalized? (and (not (is-http? url))
                           (not is-priority?))
        tab-time      (cond
                        ; Add an extra score if it's a priority URL
                        is-priority? (+ sound-extra-score idx)
                        ; If a URL is penalized, we want it to at least have a
                        ; value of 1, otherwise the tab time gets ignored and
                        ; we'd default to using the raw site time
                        is-penalized? (max url-time 1)
                        ; ... otherwise we just go with the raw URL time
                        :else url-time)
        site-time     (or (:time (get site-times (host-key (hostname url)))) 0)
        total         (+ tab-time site-time)
        score         (if is-penalized? (* total non-http-penalty) total)]
    (or (when (pos? tab-time) score)
        (- site-time idx))))


(defn score-tabs
  "Returns a hashmap of the new tab ids and their indexes, based on a tab list and
  the score function for time spent on urls and sites."
  [tabs url-times site-times settings]
  (->> tabs
       (map #(assoc % :time (time-score % url-times site-times settings)))
       (sort-by #(* -1 (:time %)))
       (map-indexed #(hash-map :index %1
                               :id (:id %2)))))





<commit_msg>Updated comments that didn't follow the style guide conventions<commit_after>(ns relevance.order
  (:require [relevance.utils :refer [on-channel url-key host-key hostname is-http? ms-day]]))


;;;;------------------------------------
;;;; Settings
;;;;------------------------------------

(def non-http-penalty 0.01)
(def sound-extra-score 9888777666)


;;;;------------------------------------
;;;; Functions
;;;;------------------------------------

(defn time-score
  "Returns a score for a tab based on the total time spent at both URLs and sites"
  [tab url-times site-times settings]
  (let [url           (:url tab)
        idx           (:index tab)
        url-time      (or (:time (get url-times (url-key url)))
                          0)
        is-priority?  (and (:sound-to-left? settings)
                           (:audible tab))
        is-penalized? (and (not (is-http? url))
                           (not is-priority?))
        tab-time      (cond
                        ;; Add an extra score if it's a priority URL
                        is-priority? (+ sound-extra-score idx)
                        ;; If a URL is penalized, we want it to at least have a
                        ;; value of 1, otherwise the tab time gets ignored and
                        ;; we'd default to using the raw site time
                        is-penalized? (max url-time 1)
                        ;; ... otherwise we just go with the raw URL time
                        :else url-time)
        site-time     (or (:time (get site-times (host-key (hostname url)))) 0)
        total         (+ tab-time site-time)
        score         (if is-penalized? (* total non-http-penalty) total)]
    (or (when (pos? tab-time) score)
        (- site-time idx))))


(defn score-tabs
  "Returns a hashmap of the new tab ids and their indexes, based on a tab list and
  the score function for time spent on urls and sites."
  [tabs url-times site-times settings]
  (->> tabs
       (map #(assoc % :time (time-score % url-times site-times settings)))
       (sort-by #(* -1 (:time %)))
       (map-indexed #(hash-map :index %1
                               :id (:id %2)))))






{'fraction_non_alphanumeric': 0.17809811671704254, 'fraction_numerical': 0.009300162752848175, 'mean_word_length': 1.3572602739726027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6251856', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1131, 'n_words': 420}