<commit_before>(defrecord Operation [name shortcut query params headers])

(derive ::integer ::printable)

(defmulti toString class)

(defmethod toString :default [x]
  (str x))

(defmethod toString String [x]
  x)

(defmethod toString ClassOrInterfaceDeclaration [x]
  (getQName x))

(defn resultToStrings [resultRow]
  (map toString resultRow))

(defn resultsToStrings [results]
  (map resultToStrings results))

(defn columnLength [headerStr resultStrs]
  (max
    (.length headerStr)
    (apply max
      (map (fn [s] (.length s)) resultStrs))))

(defn columnLengthsHelper [headersStrings resultsStrings acc]
  (if (empty? headersStrings)
    acc
    (columnLengthsHelper
      (rest headersStrings)
      (rest resultsStrings)
      (conj
        acc
        (columnLength (first headersStrings) (first resultsStrings))))))

(defn columnLengths [headersStrings, resultsStrings]
  (columnLengthsHelper headersStrings resultsStrings '()))

(defn padStr [s len]
  (if (>= (.length s) len)
    s
    (padStr (str s " ") len)))

(defn rowStr [lengths values]
  (if (empty? lengths)
    ""
    (str
      (padStr (first values) (first lengths))
      (rowStr (rest lengths) (rest values)))))

(defn sum [v]
  (apply + v))

(defn separatorStr [lengths]
  (let [n (sum lengths)]
    (clojure.string/join (repeat n "-"))))

(defn printTable [headers results]
  (let [resultsStrings (resultsToStrings results),
        headersStrings (resultToStrings headers),
        colLengths (columnLengths headersStrings resultsStrings)]
    (do
      (println "COLLENGTH " colLengths)
      (println (rowStr colLengths headersStrings))
      (println (separatorStr colLengths))
      (doall (for [r resultsStrings]
        (println (rowStr colLengths r)))))))

(defn printOperation [operation cus threshold]
  (let [headers (.headers operation),
        results ((.query operation) cus threshold)]
    (printTable headers results)))
<commit_msg>Improving printing to table<commit_after>(defrecord Operation [name shortcut query params headers])

(derive ::integer ::printable)

(defmulti toString class)

(defmethod toString :default [x]
  (str x))

(defmethod toString String [x]
  x)

(defmethod toString ClassOrInterfaceDeclaration [x]
  (getQName x))

(defn resultToStrings [resultRow]
  (into [] (map toString resultRow)))

(defn resultsToStrings [results]
  (map resultToStrings results))

(defn getN [l ind]
  (if (= ind 0)
    (first l)
    (getN (rest l) (- ind 1))))

(defn columnLength [headerStr resultStrs ind]
  (max
    (.length headerStr)
    (apply max
      (into [] (map (fn [row] (.length (nth row ind))) resultStrs)))))

(defn columnLengthsHelper [headersStrings resultsStrings acc ind]
  (if (empty? headersStrings)
    acc
    (columnLengthsHelper
      (rest headersStrings)
      resultsStrings
      (conj
        acc
        (columnLength (first headersStrings) resultsStrings ind))
      (+ 1 ind))))

(defn columnLengths [headersStrings, resultsStrings]
  (into [] (columnLengthsHelper headersStrings resultsStrings [] 0)))

(defn padStr [s len]
  (if (>= (.length s) len)
    s
    (padStr (str s " ") len)))

(defn rowStr [lengths values]
  (if (empty? lengths)
    ""
    (str
      (padStr (first values) (first lengths))
      (rowStr (rest lengths) (rest values)))))

(defn sum [v]
  (apply + v))

(defn separatorStr [lengths]
  (let [n (sum lengths)]
    (clojure.string/join (repeat n "-"))))

(defn printTable [headers results]
  (let [resultsStrings (resultsToStrings results),
        headersStrings (resultToStrings headers),
        colLengths (columnLengths headersStrings resultsStrings)]
    (do
      (println (rowStr colLengths headersStrings))
      (println (separatorStr colLengths))
      (doall (for [r resultsStrings]
        (println (rowStr colLengths r)))))))

(defn printOperation [operation cus threshold]
  (let [headers (.headers operation),
        results ((.query operation) cus threshold)]
    (printTable headers results)))

{'fraction_non_alphanumeric': 0.12028183190739809, 'fraction_numerical': 0.0010065425264217413, 'mean_word_length': 3.7949336550060315, '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': '2449636', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1222, 'n_words': 387}