Skip to content

Commit

Permalink
push game-config through the history generation
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaCrotti committed Jan 24, 2019
1 parent 95afae8 commit 4d60415
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
40 changes: 24 additions & 16 deletions src/cljc/elo/games.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
(get-rankings games players shared/default-game-config))

([games players config]
(println "config =" config)
(let [norm-games (map elo/normalize-game games)
rankings (elo/compute-rankings norm-games
(map :id players)
Expand Down Expand Up @@ -112,26 +113,33 @@
(:p2_points game)))

(defn rankings-at-idx*
[players idx all-games]
(let [current-game (nth all-games idx)
name-mapping (player->names players)
common-map
{:game-idx idx
:time (:played_at current-game)
:result (game-result current-game name-mapping)}
([players idx all-games]
(rankings-at-idx* players idx all-games shared/default-game-config))

rankings (get-rankings (take idx all-games) players)]
([players idx all-games game-config]
(let [current-game (nth all-games idx)
name-mapping (player->names players)
common-map
{:game-idx idx
:time (:played_at current-game)
:result (game-result current-game name-mapping)}

(map #(merge % common-map)
(for [r (filter #(plays? current-game (:id %)) rankings)]
{:ranking (:ranking r)
:player (name-mapping (:id r))}))))
rankings (get-rankings (take idx all-games) players)]

(map #(merge % common-map)
(for [r (filter #(plays? current-game (:id %)) rankings)]
{:ranking (:ranking r)
:player (name-mapping (:id r))})))))

(defn rankings-history
[players games]
(flatten
(for [idx (range (count games))]
(rankings-at-idx* players idx games))))
([players games]
(rankings-history players games shared/default-game-config))

([players games game-config]
(println "rankings history:" "config = " game-config)
(flatten
(for [idx (range (count games))]
(rankings-at-idx* players idx games game-config)))))

(defn longest-winning-subseq
[s]
Expand Down
10 changes: 7 additions & 3 deletions src/cljs/elo/league_detail/handlers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@
:<- [::visible-players]
:<- [::games-live-players]
:<- [::up-to-games]
:<- [::game-config]

(fn [[players visible-players games up-to] _]
(fn [[players visible-players games up-to game-config] _]
(js/console.log "Recomputing rankings history")
(let [visible-players-names (set (map :name visible-players))
full-rankings
(games/rankings-history players (truncate-games games up-to))]
(games/rankings-history players (truncate-games games up-to) game-config)]

(->> full-rankings
(filter #(contains? visible-players-names (:player %)))))))
Expand Down Expand Up @@ -330,8 +332,10 @@

(rf/reg-sub ::rankings-history-vega
:<- [::rankings-history]
:<- [::game-config]

(fn [history]
(fn [[history game-config]]
(js/console.log "history changed now")
(let [kw->keyname {:player "Player"
:ranking "Ranking"
:game-idx "Game #"
Expand Down
3 changes: 2 additions & 1 deletion src/cljs/elo/league_detail/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
(let [history (rf/subscribe [::handlers/rankings-history-vega])
rankings-domain (rf/subscribe [::handlers/rankings-domain])]
(fn []
(js/console.log "Recomputing the history and the rankings domain")
[vega/vega-inner @history @rankings-domain])))

(defn- percent
Expand Down Expand Up @@ -395,6 +396,6 @@
[stats-component ::stats-specs/best-percents]]

[:div.section.vega__table [vega-outer]]
#_[:div.section.game__config [game-config]]
[:div.section.game__config [game-config]]
[:div.section.rankings__table [rankings-table]]
[:div.section.games__table [games-table]]]))

0 comments on commit 4d60415

Please sign in to comment.