From c6bb226918fa598f662dafdb1aeeaed2bfb96334 Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Fri, 31 Jan 2020 20:46:07 +0000 Subject: [PATCH] cleanup --- src/clj/byf/api.clj | 25 +--- src/clj/byf/datascript.clj | 9 -- src/clj/byf/db.clj | 11 -- src/clj/byf/dev.clj | 13 +- src/clj/byf/fixtures.clj | 10 +- src/clj/byf/seed.clj | 80 +--------- src/cljc/byf/algorithms/elo.cljc | 8 - src/cljc/byf/games.cljc | 5 - src/cljc/byf/generators.cljc | 21 +-- src/cljc/byf/routes.cljc | 2 - src/cljc/byf/shared_config.cljc | 14 -- src/cljs/byf/admin/views.cljs | 49 +----- src/cljs/byf/auth.cljs | 3 - src/cljs/byf/common/handlers.cljs | 23 +-- src/cljs/byf/common/players.cljs | 3 - src/cljs/byf/common/views.cljs | 34 +---- src/cljs/byf/core.cljs | 47 ------ src/cljs/byf/elements.cljs | 24 +-- src/cljs/byf/league_detail/add_game.cljs | 70 +-------- src/cljs/byf/league_detail/desktop.cljs | 137 +---------------- src/cljs/byf/league_detail/games_list.cljs | 52 +------ src/cljs/byf/league_detail/handlers.cljs | 15 -- src/cljs/byf/league_detail/mobile.cljs | 7 +- src/cljs/byf/league_detail/notifications.cljs | 24 +-- src/cljs/byf/league_detail/rankings.cljs | 141 +----------------- src/cljs/byf/league_detail/stats.cljs | 78 +--------- src/cljs/byf/league_detail/utils.cljs | 11 +- src/cljs/byf/league_detail/views.cljs | 13 +- src/cljs/byf/league_list/views.cljs | 42 +----- src/cljs/byf/user/handlers.cljs | 3 - src/cljs/byf/user/views.cljs | 15 -- src/cljs/byf/utils.cljs | 21 +-- src/cljs/byf/vega.cljs | 48 +----- test/clj/byf/api_test.clj | 43 ------ test/clj/byf/seed_test.clj | 8 - test/cljc/byf/algorithms/elo_test.cljc | 10 -- test/cljc/byf/rankings_test.cljc | 33 ---- test/cljc/byf/stats_test.cljc | 24 --- 38 files changed, 21 insertions(+), 1155 deletions(-) diff --git a/src/clj/byf/api.clj b/src/clj/byf/api.clj index fecee10..f7ecfff 100644 --- a/src/clj/byf/api.clj +++ b/src/clj/byf/api.clj @@ -28,8 +28,6 @@ (:import (java.util UUID))) (reset! sente/debug-mode?_ true) -(def max-age (* 60 60 24 10)) - (def github-token-path [:oauth2/access-tokens :github :token]) (defn transaction-middleware @@ -39,15 +37,6 @@ (jdbc/with-db-transaction [tx (db/db-spec)] (handler request))))) -(defn uuid-to-str - [m] - (medley/map-vals str m)) - -(defn- as-edn - [response] - (-> response - (resp/content-type "application/edn"))) - (defn my-json-writer [k v] (cond @@ -241,13 +230,6 @@ [params] (assoc-in params [:session :cookie-attrs :same-site] :lax)) -(defn add-cache-control - [handler] - (fn [request] - (ring.util.response/header - (handler request) - "Cache-Control" (format "max-age=%s" max-age)))) - (def app (-> routes-handler (resources/wrap-resource "public") @@ -265,9 +247,4 @@ check-token log-request transaction-middleware - (wrap-oauth2 oauth2-config))) - -(defn -main [& args] - (jetty/run-jetty app {:port (-> :port - value - Integer/parseInt)})) + (wrap-oauth2 oauth2-config))) \ No newline at end of file diff --git a/src/clj/byf/datascript.clj b/src/clj/byf/datascript.clj index 2c4dc9e..1ed99e0 100644 --- a/src/clj/byf/datascript.clj +++ b/src/clj/byf/datascript.clj @@ -4,8 +4,6 @@ [clj-time.core :as t]) (:import (java.util UUID))) -(defn gen-uuid [] (UUID/randomUUID)) - (def schema {:player/name {:db/index true} :game/t1 {:db/index true} :game/t2 {:db/index true} @@ -17,13 +15,6 @@ (def conn (d/create-conn schema)) -(declare render persist) - -(defn reset-conn [db] - (reset! conn db) - (render db) - (persist db)) - ;; find all the games from a given player (def datoms diff --git a/src/clj/byf/db.clj b/src/clj/byf/db.clj index 29601b0..fbba1ee 100644 --- a/src/clj/byf/db.clj +++ b/src/clj/byf/db.clj @@ -60,11 +60,6 @@ (-> (h/select :*) (h/from :company))) -(defn load-users-sql - [] - (-> (h/select :*) - (h/from [:users]))) - (defn load-league-sql [league-id] (-> (h/select :*) @@ -90,8 +85,6 @@ (defn load-companies [] (query load-companies-sql)) -(defn load-users [] (query load-users-sql)) - (defn- store-sql [params] (-> (h/insert-into :game) @@ -158,10 +151,6 @@ {:user-id user-id :player-id player-id})) -(defn count-sql [table] - (-> (h/select :%count.*) - (h/from table))) - (defn player-name [player-id] (-> (h/select :name) diff --git a/src/clj/byf/dev.clj b/src/clj/byf/dev.clj index 9023748..5b3d010 100644 --- a/src/clj/byf/dev.clj +++ b/src/clj/byf/dev.clj @@ -8,8 +8,6 @@ (:gen-class)) -(defonce system (atom {})) - (defmethod ig/init-key :server/figwheel [_ {:keys [build] :as opts}] (log/info "Starting Figwheel") @@ -28,13 +26,4 @@ (defmethod ig/init-key :server/nrepl [_ {:keys [port]}] - (log/info "Starting Nrepl")) - -(def config - {:server/figwheel {:build "dev"} - :server/jetty {:port 3335} - :server/nrepl {}}) - -(defn -main - [& args] - (reset! system (ig/init config))) + (log/info "Starting Nrepl")) \ No newline at end of file diff --git a/src/clj/byf/fixtures.clj b/src/clj/byf/fixtures.clj index 310e330..0c943dc 100644 --- a/src/clj/byf/fixtures.clj +++ b/src/clj/byf/fixtures.clj @@ -23,12 +23,4 @@ ::p1_using ::p2_using ::p1_points - ::p2_points])) - -(defn game-gen - [] - (s/gen ::game)) - -(defn player-gen - [] - (s/gen ::player)) + ::p2_points])) \ No newline at end of file diff --git a/src/clj/byf/seed.clj b/src/clj/byf/seed.clj index 3271361..a1a296a 100644 --- a/src/clj/byf/seed.clj +++ b/src/clj/byf/seed.clj @@ -4,82 +4,4 @@ [byf.generators :as gen] [byf.shared-config :as shared] [byf.db :as db] - [taoensso.timbre :as log])) - -(def n-games 42) -(def players-names ["John" "Charlie" "Frank" "Fitz" "Emily"]) - -(defn random-game - [player-ids] - (let [p1-id (rand-nth player-ids) - p2-id (rand-nth (remove #(= % p1-id) player-ids))] - - (gen/game-gen {:p1 p1-id - :p2 p2-id - :p1_points (rand-nth (shared/opts :fifa :points)) - :p2_points (rand-nth (shared/opts :fifa :points))}))) - -(defn get-player-ids - [league-id] - (map :id - (db/query (fn [] {:select [:id] - :from [:league_players] - :where [:= :league_id league-id]})))) - -(defn random-ts - [] - (tc/to-sql-time - (let [zero (tc/to-epoch (t/date-time 2018 1 1)) - end (tc/to-epoch (t/date-time 2019 1 1)) - length (- end zero)] - - (tc/from-epoch (+ zero (rand-int length)))))) - -(defn create-league! - [] - (let [company-id (db/gen-uuid) - league-id (db/gen-uuid) - - company {:id company-id - :name "Sample Company Time Fixed"} - - league {:company_id company-id - :name "Sample League Time Fixed" - :id league-id}] - - (db/add-company! company) - (db/add-league! league) - league-id)) - -(defn- add-players! - [league-id] - (let [players (map #(gen/player-gen {:name %}) players-names)] - (doseq [n (range (count players))] - (let [pl (nth players n)] - #_(log/debug "Creating player number" n pl) - (db/add-player-full! (assoc pl - :id (:id pl) - :email "sample-email" - :league_id league-id)))) - (map :id players))) - -(defn- add-games! - [league-id player-ids] - (let [games (repeatedly n-games #(random-game player-ids)) - games-full (map #(merge % {:league_id league-id - :played_at (random-ts)}) - games)] - - (doseq [game games-full] - #_(log/debug game) - (db/add-game! game)))) - -(defn seed - [league-id] - (add-games! league-id (add-players! league-id))) - -(defn -main - [& args] - (seed (create-league!))) - -;; run witn `lein run -m byf.seed` + [taoensso.timbre :as log]));; run witn `lein run -m byf.seed` diff --git a/src/cljc/byf/algorithms/elo.cljc b/src/cljc/byf/algorithms/elo.cljc index 2e02e79..7d149ec 100644 --- a/src/cljc/byf/algorithms/elo.cljc +++ b/src/cljc/byf/algorithms/elo.cljc @@ -52,14 +52,6 @@ ([players {:keys [initial-ranking] :as config}] (zipmap players (repeat initial-ranking)))) -(defn extract-players - [games] - (->> games - (map #(take 2 %)) - (apply concat) - set - vec)) - (defn normalize-game "Normalize the game identifying winner and loser (or draw) from the number of goals. With this approach the goal difference doesn't matter, but with diff --git a/src/cljc/byf/games.cljc b/src/cljc/byf/games.cljc index 9fb1047..ae93677 100644 --- a/src/cljc/byf/games.cljc +++ b/src/cljc/byf/games.cljc @@ -84,11 +84,6 @@ (for [[k v] rankings] {:id k :ranking v})))))) -(defn result-str - [game] - (str (:p1 game) " vs " (:p2 game) ": " - (:p1_points game) " - " (:p2_points game))) - (defn- plays? [game player-id] (contains? (set ((juxt :p1 :p2) game)) player-id)) diff --git a/src/cljc/byf/generators.cljc b/src/cljc/byf/generators.cljc index b80fa49..166b568 100644 --- a/src/cljc/byf/generators.cljc +++ b/src/cljc/byf/generators.cljc @@ -38,28 +38,9 @@ (s/def ::league (s/keys :req-un [::id ::name])) -(defn- gen-single - ([spec] - (gen-single spec {})) - - ([spec ks] - (merge (g/generate (s/gen spec)) ks))) - -(defn gen - [spec] - (partial gen-single spec)) - -(def game-gen (gen ::game)) - -(def player-gen (gen ::player)) - -(def league-gen (gen ::league)) - ;; can make it more specialized? (s/def ::oauth2_token string?) (s/def ::user (s/keys :req-un [::id ::oauth2_token - ::email])) - -(def user-gen (gen ::user)) + ::email])) \ No newline at end of file diff --git a/src/cljc/byf/routes.cljc b/src/cljc/byf/routes.cljc index a69bc76..6f0ee89 100644 --- a/src/cljc/byf/routes.cljc +++ b/src/cljc/byf/routes.cljc @@ -8,6 +8,4 @@ "admin" :admin ["user/" :player-id] :player-detail}]) -(def path-for (partial bidi/path-for routes)) - (def match-route (partial bidi/match-route routes)) diff --git a/src/cljc/byf/shared_config.cljc b/src/cljc/byf/shared_config.cljc index 2c95a76..19df080 100644 --- a/src/cljc/byf/shared_config.cljc +++ b/src/cljc/byf/shared_config.cljc @@ -2,8 +2,6 @@ (def timestamp-format "YYYY-MM-DDZHH:mm:SS") -(def games #{"fifa" "street-fighter" "table-tennis"}) - ;;TODO: add a spec for the game configuration (def games-config {:fifa @@ -27,18 +25,6 @@ :logo "table_tennis.png" :draw? false}}) -(defn term - [game k] - (-> games-config game :terminology k)) - -(defn opts - [game k] - (-> games-config game :form k)) - -(defn logo - [game] - (str "/logos/" (-> games-config game :logo))) - (def default-game-config { ;; valid range from 20 to 44 :k 32 diff --git a/src/cljs/byf/admin/views.cljs b/src/cljs/byf/admin/views.cljs index 5f44fb1..b960121 100644 --- a/src/cljs/byf/admin/views.cljs +++ b/src/cljs/byf/admin/views.cljs @@ -3,51 +3,4 @@ [byf.admin.handlers :as handlers] [byf.common.views :refer [drop-down]] [byf.elements :as el] - [byf.utils :as utils])) - -(defn add-player-form - [] - (let [valid-player? (rf/subscribe [::handlers/valid-player?]) - player (rf/subscribe [::handlers/player]) - leagues (rf/subscribe [::handlers/leagues])] - - (fn [] - [:div.section - [:div - [drop-down @leagues ::handlers/league (:league_id @player) - :value-fn :id - :display-fn :name] - - [el/input - [:is-fullwidth] - {:type "text" - :value (:name @player) - :name "name" - :placeholder "John Smith" - :on-change (utils/set-val ::handlers/name)}] - - [el/input - [:is-fullwidth] - {:type "text" - :value (:email @player) - :name "email" - :placeholder "john.smith@email.com" - :on-change (utils/set-val ::handlers/email)}]] - - [:div - [el/button - [:is-primary :is-fullwidth (when-not @valid-player? "disabled")] - {:type "button" - :name "submit-game" - :on-click (if @valid-player? - #(rf/dispatch [::handlers/add-player]) - #(js/alert "Fill up the form first"))} - - "Register New Player"]]]))) - -(defn root - [] - (rf/dispatch [::handlers/load-leagues]) - (fn [] - [:div - [add-player-form]])) + [byf.utils :as utils])) \ No newline at end of file diff --git a/src/cljs/byf/auth.cljs b/src/cljs/byf/auth.cljs index 608df19..bf0a2ff 100644 --- a/src/cljs/byf/auth.cljs +++ b/src/cljs/byf/auth.cljs @@ -9,9 +9,6 @@ (def setter (partial common/setter* page)) (def getter (partial common/getter* page)) -(def default-db - {:current-user nil}) - (rf/reg-sub ::current-user (getter [:current-user])) (rf/reg-event-db ::set-current-user (setter [:current-user])) diff --git a/src/cljs/byf/common/handlers.cljs b/src/cljs/byf/common/handlers.cljs index 05985f3..2abe4f8 100644 --- a/src/cljs/byf/common/handlers.cljs +++ b/src/cljs/byf/common/handlers.cljs @@ -9,20 +9,6 @@ [clojure.test.check.generators :as gen] [clojure.spec.alpha :as s])) -(def edn-request-format - {:write #(with-out-str (pprint/pprint %)) - :content-type "application/edn"}) - -(defn- edn-read-fn - [response] - (reader/read-string (ajax-protocols/-body response))) - -(def edn-response-format - (ajax-interceptors/map->ResponseFormat - {:read edn-read-fn - :description "EDN" - :content-type ["application/edn"]})) - (def request-format (aj/json-request-format)) (def response-format (aj/json-response-format {:keywords? true})) @@ -122,11 +108,4 @@ (rf/reg-event-db id [(->check-db-interceptor page db-spec)] - handler))) - -(defn set-random-db - "Handler capable of simply setting a random intial db. - This can be used instead of initialise-db for example." - [db-spec] - (fn [db _] - (gen/generate db-spec))) + handler))) \ No newline at end of file diff --git a/src/cljs/byf/common/players.cljs b/src/cljs/byf/common/players.cljs index a4da30f..8caa1af 100644 --- a/src/cljs/byf/common/players.cljs +++ b/src/cljs/byf/common/players.cljs @@ -5,9 +5,6 @@ [re-frame.core :as rf])) ;;TODO: add more to the db? -(def db - {:players []}) - (s/def ::players (s/coll-of (s/keys :req-un [::name ::user_id ::league_id diff --git a/src/cljs/byf/common/views.cljs b/src/cljs/byf/common/views.cljs index e73be88..1728da3 100644 --- a/src/cljs/byf/common/views.cljs +++ b/src/cljs/byf/common/views.cljs @@ -1,35 +1,3 @@ (ns byf.common.views (:require [re-frame.core :as rf] - [antizer.reagent :as ant])) - -(defn drop-down - "Wrapper around a select, which allows to pass the dispatch key and - the value the select should be set to" - [opts dispatch-key value & {:keys [value-fn display-fn] - :or {value-fn identity - display-fn identity}}] - - (into - [ant/select {:on-change - #(rf/dispatch [dispatch-key %]) - :value value}] - (for [o opts] - [ant/select-option {:key (value-fn o) - :value (value-fn o)} (display-fn o)]))) - -(defn drop-down-players - [opts dispatch-key value] - [drop-down opts dispatch-key value :value-fn :id :display-fn :name]) - -(defn errors - [] - (let [error @(rf/subscribe [:failed])] - (when errors - [:div.error "Error = " (str error)]))) - -(defn footer - [] - [ant/layout-footer - [:a {:href "https://github.com/AndreaCrotti/elo" - :target "_blank"} - "Fork me on Github"]]) + [antizer.reagent :as ant])) \ No newline at end of file diff --git a/src/cljs/byf/core.cljs b/src/cljs/byf/core.cljs index 8eef496..0bdfea6 100644 --- a/src/cljs/byf/core.cljs +++ b/src/cljs/byf/core.cljs @@ -15,53 +15,6 @@ [re-frame.core :as re-frame] [reagent.core :as reagent])) -(def pages - {:league-detail league-detail-views/root - :league-list league-list-views/root - :admin admin-views/root - :player-detail user-views/root}) - -(defn- path-exists? [path] - (boolean (routes/match-route path))) - -(def debug? - ^boolean js/goog.DEBUG) - -(defn dev-setup [] - (when debug? - (set! s/*explain-out* expound/printer) - (s/check-asserts true) - (enable-console-print!))) - -(defn curr-path - [] - (-> - js/window.location.href - url - :path)) - -(defn get-current-page - [] - (let [path (curr-path) - route (routes/match-route path)] - (get pages (:handler route)))) - -(defn mount-root - [page] - (re-frame/clear-subscription-cache!) - (reagent/render [page] - (.getElementById js/document "app"))) - -(defn ^:after-load reload-hook - [] - (mount-root (get-current-page))) - -(defn nav-handler - [path] - (let [new-handler (routes/match-route path)] - (re-frame/dispatch [:set-route-params (:route-params new-handler)]) - (reload-hook))) - (defn ^:export init [] (re-frame/dispatch-sync [::league-list-handlers/initialize-db]) (re-frame/dispatch-sync [::league-detail-handlers/initialize-db]) diff --git a/src/cljs/byf/elements.cljs b/src/cljs/byf/elements.cljs index 302149b..5c1a580 100644 --- a/src/cljs/byf/elements.cljs +++ b/src/cljs/byf/elements.cljs @@ -1,24 +1,2 @@ (ns byf.elements - (:require [byf.utils :refer [classes]])) - -(defn el - [tag base-class] - (fn [cls args body] - [tag - (merge args - {:class (classes (conj cls base-class))}) - (when (some? body) - body)])) - -(defn input - [cls args] - [:input - (merge args - {:class (classes (conj cls :input))})]) - -(defn button - [cls args body] - [:button - (merge args - (:class (classes (conj cls :button)))) - body]) + (:require [byf.utils :refer [classes]])) \ No newline at end of file diff --git a/src/cljs/byf/league_detail/add_game.cljs b/src/cljs/byf/league_detail/add_game.cljs index dc25e5d..e581e6a 100644 --- a/src/cljs/byf/league_detail/add_game.cljs +++ b/src/cljs/byf/league_detail/add_game.cljs @@ -6,72 +6,4 @@ [byf.utils :as utils] [byf.common.players :as players-handlers] [byf.league-detail.handlers :as handlers] - [cljsjs.moment])) - -(def form-config - {:class "add-game-form" - :layout "horizontal" - ;; :label-col {:xs {:span 24} - ;; :sm {:span 6}} - ;; :wrapper-col {:xs {:span 24} - ;; :sm {:span 6}} -}) - -(defn- enable-button - [valid-game? opts] - (if valid-game? - opts - (assoc opts :disabled "{true}"))) - -(defn team-input - [val handler] - [ant/input-text-area - {:default-value val - :value val - :autosize {:max-rows 1} - :on-change (utils/set-val handler)}]) - -(defn game-form - [] - (let [players (rf/subscribe [::players-handlers/active-players-full]) - valid-game? (rf/subscribe [::handlers/valid-game?]) - game (rf/subscribe [::handlers/game]) - league (rf/subscribe [::handlers/league]) - game-type (or (:game_type @league) :fifa) - points-range (map str (config/opts game-type :points)) - sorted-players (sort-by :name @players)] - - [ant/form form-config - [ant/form-item {:label "Player 1"} - [common-views/drop-down-players sorted-players ::handlers/p1 (:p1 @game)]] - - [ant/form-item {:label "Goals"} - [common-views/drop-down points-range ::handlers/p1_points (:p1_points @game)]] - - [ant/form-item {:label "Team 1"} - [team-input (:p1_using @game) ::handlers/p1_using]] - - [ant/form-item {:label "Player 2"} - [common-views/drop-down-players sorted-players ::handlers/p2 (:p2 @game)]] - - [ant/form-item {:label "Goals"} - [common-views/drop-down points-range ::handlers/p2_points (:p2_points @game)]] - - [ant/form-item {:label "Team 2"} - [team-input (:p2_using @game) ::handlers/p2_using]] - - [ant/form-item {:label "Played At"} - ;; link to the right value here - [ant/date-picker {:show-time true - :format "YYYY-MM-DD HH:mm" - :value (:played_at @game) - :on-change - (fn [mo _] - (rf/dispatch [::handlers/played_at mo]))}]] - - [ant/form-item - [ant/button - (enable-button @valid-game? - {:type "primary" - :on-click #(rf/dispatch [::handlers/add-game])}) - "Add Game"]]])) + [cljsjs.moment])) \ No newline at end of file diff --git a/src/cljs/byf/league_detail/desktop.cljs b/src/cljs/byf/league_detail/desktop.cljs index 753087e..6ac9564 100644 --- a/src/cljs/byf/league_detail/desktop.cljs +++ b/src/cljs/byf/league_detail/desktop.cljs @@ -12,139 +12,4 @@ [byf.utils :as utils] [byf.vega :as vega] [cljsjs.moment] - [re-frame.core :as rf])) - -(def timestamp-format "YYYY-MM-DDZhh:mm:SS") -(def vega-last-n-games 20) - -(defn now-format - [] - (.format (js/moment) timestamp-format)) - -(defn from-to - [s f t] - (take (- t f) (drop f s))) - -(defn vega-outer - [] - (let [history (rf/subscribe [::handlers/rankings-history-vega]) - rankings-domain (rf/subscribe [::handlers/rankings-domain]) - show-graph (rf/subscribe [::handlers/show-graph]) - from-game (rf/subscribe [::handlers/from-game]) - to-game (rf/subscribe [::handlers/to-game])] - - (fn [] - (let [norm-from (or @from-game 0) - norm-to (or @to-game (count @history)) - filtered-history (from-to @history norm-from norm-to)] - - [ant/card - [ant/button - {:on-click #(rf/dispatch [::handlers/toggle-graph])} - (if @show-graph - "hide graph" - "show graph")] - - (when @show-graph - [ant/card - [vega/vega-inner filtered-history @rankings-domain]])])))) - -(defn mobile? - [] - (js/console.log "avail width " js/window.screen.availWidth) - (< js/window.screen.availWidth 500)) - -(defn results - [] - (let [show-results (rf/subscribe [::handlers/show-results])] - (fn [] - [:div.inner - (when (utils/mobile?) - [:button.button.is-fullwidth - {:on-click #(rf/dispatch [::handlers/toggle-results])} - (if @show-results - "Hide Results" - "Show Results")]) - - (when (or (not (utils/mobile?)) @show-results) - [:div.results-content - [:div {:id "rankings"} - [rankings-table]] - [vega-outer] - [:div {:id "stats"} - [stats-component ::stats-specs/highest-ranking] - [stats-component ::stats-specs/longest-winning-streak] - [stats-component ::stats-specs/longest-unbeaten-streak] - [stats-component ::stats-specs/highest-increase] - [stats-component ::stats-specs/best-percents]] - [:div {:id "games"} - [ant/card - [games-table]]]])]))) - -(defn set-current-user - "Set the current user to something, defaulting to the already set user?" - [] - (let [players (rf/subscribe [::players-handlers/players]) - sorted-players (sort-by :name @players) - current-user @(rf/subscribe [::handlers/current-user])] - - [ant/form {:layout "inline"} - [ant/form-item - [ant/button - {:on-click #(rf/dispatch [::handlers/store-current-user current-user])} - "Remember Me"]] - - [ant/form-item - [common-views/drop-down-players sorted-players - ::handlers/set-current-user current-user]]])) - -(defn go-to-internal - [place] - (set! (.-hash js/location) place)) - -(def menu-config - [["add-game" "NEW GAME"] - ["rankings" "RANKINGS"] - ["stats" "STATS"] - ["games" "GAMES"]]) - -(defn navbar - [] - (let [league-name @(rf/subscribe [::handlers/league-name])] - [ant/layout-header - (into [ant/menu {:theme "dark" - :mode "horizontal"}] - - (concat [[ant/menu-item league-name] - [ant/menu-item [:a {:href "/"} "ALL LEAGUES"]]] - (for [[k s] menu-config - :let [hashed (str "#" k)]] - [ant/menu-item [:a {:on-click #(go-to-internal hashed)} - s]])))])) - -(defn root - [] - ;; this is kind of an antipattern for reframe - (rf/dispatch [::handlers/load-league]) - (rf/dispatch [::handlers/load-games]) - (rf/dispatch [::players-handlers/load-players]) - - (let [loading? @(rf/subscribe [::handlers/loading?]) - errors @(rf/subscribe [:failed])] - [:div.root - [navbar] - - (if errors - [common-views/errors] - [ant/layout-content - (if loading? - [ant/spin {:size "large"}] - [:div.content - #_[ant/card - [set-current-user]] - [current-user-notification] - [:div {:id "add-game"} - [game-form]] - [add-user-notification] - [results]])]) - [common-views/footer]])) + [re-frame.core :as rf])) \ No newline at end of file diff --git a/src/cljs/byf/league_detail/games_list.cljs b/src/cljs/byf/league_detail/games_list.cljs index 275cfe7..133ad0b 100644 --- a/src/cljs/byf/league_detail/games_list.cljs +++ b/src/cljs/byf/league_detail/games_list.cljs @@ -3,54 +3,4 @@ [byf.common.players :as players-handlers] [byf.league-detail.utils :refer [enumerate format-date]] [byf.league-detail.handlers :as handlers] - [antizer.reagent :as ant])) - -(def columns - [{:title "game #" - :dataIndex :game-idx} - - {:title "player" - :dataIndex :player-1} - - {:title "team" - :dataIndex :p1_using} - - {:title "goals" - :dataIndex :p1_points} - - {:title "player" - :dataIndex :player-2} - - {:title "team" - :dataIndex :p2_using} - - {:title "goals" - :dataIndex :p2_points} - - {:title "day" - :dataIndex :played_at}]) - -(defn rows - [] - (let [games @(rf/subscribe [::handlers/games-live-players]) - name-mapping @(rf/subscribe [::players-handlers/name-mapping]) - rev-games (-> games enumerate reverse)] - - (for [[idx {:keys [p1 p2] :as g}] rev-games] - (merge - (select-keys g - [:p1_using :p2_using :p1_points :p2_points]) - {:player-1 (get name-mapping p1) - :player-2 (get name-mapping p2) - :played_at (format-date (:played_at g)) - :game-idx idx})))) - -(defn games-table - [] - (let [loading? @(rf/subscribe [::handlers/loading?])] - [ant/table - {:columns columns - :dataSource (rows) - :pagination true - :loading loading? - :rowKey :game-idx}])) + [antizer.reagent :as ant])) \ No newline at end of file diff --git a/src/cljs/byf/league_detail/handlers.cljs b/src/cljs/byf/league_detail/handlers.cljs index 855559c..0d6fc19 100644 --- a/src/cljs/byf/league_detail/handlers.cljs +++ b/src/cljs/byf/league_detail/handlers.cljs @@ -82,10 +82,6 @@ (rf/reg-event-db ::k (setter [:game-config :k])) (rf/reg-event-db ::initial-ranking (setter [:game-config :initial-ranking])) -(defn uuid->name - [name-mapping vals] - (medley/map-keys #(get name-mapping %) vals)) - (rf/reg-sub ::add-user-notification (getter [:add-user-notification])) (rf/reg-event-db ::add-user-notification (fn [db _] @@ -278,17 +274,6 @@ (let [inner (fn [field v] (not (contains? dead-players (field v))))] (filter #(and (inner :p1 %) (inner :p2 %)) games)))) -(defn current-user-transform - [db] - (let [current-user (ck/get :user)] - (if (some? current-user) - ;;TODO: need to set the current user as well - ;;and maybe have a cascade effect there - (-> db - (assoc-in [:game :p1] current-user) - (assoc-in [:current-user] current-user)) - db))) - ;;TODO: improve this structure a bit (rf/reg-event-db ::initialize-db (fn [db _] diff --git a/src/cljs/byf/league_detail/mobile.cljs b/src/cljs/byf/league_detail/mobile.cljs index 7e88c33..3da2d2b 100644 --- a/src/cljs/byf/league_detail/mobile.cljs +++ b/src/cljs/byf/league_detail/mobile.cljs @@ -1,7 +1,2 @@ (ns byf.league-detail.mobile - (:require [antizer.reagent :as ant])) - -(defn root - [] - [ant/button {:size "large"} - "Add game"]) + (:require [antizer.reagent :as ant])) \ No newline at end of file diff --git a/src/cljs/byf/league_detail/notifications.cljs b/src/cljs/byf/league_detail/notifications.cljs index 4abc4ee..e52c0ed 100644 --- a/src/cljs/byf/league_detail/notifications.cljs +++ b/src/cljs/byf/league_detail/notifications.cljs @@ -1,26 +1,4 @@ (ns byf.league-detail.notifications (:require [antizer.reagent :as ant] [re-frame.core :as rf] - [byf.league-detail.handlers :as handlers])) - -(defn notification - [flag content] - (when flag - [:div - [ant/alert {:type "info" - :closable true - :showIcon true - :message content}]])) - -;; make this more generic to allow different position and different content -(defn add-user-notification - [] - (let [show-notification (rf/subscribe [::handlers/add-user-notification])] - (notification @show-notification - "Thank you, your game has been recorded"))) - -(defn current-user-notification - [] - (let [current-user-set (rf/subscribe [::handlers/current-user-notification])] - (notification @current-user-set - "Thanks, I'll remember it's you next time"))) + [byf.league-detail.handlers :as handlers]));; make this more generic to allow different position and different content diff --git a/src/cljs/byf/league_detail/rankings.cljs b/src/cljs/byf/league_detail/rankings.cljs index 5be5d91..776c933 100644 --- a/src/cljs/byf/league_detail/rankings.cljs +++ b/src/cljs/byf/league_detail/rankings.cljs @@ -5,143 +5,4 @@ [byf.utils :as utils] [reagent.core :as r] [byf.league-detail.handlers :as handlers] - [byf.common.players :as players-handlers])) - -(def form-size 7) - -(defn el-result - [idx result] - [:span - {:key idx - :class (str "result__element result__" (name result))} - (-> result name string/capitalize)]) - -(defn results-boxes - [results] - [:div.result__container - (map-indexed el-result (take-last form-size results))]) - -(def hide-show-all - [:span.hide__show__all - [:i.fas.fa-eye-slash - {:title "Hide All" - :on-click #(rf/dispatch [::handlers/hide-all])}] - - [:i.fas.fa-eye - {:title "Show All" - :on-click #(rf/dispatch [::handlers/show-all])}]]) - -(def kill-revive-all - [:span - [:i.fas.fa-skull - {:title "Kill All" - :on-click #(rf/dispatch [::handlers/kill-all])}] - - [:i.fas.fa-life-ring - {:title "Revive All" - :on-click #(rf/dispatch [::handlers/revive-all])}]]) - -(defn game-slider - [] - (let [games (rf/subscribe [::handlers/games-live-players]) - up-to-games (rf/subscribe [::handlers/up-to-games])] - - (fn [] - (let [up-to-current (if (some? @up-to-games) @up-to-games (count @games))] - [:div - [:divs - [ant/slider - {:type "range" - :min 0 - :max (count @games) - :value up-to-current - :class "slider" - :on-change #(rf/dispatch [::handlers/up-to-games %])}] - - [:span.chevrons - [ant/button {:on-click #(rf/dispatch [::handlers/prev-game])} "PREV"] - [:span up-to-current] - [ant/button {:on-click #(rf/dispatch [::handlers/next-game])} "NEXT"]]]])))) - -(defn format-float - [float-value] - (string/join "" (take 3 (str float-value)))) - -(def rankings-columns - [{:title "position" - :dataIndex :position} - - {:title "name" - :dataIndex :name} - - {:title "form" - :dataIndex :results - :render (fn [t _ _] - (r/as-element - (results-boxes t)))} - - {:title "W" - :dataIndex :won} - - {:title "D" - :dataIndex :drawn} - - {:title "L" - :dataIndex :lost} - - {:title "GF" - :dataIndex :goals-for} - - {:title "GA" - :dataIndex :goals-against} - - {:title "GR" - :dataIndex :goals-ratio} - - {:title "points" - :dataIndex :ranking - :render (fn [t _ _] (int t))}]) - -(defn ->ranking-row - [results stats name-mapping {:keys [id] :as item}] - (let [{:keys [wins losses draws points-done points-received]} (get stats id) - tot-games (+ wins losses draws) - gf (/ points-done tot-games) - ga (/ points-received tot-games)] - (when (pos? tot-games) - (assoc item - :name (name-mapping id) - :results (get results id) - :won wins - :lost losses - :drawn draws - :goals-for (format-float gf) - :goals-against (format-float ga) - :goals-ratio (format-float (/ gf ga)))))) - -(defn rankings-rows - [] - (let [name-mapping @(rf/subscribe [::players-handlers/name-mapping]) - results @(rf/subscribe [::handlers/results]) - stats @(rf/subscribe [::handlers/stats]) - sorted-rankings @(rf/subscribe [::handlers/rankings]) - active-players @(rf/subscribe [::players-handlers/active-players]) - filtered-rankings (filter #(active-players (:id %)) sorted-rankings) - rows (map (fn [i] (->ranking-row results stats name-mapping i)) filtered-rankings)] - - (map-indexed - (fn [idx item] - (assoc item :position (inc idx))) - (filter some? rows)))) - -(defn rankings-table - [] - (let [loading? @(rf/subscribe [::handlers/loading?])] - [:div - [game-slider] - [ant/table - {:columns rankings-columns - :dataSource (rankings-rows) - :pagination false - :loading loading? - :rowKey :position}]])) + [byf.common.players :as players-handlers])) \ No newline at end of file diff --git a/src/cljs/byf/league_detail/stats.cljs b/src/cljs/byf/league_detail/stats.cljs index cbed7dd..f8584d3 100644 --- a/src/cljs/byf/league_detail/stats.cljs +++ b/src/cljs/byf/league_detail/stats.cljs @@ -6,80 +6,4 @@ [byf.common.players :as players-handlers] [byf.league-detail.handlers :as handlers] [byf.league-detail.utils :refer [format-date]] - [clojure.spec.alpha :as s])) - -(def stats-page-length 5) - -(defn- truncate-float - [v] - (if (float? v) (int v) v)) - -(defn- percent - [v] - (str (int v) " %")) - -(def stats-config - {::stats-specs/highest-ranking - {:handler ::handlers/highest-rankings-best - :title "Highest Score" - :fields [{:k :player :v "name"} {:k :ranking :v "ranking"} {:k :time :v "time"}] - :transform {:time format-date :ranking truncate-float}} - - ::stats-specs/longest-winning-streak - {:handler ::handlers/longest-winning-streaks - :title "Longest Winning Streak" - :fields [{:k :player :v "name"} {:k :streak :v "streak"}]} - - ::stats-specs/longest-unbeaten-streak - {:handler ::handlers/longest-unbeaten-streaks - :title "Longest Unbeaten Streak" - :fields [{:k :player :v "name"} {:k :streak :v "streak"}]} - - ::stats-specs/highest-increase - {:handler ::handlers/highest-increase - :title "Highest Points increase" - :fields [{:k :player :v "name"} {:k :points :v "points"}] - :transform {:points truncate-float}} - - ::stats-specs/best-percents - {:handler ::handlers/best-percents - :title "Best Winning %" - :fields [{:k :player :v "name"} {:k :w :v "win %"} - {:k :d :v "draw %"} {:k :l :v "loss %"}] - - :transform {:w percent :d percent :l percent}}}) - -(defn to-column-defs - [stats-key] - (->> stats-config - stats-key - :fields - (map #(rename-keys % {:k :dataIndex :v :title})))) - -(defn- transform-row - [data tr] - (reduce-kv update data tr)) - -(defn stats-table - [columns rows] - (let [loading? @(rf/subscribe [::handlers/loading?])] - [ant/table - {:columns columns - :dataSource rows - :pagination {:default-page-size stats-page-length} - :loading loading?}])) - -(defn stats-component - [kw] - (let [{:keys [handler transform title]} (kw stats-config) - stats @(rf/subscribe [handler]) - active-player-names @(rf/subscribe [::players-handlers/active-players-names]) - filtered-stats (filter #(active-player-names (:player %)) stats) - transformed (map - #(transform-row % (or transform {})) - filtered-stats)] - - (s/assert kw stats) - [:div.stat - [:label.title title] - [stats-table (to-column-defs kw) transformed]])) + [clojure.spec.alpha :as s])) \ No newline at end of file diff --git a/src/cljs/byf/league_detail/utils.cljs b/src/cljs/byf/league_detail/utils.cljs index 5393461..ffd3dd7 100644 --- a/src/cljs/byf/league_detail/utils.cljs +++ b/src/cljs/byf/league_detail/utils.cljs @@ -1,10 +1 @@ -(ns byf.league-detail.utils) - -(defn format-date - [timestamp] - (.format (js/moment timestamp) "YYYY-MM-DD")) - -(defn enumerate - [xs] - ;; without sorting it only works up to 30 !! - (sort (zipmap (map inc (range (count xs))) xs))) +(ns byf.league-detail.utils) \ No newline at end of file diff --git a/src/cljs/byf/league_detail/views.cljs b/src/cljs/byf/league_detail/views.cljs index a466697..b0bfa6c 100644 --- a/src/cljs/byf/league_detail/views.cljs +++ b/src/cljs/byf/league_detail/views.cljs @@ -1,14 +1,3 @@ (ns byf.league-detail.views (:require [byf.league-detail.mobile :as mobile] - [byf.league-detail.desktop :as desktop])) - -(defn mobile? - [] - (< js/window.screen.availWidth 500)) - -(defn root - [] - ;; this is kind of an antipattern for reframe - (if (mobile?) - [desktop/root] - [desktop/root])) + [byf.league-detail.desktop :as desktop])) \ No newline at end of file diff --git a/src/cljs/byf/league_list/views.cljs b/src/cljs/byf/league_list/views.cljs index 8003724..65171dc 100644 --- a/src/cljs/byf/league_list/views.cljs +++ b/src/cljs/byf/league_list/views.cljs @@ -9,44 +9,4 @@ [byf.routes :as routes] [byf.shared-config :as config] [byf.utils :refer [classes]] - [re-frame.core :as rf])) - -(defn sign-up-button - "Generate a generic sign up button" - [provider] - [:a {:href "/oauth2/github"} - [:span {:class (classes ["fa" (str "fa-" provider)])}] - (str "Sign in with " (string/capitalize provider))]) - -(defn sign-in-block - [] - [:div - [sign-up-button "github"]]) - -(defn league-picker - [] - (let [leagues (rf/subscribe [::handlers/leagues])] - [ant/list - (for [{:keys [id name game_type]} @leagues] - [ant/list-item {:key id} - [:img {:width "70px" - :src (config/logo (keyword game_type))}] - - [:a {:href "#" - :on-click #(accountant/navigate! - (routes/path-for :league-detail :league-id id))} - name]])])) - -(defn root - [] - (let [authenticated? @(rf/subscribe [::auth/authenticated?])] - [:div.super - #_[common-views/errors] - (if authenticated? - (do (rf/dispatch [::handlers/load-leagues]) - [:div.section - [league-picker]]) - - [:div - [sign-in-block]]) - [common-views/footer]])) + [re-frame.core :as rf])) \ No newline at end of file diff --git a/src/cljs/byf/user/handlers.cljs b/src/cljs/byf/user/handlers.cljs index 1a1057f..28d1e17 100644 --- a/src/cljs/byf/user/handlers.cljs +++ b/src/cljs/byf/user/handlers.cljs @@ -2,9 +2,6 @@ (:require [byf.common.handlers :as common] [re-frame.core :as rf])) -(def db - {:opponent nil}) - (def page ::page-id) ;;TODO: pass the spec diff --git a/src/cljs/byf/user/views.cljs b/src/cljs/byf/user/views.cljs index 8e57c1c..e7afc94 100644 --- a/src/cljs/byf/user/views.cljs +++ b/src/cljs/byf/user/views.cljs @@ -11,18 +11,3 @@ ;; - suggested opponent ;; - personal stats ;; - best performing team - -(defn head-to-head - [] - (let [players (rf/subscribe [::players-handlers/players]) - head-to-head-wins (rf/subscribe [::handlers/head-to-head-wins])] - (fn [] - ;; show win draws and losses - [:div.form-group.opponent__input - [common-views/drop-down-players players ::handlers/opponent]]))) - -(defn root - [] - [:h2 "Hello Player detail page" - [:div.user__root - [head-to-head]]]) diff --git a/src/cljs/byf/utils.cljs b/src/cljs/byf/utils.cljs index 6e541c6..90307d5 100644 --- a/src/cljs/byf/utils.cljs +++ b/src/cljs/byf/utils.cljs @@ -1,23 +1,4 @@ (ns byf.utils "Various utility functions for Clojurescript" (:require [clojure.string :as str] - [re-frame.core :as rf])) - -(def min-width 500) - -(defn classes - [cls] - (str/join " " - (map name - (filter some? cls)))) - -(defn set-val - ([handler-key transform-fn] - #(rf/dispatch [handler-key (-> % .-target .-value transform-fn)])) - - ([handler-key] - (set-val handler-key identity))) - -(defn mobile? - [] - (< js/window.screen.availWidth min-width)) + [re-frame.core :as rf])) \ No newline at end of file diff --git a/src/cljs/byf/vega.cljs b/src/cljs/byf/vega.cljs index 6c722d7..befb125 100644 --- a/src/cljs/byf/vega.cljs +++ b/src/cljs/byf/vega.cljs @@ -1,49 +1,3 @@ (ns byf.vega (:require [cljsjs.vega] - [reagent.core :as reagent])) - -(def schema-url "https://vega.github.io/schema/vega-lite/v3.0.0-rc6.json") -(def vega-div-id "rankings-over-time__visualization") - -(defn rankings-vega-definition - [history domain] - {"$schema" schema-url - "width" 500 - "height" 500 - "description" "Rankings over time" - "data" {"values" history} - "mark" {"type" "line" - "point" {"tooltip" [{"field" "Player" "type" "Nominal"}, - {"field" "Result" "type" "Nominal"} - {"field" "Game" "type" "quantitative"} - {"field" "Time" "type" "Temporal"} - {"field" "Ranking" "type" "quantitative"}]}} - - "encoding" {"y" {"field" "Ranking" - "type" "quantitative" - "scale" {"domain" domain}} - - "color" {"field" "Player" - "type" "Nominal"} - - "x" {"field" "Time" - "type" "temporal"}}}) -(defn vega-view - [] - [:div.rankings-over-time - [:div {:id vega-div-id - :class vega-div-id}]]) - -(defn vega-update - [comp] - (let [[history domain] (rest (reagent/argv comp))] - (js/vegaEmbed (str "#" vega-div-id) - (clj->js (rankings-vega-definition history domain))))) - -(defn vega-inner - [] - (reagent/create-class - {:reagent-render vega-view - :component-did-update vega-update - :component-did-mount vega-update - :display-name "Rankings Over Time Inner"})) + [reagent.core :as reagent])) \ No newline at end of file diff --git a/test/clj/byf/api_test.clj b/test/clj/byf/api_test.clj index 50a9ba0..0ae495d 100644 --- a/test/clj/byf/api_test.clj +++ b/test/clj/byf/api_test.clj @@ -12,8 +12,6 @@ (defn- gen-uuid [] (UUID/randomUUID)) -(def sample-github-token (str (UUID/randomUUID))) - ;; this league is always present, which makes it easier to write tests using it (def sample-company-id (gen-uuid)) @@ -31,47 +29,6 @@ (use-fixtures :each (join-fixtures [db/wrap-test-db-call setup-league-fixture])) -(defn- make-admin-header - [] - (format "Basic %s" (-> (b64/encode (format "%s:%s" "admin" "password")) - (bytes->str)))) - -(defn authenticated-req - [request] - (-> request - (assoc-in sut/github-token-path sample-github-token))) - -(defn read-api-call - ([endpoint] - (read-api-call endpoint {})) - - ([endpoint args] - (-> (mock/request :get endpoint args) - authenticated-req - sut/app))) - -(defn- write-api-call - [endpoint content] - (let [full-api-path (str "/api" endpoint) - {:keys [status] :as response} - (-> (mock/request :post full-api-path content) - authenticated-req - sut/app)] - - (when-not (contains? #{201 401} status) - (println "bad response, got " response) - (throw (Exception. "bad response, should be #{201, 401}"))) - response)) - -(defn- store-users! - [] - (let [p1 {:name "bob" :email "email" :league_id sample-league-id} - p2 {:name "fred" :email "email" :league_id sample-league-id} - p1-id (db/add-player-full! p1) - p2-id (db/add-player-full! p2)] - - [p1-id p2-id])) - (deftest store-results-test (testing "Should be able to store results" (let [[p1-id p2-id] (store-users!) diff --git a/test/clj/byf/seed_test.clj b/test/clj/byf/seed_test.clj index 92f32e3..7fd3c50 100644 --- a/test/clj/byf/seed_test.clj +++ b/test/clj/byf/seed_test.clj @@ -7,14 +7,6 @@ (use-fixtures :each db/wrap-test-db-call) -(defn- count-table - [t] - (:count - (first - (db/wrap-db-call - (jdbc/query (db/db-spec) - (sql/format (db/count-sql t))))))) - (deftest seed-test (testing "Seeding should work with no errors on write" (sut/seed (sut/create-league!)) diff --git a/test/cljc/byf/algorithms/elo_test.cljc b/test/cljc/byf/algorithms/elo_test.cljc index cd0150b..c2fb30d 100644 --- a/test/cljc/byf/algorithms/elo_test.cljc +++ b/test/cljc/byf/algorithms/elo_test.cljc @@ -6,14 +6,6 @@ ;; define a more generic game representation, that doesn't require ;; some form of normalization -(def games - [[:a :b 1 0] - [:b :c 0.5 0.5] - [:a :c 0 1]]) - -(def initial-rankings - (sut/initial-rankings [:a :b :c])) - (deftest new-rating-test (testing "Should compute the new rating correctly" (are [d exp] (= exp (sut/expected d)) @@ -47,8 +39,6 @@ :d 1500} (sut/compute-rankings games [:a :b :c :d]))))) -(defn- avg [xs] (/ (apply + xs) (count xs))) - ;;TODO: can probably use checking instead (deftest average-not-changing (let [gs (repeatedly 100 gen/game-gen) diff --git a/test/cljc/byf/rankings_test.cljc b/test/cljc/byf/rankings_test.cljc index 817f305..1e8a157 100644 --- a/test/cljc/byf/rankings_test.cljc +++ b/test/cljc/byf/rankings_test.cljc @@ -4,39 +4,6 @@ #?(:clj [clojure.test :refer [deftest testing is]] :cljs [cljs.test :as t :refer-macros [deftest testing is]]))) -(def sample-game - {:p2 "edbebe16-dd1c-414e-b9b2-4c9e38d1928e" - :league_id "32ddffd6-d022-48ef-9720-9ff358a13798" - :p1_using "XU" - :p1 "fb6f256d-514b-479f-a70a-63987946de15" - :played_at "2017-01-24T00:31:50Z" - :id "e0b57b6a-ab45-4e67-bc9b-4e869af4ed7f" - :p1_points 0 - :p2_points 8 - :p2_using "rH" - :recorded_at "2019-01-20T10:03:31Z"}) - -(def sample-player - {:id "fb6f256d-514b-479f-a70a-63987946de15" - :name "John" - :user_id "e2015c5d-1f17-4cb6-84c1-35a75220ec25" - :league_id "32ddffd6-d022-48ef-9720-9ff358a13798" - :player_id "fb6f256d-514b-479f-a70a-63987946de15" - :id_2 "a05f39dc-2b7b-4aa7-95c1-bf7e79b52747" - :active true}) - -(def sample-player-2 - {:id "edbebe16-dd1c-414e-b9b2-4c9e38d1928e" - :name "Emily" - :user_id "e2015c5d-1f17-4cb6-84c1-35a75220ec25" - :league_id "32ddffd6-d022-48ef-9720-9ff358a13798" - :player_id "fb6f256d-514b-479f-a70a-63987946de15" - :id_2 "a05f39dc-2b7b-4aa7-95c1-bf7e79b52747" - :active true}) - -(def players [sample-player sample-player-2]) -(def games [sample-game]) - (deftest rankings-test (testing "Simple rankings computation" (is (= [{:id "edbebe16-dd1c-414e-b9b2-4c9e38d1928e" diff --git a/test/cljc/byf/stats_test.cljc b/test/cljc/byf/stats_test.cljc index 0cc9648..9a779b6 100644 --- a/test/cljc/byf/stats_test.cljc +++ b/test/cljc/byf/stats_test.cljc @@ -4,30 +4,6 @@ :cljs [cljs.test :as t :refer-macros [deftest testing is are]]))) -(def sample-result - {"fb6f256d-514b-479f-a70a-63987946de15" - [:l :d :w :l :w :w :w :d] - - "edbebe16-dd1c-414e-b9b2-4c9e38d1928e" - [:l :w :w :d]}) - -(def sample-mapping - {"fb6f256d-514b-479f-a70a-63987946de15" "Charlie" - "edbebe16-dd1c-414e-b9b2-4c9e38d1928e" "Fitz"}) - -(def history [{:ranking 1500 - :player "Emily" - :game-idx 0 - :time "2017-01-24T00:31:50Z" - :result "John vs Emily: (0 - 8)"} - - - {:ranking 1516 - :player "Emily" - :game-idx 1 - :time "2017-02-24T00:31:50Z" - :result "John vs Emily: (0 - 8)"}]) - (deftest highest-increase-test (testing "highest increase computation" (is (= [{:player "Emily", :points 16}]