<commit_before>(ns blutwurst.tuple-generator
  (:require [taoensso.timbre :as timbre :refer [trace error]]
            [clojure.pprint :refer :all]
            [blutwurst.value-generators :refer [create-generators random-integer-under-value]]))

(defn- generator-search [column strategies]
  (if (empty? strategies)
    nil
    (let [current-strategy (first strategies)]
      (if ((:determiner current-strategy) column)
        current-strategy
        (recur column (rest strategies))))))

(defn- find-override-for-column [spec column]
  (->> (:column-generator-overrides spec)
       (filter #(re-matches (re-pattern (:column-pattern %)) (:name column)))
       first
       :generator-name))

(defn- find-generator-by-name [generator-name strategies]
  (->> strategies
       (filter #(= (:name %) generator-name))
       first))

(defn- select-generators-for-column [spec column]
  (let [generators (create-generators spec)
        override-name (find-override-for-column spec column)]

    (if (nil? override-name)
      (generator-search column generators)
      (do
        (trace "Found override " override-name " for column " column)
        (find-generator-by-name override-name generators)))))

(defn- build-dependency-selector-fn [generated-data dependency]
  (let [targeted-table (first (filter #(and (= (-> % :table :schema) (:target-schema dependency))
                                            (= (-> % :table :name) (:target-name dependency)))
                                      generated-data))
        tuple-count (count (:tuples targeted-table))]
    (fn []<commit_msg>Fixed bug causing a divide-by-zero error.<commit_after>(ns blutwurst.tuple-generator
  (:require [taoensso.timbre :as timbre :refer [trace error]]
            [clojure.pprint :refer :all]
            [blutwurst.value-generators :refer [create-generators random-integer-under-value]]))

(defn- generator-search [column strategies]
  (if (empty? strategies)
    nil
    (let [current-strategy (first strategies)]
      (if ((:determiner current-strategy) column)
        current-strategy
        (recur column (rest strategies))))))

(defn- find-override-for-column [spec column]
  (->> (:column-generator-overrides spec)
       (filter #(re-matches (re-pattern (:column-pattern %)) (:name column)))
       first
       :generator-name))

(defn- find-generator-by-name [generator-name strategies]
  (->> strategies
       (filter #(= (:name %) generator-name))
       first))

(defn- select-generators-for-column [spec column]
  (let [generators (create-generators spec)
        override-name (find-override-for-column spec column)]

    (if (nil? override-name)
      (generator-search column generators)
      (do
        (trace "Found override " override-name " for column " column)
        (find-generator-by-name override-name generators)))))

(defn- build-dependency-selector-fn [generated-data dependency]
  (let [targeted-table (first (filter #(and (= (-> % :entity :schema) (:target-schema dependency))
                                            (= (-> % :entity :name) (:target-name dependency)))
                                      generated-data))
        tuple-count (count (:tuples targeted-table))]
    (fn []
{'fraction_non_alphanumeric': 0.14316770186335404, 'fraction_numerical': 0.0, 'mean_word_length': 2.7151095732410613, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1344722', 'n_tokens_mistral': 958, 'n_tokens_neox': 933, 'n_words': 229}