Skip to content

Instantly share code, notes, and snippets.

@kawasima kawasima/ochingin.clj
Last active Aug 29, 2015

Embed
What would you like to do?
(ns ochingin
(:require [clojure.java.io :as io])
(:use [incanter core io charts]
[net.cgrand enlive-html]))
(defn salary-range-us [lang]
(with-open [rdr (io/reader (str "http://www.indeed.com/jobs?l=&q=" lang))]
(let [ds (->>
(-> (select (html-resource rdr) [:div (attr= :id "rb_Salary Estimate")])
(select [:li :a]))
(map #(re-matches #"\$([\d,]+)\+ \((\d+)\)" (get-in % [:attrs :title])))
(map (fn [_] (-> _
(update-in [1] #(-> % (.replace "," "") (Long/parseLong)))
(update-in [2] #(-> % (.replace "," "") (Long/parseLong))))))
(dataset [:label :salary :count]))
total (apply + (sel ds :cols :count))]
(add-column :percentage ($map #(/ % total) :count ds) ds))))
(defn salary-range [lang]
(with-open [rdr (io/reader (str "http://jp.indeed.com/%E6%B1%82%E4%BA%BA?l=&q=" lang))]
(let [ds (->>
(-> (select (html-resource rdr) [:div (attr= :id "rb_Salary Estimate")])
(select [:li :a]))
(map #(re-matches #"([\d,]+)万円~ \((\d+)\)" (get-in % [:attrs :title])))
(map (fn [_] (-> _
(update-in [1] #(-> % (.replace "," "") (Long/parseLong)))
(update-in [2] #(-> % (.replace "," "") (Long/parseLong))))))
(dataset [:label :salary :count]))
total (apply + (sel ds :cols :count))]
(add-column :percentage ($map #(/ % total) :count ds) ds))))
(defn draw-salary-distribution [words]
(let [ds (salary-range (first words))
chart (xy-plot (sel ds :cols :salary)
(sel ds :cols :percentage)
:legend true
:series-label (first words)
:x-label "Salary"
:y-label "Percentage")]
(doseq [lang (rest words)]
(let [ds (salary-range lang)]
(add-lines chart
(sel ds :cols :salary)
(sel ds :cols :percentage)
:series-label lang)))
(view chart)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.