Skip to content

Commit

Permalink
finish big data github challenge, still some documentation to finish
Browse files Browse the repository at this point in the history
  • Loading branch information
alx committed May 20, 2012
1 parent 28be370 commit 0910ba7
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
output.jpg
*.jpg
data-2012-05-19.json data-2012-05-20.json data-2012.json
1 change: 1 addition & 0 deletions data-2012-05-19.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"DownloadEvent":[{"count":22,"name":"canjs","owner":"jupiterjs","language":"JavaScript"},{"count":16,"name":"dbGlossary","owner":"phpManufaktur","language":null},{"count":13,"name":"serverStreamLog","owner":"josedesoto","language":"Python"},{"count":9,"name":"mdframed","owner":"marcodaniel","language":"Shell"},{"count":8,"name":"srvdir","owner":"fsouza","language":"Go"}],"CommitCommentEvent":[{"count":34,"name":"easybuild","owner":"JensTimmerman","language":"Python"},{"count":26,"name":"TrinityCore","owner":"TrinityCore","language":"C++"},{"count":18,"name":"playpen","owner":"Spuds","language":"PHP"},{"count":18,"name":"akka-protostuff-serialization","owner":"romix","language":"Java"},{"count":17,"name":"xbmc","owner":"opdenkamp","language":"C"}],"ForkEvent":[{"count":31,"name":"Spoon-Knife","owner":"octocat","language":null},{"count":13,"name":"bootstrap","owner":"twitter","language":"JavaScript"},{"count":13,"name":"react","owner":"react-php","language":"PHP"},{"count":13,"name":"AK-BK-10-MVC","owner":"bendo01","language":"PHP"},{"count":10,"name":"dotfiles","owner":"michaeljsmalley","language":"VimL"}],"PullRequestReviewCommentEvent":[{"count":65,"name":"symfony","owner":"symfony","language":"PHP"},{"count":21,"name":"sqlparse","owner":"andialbrecht","language":"Python"},{"count":20,"name":"redaxo","owner":"redaxo","language":"PHP"},{"count":18,"name":"PiplMesh","owner":"wlanslovenija","language":"Python"},{"count":13,"name":"sympy","owner":"Krastanov","language":"Python"}],"PullRequestEvent":[{"count":39,"name":"test-repository","owner":"JMSBot","language":null},{"count":33,"name":"jquery-mobile","owner":"jquery","language":"JavaScript"},{"count":20,"name":"rails","owner":"rails","language":"Ruby"},{"count":17,"name":"homebrew","owner":"mxcl","language":"Ruby"},{"count":16,"name":"scala","owner":"scala","language":"Scala"}],"IssueCommentEvent":[{"count":64,"name":"TrinityCore","owner":"TrinityCore","language":"C++"},{"count":57,"name":"4chan-x","owner":"MayhemYDG","language":"JavaScript"},{"count":50,"name":"projetBomberman","owner":"siwon","language":"C++"},{"count":46,"name":"rails","owner":"rails","language":"Ruby"},{"count":45,"name":"homebrew","owner":"mxcl","language":"Ruby"}],"IssuesEvent":[{"count":45,"name":"mmx","owner":"mmteam","language":null},{"count":44,"name":"Dragon","owner":"DragonFire","language":"C++"},{"count":40,"name":"khan-exercises","owner":"Khan","language":"JavaScript"},{"count":27,"name":"AtlantissCore","owner":"Atlantiss","language":null},{"count":22,"name":"SuperDerpy","owner":"dos1","language":"C"}],"PushEvent":[{"count":381,"name":"dotfiles","owner":"yuu-ito","language":"VimL"},{"count":177,"name":"sandbox","owner":"illusionoflife","language":"Python"},{"count":159,"name":"sample_app","owner":"davidparracatalan","language":"Ruby"},{"count":113,"name":"test-repository","owner":"ide-an","language":"Java"},{"count":96,"name":"bcom-homepage-archive","owner":"bcomdlc","language":null}],"WatchEvent":[{"count":216,"name":"react","owner":"react-php","language":"PHP"},{"count":49,"name":"bootstrap","owner":"twitter","language":"JavaScript"},{"count":38,"name":"teacup","owner":"rubymotion","language":"Ruby"},{"count":25,"name":"activerecord-reputation-system","owner":"twitter","language":"Ruby"},{"count":24,"name":"sspulltorefresh","owner":"samsoffes","language":"Objective-C"}]}
1 change: 1 addition & 0 deletions data-2012-05-20.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"DownloadEvent":[{"count":1,"name":"Open-Transactions","owner":"da2ce7","language":"C++"},{"count":1,"name":"hawkthorne-journey","owner":"kyleconroy","language":"Lua"},{"count":1,"name":"Tangerine","owner":"Tangerine-Community","language":"JavaScript"}],"CommitCommentEvent":[{"count":4,"name":"netty","owner":"netty","language":"Java"},{"count":3,"name":"sadface","owner":"benlk","language":"Python"},{"count":2,"name":"TrinityCore","owner":"gc","language":"C++"},{"count":1,"name":"ECM","owner":"Iaccidentally","language":null},{"count":1,"name":"brickhu.github.com","owner":"brickhu","language":null}],"ForkEvent":[{"count":2,"name":"Spoon-Knife","owner":"octocat","language":null},{"count":2,"name":"django-watermark","owner":"codekoala","language":"Python"},{"count":1,"name":"backbone.layoutmanager","owner":"tbranyen","language":"JavaScript"},{"count":1,"name":"jshint","owner":"jshint","language":"JavaScript"},{"count":1,"name":"net-ssh","owner":"net-ssh","language":"Ruby"}],"PullRequestReviewCommentEvent":[{"count":1,"name":"usergroup","owner":"rubytij","language":"JavaScript"},{"count":1,"name":"bitcoin","owner":"bitcoin","language":"C++"},{"count":1,"name":"picard","owner":"musicbrainz","language":"Python"}],"PullRequestEvent":[{"count":4,"name":"Vanilla","owner":"SpoutDev","language":"Java"},{"count":4,"name":"loomio","owner":"enspiral","language":"Ruby"},{"count":2,"name":"evolution","owner":"sjstoelting","language":"PHP"},{"count":2,"name":"community","owner":"neo4j","language":"Java"},{"count":2,"name":"Salesmania","owner":"B2OJustin","language":"Java"}],"IssueCommentEvent":[{"count":5,"name":"carmen","owner":"jim","language":"Ruby"},{"count":4,"name":"hagfish","owner":"mfiers","language":"Python"},{"count":4,"name":"rails","owner":"rails","language":"Ruby"},{"count":4,"name":"team-5","owner":"aaltowebapps","language":"JavaScript"},{"count":3,"name":"core","owner":"kohana","language":"PHP"}],"IssuesEvent":[{"count":8,"name":"test-repo","owner":"Axbit","language":null},{"count":4,"name":"team-5","owner":"aaltowebapps","language":"JavaScript"},{"count":4,"name":"pixieengine.com","owner":"PixieEngine","language":"ActionScript"},{"count":3,"name":"Ushahidi_Android","owner":"ushahidi","language":"Java"},{"count":3,"name":"cukebins","owner":"paoloambrosio","language":"C++"}],"PushEvent":[{"count":19,"name":"PixieDust","owner":"PixieEngine","language":"JavaScript"},{"count":15,"name":"joomla-cms","owner":"mbabker","language":"PHP"},{"count":12,"name":"sengopal.github.com","owner":"sengopal","language":"Ruby"},{"count":12,"name":"notebook","owner":"rishabhsrao","language":"JavaScript"},{"count":11,"name":"min","owner":"wreviews","language":"PHP"}],"WatchEvent":[{"count":4,"name":"async","owner":"caolan","language":"JavaScript"},{"count":3,"name":"meteor","owner":"meteor","language":"JavaScript"},{"count":3,"name":"bootstrap","owner":"twitter","language":"JavaScript"},{"count":3,"name":"webwriter","owner":"icebeat","language":"JavaScript"},{"count":2,"name":"sspulltorefresh","owner":"samsoffes","language":"Objective-C"}]}
1 change: 1 addition & 0 deletions data-2012.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"DownloadEvent":[{"count":1,"name":"Open-Transactions","owner":"da2ce7","language":"C++"},{"count":1,"name":"hawkthorne-journey","owner":"kyleconroy","language":"Lua"},{"count":1,"name":"Tangerine","owner":"Tangerine-Community","language":"JavaScript"}],"CommitCommentEvent":[{"count":4,"name":"netty","owner":"netty","language":"Java"},{"count":3,"name":"sadface","owner":"benlk","language":"Python"},{"count":2,"name":"TrinityCore","owner":"gc","language":"C++"},{"count":1,"name":"ECM","owner":"Iaccidentally","language":null},{"count":1,"name":"brickhu.github.com","owner":"brickhu","language":null}],"ForkEvent":[{"count":2,"name":"Spoon-Knife","owner":"octocat","language":null},{"count":2,"name":"django-watermark","owner":"codekoala","language":"Python"},{"count":1,"name":"backbone.layoutmanager","owner":"tbranyen","language":"JavaScript"},{"count":1,"name":"jshint","owner":"jshint","language":"JavaScript"},{"count":1,"name":"net-ssh","owner":"net-ssh","language":"Ruby"}],"PullRequestReviewCommentEvent":[{"count":1,"name":"usergroup","owner":"rubytij","language":"JavaScript"},{"count":1,"name":"bitcoin","owner":"bitcoin","language":"C++"},{"count":1,"name":"picard","owner":"musicbrainz","language":"Python"}],"PullRequestEvent":[{"count":4,"name":"Vanilla","owner":"SpoutDev","language":"Java"},{"count":4,"name":"loomio","owner":"enspiral","language":"Ruby"},{"count":2,"name":"evolution","owner":"sjstoelting","language":"PHP"},{"count":2,"name":"community","owner":"neo4j","language":"Java"},{"count":2,"name":"Salesmania","owner":"B2OJustin","language":"Java"}],"IssueCommentEvent":[{"count":5,"name":"carmen","owner":"jim","language":"Ruby"},{"count":4,"name":"hagfish","owner":"mfiers","language":"Python"},{"count":4,"name":"rails","owner":"rails","language":"Ruby"},{"count":4,"name":"team-5","owner":"aaltowebapps","language":"JavaScript"},{"count":3,"name":"core","owner":"kohana","language":"PHP"}],"IssuesEvent":[{"count":8,"name":"test-repo","owner":"Axbit","language":null},{"count":4,"name":"team-5","owner":"aaltowebapps","language":"JavaScript"},{"count":4,"name":"pixieengine.com","owner":"PixieEngine","language":"ActionScript"},{"count":3,"name":"Ushahidi_Android","owner":"ushahidi","language":"Java"},{"count":3,"name":"cukebins","owner":"paoloambrosio","language":"C++"}],"PushEvent":[{"count":19,"name":"PixieDust","owner":"PixieEngine","language":"JavaScript"},{"count":15,"name":"joomla-cms","owner":"mbabker","language":"PHP"},{"count":12,"name":"sengopal.github.com","owner":"sengopal","language":"Ruby"},{"count":12,"name":"notebook","owner":"rishabhsrao","language":"JavaScript"},{"count":11,"name":"min","owner":"wreviews","language":"PHP"}],"WatchEvent":[{"count":4,"name":"async","owner":"caolan","language":"JavaScript"},{"count":3,"name":"meteor","owner":"meteor","language":"JavaScript"},{"count":3,"name":"bootstrap","owner":"twitter","language":"JavaScript"},{"count":3,"name":"webwriter","owner":"icebeat","language":"JavaScript"},{"count":2,"name":"sspulltorefresh","owner":"samsoffes","language":"Objective-C"}]}
103 changes: 82 additions & 21 deletions image_to_printer.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,93 @@
require 'rubygems'
require 'a2_printer'
require 'RMagick'
require 'date'
require 'open-uri'
require 'zlib'
require 'yajl'
require 'json'

