Last active
August 29, 2015 13:56
-
-
Save kawasima/9221666 to your computer and use it in GitHub Desktop.
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 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