Permalink
Browse files

removed old/unused stuff

  • Loading branch information...
1 parent 32995b5 commit 6c2b1d3957f00641b4d677a68b110b358511398f @dalkvist committed Mar 27, 2013
Showing with 1 addition and 147 deletions.
  1. +1 −25 src/bf3/core.clj
  2. +0 −122 src/bf3/stats.clj
View
@@ -6,7 +6,6 @@
hiccup.page-helpers
[bf3.db :only [get-ts-users get-bl-users get-battle]]
[bf3.info :only[battle-info parse-info merge-infos]]
- [bf3.stats :only [get-stats battleday-roster get-battleday]]
[cheshire.core :only [encode generate-string]])
(:require (compojure [route :as route])
(ring.util [response :as response])
@@ -16,7 +15,6 @@
[noir.server :as server]
[clojure.string :as s]
[gaka [core :as gaka]]
- [bf3.ts :as ts]
[bf3.bl :as bl]
[clj-http.client :as client]
[clojure.core.memoize :as mem]
@@ -355,28 +353,6 @@
(response/redirect "/gc/"))
(defpage "/gc/" [] (layout "GC stuff"))
-(defpage "/gc/roster" []
- (let [roster (battleday-roster (get-stats (get-bl-users)))]
- (layout [:h1 "roster for battleday " (get-battleday)]
- (into [:div#roster]
- (for [server roster]
- (list [:h2 (str "server " (->> (filter #(= (last %) (->> server :server)) bl/server-ids)
- first key))]
- (->> (:users server)
- (map #(if (get-ki-info %)
- (hash-map :origin-name % :army "KI")
- (if (get-ta-info %)
- (hash-map :origin-name % :army "TA")
- (hash-map :origin-name % :army "HiT (not ki or ta)")
- )))
- (sort-by :army)
- (partition-by :army)
- reverse
- (map (fn [army] (list [:h3 (->> army first :army)]
- (->> army
- (map #(:origin-name %) )
- (interpose "<br/>"))))))))))))
-
(defn- get-battle-page [gameid & {:keys [start end] :or {start false end false}}]
(->> (client/get (str "http://work.dalkvist.se:8081/get-battle/" gameid
"?" (encode-params
@@ -486,7 +462,7 @@
(res/json (->> server bf3.bl/get-live-info parse-info )))
(defpage "/gc/update" []
- (layout (do (bl/save-live-users) (ts/save-live-users)
+ (layout (do (bl/save-live-users)
"loggin attendance on GC server")))
(defpage "/gc/stalking" []
View
@@ -1,122 +0,0 @@
-(ns bf3.stats
- (:require [clj-http.client :as client]
- [clojure.string :as s]
- [clojure.core.cache :as cache]
- [clojure.core.memoize :as mem]
- [clj-time.core :as time]
- [clj-time.format :as time-format]
- [bf3.bl :as bl])
- (:use [cheshire.core]
- [net.cgrand.enlive-html]
- [bf3.db])
- (:import java.net.URL))
-
-(def ^{:dynamic true} *cache-time* (* 2 60 1000))
-
-(def ^{:dynamic true} *debug* false)
-
-(defn debug [& messages]
- (when *debug*
- (println messages)))
-
-(defn- inc-date [dt]
- (time/plus dt (time/days 1)))
-
-(defn- dec-date [dt]
- (time/minus dt (time/days 1)))
-
-(defn- future-dates [& {:keys [dt]}] (iterate inc-date (if-not dt (time/now) dt)))
-
-(defn- prev-dates [& {:keys [dt]}] (iterate dec-date (if-not dt (time/now) dt)))
-
-(defn- battleday? [dt] (= 6 (time/day-of-week dt)))
-
-(defn get-battleday
- "Return the a battledat interval, :prev for the latest one, and :next for the next one"
- ([& {:keys [next weeks] :or {next false weeks 1}}]
- (->> (time/now) (time/day-of-week)
- ((fn [weekday] (if next
- (first (drop (dec weeks) (filter battleday? (future-dates ))))
- (first (drop (dec weeks) (filter battleday? (prev-dates )))))))
- (#(time/date-time (time/year %) (time/month %) (time/day %) 18 0 0 0))
- (#(time/interval % (time/plus % (time/hours 6) ))))))
-
-
-(defn- parse-stats [rows]
- (let [users (atom {})
- stats (atom {})
- current-time (:time (last rows))]
-
- (doseq [server-rows (->> rows (sort-by :server) (partition-by :server))]
- (doseq [row (sort-by :time server-rows)]
- ;;logg all online users
- (doseq [user (:users row)]
- (if (contains? @users user)
- (swap! users assoc-in [user :last-seen] (:time row))
- (swap! users assoc user {:first-seen (:time row) :server (:server row)})
- ))
-
- ;;update offline users
- (doseq [[user stat] @users]
- (when (not-any? #(= % user) (:users row))
- (swap! stats assoc user (conj (get @stats user []) stat))
- (swap! users dissoc user)))
- )
-
- ;;update users currently online
- (doseq [[user stat] @users]
- (swap! stats assoc user (conj (get @stats user [])
- (if (nil? (:last-seen stat))
- (assoc stat :last-seen current-time)
- stat)))
- (swap! users dissoc user))
-
- ;; (doseq [user @users]
- ;; ;; (println "u:" user "\nid:" (key user) "\nstats:" (val user))
- ;; (swap! intervals merge (get @intervals (key user) {})
- ;; {(key user) (first (for [server (val user)]
- ;; (do ;; (println "s:" server "\nsid:" (key server) "\nss:" (val server))
- ;; (if-not (:last-seen (val server))
- ;; {(key server) (assoc (val server) :last-seen current-time)}
- ;; (apply hash-map server)))))})
- ;; (swap! users dissoc (key user)))
- )
- @stats))
-
-(defn- get-live-stats
- "get user stats from the coll"
- ([coll]
- (sort-by first (parse-stats coll))))
-
-(def get-stats (mem/memo-ttl get-live-stats *cache-time*))
-
-(defn- stat-interval [stat]
- (time/interval (time-format/parse (:first-seen stat))
- (time-format/parse (:last-seen stat))))
-
-(defn- attended-battleday [& {:keys [stats weeks]}]
- (filter #(time/overlaps? (get-battleday :weeks weeks)
- (stat-interval %)) stats))
-
-g(defn- get-active-users [stats]
- (->> stats (map :user) distinct (pmap #(->> % bl/get-username ))
- (filter #(not-empty %))))
-
-;;TODO take used servers as list, alt check if bl can give private flag
-(defn- roster-last-battleday ([] (roster-last-battleday (test-stats)))
- ([stats & {:keys [weeks] :or {weeks 1}}]
- (->> stats
- (mapcat #(for [stat (last %)]
- (assoc stat :user (first %))))
- (attended-battleday :weeks weeks :stats)
- (filter (fn [s] (some #(= % (:server s)) (vals bl/server-ids))))
- (sort-by :server)
- (partition-by :server)
- (map #(hash-map :server (:server (first %))
- :users (->> %
- get-active-users
- (map s/lower-case)
- distinct
- sort))))))
-
-(def battleday-roster (mem/memo-ttl roster-last-battleday *cache-time*))

0 comments on commit 6c2b1d3

Please sign in to comment.