<commit_before>(ns ophion.store
  (:require
   [clojure.set :as set]
   [ophion.mongo :as db]
   [ophion.query :as query]))

(defn store-query
  [graph db {:keys [user key focus path query]}]
  (let [pure (query/delabelize query)]
    (db/insert!
     db :ophionquery
     {:user user
      :key key
      :focus focus
      :path path
      :query pure})
    (let [{:keys [results commit]} (query/perform graph pure)
          index (map-indexed
                 (fn [index result]
                   {:key key
                    :order index
                    :result result})
                 results)]
      (db/bulk-insert! db :ophionresults index)
      (commit)
      {:stored (count index)})))

(defn all-queries
  [db]
  (let [queries
        (map
         #(dissoc % :_id)
         (db/find-all db :ophionquery))]
    (group-by :focus queries)))

(defn load-query
  [db {:keys [user key]}]
  (db/query
   db :ophionquery
   {:user user
    :key key}))

(defn load-results
  [db key]
  (db/aggregate<commit_msg>adding current query into saving<commit_after>(ns ophion.store
  (:require
   [clojure.set :as set]
   [ophion.mongo :as db]
   [ophion.query :as query]))

(defn store-query
  [graph db {:keys [user key focus path query current]}]
  (let [pure (query/delabelize query)
        insert {:user user
                :key key
                :focus focus
                :path path
                :current current
                :query pure}]
    (db/insert! db :ophionquery insert)
    (let [{:keys [results commit]} (query/perform graph pure)
          index (map-indexed
                 (fn [index result]
                   {:key key
                    :order index
                    :result result})
                 results)]
      (db/bulk-insert! db :ophionresults index)
      (commit)
      {:stored (count index)})))

(defn all-queries
  [db]
  (let [queries
        (map
         #(dissoc % :_id)
         (db/find-all db :ophionquery))]
    (group-by :focus queries)))

(defn load-query
  [db {:keys [user key]}]
  (db/query
   db :ophionquery
   {:user user
    :key key}))

(defn load-results
  [db key]
  (db/aggregate
{'fraction_non_alphanumeric': 0.12650602409638553, 'fraction_numerical': 0.0, 'mean_word_length': 1.818537859007833, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '471567', 'n_tokens_mistral': 725, 'n_tokens_neox': 700, 'n_words': 204}