Created
March 23, 2011 23:30
-
-
Save marvinthepa/884258 to your computer and use it in GitHub Desktop.
Script to get repository statistics clojure-scala-groovy from github
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
;; project.clj | |
;(defproject github-stat "0.0.1-SNAPSHOT" | |
; :dependencies [[clojure "1.2.0"] | |
; [clojure-contrib "1.2.0"] | |
; [clj-http "0.1.3"] | |
; [incanter "1.2.3"]]) | |
(ns github.fun | |
(:use clojure.contrib.json clojure.contrib.pprint | |
[incanter core stats charts]) | |
(:require [clj-http.client :as client]) | |
(:import java.text.SimpleDateFormat)) | |
(def timer (atom [0 (System/currentTimeMillis)])) | |
; github only allows 60 requests per minute.. | |
(defn update-timer [t] | |
(let [now (System/currentTimeMillis) | |
no (first t) | |
timestamp (second t) | |
diff (- now timestamp) | |
minute (* 60 1000)] | |
(cond (>= diff minute) [0 now] | |
(>= no 59) (do | |
(Thread/sleep (- minute diff)) | |
[0 now]) | |
:else [(inc no) timestamp]))) | |
(defn get-page [lang page] | |
(do | |
(swap! timer update-timer) | |
(read-json (:body | |
(client/get | |
(str "http://github.com/api/v2/json/repos/search/" | |
"language:" lang | |
"?start_page=" page)))))) | |
(defn get-repositories [lang] | |
(->> (rest (range)) | |
(map (partial get-page lang)) | |
(map :repositories) | |
(take-while #(> (count %) 0)) | |
(reduce concat))) | |
(defn parse-date [date] | |
(.getTime | |
(.parse (SimpleDateFormat. "yyyy/MM/dd HH:mm:ss Z") date))) | |
(defn dates [lang] | |
(->> (get-repositories lang) | |
(map :created_at) | |
(map parse-date) | |
sort)) | |
(defn data [lang] | |
(let [l (dates lang)] | |
[l (range (count l))])) | |
(def clojure (data "Clojure")) | |
(def scala (data "Scala")) | |
(def groovy (data "Groovy")) | |
(-> | |
(time-series-plot (first clojure) (second clojure) | |
:legend true | |
:series-label "Clojure" | |
:x-label "t" | |
:y-label "# of repos") | |
(add-lines (first scala) (second scala) | |
:series-label "Scala") | |
(add-lines (first groovy) (second groovy) | |
:series-label "Groovy") | |
view) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment