<commit_before>(ns overseer.status
  "Functions for querying the state of jobs in the system"
  (:require [datomic.api :as d]
            [clojure.set :as set]))

(defn jobs-with-status
  "Find all job IDs with a given status (e.g. :unstarted)"
  [db status]
  (->> (d/q '[:find ?jid
              :in $ ?status
              :where
              [?e :job/status ?status]
              [?e :job/id ?jid]]
            db
            status)
       (map first)
       (set)))

(defn jobs-unfinished
  "Find all job IDs that are not yet complete."
  [db]
  (->> (d/q '[:find ?jid
              :where
              [?e :job/status ?s]
              [((comp not contains?) #{:finished :aborted :failed} ?s)]
              [?e :job/id ?jid]]
            db)
       (map first)
       (into #{})))

(defn jobs-ready
  "Find all job IDs that are ready to run.
   Works by finding all jobs that are not yet done, and subtracting the
   jobs who dependencies are not yet ready."
  [db]
  (let [unfinished (jobs-unfinished db)]
    (set/difference
      unfinished
      (->> (d/q '[:find ?jid
                  :in $ [?unfinished-jids ...]
                  :where
                  [?j :job/id ?unfinished-jids]
                  [?j :job/id ?jid]
                  [?j :job/dep ?dj]
                  [?dj :job/status ?djs]
                  [(not= :finished ?djs)]]
                db
                unfinished)
           (map first)
           (into #{})))))
<commit_msg>Adjust datomic :where query whitespace<commit_after>(ns overseer.status
  "Functions for querying the state of jobs in the system"
  (:require [datomic.api :as d]
            [clojure.set :as set]))

(defn jobs-with-status
  "Find all job IDs with a given status (e.g. :unstarted)"
  [db status]
  (->> (d/q '[:find ?jid
              :in $ ?status
              :where [?e :job/status ?status]
                     [?e :job/id ?jid]]
            db
            status)
       (map first)
       (set)))

(defn jobs-unfinished
  "Find all job IDs that are not yet complete."
  [db]
  (->> (d/q '[:find ?jid
              :where [?e :job/status ?s]
                     [((comp not contains?) #{:finished :aborted :failed} ?s)]
                     [?e :job/id ?jid]]
            db)
       (map first)
       (into #{})))

(defn jobs-ready
  "Find all job IDs that are ready to run.
   Works by finding all jobs that are not yet done, and subtracting the
   jobs who dependencies are not yet ready."
  [db]
  (let [unfinished (jobs-unfinished db)]
    (set/difference
      unfinished
      (->> (d/q '[:find ?jid
                  :in $ [?unfinished-jids ...]
                  :where [?j :job/id ?unfinished-jids]
                         [?j :job/id ?jid]
                         [?j :job/dep ?dj]
                         [?dj :job/status ?djs]
                         [(not= :finished ?djs)]]
                db
                unfinished)
           (map first)
           (into #{})))))

{'fraction_non_alphanumeric': 0.13663967611336034, 'fraction_numerical': 0.0, 'mean_word_length': 1.442339373970346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1516220', 'n_tokens_mistral': 964, 'n_tokens_neox': 929, 'n_words': 298}