<commit_before>(ns vignette.util.query-options)

(def query-opts-map {:fill "fill"})

(defn extract-query-opts
  [request]
  (reduce (fn [running [key val]]
            (if (contains? query-opts-map (keyword key))
              (assoc running (keyword key) val)
              running))
          {} (:query-params request)))

(defn query-opts
  [data]
  (if (empty? (:options data))
    nil
    (:options data)))

(defn query-opt
  [data opt]
  (get (query-opts data) opt))

(defn query-opts-str
  [data]
  (if-let [options (query-opts data)]
    (str "["
         (clojure.string/join "," (sort (map (fn [[k v]]
                                               (str (name k) "=" v))
                                             options)))
         "]")
    ""))

(defn query-opts->thumb-args
  [data]
  (reduce (fn [running [opt-key val]]
            (if-let [opt (get query-opts-map opt-key)]
              (conj running (str "--" opt) (str val))
              running))
          []
          (query-opts data)))

(defn modify-temp-file
  [data filename]
  (cond
    (= (query-opt data :fill) "transparent") (str "png:" filename)
    :else filename))<commit_msg>add format query parameter<commit_after>(ns vignette.util.query-options)

(def query-opts-map {:fill "fill"
                     :format "format"})

(defn extract-query-opts
  [request]
  (reduce (fn [running [key val]]
            (if (contains? query-opts-map (keyword key))
              (assoc running (keyword key) val)
              running))
          {} (:query-params request)))

(defn query-opts
  [data]
  (if (empty? (:options data))
    nil
    (:options data)))

(defn query-opt
  [data opt]
  (get (query-opts data) opt))

(defn query-opts-str
  [data]
  (if-let [options (query-opts data)]
    (str "["
         (clojure.string/join "," (sort (map (fn [[k v]]
                                               (str (name k) "=" v))
                                             options)))
         "]")
    ""))

(defn query-opts->thumb-args
  [data]
  (reduce (fn [running [opt-key val]]
            (if-let [opt (get query-opts-map opt-key)]
              (conj running (str "--" opt) (str val))
              running))
          []
          (query-opts data)))

(defn modify-temp-file
  [data filename]
  (cond
    (query-opt data :format) (str (query-opt data :format) ":" filename)
    (= (query-opt data :fill) "transparent") (str "png:" filename)
    :else filename))
{'fraction_non_alphanumeric': 0.16081632653061226, 'fraction_numerical': 0.0, 'mean_word_length': 1.8043478260869565, 'pattern_counts': {'":': 1, '<': 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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7132192', 'n_tokens_mistral': 784, 'n_tokens_neox': 770, 'n_words': 212}