<commit_before>(ns com.sixsq.slipstream.ssclj.api.dev-server
  (:require
    [com.sixsq.slipstream.ssclj.app.server            :as server]
    [com.sixsq.slipstream.ssclj.resources.seeds.event :as es]
    [com.sixsq.slipstream.ssclj.usage.seeds.usages    :as us]))

(def ^:private ^:dynamic *server-port* nil)

(defonce server
  (delay
    (println (str "Server started at localhost:" *server-port*))
    (server/start *server-port*)))

(defn bootstrap
  [& {:keys [port events summaries user summaries clouds]
      :or {port       8201
           events     45
           summaries  45
           clouds     ["aws" "exo"]
           user       :bob}}]
    (binding [*server-port* port] @server)
    (println (str "Seeding " events " events for user '" (name user) "'..." ))
    (es/seed! events user)
    (println (str "Seeding " summaries " summaries for clouds '" clouds "' for user '" (name user) "'..."))
    (us/seed-summaries! summaries user clouds))

(println)
(println "Type (api/bootstrap) to start a server with 45 events and 45 summaries for user 'bob'")
(println "For customised values use named parameters like:")
(println "     :user      \"anotheruser\"")
(println "     :events    100")
(println "     :summaries 100")
(println "     :clouds    [\"onecloud\" \"anothercloud\"]")
(println)<commit_msg>change: enhance dev-db bootstrap, #443<commit_after>(ns com.sixsq.slipstream.ssclj.api.dev-server
  (:require
    [korma.core                                       :as kc]
    [com.sixsq.slipstream.ssclj.app.server            :as server]
    [com.sixsq.slipstream.ssclj.resources.seeds.event :as es]
    [com.sixsq.slipstream.ssclj.usage.seeds.usages    :as us]))

(def ^:private ^:dynamic *server-port* nil)

(defonce server
  (delay
    (println (str "Server started at localhost:" *server-port*))
    (server/start *server-port*)))

(kc/defentity resources)
(kc/defentity usage_summaries)

(defn db-content
  []
  {:resource  (->> (kc/select resources)
                   (map :id)
                   (map (partial re-find #"(.*)/.*"))
                   (map second)
                   frequencies)
   :summaries (->> (kc/select usage_summaries)
                   (map :user)
                   frequencies)})

(defn empty-db?
  []
  (->> (db-content) vals (every? #{{}})))

(defn bootstrap
  [& {:keys [port events summaries user summaries clouds clean]
      :or {port       8201
           events     45
           summaries  45
           clouds     ["aws" "exo"]
           user       :bob
           clean      true}}]
    (binding [*server-port* port] @server)
    (println (str "Seeding " events " events for user '" (name user) "'..." ))
    (when clean
      (println "All DB entries will be deleted. Use (bootstrap :clean false) to avoid it."))
    (es/seed! events user :clean clean)
    (println (str "Seeding " summaries " summaries for clouds '" clouds "' for user '" (name user) "'..."))
    (us/seed-summaries! summaries user clouds :clean clean)
    (println "The current state of the DB is:")
    (clojure.pprint/pprint (db-content)))

(println)
(println "Type (api/bootstrap) to start a server with 45 events and 45 summaries for user 'bob'")
(println "For customised values use named parameters like:")
(println "     :user      \"anotheruser\"")
(println "     :events    100")
(println "     :summaries 100")
(println "     :clouds    [\"onecloud\" \"anothercloud\"]")
(println)
{'fraction_non_alphanumeric': 0.14632009345794392, 'fraction_numerical': 0.01139018691588785, 'mean_word_length': 2.473630831643002, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '18468', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1090, 'n_words': 309}