Skip to content

Instantly share code, notes, and snippets.

View markmarkoh's full-sized avatar

Mark DiMarco markmarkoh

View GitHub Profile
mark@stats:~/$ ruby test.rb
document : 300.0
image : 17910.0
video : 1000.0
def pie(data_array)
@labels = ""
@data_str = ""
@data = []
@sum = 0
data_array.find().to_a.each do |f|
@labels += "#{f['_id']}|"
@sum += f['value']['count'].to_i
@data.push(f['value']['count'].to_i)
end
%h1
Stats
#upload
Uploaded File Breakdown
#pie= @upload_types
require 'rubygems'
require 'sinatra'
require 'haml'
require 'model'
set :port, 80
get '/' do
protected!
{"video", [{count: 1}, {count: 1}, {count: 1}, {count: 1}]}
function() {
emit(this.time - (this.time % 86400), {count: 1});
}
require 'rubygems'
require 'mongo'
def db
$db ||= Mongo::Connection.new("localhost", 27017).db("logs")
end
def logs
$logs ||= db.collection("flex")
end
require 'model'
require 'time'
@s = Chart.count_all_activity
@s.find().to_a.each do |f|
puts "#{f['_id']} (#{Time.at(f['_id'])}) : #{f['value']['count']}"
end
mark@stats:~/$ ruby test.rb
...more results...
1260835200.0 (Tue Dec 15 00:00:00 +0000 2009) : 316.0
1260921600.0 (Wed Dec 16 00:00:00 +0000 2009) : 1874.0
1261008000.0 (Thu Dec 17 00:00:00 +0000 2009) : 516.0
1261094400.0 (Fri Dec 18 00:00:00 +0000 2009) : 642.0
...more results...
mark@stats:~/$
%html
%head
%title Stats Server
%meta{"http-equive" => "Content-Type", :content=>"text/html; charset=utf-8"}/
<script type="text/javascript" src="/flot/jquery.js"></script>
<script language="javascript" type="text/javascript" src="/flot/jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="/flot/jquery.flot.selection.js"></script>
%body
=yield