Pastoid

Madness

The page you are looking at now is at this URL: http://pastoid.com/aup

This paste was last updated on April 2, 2009 at 7:53 am.

Pasted Coderaw

module Judge::Models
  class User < Base
    has_many :judgments
  end
 
  class Judgment < Base
    belongs_to :users
    belongs_to :resource
  end
 
  class Topic < Base
    has_many :resources
    has_many :judgments
  end
 
  class Resource < Base
    has_many :judgments
    belongs_to :topic
  end
 
  class BestResource < Base
    belongs_to :user
    belongs_to :topic
    has_one :resource
  end
 
end
 
module Judge::Controllers
 
  class Judge < R '/judge'
    def get
        # Work out which is the appropriate topic to judge
 
        # Topics that have not had a best resource judgment made
        unbest = Judge::Models::Topic.all(:joins => 'OUTER LEFT JOIN best_resources ON topics.id = best_resources.topic_id', :conditions => 'best_resources.id IS NULL')
 
        # We've finished judging all the topics, move on to the next task
        if unbest.length == 0
          @state.user.stint.done_judgments = true
          @state.user.stint.save
          redirect Index
        else
          # Get the topics that have resources that haven't been judged
          unjudged = Topic.all(:joins => "INNER JOIN resources ON resources.topic_id = topics.id OUTER LEFT JOIN judgments ON (judgments.resource_id = resourc
es.id AND judgments.user_id = #{@state.user.id})", :conditions => 'judgments.id IS NULL', :group => 'topics.id')
 
          # If there is a topic in unbest that's not in unjudged, judge the best resource
          unfinished = unbest - unjudged
          topic = if unfinished.length > 0
            Topic.find(unfinished.shift)
 
          else
            # Get the topics that have resources that haven't been judged in the form {:id => :count}
            topics = Topic.count(:joins => "INNER JOIN resources ON resources.topic_id = topics.id OUTER LEFT JOIN judgments ON (judgments.resource_id = resou
rces.id AND judgments.user_id = #{@state.user.id})", :conditions => 'judgments.id IS NULL', :group => 'topics.id')
 
            # If there's only one topic, use it
            if topics.length == 1
              Topic.find(topics.keys[0])
 
            # If there is a partly judged topic, it will be first, so judge it
            elsif topics[topics.keys[0]] < topics[topics.keys[1]]
              Topic.find(topics.keys[0])
 
            # Otherwise take a random topic
            else
              Topic.find(topics.keys[rand(topics.length)])
            end
 
          end
          # There are topics left to judge, redirect to /topic/(id)/judge
          redirect TopicController, topic.id, 'judge'
        end
      end
 
    end
  end
end
 

Toggle wordwrap

Referring DomainHits
pastoid.com 140
Unknown Referer 127
www.google.com 1
Is this paste spam?
<Hide