<commit_before>(ns birdwatch.stats.timeseries
  (:require [birdwatch.util :as util]))

(defn date-round
  "Returns function that rounds the provided seconds since epoch down to the
   nearest time interval s e.g. (date-round 60) creates a function that takes
   seconds t and rounds them to the nearest minute."
  [s]
  (fn [t] (* s (Math/floor (/ t s)))))

(def m 60)
(def qhr (* 15 m))
(def hr (* 60 m))
(def qday (* 6 hr))
(def day (* 24 hr))

(defn grouping-interval
  "Determines duration of individual intervals (bars) depending on duration of
   timespan between newest and oldest."
  [newest oldest]
  (cond
   (> (- newest oldest) (* 20 day)) day  ;round by nearest day
   (> (- newest oldest) (* 5 day))  qday ;round by nearest quarter day
   (> (- newest oldest) (* 20 hr))  hr   ;round by nearest hour
   (> (- newest oldest) (* 4 hr))   qhr  ;round by nearest quarter hour
   :else                            m))  ;round by nearest minute

(defn empty-ts-map
  "Generates map with all rounded intervals between oldest and newest,
   initialized to a count of 0."
  [newest oldest interval]
  (let [rounder (date-round interval)
        values (range (rounder oldest) (rounder newest) interval)]
    (apply sorted-map-by < (flatten [(interpose 0 values) 0]))))
<commit_msg>comments; naming<commit_after>(ns birdwatch.stats.timeseries
  (:require [birdwatch.util :as util]))

(defn date-round
  "Returns function that rounds the provided seconds since epoch down to the
   nearest time interval; for example (date-round 60) creates a function that
   takes seconds t and rounds them to the nearest minute."
  [interval]
  (fn [t] (* interval (Math/floor (/ t interval)))))

(def m 60)
(def qhr (* 15 m))
(def hr (* 60 m))
(def qday (* 6 hr))
(def day (* 24 hr))

(defn grouping-interval
  "Determines duration of individual intervals (bars) depending on duration of
   timespan between newest and oldest."
  [newest oldest]
  (cond
   (> (- newest oldest) (* 20 day)) day  ;round by nearest day
   (> (- newest oldest) (* 5 day))  qday ;round by nearest quarter day
   (> (- newest oldest) (* 20 hr))  hr   ;round by nearest hour
   (> (- newest oldest) (* 4 hr))   qhr  ;round by nearest quarter hour
   :else                            m))  ;round by nearest minute

(defn empty-ts-map
  "Generates map with all rounded intervals between oldest and newest,
   initialized to a count of 0."
  [newest oldest interval]
  (let [rounder (date-round interval)
        values (range (rounder oldest) (rounder newest) interval)]
    (apply sorted-map-by < (flatten [(interpose 0 values) 0]))))

{'fraction_non_alphanumeric': 0.11538461538461539, 'fraction_numerical': 0.015384615384615385, 'mean_word_length': 3.195161290322581, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4824049', 'n_tokens_mistral': 820, 'n_tokens_neox': 773, 'n_words': 341}