1 Commits
v2.0 ... dev

Author SHA1 Message Date
94ae848e52 #9 post filter dates
Some checks failed
Compile and test using leiningen / Run tests (push) Has been cancelled
2026-02-24 00:00:31 +01:00
2 changed files with 63 additions and 31 deletions

View File

@@ -17,6 +17,7 @@
(pp/pprint params)
(println "Positional args:" (s/join "," (:lambdaisland.cli/argv params))))
(defn cmd-check-playing
"Check if the player is playing right now."
[player-name player-tag & {:keys [lol tft template continuous every-seconds max header]
@@ -52,6 +53,8 @@
(cmd-check-playing "Walid Georgey" "EUW") ;; This kills the REPL
(cmd-check-playing "Walid Georgey" "EUW" :continuous true :max 2) ;; Infinite loop if max is nil
)
(defn print-table
[matches-data]
(let [no-participants (map #(dissoc % :participants) matches-data)
@@ -132,37 +135,6 @@
:winner false}]
":"))
(defn add-calculated-data
[puuid match-data]
(-> match-data
(assoc :winner (player-won? puuid match-data))
(assoc :champion (:champion (filter-by-player puuid match-data)))
(assoc :placement (:placement (filter-by-player puuid match-data)))
))
(defn get-matches
[player-name player-tag & {:keys [lol tft since until max]
:or {lol true
tft true}
:as params}]
(let [call-params (cond-> {}
max (assoc :count max)
since (assoc :startTime (/ (process-time-literal since) 1000))
until (assoc :endTime (/ (process-time-literal until) 1000)))
lol-puuid (get-lol-puuid player-name player-tag)
tft-puuid (get-tft-puuid player-name player-tag)]
(when @debug (println "Params") (pp/pprint call-params))
(cond-> []
lol (concat (map #(add-calculated-data lol-puuid (get-lol-match-data %))
(get-lol-matches lol-puuid call-params)))
tft (concat (map #(add-calculated-data tft-puuid (get-tft-match-data %))
(get-tft-matches tft-puuid call-params))))))
(comment
(reset! debug true)
(get-matches "Walid Georgey" "EUW" :max 3))
(defn cmd-show-matches
"Show basic info about matches played by player"

View File

@@ -2,6 +2,7 @@
(:require [rcorral.api.core :refer :all]
[rcorral.date-util :refer :all]
[riot.riot-api :refer :all]
[clojure.pprint :as pp]
[tick.core :as t])
(:import [java.util Date])
(:gen-class))
@@ -62,12 +63,25 @@
(first (filter #(= (:puuid %) puuid) (:participants match-data))))
(defn filter-by-start-timestamp
[ts match-data]
(when @debug (println "filter by start:" ts))
(filter #(< ts (:start %)) match-data))
(defn filter-by-end-timestamp
[ts match-data]
(when @debug (println "filter by end:" ts))
(filter #(> ts (:end %)) match-data))
(defn player-won?
[puuid match-data]
(if (and puuid match-data)
(:win (filter-by-player puuid match-data))
(do (println "Invalid puuid or match data") false)))
(defn player-alive?
[puuid participants]
(let [player-data (first (filter #(= (:puuid %) puuid) participants))
@@ -168,6 +182,52 @@
1767819383643
)
(defn filter-by-dates
"This is a workaround for a bug in the API"
[params match-data]
(if (some? match-data)
(cond->> match-data
(some? (:startTime params)) (filter-by-start-timestamp (* 1000 (:startTime params)))
(some? (:endTime params)) (filter-by-end-timestamp (* 1000 (:endTime params))))
match-data))
(defn add-calculated-data
[puuid match-data]
(-> match-data
(assoc :winner (player-won? puuid match-data))
(assoc :champion (:champion (filter-by-player puuid match-data)))
(assoc :placement (:placement (filter-by-player puuid match-data)))))
(defn get-matches
[player-name player-tag & {:keys [lol tft since until max]
:or {lol true
tft true}
:as params}]
(let [call-params (cond-> {}
max (assoc :count max)
since (assoc :startTime (/ (process-time-literal since) 1000))
until (assoc :endTime (/ (process-time-literal until) 1000)))
lol-puuid (get-lol-puuid player-name player-tag)
tft-puuid (get-tft-puuid player-name player-tag)]
(when @debug (println "get-matches Params") (pp/pprint call-params))
(cond-> []
lol (concat (filter-by-dates
call-params (map #(add-calculated-data lol-puuid (get-lol-match-data %))
(get-lol-matches lol-puuid call-params))))
tft (concat (filter-by-dates
call-params (map #(add-calculated-data tft-puuid (get-tft-match-data %))
(get-tft-matches tft-puuid call-params)))))))
(comment
(reset! debug true)
(get-matches "Walid Georgey" "EUW" :max 3 :tft false)
)
;; Check if it's playing
(defn is-playing-lol?