serial = SerialConnection.new
printer = A2Printer.new serial

printer.begin
printer.set_default
def json_counter(data, json, key)
data.select{|event| event["type"] == key}.each do |event|
repo_name = event["repository"]["name"]
if existing_event = json[key].select{|repo| repo["repository"]["name"] == repo_name}.first
existing_event["count"] += 1
else
json[key] << event.merge({"count" => 1})
end
end
end

source = "/Users/alx/code/le_github/output.jpg"
image = Magick::Image::read(source).first
def import_bigdata
date = (DateTime.now - 2).strftime("%Y-%m-%d")
data = []
24.times do |index|
url = "http://data.githubarchive.org/#{date}-#{index}.json.gz"
p "parsing #{url}"
gz = open(url)
js = Zlib::GzipReader.new(gz).read
data.concat(Yajl::Parser.parse("[" + js.gsub("}{", "},{") + "]"))
end

if(image.rows < 384)
printer.print_image(source)
else
p "large_image"
images = []
# cut images in 384px height images
((image.rows / 384) + 1).times do |index|
image_source = source.gsub(".jpg", "_#{index}.jpg")
json_data = {
"DownloadEvent" => [],
"CommitCommentEvent" => [],
"ForkEvent" => [],
"PullRequestReviewCommentEvent" => [],
"PullRequestEvent" => [],
"IssueCommentEvent" => [],
"IssuesEvent" => [],
"PushEvent" => [],
"WatchEvent" => []
}
json_data.each_key{|key| json_counter(data, json_data, key)}

cut_image = image.crop(0,index*384,384,384)
cut_image.write image_source
json_data.each do |key, repos|
repos.sort!{|a, b| b["count"] <=> a["count"]}.slice!(5, repos.length)
repos.map! do |repo|
{
"count" => repo["count"],
"name" => repo["repository"]["name"],
"owner" => repo["repository"]["owner"],
"language" => repo["repository"]["language"]
}
end
end

images << image_source
File.open("data-#{date}.json", "w") do |file|
file.write json_data.to_json
end
images.each do |image_source|
p image_source
printer.print_image(image_source)
end

def print
serial = SerialConnection.new
printer = A2Printer.new serial

printer.begin
printer.set_default

source = "/Users/alx/code/le_github/output.jpg"
image = Magick::Image::read(source).first

if(image.rows < 384)
printer.print_image(source)
else
p "large_image"
images = []
# cut images in 384px height images
((image.rows / 384) + 1).times do |index|
image_source = source.gsub(".jpg", "_#{index}.jpg")

cut_image = image.crop(0,index*384,384,384)
cut_image.write image_source

images << image_source
end
images.each do |image_source|
p image_source
printer.print_image(image_source)
end
end
end

print
35 changes: 29 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,44 @@
<span id="edition"></span>
</div>

<div id="bubble" class="row">
<div class="row">
<ul class="block-grid two-up">
<li>
<h2>Forks</h2>
<ul id="ForkEvent"></ul>
</li>
<li>
<h2>Downloads</h2>
<ul id="DownloadEvent"></ul>
</li>
<li>
<h2>Issues</h2>
<ul id="IssuesEvent"></ul>
</li>
<li>
<h2>Pull Reqs</h2>
<ul id="PullRequestEvent"></ul>
</li>
<li>
<h2>Push</h2>
<ul id="PushEvent"></ul>
</li>
<li>
<h2>Watch</h2>
<ul id="WatchEvent"></ul>
</li>
</ul>
</div>

<div id="octodex" class="row">
</div>
<div id="octodex" class="row"></div>
</div>
<!-- container -->




<!-- Included JS Files -->
<script src="javascripts/jquery.min.js"></script>
<script src="javascripts/foundation.js"></script>
<script src="javascripts/moment.min.js"></script>
<script src="javascripts/d3.v2.min.js"></script>
<script src="javascripts/app.js"></script>

</body>
Expand Down
26 changes: 23 additions & 3 deletions javascripts/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* Foundation v2.2.1 http://foundation.zurb.com */
jQuery(document).ready(function ($) {

/* Use this js doc for all application specific JS */
/* Use this js doc for all application specific JS */

/* TABS --------------------------------- */
/* Remove if you don't need :) */
Expand Down Expand Up @@ -94,6 +93,9 @@ jQuery(document).ready(function ($) {

/* DISABLED BUTTONS ------------- */
/* Gives elements with a class of 'disabled' a return: false; */
var yesterday = moment().subtract('days', 2);

$("#edition").html(yesterday.format("DD/MM/YYYY"));

$.ajax({
type: "GET",
Expand All @@ -105,12 +107,30 @@ jQuery(document).ready(function ($) {

// If there was entry yesterday, select it
var first_entry_day = moment(entries.find('updated')[0].textContent.split("T")[0], "YYYY-MM-DD");
var yesterday = moment().subtract('days', 1);
if(first_entry_day.diff(yesterday, 'days') == 0){
selected_entry = entries[0]
}

$("#octodex").html("<span class='fancy'><img src='" + $(selected_entry).find('img').attr('src') + "'></span>");
}
});

$.getJSON(yesterday.format("[data-]YYYY-MM-DD[.json]"), function(data) {
var items = [];

$.each(data, function(key, repo) {
var items = [];
var max_count = repo[0]["count"];
$.each(repo, function(){
items.push("<li class='project'><span class='count black round label' style='padding-left:");
items.push(Math.abs(this["count"] * 50 / max_count));
items.push("px'>" + this["count"] + "</span>");
if(this["language"] != null)
items.push("<span class='lang black radius label'>" + this["language"] + "</span>");
items.push("<br><a href='http://github.com/" + this["owner"] + "/" + this["name"] + "/'>");
items.push(this["owner"] + "/" + this["name"] + "</a></li>");
});
$("#" + key).html(items.join(""));
});
});
});
4 changes: 4 additions & 0 deletions javascripts/d3.v2.min.js

Large diffs are not rendered by default.

80 changes: 59 additions & 21 deletions stylesheets/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
----------------------------------------- */
.container {
width:384px;
margin: 0 auto;
padding: 0;
}

Expand All @@ -24,26 +25,63 @@
min-width: 384px;
}

.block-grid.two-up {
margin-left: -2%;
}

.block-grid.two-up > li {
margin-left: 2%;
width: 48%;
margin-bottom: 2%;
}

#logo {
margin:0 auto;
text-align:center;
}

span,img{padding:0;margin:0;border:0;}
.fancy{
position:relative;
display:inline-block;
font-size:0;
line-height:0;
}

.fancy:after{
position:absolute;
top:1px;
left:1px;
bottom:1px;
right:1px;
border:1px solid rgba(255,255,255,0.5);
outline:1px solid rgba(0,0,0,0.2);
content:" ";
text-align: center;
}


#edition{
color:#000;
font-size:20px;
font-weight:bold;
float:right;
}

ul {
color:#fff;
background-color: #000;
margin:0;
}

li {
color:#000;
background-color: #fff;
margin:0;
}

ul h2 {
color:#fff;
background-color: #000;
font-size:24px;
text-align:right;
margin: 0;
}

.count{
float:left;
}

.lang{
float:right;
}

li.project {
border-bottom: 3px solid #333;
font-size:16px;
text-align:right;
padding:2px;
}

li.project a{
color:#000;
}

0 comments on commit 0910ba7

Please sign in to comment.