Skip to content

Instantly share code, notes, and snippets.

@EvanZ
Created August 10, 2014 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EvanZ/f18c9091dbb63c4b55c9 to your computer and use it in GitHub Desktop.
Save EvanZ/f18c9091dbb63c4b55c9 to your computer and use it in GitHub Desktop.
nba dsl
(ns flambo.clojure.spark.demo
(:require [flambo.conf :as conf])
(:require [flambo.api :as f])
(:require [clojure.data.json :as json]))
(def c (-> (conf/spark-conf)
(conf/master "local[*]")
(conf/app-name "nba_dsl")))
(def sc (f/spark-context c))
(def plays (f/text-file sc "/Users/evanzamir/Code/Clojure/flambo-nba/resources/plays.json")) ;; returns an unrealized lazy dataset
(defn field-goals-made-by-player
[team p]
(let
[fgm
(-> p
(f/map (f/fn [x] (json/read-str x :key-fn keyword)))
(f/filter (f/fn [x] (and (= "fga" (:type x))
(= 3 (:value x))
(= true (:made x))
(= team (:team x)))))
(f/map (f/fn [x] [(.toUpperCase (:shooter x)) 1]))
(f/reduce-by-key (f/fn [x y] (+ x y)))
f/collect)]
(clojure.pprint/pprint (sort-by last > fgm))))
(field-goals-made-by-player "Warriors" plays)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment