-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRankOrderChart.rb
More file actions
42 lines (33 loc) · 832 Bytes
/
Copy pathRankOrderChart.rb
File metadata and controls
42 lines (33 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "mysql2",
:host => "localhost",
:database => "data_mining",
:username => "root",
:password => ""
)
class School < ActiveRecord::Base
end
class Response < ActiveRecord::Base
belongs_to :school
end
clusters = {}
responses = Response.find(:all)
schools = School.find(:all)
n = 1
responses.each do |r|
cluster = schools[schools.index {|s| s[:school_id] == r[:school_id]}][:cluster]
clusters[cluster] = [] if clusters[cluster].nil?
clusters[cluster] << r
n += 1
end
sorted_clusters = clusters.keys.sort {|x,y| clusters[y].count <=> clusters[x].count}
cdf = 0
n=1
sorted_clusters.each do |c|
fraction = clusters[c].count/responses.count.to_f
cdf += fraction
puts "#{n} & #{c} & #{fraction} & #{cdf} \\"
n += 1
end