Last active
June 18, 2016 17:35
-
-
Save sooheon/4b034ea56af9981b5ad337fe01fd0f05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; planck script for checking dcss win stats. | |
;; `brew install planck', then run this script with `planck crawl_won.cljs $USER'. | |
;; Currently only checks default location of logfile. | |
(ns crawl-won | |
(:require [planck.core :refer [*command-line-args* slurp]] | |
[clojure.string :as str] | |
goog.string.format)) | |
(defn filepath [user] | |
(goog.string.format "/Users/%s/Library/Application Support/Dungeon Crawl Stone Soup/saves/logfile" user)) | |
(defn parse-line [line] | |
(->> (str/split line #":") | |
(filter #(str/includes? % "=")) | |
(map #(str/split % #"=")) | |
(map (fn [[k v]] | |
[(keyword k) v])) | |
(into {}))) | |
(defn main [user] | |
(let [games (->> (filepath (or user "sooheon")) | |
slurp | |
str/split-lines | |
(map parse-line)) | |
total-games (count games) | |
wins (filter #(= (:ktyp %) "winning") games) | |
winning-chars (->> (frequencies (map :char wins)) | |
(map (fn [[k v]] (goog.string.format "%sx%s" v k))) | |
(str/join " ")) | |
win-ratio (double (* 100 (/ (count wins) total-games)))] | |
(println | |
(goog.string.format "You have won %s times in %s games (%.2f%%): %s" | |
(count wins) | |
total-games | |
win-ratio | |
winning-chars)))) | |
(main (first *command-line-args*)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment