Skip to content

Instantly share code, notes, and snippets.

@pencilcheck
Created November 24, 2013 01:33
Show Gist options
  • Save pencilcheck/7622265 to your computer and use it in GitHub Desktop.
Save pencilcheck/7622265 to your computer and use it in GitHub Desktop.
我寫了一個小程式來看checkin的變化,還真的沒什麼好玩的,也不知道要怎麼跟其他結合,不過你們如果有興趣的話,請到以下連結下載,然後請解壓Yelp的dataset一起放在一個資料夾後跑ruby checkin.rb就會產生一個圖檔叫checkin_chart.png
require 'json'
require 'gchart'
def axis
#(0..6).to_a.map { |day| (0..23).to_a.map { |hour| "#{hour}-#{day}" } }.flatten
(0..0).to_a.map { |day| (0..23).to_a.map { |hour| "#{hour}-#{day}" } }.flatten
end
data = Hash[axis.map {|a| [a, 0]}]
File.open('yelp_academic_dataset_checkin.json').readlines.map do |line|
object = JSON.parse line
object["checkin_info"].each_pair { |key, value| data[key] += value if data.has_key?(key) }
end
p data
Gchart.new(
type: 'bar',
size: '600x400',
bar_width_and_spacing: '20,3',
title: 'Checkin Visualization',
bg: 'EFEFEF',
data: axis.map { |a| data[a] },
filename: 'checkin_chart.png',
legent_position: 'bottom',
axis_with_labels: [['x'], ['y']],
axis_labels: [axis],
).file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment