Skip to content

Commit

Permalink
Merge pull request #43 from MastodonC/feature/additional-sankeys-for-…
Browse files Browse the repository at this point in the history
…investigation

Additional Sankey plots
  • Loading branch information
seb231 authored Mar 12, 2018
2 parents fdfa5a0 + 7d9feb8 commit 9174dd1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/clj/witan/send/charts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,27 @@
(sankey {:title "Joiner transitions"}))
(move-file "Rplots.pdf" (str "target/Joiner_Transitions.pdf")))

(defn sankey-setting-specific [data setting-to]
(defn sankey-setting-specific-transitions [data setting-to]
(->> data
(remove v/joiner?)
(remove v/leaver?)
(filter #(= (:setting-2 %) setting-to))
(map #(-> (update % :setting-1 name) (update :setting-2 name)))
(gather-set-data :to "From" "To")
(seq-of-maps->data-frame)
(sankey {:title (str "Joiner transitions")}))
(sankey {:title (str "Mover transitions")}))
(move-file "Rplots.pdf" (str "target/" (name setting-to) "_Transitions.pdf")))

(defn sankey-setting-specific-movers-to [data setting-to]
(->> data
(remove v/joiner?)
(remove v/leaver?)
(filter #(= (:setting-2 %) setting-to))
(filter #(not= (:setting-1 %) setting-to))
(map #(-> (update % :setting-1 name) (update :setting-2 name)))
(gather-set-data :to "From" "To")
(seq-of-maps->data-frame)
(sankey {:title (str "Mover transitions")}))
(move-file "Rplots.pdf" (str "target/" (name setting-to) "_Mover_Transitions.pdf")))

(defn pull-year
Expand Down
6 changes: 4 additions & 2 deletions src/clj/witan/send/send.clj
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,10 @@
(= setting-2 sc/non-send))) transitions-data)
mover-rates (mover-rate filter-movers)
mover-rates-CI (map #(confidence-interval mover-rates %) years)
n-colours (take (count years) ch/palette)
;;n-colours (vec (repeatedly (count years) ch/random-colour)) ;; alternative random colour selection
n-colours (take (count years) ch/palette)]
;;future-transitions (mapcat u/projection->transitions projection) ;; for projection investigation
]
(report/info "First year of input data: " (report/bold (first years)))
(report/info "Final year of input data: " (report/bold (inc (last years))))
(report/info "Final year of projection: " (report/bold (+ (last years) (count (map :total-in-send send-output)))))
Expand Down Expand Up @@ -646,7 +648,7 @@
(run! #(ch/sankey-transitions transitions-data % valid-settings) years)
(ch/sankey-joiners transitions-data)
(when (not= 1 modify-transition-by)
(run! (partial ch/sankey-setting-specific transitions-data) (map :setting-1 (ds/row-maps settings-to-change))))
(run! (partial ch/sankey-setting-specific-transitions transitions-data) (map :setting-1 (ds/row-maps settings-to-change))))
(ch/ribbon-plot joiner-rates-CI "Joiner" years n-colours)
(ch/ribbon-plot leaver-rates-CI "Leaver" years n-colours)
(ch/ribbon-plot mover-rates-CI "Mover" years n-colours)
Expand Down
14 changes: 14 additions & 0 deletions src/clj/witan/send/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,17 @@

(defn int-ceil [n]
(int (Math/ceil n)))

(defn projection-state-to-map [[calendar-year-2 ay-2 state-1 state-2]]
(let [[need-1 setting-1] (states/need-setting state-1)
[need-2 setting-2] (states/need-setting state-2)]
(hash-map :calendar-year calendar-year-2
:setting-1 setting-1
:need-1 need-1
:academic-year-1 (dec ay-2)
:setting-2 setting-2
:need-2 need-2
:academic-year-2 ay-2)))

(defn projection->transitions [[state sum]]
(repeat sum (projection-state-to-map state)))

0 comments on commit 9174dd1

Please sign in to comment.