donors_choose-data 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/README.textile +57 -0
- data/Rakefile +16 -0
- data/donors_choose-data.gemspec +24 -0
- data/lib/donors_choose-data.rb +5 -0
- data/lib/donors_choose-data/data.rb +18 -0
- data/lib/donors_choose-data/data/account.rb +10 -0
- data/lib/donors_choose-data/data/city.rb +9 -0
- data/lib/donors_choose-data/data/donation.rb +10 -0
- data/lib/donors_choose-data/data/essay.rb +10 -0
- data/lib/donors_choose-data/data/giftcard.rb +8 -0
- data/lib/donors_choose-data/data/project.rb +16 -0
- data/lib/donors_choose-data/data/resource.rb +10 -0
- data/lib/donors_choose-data/data/school.rb +11 -0
- data/lib/donors_choose-data/data/teacher.rb +11 -0
- data/lib/donors_choose-data/version.rb +3 -0
- data/test/donors_choose-data/data/account_test.rb +17 -0
- data/test/donors_choose-data/data/city_test.rb +17 -0
- data/test/donors_choose-data/data/donation_test.rb +16 -0
- data/test/donors_choose-data/data/essay_test.rb +17 -0
- data/test/donors_choose-data/data/giftcard_test.rb +13 -0
- data/test/donors_choose-data/data/project_test.rb +33 -0
- data/test/donors_choose-data/data/resource_test.rb +17 -0
- data/test/donors_choose-data/data/school_test.rb +16 -0
- data/test/donors_choose-data/data/teacher_test.rb +21 -0
- data/test/test_helper.rb +15 -0
- metadata +125 -0
data/Gemfile
ADDED
data/README.textile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
h1. donors_choose-data
|
2
|
+
|
3
|
+
*NOTE:* If you are looking for an API wrapper for DonorsChoose.org, please checkout "https://github.com/JumpstartLab/donors_choose":https://github.com/JumpstartLab/donors_choose
|
4
|
+
|
5
|
+
This library sprung from the 2011 Hacking Education contest for DonorsChoose.org. (http://www.donorschoose.org/hacking-education)
|
6
|
+
|
7
|
+
The DonorsChoose::Data module match up the normalized data provided by DonorsChoose.org to classes that inherit from ActiveRecord::Base.
|
8
|
+
|
9
|
+
*This gem assumes you have loaded the DonorsChoose.org datasets into a PostgreSQL database and normalized the data. See the "contest documentation":http://developer.donorschoose.org/the-data/data-schema for more information.*
|
10
|
+
|
11
|
+
h2. Usage
|
12
|
+
|
13
|
+
<pre>
|
14
|
+
gem install donors_choose-data
|
15
|
+
</pre>
|
16
|
+
|
17
|
+
<pre>
|
18
|
+
project = DonorsChooseData::Data::Project.first
|
19
|
+
project.donations
|
20
|
+
school = DonorsChooseData::Data::School.last
|
21
|
+
school.teachers
|
22
|
+
</pre>
|
23
|
+
|
24
|
+
|
25
|
+
h3. Rails
|
26
|
+
|
27
|
+
If you'd like to use it in Rails, just add the following to your Gemfile:
|
28
|
+
|
29
|
+
<pre>
|
30
|
+
gem 'donors_choose-data'
|
31
|
+
</pre>
|
32
|
+
|
33
|
+
h3. Stand alone
|
34
|
+
|
35
|
+
If you'd like to use it stand alone, do the following:
|
36
|
+
|
37
|
+
Create a database.yml, very similar to what you'd have in Rails:
|
38
|
+
|
39
|
+
bq. adapter: postgresql
|
40
|
+
host: localhost
|
41
|
+
username: postgres
|
42
|
+
password: password
|
43
|
+
port: 5432
|
44
|
+
database: donors_choose_data
|
45
|
+
schema_search_path: public
|
46
|
+
|
47
|
+
Then, drop into irb, require the gem, and establish the db connection
|
48
|
+
|
49
|
+
<pre>
|
50
|
+
terminal$ irb
|
51
|
+
irb(main):001:0> require 'rubygems'
|
52
|
+
irb(main):001:0> require 'donors_choose-data'
|
53
|
+
irb(main):001:0> DonorsChooseData::Data.connect(YAML.load(File.read('database.yml')))
|
54
|
+
irb(main):001:0> DonorsChooseData::Data::Project.first
|
55
|
+
</pre>
|
56
|
+
|
57
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Bundler tasks
|
2
|
+
require 'bundler'
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
|
5
|
+
# Test tasks
|
6
|
+
require 'rake'
|
7
|
+
require 'rake/testtask'
|
8
|
+
|
9
|
+
desc "Run basic tests"
|
10
|
+
Rake::TestTask.new("test_units") { |t|
|
11
|
+
t.pattern = 'test/*/*/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
t.warning = true
|
14
|
+
}
|
15
|
+
|
16
|
+
task :default => [:test_units]
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "donors_choose-data/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "donors_choose-data"
|
7
|
+
s.version = DonorsChooseData::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["markmcspadden@gmail.com"]
|
10
|
+
s.email = [""]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Libaries to assist with mining data from donorschoose.org Hacking Education project}
|
13
|
+
s.description = %q{}
|
14
|
+
|
15
|
+
s.rubyforge_project = "donors_choose-data"
|
16
|
+
|
17
|
+
s.add_dependency 'activerecord', '> 3.0'
|
18
|
+
s.add_dependency 'pg'
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'pg'
|
3
|
+
|
4
|
+
module DonorsChooseData
|
5
|
+
module Data
|
6
|
+
|
7
|
+
# Use this if you're going standalone (aka sans Rails)
|
8
|
+
def self.connect(postgres_config = {})
|
9
|
+
# Connect with db
|
10
|
+
ActiveRecord::Base.establish_connection(postgres_config)
|
11
|
+
end
|
12
|
+
|
13
|
+
Dir.glob("#{File.dirname __FILE__}/data/*.rb").each do |f|
|
14
|
+
require f
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module DonorsChooseData
|
2
|
+
module Data
|
3
|
+
class Project < ActiveRecord::Base
|
4
|
+
set_table_name :normalized_project
|
5
|
+
set_primary_key :_projectid
|
6
|
+
|
7
|
+
belongs_to :school, :foreign_key => :_schoolid
|
8
|
+
belongs_to :teacher, :foreign_key => :_teacher_acctid
|
9
|
+
|
10
|
+
has_one :essay, :foreign_key => :_projectid
|
11
|
+
|
12
|
+
has_many :donations, :foreign_key => :_projectid
|
13
|
+
has_many :resources, :foreign_key => :_projectid
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module DonorsChooseData
|
2
|
+
module Data
|
3
|
+
class Teacher < ActiveRecord::Base
|
4
|
+
set_table_name :normalized_teacher
|
5
|
+
set_primary_key :_teacher_acctid
|
6
|
+
|
7
|
+
has_many :projects, :foreign_key => :_teacher_acctid
|
8
|
+
has_many :schools, :through => :projects
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
class AccountTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@account = DonorsChooseData::Data::Account.order(:_acctid).first
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_account_setup
|
10
|
+
assert_equal "00008481214e948f070337066f875fb2", @account._acctid
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_city_setup
|
14
|
+
assert_equal 4474, @account.city.id
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
class CityTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@city = DonorsChooseData::Data::City.first
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_city_setup
|
10
|
+
assert_equal 1, @city.id
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_accounts_setup
|
14
|
+
assert_equal "c4127fe826abef12174ca4d0e7288f88", @city.accounts.first._acctid
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
class DonationTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@donation = DonorsChooseData::Data::Donation.order(:_donationid).first
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_donation_setup
|
10
|
+
assert_equal "0000023f507999464aa2b78875b7e5d6", @donation._donationid
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_project_setup
|
14
|
+
assert_equal "69bf3a609bb4673818e0eebd004ea504", @donation.project._projectid
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
class EssayTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@essay = DonorsChooseData::Data::Essay.order(:_projectid).first
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_essay_setup
|
10
|
+
assert_equal "0000023f507999464aa2b78875b7e5d6", @essay._projectid
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_project_setup
|
14
|
+
assert_equal "0000023f507999464aa2b78875b7e5d6", @essay.project._projectid
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
class GiftcardTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@giftcard = DonorsChooseData::Data::Giftcard.order(:_giftcardid).first
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_giftcard_setup
|
10
|
+
assert_equal "000238b44c187c254752736e53ee46f2", @giftcard._giftcardid
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
class ProjectTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@project = DonorsChooseData::Data::Project.order(:_projectid).first
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_project_setup
|
10
|
+
assert_equal "0000023f507999464aa2b78875b7e5d6", @project._projectid
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_donation_setup
|
14
|
+
assert_equal "ee519de971e6ec8961f5efa06c6ed191", @project.donations.first._donationid
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_essay_setup
|
18
|
+
assert_equal "0000023f507999464aa2b78875b7e5d6", @project.essay._projectid
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_teacher_setup
|
22
|
+
assert_equal "5ac258059d9c4fc4db5c1a92b7204db0", @project.teacher._teacher_acctid
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_resources_setup
|
26
|
+
assert_equal "179328a86f77fd5516d122f371c41d32", @project.resources.first._resourceid
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_school_setup
|
30
|
+
assert_equal "c8eafeea02033a1cacd629b410668d55", @project.school._schoolid
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
class ResourceTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@resource = DonorsChooseData::Data::Resource.order(:_resourceid).first
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_resource_setup
|
10
|
+
assert_equal "00000170fe6288e0bc4d136e7d9b5ff2", @resource._resourceid
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_project_setup
|
14
|
+
assert_equal "401699836249c08c7a686b33e243b826", @resource.project._projectid
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
class SchoolTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@school = DonorsChooseData::Data::School.order(:_schoolid).first
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_school_setup
|
10
|
+
assert_equal "00064eac8b3d1f6dea8a07559922ed58", @school._schoolid
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_project_setup
|
14
|
+
assert_equal "2934f1c8ae5069a41fe601dcf57601be", @school.projects.first._projectid
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
class TeacherTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@teacher = DonorsChooseData::Data::Teacher.order(:_teacher_acctid).first
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_teacher_setup
|
10
|
+
assert_equal "0000fc70ad0a307d08f88a484dd99cb4", @teacher._teacher_acctid
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_projects_setup
|
14
|
+
assert_equal "dde9ff3a749c46a5d6d6be4f37b0dba6", @teacher.projects.first._projectid
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_schools_setup
|
18
|
+
assert_equal "3a379fd45cb12c92c3c4283e97421111", @teacher.schools.first._schoolid
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/donors_choose-data/data")
|
6
|
+
|
7
|
+
postgres_config = { :adapter => "postgresql",
|
8
|
+
:host => "localhost",
|
9
|
+
:username => "postgres",
|
10
|
+
:password => "password",
|
11
|
+
:port => 5432,
|
12
|
+
:database => "donors_choose_data",
|
13
|
+
:schema_search_path => "public" }
|
14
|
+
|
15
|
+
DonorsChooseData::Data.connect postgres_config
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: donors_choose-data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- markmcspadden@gmail.com
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-02-14 00:00:00 -06:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activerecord
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
version: "3.0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: pg
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
type: :runtime
|
46
|
+
version_requirements: *id002
|
47
|
+
description: ""
|
48
|
+
email:
|
49
|
+
- ""
|
50
|
+
executables: []
|
51
|
+
|
52
|
+
extensions: []
|
53
|
+
|
54
|
+
extra_rdoc_files: []
|
55
|
+
|
56
|
+
files:
|
57
|
+
- Gemfile
|
58
|
+
- README.textile
|
59
|
+
- Rakefile
|
60
|
+
- donors_choose-data.gemspec
|
61
|
+
- lib/donors_choose-data.rb
|
62
|
+
- lib/donors_choose-data/data.rb
|
63
|
+
- lib/donors_choose-data/data/account.rb
|
64
|
+
- lib/donors_choose-data/data/city.rb
|
65
|
+
- lib/donors_choose-data/data/donation.rb
|
66
|
+
- lib/donors_choose-data/data/essay.rb
|
67
|
+
- lib/donors_choose-data/data/giftcard.rb
|
68
|
+
- lib/donors_choose-data/data/project.rb
|
69
|
+
- lib/donors_choose-data/data/resource.rb
|
70
|
+
- lib/donors_choose-data/data/school.rb
|
71
|
+
- lib/donors_choose-data/data/teacher.rb
|
72
|
+
- lib/donors_choose-data/version.rb
|
73
|
+
- test/donors_choose-data/data/account_test.rb
|
74
|
+
- test/donors_choose-data/data/city_test.rb
|
75
|
+
- test/donors_choose-data/data/donation_test.rb
|
76
|
+
- test/donors_choose-data/data/essay_test.rb
|
77
|
+
- test/donors_choose-data/data/giftcard_test.rb
|
78
|
+
- test/donors_choose-data/data/project_test.rb
|
79
|
+
- test/donors_choose-data/data/resource_test.rb
|
80
|
+
- test/donors_choose-data/data/school_test.rb
|
81
|
+
- test/donors_choose-data/data/teacher_test.rb
|
82
|
+
- test/test_helper.rb
|
83
|
+
has_rdoc: true
|
84
|
+
homepage: ""
|
85
|
+
licenses: []
|
86
|
+
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
requirements: []
|
109
|
+
|
110
|
+
rubyforge_project: donors_choose-data
|
111
|
+
rubygems_version: 1.3.7
|
112
|
+
signing_key:
|
113
|
+
specification_version: 3
|
114
|
+
summary: Libaries to assist with mining data from donorschoose.org Hacking Education project
|
115
|
+
test_files:
|
116
|
+
- test/donors_choose-data/data/account_test.rb
|
117
|
+
- test/donors_choose-data/data/city_test.rb
|
118
|
+
- test/donors_choose-data/data/donation_test.rb
|
119
|
+
- test/donors_choose-data/data/essay_test.rb
|
120
|
+
- test/donors_choose-data/data/giftcard_test.rb
|
121
|
+
- test/donors_choose-data/data/project_test.rb
|
122
|
+
- test/donors_choose-data/data/resource_test.rb
|
123
|
+
- test/donors_choose-data/data/school_test.rb
|
124
|
+
- test/donors_choose-data/data/teacher_test.rb
|
125
|
+
- test/test_helper.rb
|