diff --git a/src/clj/witan/send/charts.clj b/src/clj/witan/send/charts.clj index a10d8537..afb89dcb 100644 --- a/src/clj/witan/send/charts.clj +++ b/src/clj/witan/send/charts.clj @@ -73,7 +73,7 @@ (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?) @@ -81,7 +81,19 @@ (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 diff --git a/src/clj/witan/send/send.clj b/src/clj/witan/send/send.clj index 0612269a..411cb8c3 100644 --- a/src/clj/witan/send/send.clj +++ b/src/clj/witan/send/send.clj @@ -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))))) @@ -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) diff --git a/src/clj/witan/send/utils.clj b/src/clj/witan/send/utils.clj index 1d0d546f..5d0ac3cf 100644 --- a/src/clj/witan/send/utils.clj +++ b/src/clj/witan/send/utils.clj @@ -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)))