~drewr/baklava

8f23d21278a24ab792867d427b216ad27e4c6cd2 — Drew Raines a month ago e2a6ea8 main
WIP
1 files changed, 69 insertions(+), 12 deletions(-)

M src/baklava/workday.clj
M src/baklava/workday.clj => src/baklava/workday.clj +69 -12
@@ 23,6 23,7 @@
   "Cost Center - ID"
   "Manager"
   "Job Profile"
   "Region"
   ])

(defprotocol Employee


@@ 44,8 45,8 @@
  "
  [dataset management-chain-level name]
  (-> dataset
      (ds/select (conj common-columns management-chain-level)
                 :all)
      #_(ds/select (conj common-columns management-chain-level)
                   :all)
      (ds/filter-column
       management-chain-level
       #(if (string? %) (.startsWith % name)))


@@ 58,7 59,7 @@

(defn reports-into [graph emp]
  #_(locking *out*
    (prn emp))
      (prn emp))
  (let [reps (direct-reports graph emp)]
    (lazy-seq
     (when (seq reps)


@@ 66,17 67,73 @@
             (apply concat (rest reps)
                    (map #(reports-into graph %) (rest reps))))))))

(defn employee [dataset prefix]
  (-> dataset
      (ds/filter-column
       "Preferred Name" #(and (string? %) (.startsWith % prefix)))
      (ds/select common-columns :all)))
(def employee
  (fn [dataset prefix]
    (-> dataset
        (ds/filter-column
         "Preferred Name" #(and (string? %) (.startsWith % prefix)))
        #_(ds/select common-columns :all)
        ds/rows
        first)))

(defn clean-title [s]
  (if (and (string? s))
    (let [[_ title] (re-find #"([^,-]+)" s)]
      (.trim title))
    s))

(defn make-node [emp]
  [(get emp "Employee ID")
   (merge
    {:fontname "helvetica"
     :fontcolor "black"
     :label (format "%s\n%s"
                    (get emp "Preferred Name")
                    (clean-title
                     (get emp "Business Title")))
     :style "filled"}
    (match [(get emp "Management Level")]
      ["11 - Entry"]
      {:fillcolor "ghostwhite"}
      ["12 - Intermediate"]
      {:fillcolor "azure"}
      ["13 - Specialist"]
      {:fillcolor "lightcyan"}
      ["14 - Expert"]
      {:fillcolor "lightblue"}
      ["15 - Scholar"]
      {:fillcolor "lightskyblue"}
      ["16 - Strategist"]
      {:fillcolor "deepskyblue1"}
      ["23 - Manager"]
      {:fillcolor "palegreen1"}
      ["24 - Sr Manager"]
      {:fillcolor "palegreen2"}
      ["25 - Director"]
      {:fillcolor "palegreen3"}
      :else
      {:fontcolor "black"
       :fillcolor "gray"}))
   ])

(defn make-edge [dataset emp]
  (when (get emp "Manager")
    [(get emp "Employee ID")
     (get (employee dataset (get emp "Manager"))
          "Employee ID") {:label ""}]))

(defn org-graph [dataset management-chain-level name]
  (->> (employees-under dataset management-chain-level name)
       (map (fn [x]
              [(get x "Preferred Name") (get x "Manager")]))
       (apply uber/digraph)))
  (let [mknod make-node
        emps (conj (employees-under dataset management-chain-level name)
                   (employee dataset name))
        g (uber/digraph)
        g-with-nodes (->> emps
                          (map mknod)
                          (uber/add-nodes-with-attrs* g))]
    (->> emps
         (map (partial make-edge dataset))
         (filter identity)
         (uber/add-edges* g-with-nodes))))

(defn managers [graph]
  (->> graph