88
BigData avec Incanter et Clojure JUG Summer Camp 2012 Claude Falguière @cfalguiere goo.gl/4mmJQ 1 1 jeudi 13 septembre 2012

Incanter bigdata jsc2012

Embed Size (px)

DESCRIPTION

Présentation BigData avec Incanter et Clojure au JUG Summer Camp 2012. La version video des slides est sur YouTube http://youtu.be/a5aUrGOWPK0

Citation preview

Page 1: Incanter bigdata jsc2012

BigData avec Incanter et ClojureJUG Summer Camp 2012

Claude Falguière @cfalguiere

goo.gl/4mmJQ1

1jeudi 13 septembre 2012

Page 2: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

AU PROGRAMME

2

Lire et explorer des données

Faire un job MapReduce Hadoop

Générer un rapport HTML

Stocker les données dans MongoDB

Construire un projet Clojure

avec Clojure

2jeudi 13 septembre 2012

Page 3: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

VOTRE MISSION SI VOUS L’ACCEPTEZ ...

3

filtrage des erreurstransformer les donnéesregrouper par catégories

charts, distributions, corrélations

500 utilisateurs x 5h de test environ 1 000 000 relevés

rapports d’analyse de tests de performance

3jeudi 13 septembre 2012

Page 4: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

INCANTER

4

+=Math, Stats, Graps

4jeudi 13 septembre 2012

Page 5: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

INCANTER

5

DSL

manipulation de matrices et tables

statistiquescharts

modèlestest d’hypothèse

5jeudi 13 septembre 2012

Page 6: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

INCANTER

6

Motivation pour se mettre à Clojure Langage Fonctionnel

Ecosystème JavaNetlib

Parallel ColtJFreeChart

6jeudi 13 septembre 2012

Page 7: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

CLAUDE FALGUIERE

@cfalguiere

7

goo.gl/4mmJQ

http://cfalguiere.wordpress.com

7jeudi 13 septembre 2012

Page 8: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

ET VOUS ?

8

? ? ?

8jeudi 13 septembre 2012

Page 9: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere9

Petit rappel Clojure

9jeudi 13 septembre 2012

Page 10: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

HELLO WORLD

10

(def conference "JUG Summer Camps")(println "Hello" conference)

(println "Hello JUG Summer Camp")

(count (str "Hello" conference))

-> "Hello JUG Summer Camp"

10jeudi 13 septembre 2012

Page 11: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LES NOMBRES

11

(+ 1 2 3) -> 7

(= 2 (+ 1 1)) -> true

(+ 4 (* 2 3)) -> 10

11jeudi 13 septembre 2012

Page 12: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

Lire et explorer des données

12

12jeudi 13 septembre 2012

Page 13: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

SE LANCER

13

La voie du novice

1) downloader Incanter

2) lancer le REPL

13jeudi 13 septembre 2012

Page 15: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

PREMIER SCRIPT

15

15jeudi 13 septembre 2012

Page 16: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LIRE DES DONNÉES

16

(def ds (read-dataset "readings.csv" :header true))

équivalent pour Excel

