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
(defn come-back? [match-to-fix] | |
(let [match (fix-match match-to-fix) | |
first-scored-side (first-scored-side match) | |
winner-side (winner-side match)] | |
(and (not (nil? winner-side)) | |
(not= winner-side first-scored-side)))) |
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
(defn own-goal? [event] | |
(= "goal-own" (:type_of_event event))) | |
(defn own-goals [events] | |
(->> events (filter own-goal?))) | |
(defn remove-own-goals [events] | |
(remove own-goal? events)) | |
(defn fix-match [match-to-fix] |
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
(defn teams [match] | |
(select-keys match [:home_team_country :away_team_country :winner])) |
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
(defn winner-side [match] | |
(let [winner (:winner match)] | |
(cond | |
(= winner (:home_team_country match)) :home | |
(= winner (:away_team_country match)) :away))) | |
(defn come-back? [match] | |
(let [first-scored-side (first-scored-side match) | |
winner-side (winner-side match)] | |
(and (not (nil? winner-side)) |
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
(defn team-goal-times [events side] | |
(->> events | |
(filter goal?) | |
(map :time) | |
(map part-and-time) | |
(map vector (repeat side)))) |
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
(defn first-scored-side [match] | |
(let [goal-times | |
(concat | |
(team-goal-times (:home_team_events match) :home) | |
(team-goal-times (:away_team_events match) :away))] | |
(->> goal-times (sort-by second) first first))) |
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
(require '[clojure.string :as string]) | |
(defn goal-time [t] | |
(->> | |
(string/split t #"\+") | |
(map string/trim) | |
(map #(string/replace % #"'" "")) | |
(map #(Integer/parseInt %)) | |
(reduce +))) |
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
(defn goal? [e] | |
(let [type (:type_of_event e)] | |
(or (= "goal" type) | |
(= "goal-penalty" type) | |
(= "goal-own" type)))) |
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
(->> lst | |
(map op1) | |
(map op2) | |
(filter p1) | |
first) | |
lst.stream() | |
.map(op1) | |
.map(op2) | |
.filter(p1) |
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
(ns worldcup.matches | |
(:require | |
[clj-http.client :as http])) | |
(def api-root "https://worldcup.sfg.io") | |
(defn get-all-matches [] | |
(-> | |
(http/get (str api-root "/matches") {:as :json}) | |
:body)) |