From 3d34de1a94f1277277f239e2c98c519fc610a302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kurt=20G=C3=B6del?= Date: Sat, 11 Jul 2009 12:55:24 -0400 Subject: [PATCH] display svd result --- app/controllers/questions_controller.rb | 19 +++++++++++++++++++ app/views/questions/svd.csv.haml | 11 +++++++++++ app/views/questions/svd.xml.haml | 17 +++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 app/views/questions/svd.csv.haml create mode 100644 app/views/questions/svd.xml.haml diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index d192f87..0754e8d 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -1,4 +1,6 @@ class QuestionsController < ApplicationController + include Algorithms::Rank::RSVD + before_filter :force_xml # GET /questions/1 @@ -58,4 +60,21 @@ def list @all_items_count = Item.count(:conditions => { :user_id => current_user.id }) @votes_count = Prompt.count(:joins => "INNER JOIN votes ON (votes.prompt_id=prompts.id)", :conditions => { :question_id => current_user.question_ids }) end + + # GET /questions/1 + # ==== Return + # Question SVD. + # ==== Options (params) + # id:: Converted to integer. ID of question. + # ==== Raises + # PermissionError:: If question does not belong to user. + def svd + @question = Question.first(:conditions => { :id => params[:id], :user_id => current_user.id }) + if @question + sol = load_solution(@question.id) + if sol && sol.shift + @h, @v, @p, @items, @visits = sol + end + end + end end \ No newline at end of file diff --git a/app/views/questions/svd.csv.haml b/app/views/questions/svd.csv.haml new file mode 100644 index 0000000..a6bea0d --- /dev/null +++ b/app/views/questions/svd.csv.haml @@ -0,0 +1,11 @@ +type,row,col,value +-@items.each_index do |i| + ==item,#{i},0,#{@items[i]} +-@visits.each_index do |i| + ==visit,#{i},0,#{@visits[i]} +-@v.rows.each_with_index do |row, i| + -row.elems.each_with_index do |e, j| + ==v,#{i},#{j},#{e} +-@p.rows.each_with_index do |row, i| + -row.elems.each_with_index do |e, j| + ==p,#{i},#{j},#{e} diff --git a/app/views/questions/svd.xml.haml b/app/views/questions/svd.xml.haml new file mode 100644 index 0000000..99e52b4 --- /dev/null +++ b/app/views/questions/svd.xml.haml @@ -0,0 +1,17 @@ +%question{:id => @question.id, :h => @h} + %items + -@items.each_index do |i| + %item{:id => @items[i]}= i + %visits + -@visits.each_index do |i| + %visit{:id => @visits[i]}= i + %v + -@v.rows.each_with_index do |row, i| + %row{:index => i} + -row.elems.each_with_index do |e, j| + %col{:index => j}= e + %p + -@p.rows.each_with_index do |row, i| + %row{:index => i} + -row.elems.each_with_index do |e, j| + %col{:index => j}= e \ No newline at end of file