(use '(incanter core io stats charts))

(save ds "./data.csv")

16jeudi 13 septembre 2012

Page 17: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LES COLLECTIONS

17

(def colors ["red" "magenta" "orange"])

(def colors ‘("red" "magenta" "orange"))

,

(def colors #{"red" "magenta" "orange"})

Clojure

17jeudi 13 septembre 2012

Page 18: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LES COLLECTIONS

18

MatrixDataset

Incanter

18jeudi 13 septembre 2012

Page 19: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LES MAPS

19

(def conf {:name "JUG Summer Camp" :location "La Rochelle" })

,

Clojure

19jeudi 13 septembre 2012

Page 20: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

JEU DE DONNÉES

20

t lb ts s rc shop srch userId ...

754 "SU01-HomePage-Page" 1330419301862 "true" 200 "MAF" "gants" "PT1022809551"

20jeudi 13 septembre 2012

Page 21: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LES COLONNES

21

user>($ :t ds)

user> (mean ($ :t ds)) 994,75

21jeudi 13 septembre 2012

Page 22: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

QUANTILE 95%

22

(quantile ($ :t ds) :probs [0.95])

Temps maximum pour 95% des relevés

911.1758241758242

22jeudi 13 septembre 2012

Page 23: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

($ [:lb :t :shop] ds )

LES COLONNES

23

(view ($ [:lb :t :shop] ds )) ->

23jeudi 13 septembre 2012

Page 24: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LES LIGNES

24

($where {:s "true"} ds) -> les lignes OK

24jeudi 13 septembre 2012

Page 25: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

($where {:s "true" ds)

LES LIGNES

25

($where {:s "true" :shop {:$in #{"MAF", "FAB"}} ds)

($where {:s "true" :shop {:$in #{"MAF", "FAB"}} :t {:$gt 3000 :$lt 5000}} ds)

25jeudi 13 septembre 2012

Page 26: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

WITH-DATA

26

($where {:shop "MAF"} ds)

($ :t ($where {:shop "MAF"} ds))

(view ($ :t ($where {:shop "MAF"} ds)))

(with-data ds

(view ($ :t ($where {:shop "MAF"} ))))ds

26jeudi 13 septembre 2012

Page 27: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

INCANTER CHARTS

27

Time-series

Histograms

Bar charts

Box Plot

Scatter Plot

27jeudi 13 septembre 2012

Page 28: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

(time-series-plot :ts :t :data ds)

(view (time-series-plot :ts :t :data ds))

(view (time-series-plot :ts :t :data ds :title "Readings" :x-label "time" :y-label "resp. time (ms)" :legend true :series-label "duration ms"))

28jeudi 13 septembre 2012

Page 29: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

(time-series-plot :ts :t :data ds :title "Readings" :x-label "time" :y-label "resp. time (ms)" :legend true :series-label "duration ms" )

29

(doto (time-series-plot :ts :t :data ds :title "Readings" :x-label "time" :y-label "resp. time (ms)" :legend true :series-label "duration ms" ) (add-lines ts (repeat 3000) :series-label "threshold") (set-stroke-color java.awt.Color/blue :series 0) (set-stroke :width 1 :series 0) (set-stroke-color java.awt.Color/red :series 1) (set-stroke :width 3 :series 1) view)

29jeudi 13 septembre 2012

Page 30: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

(time-series-plot :ts :t :data ds :title "Readings" :x-label "time" :y-label "resp. time (ms)" :legend true :series-label "duration ms" )

(time-series-plot...

DOTO

30

(add-lines (time-series-plot...

(set-stroke-color (add-lines (time-series-plot...

(view (set-stroke-color (add-lines (time-series-plot...

(time-series-plot :ts :t :data ds :title "Readings" :x-label "time" :y-label "resp. time (ms)" :legend true :series-label "duration ms" ) (add-lines ts (repeat 3000) :series-label "threshold")

(time-series-plot :ts :t :data ds :title "Readings" :x-label "time" :y-label "resp. time (ms)" :legend true :series-label "duration ms" ) (add-lines ts (repeat 3000) :series-label "threshold") (set-stroke-color java.awt.Color/blue :series 0)

(time-series-plot :ts :t :data ds :title "Readings" :x-label "time" :y-label "resp. time (ms)" :legend true :series-label "duration ms" ) (add-lines ts (repeat 3000) :series-label "threshold") (set-stroke-color java.awt.Color/blue :series 0) view

(doto (time-series-plot :ts :t :data ds :title "Readings" :x-label "time" :y-label "resp. time (ms)" :legend true :series-label "duration ms" ) (add-lines ts (repeat 3000) :series-label "threshold") (set-stroke-color java.awt.Color/blue :series 0) view)

30jeudi 13 septembre 2012

Page 31: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

REGROUPEMENT

31

(def groups ($group-by :shop ds))

{ "MAF" "FAB" }{ {:shop "MAF"} {:shop "FAB"} }

31jeudi 13 septembre 2012

Page 32: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

(get groups {:shop "MAF"})

LIRE UN GROUPE

32

32jeudi 13 septembre 2012

Page 33: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

$ROLLUP

33

user> ($rollup count :t :shop ds)

Applique une fonction à chaque entrée d’un $group-by

fonction regroupement[:shop :t]["MSK" 170]["KIE" 76]["OIB" 342]["FAB" 171]...

33jeudi 13 septembre 2012

Page 34: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

MOYENNE

34

user> ($rollup mean :t :lb ds)

Moyenne par groupe

[:lb :t]["SU61-BrowseCat2-Page" 911.1758241758242]["SU43-Paiment-Page" 1770.6004566210045]["SU42-DeliveryAndBilling-Page" 732.0340136054422]["SU41-CustomerDetails-Page" 608.2222222222222]...

34jeudi 13 septembre 2012

Page 35: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

($rollup count :t :shop ds)

user>(view (bar-chart :shop :t :vertical false :data ($rollup count :t :shop ds)))

DIAGRAMMES EN BARRES

35

35jeudi 13 septembre 2012

Page 36: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

(histogram :t :data ds)

ENREGISTRER LES CHARTS

36

(save (histogram :t :data ds) "histogram.png")

36jeudi 13 septembre 2012

Page 37: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

REJOUER LE SCRIPT

37

(use '(incanter core io stats charts))(def ds (read-dataset "../data/readings.csv" :header true) )(save (histogram :ts :t :data ds) "histogram.png")(println ($rollup mean :t :lb ds))

analyse.clj

user>(load-file "analyse.clj")

37jeudi 13 septembre 2012

Page 38: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

ET ENSUITE ...

38

Les limitations du REPL seul- difficile d’écrire des commandes complexes- pas de tests unitaires - que les libs fournies dans l’uberjar incanter

lein ...

38jeudi 13 septembre 2012

Page 39: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere39

Construire un projet Clojure

39jeudi 13 septembre 2012

Page 40: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

L’ECOSYSTEME CLOJURE

40

build et gestion de dépendance lein (leiningen)

repos Mavenclojars, sonatype

tests unitairesclojure.test (built-in), midge

intégration avec les IDEswank, jark

40jeudi 13 septembre 2012

Page 41: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

L’ATELIER

41

REPL + editeur de texteou

Emacs + Slime + SwankEclipse + CounterClockWiseIDEA + La Clojure + LeiningenNetbeans + EnclojureVim + VimClojure

41jeudi 13 septembre 2012

Page 42: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

SE LANCER

42

La voie du gourou

installer leiningen

lein new myproject

configurer project.clj

lein <task>

42jeudi 13 septembre 2012

Page 43: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

NEW

43

demo classes lib project.clj src demo core.clj test demo test core.clj

demo classes lib project.clj src demo core.clj test demo test core.clj

43jeudi 13 septembre 2012

Page 44: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

(defproject demo "1.0.0-SNAPSHOT" :description "demos incanter " )

PROJECT.CLJ

44

(defproject demo "1.0.0-SNAPSHOT" :description "demos incanter" :dependencies [[org.clojure/clojure "1.3.0"] [incanter "1.3.0"] ] )

(defproject demo "1.0.0-SNAPSHOT" :description "demos incanter" :dependencies [[org.clojure/clojure "1.3.0"] [incanter "1.3.0"] ] :dev-dependencies [[swank-clojure "1.4.2"]])

44jeudi 13 septembre 2012

Page 45: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

myproject classes lib project.clj

.m2 repository

DEPENDANCES

45

>lein deps

Clojars

Sonatype.m2 repository incanter incanter 1.3.0 incanter-1.3.0.jar

demo classes lib incanter-1.3.0.jar project.clj

45jeudi 13 septembre 2012

Page 46: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

TEST UNITAIRES

46

(deftest test-f1 (is 6 (f1 3)))

(defn f1 [s] (* 2 s))

clojure.test (built-in)

46jeudi 13 septembre 2012

Page 47: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

NAMESPACES

47

(ns demo.test.core (:use demo.core) (:use clojure.test))

(deftest test-f1 (is 6 (f1 3)))

(ns demo.core)

(defn f1 [s] (* 2 s))

demo classes lib project.clj src demo core.clj test demo test core.clj

47jeudi 13 septembre 2012

Page 48: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

RECHERCHER PAR DATE

48

user> (view ($where {:timestamp {:$gt start-time :$lt end-time}} ds)) user> (let [ start-time end-time ] (view ($where {:timestamp {:$gt start-time :$lt end-time}} ds)))

user> (let [ start-time (date-time 2012 02 28 8 55) ] (view ($where {:timestamp {:$gt start-time :$lt end-time}} ds)))

user> (let [ start-time (date-time 2012 02 28 8 55) end-time (date-time 2012 02 28 8 57) ] (view ($where {:timestamp {:$gt start-time :$lt end-time}} ds)))

(ns demo.utils (:use [clj-time.core :only date-time]) )

48jeudi 13 septembre 2012

Page 49: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

TEST TIME

49

(deftest test-readable-timestamp (is ) )

(deftest test-readable-timestamp (is (= 2012 (year adate ))) )

(deftest test-readable-timestamp (let [ result (readable-timestamp ds) ] (is (= 2012 (year (sel result :rows 0 :cols :timestamp ))))))

(deftest test-readable-timestamp (let [ ds (dataset [:ts] [{:ts 1330418007548} {:ts 1330418007549}]) result (readable-timestamp ds) ] (is (= 2012 (year (sel result :rows 0 :cols :timestamp ))))))

49jeudi 13 septembre 2012

Page 50: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

MAPPER UNE COLONNE

50

($map fct-to-date :ts ds )

50jeudi 13 septembre 2012

Page 51: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

CLJ-TIME (JODA)

51

(coerce/from-long 1330418007548)

#<Date Tue Feb 28 09:33:27 CET 2012>

(ns demo.utils (:require [clj-time.coerce :as coerce]) )

51jeudi 13 septembre 2012

Page 52: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

($map :ts ds ) ($map #(coerce/from-long %) :ts ds )

MAPPER UNE COLONNE

52

fonction anonyme

arg

52jeudi 13 septembre 2012

Page 53: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

AUGMENTER LE DATASET

53

($map #(coerce/from-long %) :ts ds )

(dataset [:timestamp]

($map #(coerce/from-long %) :ts ds ))

(conj-cols ds (dataset [:timestamp]

($map #(coerce/from-long %) :ts ds )))

(defn readable-timestamp [ds] (conj-cols ds (dataset [:timestamp]

($map #(coerce/from-long %) :ts ds ))))

53jeudi 13 septembre 2012

Page 54: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LEIN TEST

54

>lein test Testing loaderdemo.test.jmeterloaderRan 3 tests containing 5 assertions.0 failures, 0 errors.Testing loaderdemo.test.xmlloaderRan 5 tests containing 13 assertions.0 failures, 0 errors.Testing loaderdemo.test.coreTesting loaderdemo.test.jmeterloaderTesting loaderdemo.test.xmlloaderRan 9 tests containing 19 assertions.0 failures, 0 errors.

54jeudi 13 septembre 2012

Page 55: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

SCRIPT

55

(ns demo.core:use [[incanter.core] [demo.utils]] ;; readable-timestamp:require [[incanter.io :as io]

[incanter.stats :as stats][incanter.charts :as charts]])

(let [ds (readable-timestamp(io/read-dataset "readings.csv"))](save (charts/time-series-plot :ts :t :data ds) "times.png")(println ($rollup mean :t :lb ds)))

demo/core.clj

55jeudi 13 septembre 2012

Page 56: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

MAIN

56

(ns demo.core:use [[incanter.core] [demo.utils]] ;; readable-timestamp:require [[incanter.io :as io]

[incanter.stats :as stats][incanter.charts :as charts]])

(defn -main [& args] (let [ds (readable-timestamp(io/read-dataset "readings.csv"))] (save (charts/time-series-plot :ts :t :data ds) "times.png")(println ($rollup mean :t :lb ds)))

lein runNo :main namespace specified in project.clj.

demo/core.clj

56jeudi 13 septembre 2012

Page 57: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LEIN RUN

57

(defproject demo "1.0.0-SNAPSHOT" :description "demos incanter" :dependencies ... :dev-dependencies ... :main demo.core)

lein runread 1738

57jeudi 13 septembre 2012

Page 58: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LEIN REPL

58

lein replREPL started; server listening on localhost port 61426demo.core=>

58jeudi 13 septembre 2012

Page 59: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LES GRIMOIRES

59

incanter.orgdata-sorcery.org

github.com/liebke/incanter

Incanter sur StackoverflowIncanter Google Group

59jeudi 13 septembre 2012

Page 60: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere60

Stocker les données

60jeudi 13 septembre 2012

Page 61: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

ARCHITECTURE

61

Clojure

Document

CongoMongo

Incanter.mongodb

MongoDBServer

61jeudi 13 septembre 2012

Page 62: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

SE CONNECTER

62

(ns dm (:require [somnium.congomongo :as cm] [incanter.core :as incanter] [incanter.mongodb :as im]))

(def conn (cm/make-connection :demodb))

#'demomongo/conn

62jeudi 13 septembre 2012

Page 63: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

(im/insert-dataset :readings ds)

MASS INSERT

63

(cm/with-mongo conn (im/insert-dataset :readings ds))

({:ts "1330419301862", :search__phrase "gants", :userId "PT1022809551", ...

63jeudi 13 septembre 2012

Page 64: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

DANS MONGO

64

mongoconnecting to: test> show dbsdemodb 0.203125GBlocal (empty)

{ "_id" : ObjectId("5034e71703643050fef59474"), "ts" : "1330419324275", "search__phrase" : "gants", "userId" : "PT1022809551", "hrts" : "2012-02-28T08:55:24.275Z", "rc" : NumberLong(200), "productId" : "8519304225180894762", "shop" : "MAF", "lb" : "SU12b-PickProduct-Page", "t" : NumberLong(1177), "s" : "true" }...

db.readings.find( {'lb':'SU12b-PickProduct-Page', 'shop':'MAF', 'search__phrase:‘gants’} )

64jeudi 13 septembre 2012

Page 65: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LIRE

65

(im/fetch-dataset :readings ))

(cm/fetch :readings :where {:shop "MAF"} )

({:ts "1330419301862", :search__phrase "gants", :userId "PT1022809551", :hrts "2012-02-28T08:55:01.862Z", ...

65jeudi 13 septembre 2012

Page 66: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

JDBC

66

pas d’intégration Incanter JDBC

des librairies Clojureclojure.java.jdbcKormaClojureQL

66jeudi 13 septembre 2012

Page 67: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere67

Générer un rapport HTML

67jeudi 13 septembre 2012

Page 68: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LE WEB ET CLOJURE

68

Ring

Moustache ou Compojure

Enlive ou Hiccup

68jeudi 13 septembre 2012

Page 69: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LE RAPPORT

69

69jeudi 13 septembre 2012

Page 70: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

HICCUP

70

(ns hiccupdemo.core (:use hiccup.core) (:use hiccup.page) (:use hiccup.element)

70jeudi 13 septembre 2012

Page 71: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

(defn build-table [{:keys [rows]}] (html ))

FORMATER LA TABLE

71

(defn build-table [{:keys [rows]}] (html [:table ]))

(defn build-table [{:keys [rows]}] (html [:table (table-headers) (map table-row rows) ]))

71jeudi 13 septembre 2012

Page 72: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

(defn table-row [{:keys [lb count mean min max q95]}] (html [:tr [:td lb] [:td {:class "number"} count] [:td {:class "number"} mean ] ... ]]))

FORMATER LA LIGNE

72

(defn table-row [{:keys [lb count mean min max q95]}] (html [:tr [:td lb] [:td {:class "number"} count] [:td {:class "number"} (format "%6.2f" mean)]... ]]))

72jeudi 13 septembre 2012

Page 73: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

DESTRUCTURINGDE MAP

73

(defn build-table [statsds] (html [:table (table-headers) (map table-row (:rows statsds)) ]))

user=> (keys statsds)(:column-names :rows)

73jeudi 13 septembre 2012

Page 74: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

DESTRUCTURINGDE MAP

74

user=> (keys statsds)(:column-names :rows)

(defn build-table [{:keys [rows]}] (html [:table (table-headers) (map table-row rows) ]))

74jeudi 13 septembre 2012

Page 75: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere75

45350 relevés"Elapsed time: 24940.557 msecs" => loader"Elapsed time: 24542.737 msecs" => 1er chart"Elapsed time: 3042.975 msecs" => 2eme chart"Elapsed time: 24317.2 msecs" => stats"Elapsed time: 122.479 msecs" => rapport

75jeudi 13 septembre 2012

Page 76: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

OPTIONS JVM

76

lein runException in thread "AWT-Shutdown" java.lang.OutOfMemoryError: Java heap space! at java.util.IdentityHashMap$Values.iterator(IdentityHashMap.java:1009)! at java.util.Collections$SynchronizedCollection.iterator(Collections.java:1573)

:main perfdemo.core :jvm-opts ["-Xmx1g"] )

project.clj

76jeudi 13 septembre 2012

Page 77: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

PERFORMANCE

77

Consolesurtout ne listez pas les données :o

Mémoiredonnées accumulées dans le dataset

IO Disquesi beaucoup de graphes à sauver sur disque

77jeudi 13 septembre 2012

Page 78: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere78

Faire un job MapReduce Hadoop

78jeudi 13 septembre 2012

Page 79: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

MAP REDUCE

79

79jeudi 13 septembre 2012

Page 80: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

input

output

:input-format source format

CLOJURE-HADOOP

80

:map-reader fn:map fn

:reduce fn

(defjob/defjob job :map my-map :map-reader wrap/int-string-map-reader :reduce my-reduce :input-format :text)

80jeudi 13 septembre 2012

Page 81: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere81

81jeudi 13 septembre 2012

Page 82: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

MAP

82

(defn my-map [key line] (cond (= key 0) [] :else ... ))

(defn my-map [key line] (cond (= key 0) [] :else [["all" t] [ lb t] [ shop t]] )))

(defn my-map [key line] (cond (= key 0) [] :else [["all" t] [(str "lb:" lb) t] [(str "shop:" shop) t]] )))

(defn csv-line-parser [line] (map #(.trim %) (first (csv/parse-csv line))))

;; require clojure-csv

(defn my-map [key line] (cond (= key 0) [] :else (let [ cells (csv-line-parser line) ] [["all" t] [(str "lb:" lb) t] [(str "shop:" shop) t]] )))

(defn csv-line-parser [line] (map #(.trim %) (first (csv/parse-csv line))))

;; require clojure-csv

(defn my-map [key line] (cond (= key 0) [] :else (let [ cells (csv-line-parser line) t (nth cells 0) ] [["all" t] [(str "lb:" lb) t] [(str "shop:" shop) t]] )))

(defn csv-line-parser [line] (map #(.trim %) (first (csv/parse-csv line))))

;; require clojure-csv

(defn my-map [key line] (cond (= key 0) [] :else (let [ cells (csv-line-parser line) t (nth cells 0) ] [["all" t] [(str "lb:" lb) t] [(str "shop:" shop) t]] )))

(defn csv-line-parser [line] (map #(.trim %) (first (csv/parse-csv line))))

;; require clojure-csv

(defn my-map [key line] (cond (= key 0) [] :else (let [ cells (csv-line-parser line) t (Long/parseLong (nth cells 0)) ] [["all" t] [(str "lb:" lb) t] [(str "shop:" shop) t]] )))

(defn csv-line-parser [line] (map #(.trim %) (first (csv/parse-csv line))))

;; require clojure-csv

(defn my-map [key line] (cond (= key 0) [] :else (let [ cells (csv-line-parser line) t (Long/parseLong (nth cells 0)) [lb, shop] (map #(nth cells %) [1,6])] [["all" t] [(str "lb:" lb) t] [(str "shop:" shop) t]] )))

82jeudi 13 septembre 2012

Page 83: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere83

83jeudi 13 septembre 2012

Page 84: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

REDUCE

84

(defn my-reduce [key values-fn] [[(str key ":count") (count values-fn)] [(str key ":mean") (stats/mean values-fn)]])

84jeudi 13 septembre 2012

Page 85: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LEIN JAR

85

lein jar

et installer déployer dans hadoop

85jeudi 13 septembre 2012

Page 86: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

CASCALOG

86

Cascading + Datalog + Clojure

user=> (?<- (stdout) [?person ?age] (age ?person ?age) (< ?age 30))

Dites, vous aimez Prolog ?

86jeudi 13 septembre 2012

Page 87: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

LES ÉCOLES DE MAGIE

87

Paris Clojure User Group

http://dev.clojure.org/display/community/Clojure+User+Groups

Clojure sur Stackoverflow

4clojure.comlabrepl

87jeudi 13 septembre 2012

Page 88: Incanter bigdata jsc2012

JUG Summer Camp 2012 Claude Falguiere

CLAUDE FALGUIERE

@cfalguiere

88

goo.gl/4mmJQ Merci

88jeudi 13 septembre 2012