Skip to content

Instantly share code, notes, and snippets.

@chrismurrph
Created August 12, 2018 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismurrph/10c485f48e307936589fc5b1ddc93331 to your computer and use it in GitHub Desktop.
Save chrismurrph/10c485f48e307936589fc5b1ddc93331 to your computer and use it in GitHub Desktop.
(defn identities-and-stages-hof
"The data doesn't have a player-year so we create it now. Also the games need to be
unique on their own, as they are stored in their own table.
Also the simplification of the lines for stage :improved is handled here.
The work for :nyt stage can be done always as :naive doesn't use those keys."
[desired-labels {:keys [stage]}]
(fn [idx {:keys [pname year games max] :as player-year}]
(let [player-year-id (make-player-year-id pname year)
label {:pname pname :year year}
make-simple (fn [games n]
(if (= :improved stage)
(->clj (simplify (clj->js games) n))
games))]
(assoc player-year
:idx idx
:key idx
:ui/desired? (boolean (desired-labels label))
:player-year-id player-year-id
:games (->> games
(mapv (fn [{:keys [x y]}]
(let [id (str player-year-id "_" x)]
{:id id :key id :x x :y y})))
(#(make-simple % simplification)))
;; Easier to put these in than have a playerMap (not even used at :naive stage, but no harm having here)
:x 41
:y max))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment