<commit_before>(ns kbilling.plans
  (:require [kbilling.plans.transform :as tf]))

(def reflect-fn (js/require "function-to-string"))

(defn load-cost-fn [f path]
  (let [params (vec (map keyword (.-params (reflect-fn f))))]     ;TODO prefix local params with cycle key
    (fn [vars] (apply f (map #(vars %) params)))))                ;TODO test

(defn load-map [x path]
  (cond
    (map? x)
    (into {}
          (for [[k v] x]
            [k (case k
                 :$begin (set (map keyword v))
                 :$cost (load-cost-fn v path)
                 (load-map v (conj path k)))]))

    :else x))

(defn root-require [path]
  (js/require (str (.cwd js/process) "/" path)))

(def load-plan
  (memoize #(load-map (js->clj (root-require %) :keywordize-keys true) [])))<commit_msg>rename load-map -> load-v<commit_after>(ns kbilling.plans
  (:require [kbilling.plans.transform :as tf]))

(def reflect-fn (js/require "function-to-string"))

(defn load-cost-fn [f path]
  (let [params (vec (map keyword (.-params (reflect-fn f))))] ;TODO prefix local params with cycle key
    (fn [vars] (apply f (map #(vars %) params)))))          ;TODO test

(defn load-v [x path]
  (cond
    (map? x)
    (into {} (for [[k v] x]
               [k (case k
                    :$begin (set (map keyword v))
                    :$cost (load-cost-fn v path)
                    (load-v v (conj path k)))]))

    :else x))

(defn root-require [path]
  (js/require (str (.cwd js/process) "/" path)))

(def load-plan
  (memoize #(load-v (js->clj (root-require %) :keywordize-keys true) [])))
{'fraction_non_alphanumeric': 0.17870722433460076, 'fraction_numerical': 0.0, 'mean_word_length': 2.310272536687631, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '3675953', 'n_tokens_mistral': 573, 'n_tokens_neox': 553, 'n_words': 172}