reputation 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. data/.infinity_test +35 -0
  2. data/.rspec +2 -0
  3. data/app/models/reputation_behaviour.rb +38 -0
  4. data/app/models/reputation_intermediate_value.rb +22 -0
  5. data/app/models/reputation_rule.rb +107 -0
  6. data/generators/reputation/reputation_generator.rb +11 -0
  7. data/generators/reputation/templates/reputation_create_tables.rb +37 -0
  8. data/lib/reputation.rb +3 -0
  9. data/lib/reputation/engine.rb +8 -0
  10. data/lib/reputation/functions.rb +4 -0
  11. data/lib/reputation/functions/generalised_logistic_curve.rb +37 -0
  12. data/lib/reputation/functions/linear.rb +21 -0
  13. data/lib/reputation/functions/mixin.rb +44 -0
  14. data/lib/reputation/functions/step.rb +27 -0
  15. data/lib/reputation/user.rb +38 -0
  16. data/rails/init.rb +1 -0
  17. data/spec/functions/generalised_logistic_curve_spec.rb +50 -0
  18. data/spec/functions/linear_spec.rb +21 -0
  19. data/spec/functions/step_spec.rb +28 -0
  20. data/spec/helpers/functions.rb +13 -0
  21. data/spec/models/behaviour_spec.rb +31 -0
  22. data/spec/models/intermediate_value_spec.rb +29 -0
  23. data/spec/models/rule_spec.rb +233 -0
  24. data/spec/models/user_spec.rb +25 -0
  25. data/spec/rails_root/Rakefile +10 -0
  26. data/spec/rails_root/app/controllers/application_controller.rb +10 -0
  27. data/spec/rails_root/app/helpers/application_helper.rb +3 -0
  28. data/spec/rails_root/app/models/user.rb +3 -0
  29. data/spec/rails_root/config/boot.rb +114 -0
  30. data/spec/rails_root/config/database.yml +16 -0
  31. data/spec/rails_root/config/environment.rb +41 -0
  32. data/spec/rails_root/config/environments/development.rb +17 -0
  33. data/spec/rails_root/config/environments/test.rb +28 -0
  34. data/spec/rails_root/config/initializers/backtrace_silencers.rb +7 -0
  35. data/spec/rails_root/config/initializers/cookie_verification_secret.rb +7 -0
  36. data/spec/rails_root/config/initializers/inflections.rb +10 -0
  37. data/spec/rails_root/config/initializers/mime_types.rb +5 -0
  38. data/spec/rails_root/config/initializers/new_rails_defaults.rb +21 -0
  39. data/spec/rails_root/config/initializers/session_store.rb +15 -0
  40. data/spec/rails_root/config/routes.rb +43 -0
  41. data/spec/rails_root/db/development.sqlite3 +0 -0
  42. data/spec/rails_root/db/migrate/20110414125319_create_users.rb +11 -0
  43. data/spec/rails_root/db/migrate/20110812160932_reputation_create_tables.rb +37 -0
  44. data/spec/rails_root/db/schema.rb +48 -0
  45. data/spec/rails_root/db/test.sqlite3 +0 -0
  46. data/spec/rails_root/log/development.log +3471 -0
  47. data/spec/rails_root/log/test.log +27696 -0
  48. data/spec/rails_root/script/about +4 -0
  49. data/spec/rails_root/script/console +3 -0
  50. data/spec/rails_root/script/dbconsole +3 -0
  51. data/spec/rails_root/script/destroy +3 -0
  52. data/spec/rails_root/script/generate +3 -0
  53. data/spec/rails_root/script/performance/benchmarker +3 -0
  54. data/spec/rails_root/script/performance/profiler +3 -0
  55. data/spec/rails_root/script/plugin +3 -0
  56. data/spec/rails_root/script/runner +3 -0
  57. data/spec/rails_root/script/server +3 -0
  58. data/spec/scenarios/collection_spec.rb +118 -0
  59. data/spec/scenarios/singular_spec.rb +84 -0
  60. data/spec/spec.opts +3 -0
  61. data/spec/spec_helper.rb +15 -0
  62. metadata +289 -0
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
4
+ require 'commands/about'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/dbconsole'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/destroy'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/generate'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
+ require 'commands/performance/benchmarker'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
+ require 'commands/performance/profiler'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/plugin'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/runner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/server'
@@ -0,0 +1,118 @@
1
+ require 'spec_helper'
2
+
3
+ describe "User posting messages" do
4
+
5
+ before do
6
+ @user = User.create! :name => 'bob'
7
+
8
+ # Two equally weighted rules
9
+ ReputationRule.create :name => 'misc', :weighting => 1, :kind => 'singular'
10
+ # Create a new_message rule, where messages over 400 characters are treated positively, and messages lower negatively
11
+ # The aggregate_function is linear with a gradient of 0.2. i.e after 5 positive messages they will reach the maximum
12
+ ReputationRule.create :name => 'new_message',
13
+ :weighting => 1,
14
+ :kind => 'collection',
15
+ :function => 'step',
16
+ :constants => { :c => 400 },
17
+ :aggregate_function => 'linear',
18
+ :aggregate_constants => { :m => 0.2 }
19
+ end
20
+
21
+ describe "adding good content" do
22
+
23
+ it "should increase reputation" do
24
+ expect {
25
+ @user.behaviours.add 'new_message', 401
26
+ }.to change {
27
+ @user.reputation
28
+ }.by_at_least(0.1)
29
+ end
30
+
31
+ end
32
+
33
+ describe "adding a good message, then a bad one" do
34
+
35
+ it "should keep reputation static" do
36
+ @user.behaviours.add 'new_message', 401
37
+
38
+ expect {
39
+ @user.behaviours.add 'new_message', 401
40
+ @user.behaviours.add 'new_message', 399
41
+ }.to_not change {
42
+ @user.reputation
43
+ }
44
+ end
45
+
46
+ end
47
+
48
+ describe "adding a bad message" do
49
+
50
+ it "should reduce reputation" do
51
+ expect {
52
+ @user.behaviours.add 'new_message', 399
53
+ }.to change {
54
+ @user.reputation
55
+ }.by_at_least(-0.5).by_at_most(-0.1)
56
+ end
57
+
58
+ end
59
+
60
+ describe "multiple times but not changing content" do
61
+
62
+ it "should increase reputation" do
63
+ @user.behaviours.add 'new_message', 401
64
+
65
+ expect {
66
+ @user.behaviours.add 'new_message', 401
67
+ }.to change {
68
+ @user.reputation
69
+ }.by_at_least(0.1)
70
+ end
71
+
72
+ end
73
+
74
+ describe "adding content, then increasing the weighting" do
75
+
76
+ it "should increase reputation" do
77
+ @user.behaviours.add 'new_message', 1401
78
+
79
+ expect {
80
+ ReputationRule.find_by_name("new_message").update_attribute :weight, 2
81
+ }.to change {
82
+ @user.reputation
83
+ # in format of relative weighting * the gradient of the linear aggregate function
84
+ }.from(1/2.0 * 0.2).to(2/3.0 * 0.2)
85
+ end
86
+
87
+ end
88
+
89
+ describe "adding lots of good content" do
90
+
91
+ it "should not increase reputation past 0.5" do
92
+ @user.behaviours.add 'new_message', 401
93
+ @user.behaviours.add 'new_message', 401
94
+ @user.behaviours.add 'new_message', 401
95
+ @user.behaviours.add 'new_message', 401
96
+ @user.behaviours.add 'new_message', 401
97
+
98
+ # There are 2 rules with equal weighting so value is 0.5
99
+ @user.reputation.should == 0.5
100
+ end
101
+
102
+ end
103
+
104
+ describe "adding lots of bad content" do
105
+
106
+ it "should not decrease reputation past -0.5" do
107
+ @user.behaviours.add 'new_message', 399
108
+ @user.behaviours.add 'new_message', 399
109
+ @user.behaviours.add 'new_message', 399
110
+ @user.behaviours.add 'new_message', 399
111
+ @user.behaviours.add 'new_message', 399
112
+
113
+ @user.reputation.should == -0.5
114
+ end
115
+
116
+ end
117
+
118
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ describe "User updating a profile by" do
4
+
5
+ before do
6
+ @user = User.create! :name => 'bob'
7
+
8
+ # Two equally weighted rules
9
+ ReputationRule.create :name => 'misc', :weighting => 1, :kind => 'singular'
10
+ ReputationRule.create :name => 'profile_update', :weighting => 1, :kind => 'singular'
11
+ end
12
+
13
+ describe "adding content" do
14
+
15
+ it "should increase reputation" do
16
+ expect {
17
+ @user.behaviours.add 'profile_update', 0.5
18
+ }.to change {
19
+ @user.reputation
20
+ }.by_at_least(0.1)
21
+ end
22
+
23
+ end
24
+
25
+ describe "adding content and then removing" do
26
+
27
+ it "should keep reputation static" do
28
+ @user.behaviours.add 'profile_update', 0.5
29
+
30
+ expect {
31
+ @user.behaviours.add 'profile_update', 0.7
32
+ @user.behaviours.add 'profile_update', 0.5
33
+ }.to_not change {
34
+ @user.reputation
35
+ }
36
+ end
37
+
38
+ end
39
+
40
+ describe "adding content and then removing more" do
41
+
42
+ it "should reduce reputation" do
43
+ @user.behaviours.add 'profile_update', 0.5
44
+
45
+ expect {
46
+ @user.behaviours.add 'profile_update', 0.7
47
+ @user.behaviours.add 'profile_update', 0.3
48
+ }.to change {
49
+ @user.reputation
50
+ }.by_at_least(-0.5).by_at_most(-0.1)
51
+ end
52
+
53
+ end
54
+
55
+ describe "multiple times but not changing content" do
56
+
57
+ it "should keep reputation static" do
58
+ @user.behaviours.add 'profile_update', 0.7
59
+
60
+ expect {
61
+ @user.behaviours.add 'profile_update', 0.7
62
+ @user.behaviours.add 'profile_update', 0.7
63
+ }.to_not change {
64
+ @user.reputation
65
+ }
66
+ end
67
+
68
+ end
69
+
70
+ describe "adding content, then increasing the weighting" do
71
+
72
+ it "should increase reputation" do
73
+ @user.behaviours.add 'profile_update', 1
74
+
75
+ expect {
76
+ ReputationRule.find_by_name('profile_update').update_attribute :weight, 2
77
+ }.to change {
78
+ @user.reputation
79
+ }.by_at_least(0.1)
80
+ end
81
+
82
+ end
83
+
84
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
@@ -0,0 +1,15 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path(File.dirname(__FILE__) + "/rails_root/config/environment")
3
+
4
+ $:.unshift File.expand_path(File.dirname(File.dirname(__FILE__)))
5
+
6
+ require 'reputation'
7
+ require 'shoulda'
8
+ require 'spec/rails'
9
+ Spec::Runner.configure do |config|
10
+ # config
11
+ end
12
+
13
+ Dir.glob('spec/helpers/*.rb') do |f|
14
+ require f
15
+ end
metadata ADDED
@@ -0,0 +1,289 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reputation
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Theo Cushion
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-12 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ name: googlecharts
32
+ type: :runtime
33
+ prerelease: false
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ hash: 3
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ name: launchy
46
+ type: :runtime
47
+ prerelease: false
48
+ requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ version_requirements: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ name: sqlite3
60
+ type: :development
61
+ prerelease: false
62
+ requirement: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ version_requirements: &id004 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ name: rake
74
+ type: :development
75
+ prerelease: false
76
+ requirement: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ version_requirements: &id005 !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ name: rspec
88
+ type: :development
89
+ prerelease: false
90
+ requirement: *id005
91
+ - !ruby/object:Gem::Dependency
92
+ version_requirements: &id006 !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ hash: 9
98
+ segments:
99
+ - 1
100
+ - 3
101
+ version: "1.3"
102
+ name: rspec-rails
103
+ type: :development
104
+ prerelease: false
105
+ requirement: *id006
106
+ - !ruby/object:Gem::Dependency
107
+ version_requirements: &id007 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ name: shoulda
117
+ type: :development
118
+ prerelease: false
119
+ requirement: *id007
120
+ - !ruby/object:Gem::Dependency
121
+ version_requirements: &id008 !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - "="
125
+ - !ruby/object:Gem::Version
126
+ hash: 21
127
+ segments:
128
+ - 2
129
+ - 3
130
+ - 11
131
+ version: 2.3.11
132
+ name: rails
133
+ type: :development
134
+ prerelease: false
135
+ requirement: *id008
136
+ description: reputation is designed to help calculate reputation scores based on user behaviour and rules that are easily editable.
137
+ email: theo.c@zepler.net
138
+ executables: []
139
+
140
+ extensions: []
141
+
142
+ extra_rdoc_files: []
143
+
144
+ files:
145
+ - lib/reputation/engine.rb
146
+ - lib/reputation/functions/generalised_logistic_curve.rb
147
+ - lib/reputation/functions/linear.rb
148
+ - lib/reputation/functions/mixin.rb
149
+ - lib/reputation/functions/step.rb
150
+ - lib/reputation/functions.rb
151
+ - lib/reputation/user.rb
152
+ - lib/reputation.rb
153
+ - app/models/reputation_behaviour.rb
154
+ - app/models/reputation_intermediate_value.rb
155
+ - app/models/reputation_rule.rb
156
+ - generators/reputation/reputation_generator.rb
157
+ - generators/reputation/templates/reputation_create_tables.rb
158
+ - rails/init.rb
159
+ - spec/functions/generalised_logistic_curve_spec.rb
160
+ - spec/functions/linear_spec.rb
161
+ - spec/functions/step_spec.rb
162
+ - spec/helpers/functions.rb
163
+ - spec/models/behaviour_spec.rb
164
+ - spec/models/intermediate_value_spec.rb
165
+ - spec/models/rule_spec.rb
166
+ - spec/models/user_spec.rb
167
+ - spec/rails_root/app/controllers/application_controller.rb
168
+ - spec/rails_root/app/helpers/application_helper.rb
169
+ - spec/rails_root/app/models/user.rb
170
+ - spec/rails_root/config/boot.rb
171
+ - spec/rails_root/config/database.yml
172
+ - spec/rails_root/config/environment.rb
173
+ - spec/rails_root/config/environments/development.rb
174
+ - spec/rails_root/config/environments/test.rb
175
+ - spec/rails_root/config/initializers/backtrace_silencers.rb
176
+ - spec/rails_root/config/initializers/cookie_verification_secret.rb
177
+ - spec/rails_root/config/initializers/inflections.rb
178
+ - spec/rails_root/config/initializers/mime_types.rb
179
+ - spec/rails_root/config/initializers/new_rails_defaults.rb
180
+ - spec/rails_root/config/initializers/session_store.rb
181
+ - spec/rails_root/config/routes.rb
182
+ - spec/rails_root/db/development.sqlite3
183
+ - spec/rails_root/db/migrate/20110414125319_create_users.rb
184
+ - spec/rails_root/db/migrate/20110812160932_reputation_create_tables.rb
185
+ - spec/rails_root/db/schema.rb
186
+ - spec/rails_root/db/test.sqlite3
187
+ - spec/rails_root/log/development.log
188
+ - spec/rails_root/log/test.log
189
+ - spec/rails_root/Rakefile
190
+ - spec/rails_root/script/about
191
+ - spec/rails_root/script/console
192
+ - spec/rails_root/script/dbconsole
193
+ - spec/rails_root/script/destroy
194
+ - spec/rails_root/script/generate
195
+ - spec/rails_root/script/performance/benchmarker
196
+ - spec/rails_root/script/performance/profiler
197
+ - spec/rails_root/script/plugin
198
+ - spec/rails_root/script/runner
199
+ - spec/rails_root/script/server
200
+ - spec/scenarios/collection_spec.rb
201
+ - spec/scenarios/singular_spec.rb
202
+ - spec/spec.opts
203
+ - spec/spec_helper.rb
204
+ - .rspec
205
+ - .infinity_test
206
+ has_rdoc: true
207
+ homepage: http://github.com/theozaurus/reputation
208
+ licenses: []
209
+
210
+ post_install_message:
211
+ rdoc_options: []
212
+
213
+ require_paths:
214
+ - lib
215
+ required_ruby_version: !ruby/object:Gem::Requirement
216
+ none: false
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ hash: 3
221
+ segments:
222
+ - 0
223
+ version: "0"
224
+ required_rubygems_version: !ruby/object:Gem::Requirement
225
+ none: false
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ hash: 23
230
+ segments:
231
+ - 1
232
+ - 3
233
+ - 6
234
+ version: 1.3.6
235
+ requirements: []
236
+
237
+ rubyforge_project:
238
+ rubygems_version: 1.6.2
239
+ signing_key:
240
+ specification_version: 3
241
+ summary: Designed to help manage reputations based on user behavior
242
+ test_files:
243
+ - spec/functions/generalised_logistic_curve_spec.rb
244
+ - spec/functions/linear_spec.rb
245
+ - spec/functions/step_spec.rb
246
+ - spec/helpers/functions.rb
247
+ - spec/models/behaviour_spec.rb
248
+ - spec/models/intermediate_value_spec.rb
249
+ - spec/models/rule_spec.rb
250
+ - spec/models/user_spec.rb
251
+ - spec/rails_root/app/controllers/application_controller.rb
252
+ - spec/rails_root/app/helpers/application_helper.rb
253
+ - spec/rails_root/app/models/user.rb
254
+ - spec/rails_root/config/boot.rb
255
+ - spec/rails_root/config/database.yml
256
+ - spec/rails_root/config/environment.rb
257
+ - spec/rails_root/config/environments/development.rb
258
+ - spec/rails_root/config/environments/test.rb
259
+ - spec/rails_root/config/initializers/backtrace_silencers.rb
260
+ - spec/rails_root/config/initializers/cookie_verification_secret.rb
261
+ - spec/rails_root/config/initializers/inflections.rb
262
+ - spec/rails_root/config/initializers/mime_types.rb
263
+ - spec/rails_root/config/initializers/new_rails_defaults.rb
264
+ - spec/rails_root/config/initializers/session_store.rb
265
+ - spec/rails_root/config/routes.rb
266
+ - spec/rails_root/db/development.sqlite3
267
+ - spec/rails_root/db/migrate/20110414125319_create_users.rb
268
+ - spec/rails_root/db/migrate/20110812160932_reputation_create_tables.rb
269
+ - spec/rails_root/db/schema.rb
270
+ - spec/rails_root/db/test.sqlite3
271
+ - spec/rails_root/log/development.log
272
+ - spec/rails_root/log/test.log
273
+ - spec/rails_root/Rakefile
274
+ - spec/rails_root/script/about
275
+ - spec/rails_root/script/console
276
+ - spec/rails_root/script/dbconsole
277
+ - spec/rails_root/script/destroy
278
+ - spec/rails_root/script/generate
279
+ - spec/rails_root/script/performance/benchmarker
280
+ - spec/rails_root/script/performance/profiler
281
+ - spec/rails_root/script/plugin
282
+ - spec/rails_root/script/runner
283
+ - spec/rails_root/script/server
284
+ - spec/scenarios/collection_spec.rb
285
+ - spec/scenarios/singular_spec.rb
286
+ - spec/spec.opts
287
+ - spec/spec_helper.rb
288
+ - .rspec
289
+ - .infinity_test