<commit_before>(ns open-company.resources.stakeholder-update
  (:require [clojure.string :as s]
            [schema.core :as schema]
            [if-let.core :refer (if-let*)]
            [defun :refer (defun-)]
            [open-company.lib.slugify :as slug]
            [open-company.resources.common :as common]
            [open-company.resources.company :as company]
            [open-company.resources.section :as section]))

;; ----- RethinkDB metadata -----

(def table-name common/stakeholder-update-table-name)
(def primary-key :id)

;; ----- Utility functions -----

(defn- slug-for
  "Create a slug for the stakeholder update from the slugified title and a short UUID."
  [title]
  (let [non-blank-title (if (s/blank? title) "update" title)]
    (str (slug/slugify non-blank-title) "-" (subs (str (java.util.UUID/randomUUID)) 0 4))))

(defun- sections-for
  "Recursive function to get each specified section and add it to the stakeholder update."
  ([su-props conn] (sections-for su-props conn (:sections su-props)))
  
  ([su-props _conn sections :guard empty?] su-props)
  
  ([su-props conn sections]
    (let [company-slug (:company-slug su-props)
          section-name (keyword (first sections))
          as-of (:created-at su-props)
          section (section/get-section conn company-slug section-name as-of)
          clean-section (dissoc section :section-name :id :company-slug)]
      (recur (assoc su-props section-name clean-section) conn (rest sections)))))
  
;; ----- Stakeholder update CRD (Create, Read, Delete) -----

(schema/defn ->stakeholder-update :- common/Stakeholder-update
  "Take a minimal map describing a stakeholder-update and a user and 'fill the blanks'"
  
  ([conn company su-props user] (->stakeholder-update conn company su-props (common/current-timestamp) user))
  
  ([conn company {:keys [title sections] :as su-props} timestamp user]
  {:pre [(map? conn)
         (string? title)
         (sequential? sections)
         (map? user)]
   :post [(map? %)]} ; title and sections required
  (-> su-props
    (assoc :slug (slug-for title))
    (assoc :company-slug (:slug company))
    (merge (select-keys company [:name :description :logo :logo-width :logo-height])) ; freeze some props of company
    (update :title #(or % ""))
    (assoc :author (common/author-for-user user))
    (assoc :created-at timestamp)
    (sections-for conn))))
<commit_msg>Remove unused :description from company copy.<commit_after>(ns open-company.resources.stakeholder-update
  (:require [clojure.string :as s]
            [schema.core :as schema]
            [if-let.core :refer (if-let*)]
            [defun :refer (defun-)]
            [open-company.lib.slugify :as slug]
            [open-company.resources.common :as common]
            [open-company.resources.company :as company]
            [open-company.resources.section :as section]))

;; ----- RethinkDB metadata -----

(def table-name common/stakeholder-update-table-name)
(def primary-key :id)

;; ----- Utility functions -----

(defn- slug-for
  "Create a slug for the stakeholder update from the slugified title and a short UUID."
  [title]
  (let [non-blank-title (if (s/blank? title) "update" title)]
    (str (slug/slugify non-blank-title) "-" (subs (str (java.util.UUID/randomUUID)) 0 4))))

(defun- sections-for
  "Recursive function to get each specified section and add it to the stakeholder update."
  ([su-props conn] (sections-for su-props conn (:sections su-props)))
  
  ([su-props _conn sections :guard empty?] su-props)
  
  ([su-props conn sections]
    (let [company-slug (:company-slug su-props)
          section-name (keyword (first sections))
          as-of (:created-at su-props)
          section (section/get-section conn company-slug section-name as-of)
          clean-section (dissoc section :section-name :id :company-slug)]
      (recur (assoc su-props section-name clean-section) conn (rest sections)))))
  
;; ----- Stakeholder update CRD (Create, Read, Delete) -----

(schema/defn ->stakeholder-update :- common/Stakeholder-update
  "Take a minimal map describing a stakeholder-update and a user and 'fill the blanks'"
  
  ([conn company su-props user] (->stakeholder-update conn company su-props (common/current-timestamp) user))
  
  ([conn company {:keys [title sections] :as su-props} timestamp user]
  {:pre [(map? conn)
         (string? title)
         (sequential? sections)
         (map? user)]
   :post [(map? %)]} ; title and sections required
  (-> su-props
    (assoc :slug (slug-for title))
    (assoc :company-slug (:slug company))
    (merge (select-keys company [:name :logo :logo-width :logo-height])) ; freeze some props of company
    (update :title #(or % ""))
    (assoc :author (common/author-for-user user))
    (assoc :created-at timestamp)
    (sections-for conn))))

{'fraction_non_alphanumeric': 0.1465284974093264, 'fraction_numerical': 0.0008290155440414508, 'mean_word_length': 2.94281045751634, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5929900', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1502, 'n_words': 452}