<commit_before>(ns tick.docs.app
  (:require
   [reagent.core :as r]
   [tick.alpha.api :as t]
   [clojure.string :refer [lower-case capitalize]]
   [cljs.js :refer [empty-state eval js-eval eval-str]]
   [cljs.tools.reader :refer [read-string]]
   [cljs.env :as env]
   [shadow.cljs.bootstrap.browser :as boot]))

(defn eval-code [s cb label]
  (let [env (env/default-compiler-env)]
    (boot/init
      env
      {:path "js/bootstrap"
       :load-on-init #{'tick.alpha.api}}
      (fn []
        (eval-str
          env
          (str "(ns tick.repl (:require [tick.alpha.api :as t])
                              (:refer-clojure))" s)
          (str "[" label "]")
          {:eval js-eval
           :loader (partial boot/load env)}
          (fn [x] (cb x)))))))

(defn day-midnight-today []
  (t/day-of-week (t/end (t/bounds (t/today)))))

(defn day-midnight-tomorrow []
  (t/day-of-week (t/end (t/bounds (t/tomorrow)))))

(defn two-days-from-today []
  (str "on " (capitalize (str (day-midnight-tomorrow))) " morning"))

(defn button [label cb]
  [:button
   {:key label
    :onClick cb}
   label])

(defn code-component [code result label]
  [:div
   [:div.content
    [:pre.highlight
     [:code.language-clojure {:data-lang "clojure"} code (when-let [v @result] (str " => " v))]
     [:div.code-buttons
      (list
        (button "Eval" (fn [ev]
                         (eval-code code<commit_msg>Fixing tick evals<commit_after>(ns tick.docs.app
  (:require
   [reagent.core :as r]
   [tick.alpha.api :as t]
   [clojure.string :refer [lower-case capitalize]]
   [cljs.js :refer [empty-state eval js-eval eval-str]]
   [cljs.tools.reader :refer [read-string]]
   [cljs.env :as env]
   [shadow.cljs.bootstrap.browser :as boot]))

(defn eval-code [s cb label]
  (let [env (env/default-compiler-env)]
    (boot/init
      env
      {:path "js/bootstrap"
       :load-on-init #{'tick.alpha.api}}
      (fn []
        (eval-str
          env
          (str "(require '[tick.alpha.api :as t])\n\n" s)
          (str "[" label "]")
          {:ns 'tick.repl
           :eval js-eval
           :loader (partial boot/load env)}
          (fn [x] (cb x)))))))

(defn day-midnight-today []
  (t/day-of-week (t/end (t/bounds (t/today)))))

(defn day-midnight-tomorrow []
  (t/day-of-week (t/end (t/bounds (t/tomorrow)))))

(defn two-days-from-today []
  (str "on " (capitalize (str (day-midnight-tomorrow))) " morning"))

(defn button [label cb]
  [:button
   {:key label
    :onClick cb}
   label])

(defn code-component [code result label]
  [:div
   [:div.content
    [:pre.highlight
     [:code.language-clojure {:data-lang "clojure"} code (when-let [v @result] (str " => " v))]
     [:div.code-buttons
      (list
        (button "Eval" (fn [ev]
                         (eval-code code
{'fraction_non_alphanumeric': 0.18051575931232092, 'fraction_numerical': 0.0, 'mean_word_length': 2.293632075471698, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5257167', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1034, 'n_words': 242}