Permalink
Browse files

forgot some files.

  • Loading branch information...
1 parent 2ca9009 commit 498e40051b43bf41cc5d90d9974668d1555df5b4 @mfine mfine committed Apr 12, 2012
Showing with 50 additions and 0 deletions.
  1. +23 −0 lib/ranked/ranking.rb
  2. +27 −0 scripts/sample.rb
View
@@ -0,0 +1,23 @@
+module Ranked
+ module Ranking
+
+ def self.ladder
+ ladder = []
+ Result.order(:at).each do |r|
+ ladder.push(r.winner_id) unless ladder.include?(r.winner_id)
+ ladder.push(r.loser_id) unless ladder.include?(r.loser_id)
+
+ winner_index = ladder.index(r.winner_id)
+ loser_index = ladder.index(r.loser_id)
+
+ if winner_index > loser_index
+ ladder.delete_at(winner_index)
+ ladder = ladder.insert(loser_index, r.winner_id)
+ end
+ end
+
+ ladder.map { |i| Player[i] }
+ end
+
+ end
+end
View
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+
+$:.unshift(File.expand_path(File.join(File.dirname(File.dirname($0)), "lib")))
+
+require "sequel"
+
+require "ranked/log"
+require "ranked/conf"
+require "ranked/autoload"
+
+include Ranked
+
+if db = Sequel.connect(Conf.database_url)
+ ok = db.test_connection
+ Log.notice ok: ok
+ if ok
+ db.tables.each { |model| Sequel::Model(model) }
+ p1 = Player.create user: "fine@heroku.com"
+ p2 = Player.create user: "pedro@heroku.com"
+ p3 = Player.create user: "blake@heroku.com"
+ Result.create at: Time.now, winner_id: p1.id, loser_id: p2.id
+ Result.create at: Time.now + 1000, winner_id: p1.id, loser_id: p3.id
+ Result.create at: Time.now + 2000, winner_id: p2.id, loser_id: p3.id
+ end
+end
+
+

0 comments on commit 498e400

Please sign in to comment.