Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaCrotti committed Jan 31, 2020
1 parent 1007e83 commit ff03232
Show file tree
Hide file tree
Showing 38 changed files with 21 additions and 1,155 deletions.
25 changes: 1 addition & 24 deletions src/clj/byf/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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)))
9 changes: 0 additions & 9 deletions src/clj/byf/datascript.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down
11 changes: 0 additions & 11 deletions src/clj/byf/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 :*)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 1 addition & 12 deletions src/clj/byf/dev.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

(:gen-class))

(defonce system (atom {}))

(defmethod ig/init-key :server/figwheel
[_ {:keys [build] :as opts}]
(log/info "Starting Figwheel")
Expand All @@ -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"))
10 changes: 1 addition & 9 deletions src/clj/byf/fixtures.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
80 changes: 1 addition & 79 deletions src/clj/byf/seed.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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`
8 changes: 0 additions & 8 deletions src/cljc/byf/algorithms/elo.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/cljc/byf/games.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
21 changes: 1 addition & 20 deletions src/cljc/byf/generators.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
2 changes: 0 additions & 2 deletions src/cljc/byf/routes.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
14 changes: 0 additions & 14 deletions src/cljc/byf/shared_config.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
49 changes: 1 addition & 48 deletions src/cljs/byf/admin/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"
: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]))
3 changes: 0 additions & 3 deletions src/cljs/byf/auth.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
Loading

0 comments on commit ff03232

Please sign in to comment.