<commit_before>(ns viewer.model.ship
  (:require [appengine-magic.services.datastore :as ds]))

(ds/defentity Ship [^{:tag :key} name, ^{:tag :clj} data])

(defn delete-all []
  (ds/delete!
   (ds/query :kind Ship)))

(defn put-ship [name data]
  (let [s (Ship. name data)]
    (ds/save! s)
    name))

(defn update-db [ships]
  (delete-all)
  (map (fn [s] (put-ship (-> s :ship :typename) s))
       ships))

(defn get-ship [name]
  (first (ds/query :kind Ship :filter (= :name name))))

<commit_msg>Fix NPE when ship not found.<commit_after>(ns viewer.model.ship
  (:require [appengine-magic.services.datastore :as ds]))

(ds/defentity Ship [^{:tag :key} name, ^{:tag :clj} data])

(defn delete-all []
  (ds/delete!
   (ds/query :kind Ship)))

(defn put-ship [name data]
  (let [s (Ship. name (ds/as-text (pr-str data)))]
    (ds/save! s)
    name))

(defn update-db [ships]
  (delete-all)
  (map (fn [s] (put-ship (-> s :ship :typename) s))
       ships))

(defn get-ship [name]
  (let [ship (first (ds/query :kind Ship :filter (= :name name)))]
    (if (not (nil? ship))
      {:name (:name ship) :data (read-string (.getValue (:data ship)))})))


{'fraction_non_alphanumeric': 0.20417028670721113, 'fraction_numerical': 0.0, 'mean_word_length': 3.3969465648854964, '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': '4521855', 'n_tokens_mistral': 464, 'n_tokens_neox': 453, 'n_words': 131}