Merge head
authorJohn Dong <jdong@mit.edu>
Thu, 30 Aug 2007 23:13:09 +0000 (19:13 -0400)
committerJohn Dong <jdong@mit.edu>
Thu, 30 Aug 2007 23:13:09 +0000 (19:13 -0400)
app/controllers/account_controller.rb
app/models/election.rb
config/environment.rb
config/environments/development.rb
config/environments/production.rb
config/environments/test.rb
public/stylesheets/ie6hacks.css

index e8adcf0fe809b8a466f38eb7161e5af765060104..524d743ee0161551cbb97909f26f179e3c93e134 100644 (file)
@@ -25,6 +25,10 @@ class AccountController < ApplicationController
       flash[:notice] = "Logged in successfully"
     end
   end
+  
+  def forgot_password
+    raise "Not Implemented!"
+  end
 
   def signup
     @user = User.new(params[:user])
index 7fa138ef4c433b4aafc239cd573aaf04a31bb8fb..99d64f93cc55424b34f82dac24d0dce9a1e4fc73 100644 (file)
@@ -88,8 +88,28 @@ class Election < ActiveRecord::Base
     longdesc.length > 0 ? longdesc : nil 
   end
   
-  #Calculate Election Results
+  #Calculate results if not in memcache
   def results
+    # Assignment is intentional
+    if Cache and c = Cache.get("election_results:#{id}:#{self.votes.length}")
+      @plurality_result = c['plurality']
+      @approval_result = c['approval']
+      @condorcet_result = c['condorcet']
+      @ssd_result = c['ssd']
+      @borda_result = c['borda']
+      return c
+    elsif Cache
+      # memcache is available, but missed.
+      results = self.results!
+      Cache.set("election_results:#{id}:#{self.votes.length}", results)
+      return results
+    else
+      return self.results!
+    end
+  end
+
+  #Always Calculate Election Results
+  def results!
     # initalize the tallies to empty arrays
     preference_tally = Array.new
     plurality_tally = Array.new
@@ -129,7 +149,6 @@ class Election < ActiveRecord::Base
     
     names
   end
-  
 end
 
 
index 5ea9f103de256e61f44349285a358559b2b3a11c..fcabdd87aa6279b6003532259625536ac62e3fb3 100644 (file)
@@ -65,7 +65,6 @@ require 'uniq_token'
 require 'randarray'
 require 'gruff-0.2.8/lib/gruff'
 require 'sparklines'
-
 require 'rubyvote'
 ELECTION_TYPES = {'ssd' => "Schulze Sequential Dropping",
                   'plurality' => "Plurality/First Past the Post",
index 12a3e04e5fb70df7ae8d679999e2ee76cd50fe20..198c2bdafe91f92df9e624308df375b3dec695b2 100644 (file)
@@ -1,5 +1,6 @@
 # Settings specified here will take precedence over those in config/environment.rb
-
+#disable memcache
+Cache=nil
 # In the development environment your application's code is reloaded on
 # every request.  This slows down response time but is perfect for development
 # since you don't have to restart the webserver when you make code changes.
index cb295b83f17285331882dfdc0eebddaecf32f773..3192ef53fe394680cdc5785a3605c9ccfc1656ca 100644 (file)
@@ -1,5 +1,8 @@
 # Settings specified here will take precedence over those in config/environment.rb
-
+#
+#Enable memcache
+require('memcache')
+Cache=MemCache.new('localhost', :compression => true)
 # The production environment is meant for finished, "live" apps.
 # Code is not reloaded between requests
 config.cache_classes = true
index 7c2f617db2b1810fd86d3c15418b607403b991ca..a1a2608bbfd3ef55531c08d37403266a0d7d463f 100644 (file)
@@ -1,5 +1,6 @@
 # Settings specified here will take precedence over those in config/environment.rb
-
+#disable memcache
+Cache=nil
 # The test environment is used exclusively to run your application's
 # test suite.  You never need to work with it otherwise.  Remember that
 # your test database is "scratch space" for the test suite and is wiped
index 9aa34222567a6439aa63cd47302e2cb16bf36616..eefd731df2a640dabc557b350eb0e4358f711fc5 100644 (file)
@@ -24,7 +24,7 @@ div#bar-right {
   clear: right;
 }
 
-ol {
+li.moveable {
   list-style-type: none;
 }
 

Benjamin Mako Hill || Want to submit a patch?