aboutsummaryrefslogtreecommitdiff
path: root/src/index.cljs.hl
blob: 8ecbc8c6d3c5892ba2f19be9c0c196a4d5e70fd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(page "index.html"
  (:require [app.rpc :as rpc]))

(defc= scoreboard (merge (sorted-map) rpc/scoreboard))
(defc= problems (mapcat (fn [[id person]]
                          (map (partial vector id) (:problems person)))
                        scoreboard))
(defc= scores
       (reverse (sort
         (map (fn [[id person]]
                [(apply
                   +
                   (concat
                     (map (fn [[prob state]]
                            (if (and
                                  (= :solved state)
                                  (not (contains? (:problems person) prob)))
                              1
                              0))
                          (:scores person))
                     (map (fn [prob]
                            (if (some (fn [[id2 person2]]
                                        (and
                                          (= :solved
                                             (get (:scores person) prob))
                                          (= :solved
                                             (get (:scores person2) prob))
                                          (not= id id2)))
                                      scoreboard)
                              1
                              0))
                          (:problems person))))
                 id])
              scoreboard))))

(rpc/init)

(html
  (head
    (link :rel "stylesheet" :type "text/css" :href "css/main.css")
    (title "Potluck CTF"))
  (body
    (h1 "Potluck CTF")
    (text "Login/Register?")
    (h2 "Scoreboard")
    (table
      (thead
        (tr
          (th)
          (th)
          (loop-tpl :bindings [probs (cell= (partition-by first problems))]
                    (th :text (cell= (:name (get scoreboard
                                                 (first (first probs)))))
                        :colspan (cell= (count probs)))))
        (tr
          (th "Player")
          (th "Score")
          (loop-tpl :bindings [[owner name] problems]
                    (th :text name))))
      (tbody
        (loop-tpl :bindings [[score id] scores]
                  (let [player (cell= (get scoreboard id))]
                    (tr
                      (td :text (cell= (:name player)))
                      (td :text score)
                      (loop-tpl :bindings [[owner _name] problems]
                                (td :text (cell=
                                            (name (get (:scores player)
                                                       _name
                                                       :unsolved))))))))
        ))))

;; vim: set expandtab ts=2 sw=2 filetype=clojure :