2010-05-31 22:15:44 +02:00
|
|
|
|
require "camping"
|
|
|
|
|
require "camping/session"
|
2010-05-18 15:07:50 +02:00
|
|
|
|
require "pathname"
|
2010-05-18 15:32:30 +02:00
|
|
|
|
require "markaby"
|
|
|
|
|
|
|
|
|
|
Markaby::Builder.set(:indent, 2)
|
2010-05-18 15:07:50 +02:00
|
|
|
|
|
|
|
|
|
Camping.goes :Anne
|
|
|
|
|
|
2010-06-01 00:09:16 +02:00
|
|
|
|
PUBLIC_DIR = Pathname.new(__FILE__).dirname + "public"
|
|
|
|
|
IMAGE_DIR = PUBLIC_DIR + "images"
|
2010-05-18 15:07:50 +02:00
|
|
|
|
|
2010-05-18 22:47:14 +02:00
|
|
|
|
module Anne
|
|
|
|
|
|
|
|
|
|
include Camping::Session
|
|
|
|
|
secret "JeMoeder"
|
|
|
|
|
|
2010-05-18 23:54:15 +02:00
|
|
|
|
def self.create
|
|
|
|
|
Anne::Models.create_schema
|
|
|
|
|
end
|
|
|
|
|
|
2010-05-18 22:47:14 +02:00
|
|
|
|
end
|
|
|
|
|
|
2010-05-18 15:07:50 +02:00
|
|
|
|
module Anne::Models
|
|
|
|
|
|
|
|
|
|
class User < Base
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
class Vote < Base
|
|
|
|
|
belongs_to :user
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
class BasicFields < V 1.0
|
|
|
|
|
def self.up
|
|
|
|
|
create_table User.table_name do |t|
|
2010-06-08 08:41:29 +02:00
|
|
|
|
t.string :study, :gender, :spaciousness, :email, :comments
|
2010-05-18 15:07:50 +02:00
|
|
|
|
t.integer :study_year
|
|
|
|
|
t.boolean :colorblind, :prize, :results
|
|
|
|
|
t.timestamps
|
|
|
|
|
end
|
|
|
|
|
create_table Vote.table_name do |t|
|
|
|
|
|
t.string :image, :choice
|
|
|
|
|
t.integer :user_id
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.down
|
|
|
|
|
drop_table User.table_name
|
|
|
|
|
drop_table Vote.table_name
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
module Anne::Helpers
|
|
|
|
|
|
|
|
|
|
def next_image
|
2010-05-18 23:54:15 +02:00
|
|
|
|
all_images =
|
2010-05-28 16:32:26 +02:00
|
|
|
|
Pathname.glob(IMAGE_DIR + "*-l.png").map { |img| img.basename.to_s.sub("-l.png", "") }
|
2010-05-18 23:54:15 +02:00
|
|
|
|
all_votes =
|
|
|
|
|
Anne::Models::Vote.find(:all,
|
|
|
|
|
:conditions => { :user_id => @state["user"].id })
|
|
|
|
|
voted_images = all_votes.map { |vote| vote.image }
|
2010-05-18 15:07:50 +02:00
|
|
|
|
remaining_images = all_images - voted_images
|
|
|
|
|
return nil, 100 if remaining_images.empty?
|
2010-05-18 23:54:15 +02:00
|
|
|
|
return remaining_images.sort_by { rand }.first,
|
2010-05-27 17:22:20 +02:00
|
|
|
|
100 - (remaining_images.length * 100.0 / all_images.length).ceil
|
2010-05-18 15:07:50 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
module Anne::Controllers
|
|
|
|
|
|
|
|
|
|
class Index
|
|
|
|
|
def get
|
|
|
|
|
render :intro
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
class Start
|
|
|
|
|
def get
|
2010-05-18 22:47:14 +02:00
|
|
|
|
return redirect Vote if @state["user"]
|
2010-05-18 15:07:50 +02:00
|
|
|
|
render :start
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def post
|
2010-05-18 22:47:14 +02:00
|
|
|
|
@state["user"] = User.create(
|
|
|
|
|
:study => @input.user_study,
|
|
|
|
|
:study_year => @input.user_study_year,
|
|
|
|
|
:gender => @input.user_gender,
|
|
|
|
|
:colorblind => @input.user_colorblind == "ja",
|
|
|
|
|
:spaciousness => @input.user_spaciousness)
|
|
|
|
|
redirect Vote
|
2010-05-18 15:07:50 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2010-05-18 22:47:14 +02:00
|
|
|
|
class Vote
|
|
|
|
|
def get
|
|
|
|
|
return redirect Index if not @state["user"]
|
|
|
|
|
image, progress = next_image
|
|
|
|
|
return redirect Finish if image.nil?
|
|
|
|
|
render :vote, image, progress
|
2010-05-18 15:07:50 +02:00
|
|
|
|
end
|
|
|
|
|
|
2010-05-18 22:47:14 +02:00
|
|
|
|
def post
|
2010-05-28 16:32:26 +02:00
|
|
|
|
choice = if @input["left.x"] then "left"
|
|
|
|
|
elsif @input["right.x"] then "right"
|
2010-05-18 23:54:15 +02:00
|
|
|
|
else raise "no choice made!"
|
2010-05-18 15:07:50 +02:00
|
|
|
|
end
|
2010-05-18 22:47:14 +02:00
|
|
|
|
vote = Anne::Models::Vote.create( :user_id => @state["user"].id,
|
|
|
|
|
:image => @input.image,
|
|
|
|
|
:choice => choice )
|
|
|
|
|
redirect Vote
|
2010-05-18 15:07:50 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
class ImageX
|
|
|
|
|
def get(file)
|
|
|
|
|
unless file =~ /\.\./
|
2010-05-28 16:32:26 +02:00
|
|
|
|
headers["Content-Type"] = "image/png"
|
2010-06-01 00:09:16 +02:00
|
|
|
|
headers["X-Sendfile"] =
|
|
|
|
|
(IMAGE_DIR.relative_path_from(PUBLIC_DIR) + file).to_s
|
2010-05-18 15:07:50 +02:00
|
|
|
|
else
|
|
|
|
|
@status = 403
|
|
|
|
|
"You're not allowed to retrieve #{file}!"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2010-05-18 22:47:14 +02:00
|
|
|
|
class Finish
|
|
|
|
|
def get
|
|
|
|
|
return redirect Index if not @state["user"]
|
|
|
|
|
return redirect Vote unless next_image.first.nil?
|
2010-05-28 18:12:03 +02:00
|
|
|
|
return redirect Thanks unless @state["user"].results.nil?
|
2010-05-18 15:07:50 +02:00
|
|
|
|
render :finish
|
|
|
|
|
end
|
2010-05-18 23:54:15 +02:00
|
|
|
|
|
|
|
|
|
def post
|
2010-05-28 18:12:03 +02:00
|
|
|
|
user = @state["user"]
|
2010-05-18 23:54:15 +02:00
|
|
|
|
raise "unknown user" if user.nil?
|
|
|
|
|
user.email = @input.email
|
|
|
|
|
user.prize = !@input.prize.nil?
|
|
|
|
|
user.results = !@input.results.nil?
|
2010-06-08 08:41:29 +02:00
|
|
|
|
user.comments = @input.comments
|
2010-05-18 23:54:15 +02:00
|
|
|
|
user.save
|
|
|
|
|
redirect Thanks
|
|
|
|
|
end
|
2010-05-18 15:07:50 +02:00
|
|
|
|
end
|
|
|
|
|
|
2010-05-18 15:42:54 +02:00
|
|
|
|
class Style < R '/style\.css'
|
|
|
|
|
STYLE = File.read(__FILE__).gsub(/.*__END__/m, '')
|
|
|
|
|
|
|
|
|
|
def get
|
|
|
|
|
@headers['Content-Type'] = 'text/css; charset=utf-8'
|
|
|
|
|
STYLE
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2010-05-18 23:54:15 +02:00
|
|
|
|
class Thanks
|
|
|
|
|
def get
|
|
|
|
|
render :thanks
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2010-05-18 15:07:50 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
module Anne::Views
|
|
|
|
|
|
|
|
|
|
def layout
|
|
|
|
|
xhtml_strict do
|
|
|
|
|
head do
|
2010-05-27 17:22:20 +02:00
|
|
|
|
title "Enquête ruimtelijke effecten"
|
2010-05-18 15:42:54 +02:00
|
|
|
|
link :rel => "stylesheet", :type => "text/css",
|
|
|
|
|
:media => "screen", :href => "/style.css"
|
2010-05-18 15:07:50 +02:00
|
|
|
|
end
|
|
|
|
|
body do
|
2010-05-18 15:32:30 +02:00
|
|
|
|
div.header! do
|
2010-06-21 19:37:44 +02:00
|
|
|
|
h1 do
|
|
|
|
|
span.left "Enquête ruimtelijke effecten"
|
|
|
|
|
img.right :src => R(ImageX, "tuelogo.gif"),
|
|
|
|
|
:alt => "[TU/e logo]",
|
|
|
|
|
:style => "right: 180px";
|
|
|
|
|
img.right :src => R(ImageX, "philipslogo.gif"),
|
|
|
|
|
:alt => "[Philips logo]",
|
|
|
|
|
:style => "padding: 5px 5px; margin: 13px 0px; background: white;"
|
|
|
|
|
end
|
2010-05-18 15:32:30 +02:00
|
|
|
|
end
|
|
|
|
|
div.content! { self << yield }
|
2010-05-31 22:15:44 +02:00
|
|
|
|
div.footer! do
|
|
|
|
|
p "Copyright © 2010 Anne Pijl, Bram Senders, Paul van Tilburg"
|
|
|
|
|
end
|
2010-05-18 15:07:50 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def intro
|
2010-05-28 16:44:24 +02:00
|
|
|
|
p "Met deze enquête worden een aantal ruimtelijke effecten onderzocht. " \
|
2010-05-31 22:15:44 +02:00
|
|
|
|
"Je krijgt 45 keer twee afbeeldingen te zien. Je kiest welke afbeelding" \
|
|
|
|
|
" je ruimtelijker ervaart. In welke afbeelding zie je meer diepte, " \
|
|
|
|
|
"welke afbeelding lijkt jou het meest 3-dimensionaal? Als je het niet " \
|
2010-06-09 14:14:09 +02:00
|
|
|
|
"weet, klik je op een willekeurige afbeelding. De test duurt 5 " \
|
2010-05-31 22:15:44 +02:00
|
|
|
|
"minuten. Succes!"
|
|
|
|
|
|
2010-06-21 16:01:55 +02:00
|
|
|
|
p "Doe de test volledig om kans te maken op eerste prijs van een " \
|
|
|
|
|
"Philips Living Colors lamp of de tweede prijs van 20 euro."
|
2010-05-27 17:22:20 +02:00
|
|
|
|
p "– Anne Pijl"
|
2010-05-31 19:01:51 +02:00
|
|
|
|
|
|
|
|
|
form :action => R(Start), :method => :get do
|
|
|
|
|
input :type => "submit", :value => "Ga verder"
|
|
|
|
|
end
|
2010-05-18 15:07:50 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def make_select(label_name, name, options)
|
|
|
|
|
p do
|
|
|
|
|
label label_name, :for => name
|
|
|
|
|
select :name => name do
|
|
|
|
|
options.each { |option_str| option option_str }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def start
|
2010-05-27 17:22:20 +02:00
|
|
|
|
h2 "Persoonlijke karakteristieken"
|
|
|
|
|
p "Graag zou ik ten behoeve van de statistiek het volgende van je willen weten:"
|
2010-05-18 15:07:50 +02:00
|
|
|
|
|
|
|
|
|
form :action => R(Start), :method => :post do
|
2010-05-31 19:01:51 +02:00
|
|
|
|
make_select "Faculteit", "user_study",
|
2010-05-27 17:22:20 +02:00
|
|
|
|
["niet van toepassing",
|
|
|
|
|
"Biomedische Technologie",
|
|
|
|
|
"Bouwkunde",
|
|
|
|
|
"Electrical Engineering",
|
|
|
|
|
"Industrial Design",
|
|
|
|
|
"Scheikundige Technologie",
|
|
|
|
|
"Industrial Engineering & Innovation Sciences",
|
|
|
|
|
"Technische Natuurkunde",
|
|
|
|
|
"Werktuigbouwkunde",
|
|
|
|
|
"Wiskunde & Informatica"]
|
2010-05-31 22:15:44 +02:00
|
|
|
|
make_select "Studiejaar", "user_study_year",
|
|
|
|
|
["niet van toepassing"] + (1998..2009).to_a
|
2010-05-18 15:07:50 +02:00
|
|
|
|
make_select "Geslacht", "user_gender", ["", "man", "vrouw"]
|
2010-05-27 17:22:20 +02:00
|
|
|
|
make_select "Ben je kleurenblind?", "user_colorblind", ["nee", "ja"]
|
|
|
|
|
make_select "Vind je dat je een goed ruimtelijk voorstellingsvermogen hebt?",
|
|
|
|
|
"user_spaciousness", ["neutraal", "ja", "nee"]
|
2010-05-18 15:07:50 +02:00
|
|
|
|
|
2010-05-31 13:25:58 +02:00
|
|
|
|
input :type => "submit", :value => "Start de enquête!"
|
2010-05-18 15:07:50 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def vote(image, progress = 0)
|
2010-05-18 15:32:30 +02:00
|
|
|
|
h2 "Welk beeld is ruimtelijker?"
|
2010-06-01 12:01:59 +02:00
|
|
|
|
form.images! :action => R(Vote), :method => :post do
|
2010-05-18 15:07:50 +02:00
|
|
|
|
input :type => "hidden", :name => "image", :value => image
|
2010-06-21 19:37:44 +02:00
|
|
|
|
input :type => "image", :src => R(ImageX, "#{image}-l.png"),
|
|
|
|
|
:name => "left", :class => "left image"
|
|
|
|
|
input :type => "image", :src => R(ImageX, "#{image}-r.png"),
|
|
|
|
|
:name => "right", :class => "right image"
|
2010-05-31 19:01:51 +02:00
|
|
|
|
end
|
|
|
|
|
div.progressbar! do
|
2010-05-31 22:15:44 +02:00
|
|
|
|
div.done! :style => "width: #{progress}%" do end
|
2010-05-18 15:07:50 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def finish
|
2010-05-27 17:22:20 +02:00
|
|
|
|
h2 "Dank je wel voor het meedoen aan dit onderzoek."
|
2010-05-31 22:15:44 +02:00
|
|
|
|
p "Als je geïnteresseerd bent in de resultaten van de enquête of je wilt " \
|
2010-06-21 16:01:55 +02:00
|
|
|
|
"meedingen naar de Philips Living Colors lamp of de prijs van 20 " \
|
|
|
|
|
"euro, vul dan hier je e-mailadres in."
|
2010-05-18 15:07:50 +02:00
|
|
|
|
|
2010-05-18 22:47:14 +02:00
|
|
|
|
form :action => R(Finish), :method => :post do
|
2010-05-18 15:07:50 +02:00
|
|
|
|
p do
|
|
|
|
|
label "E-mailadres", :for => "email"
|
|
|
|
|
input :type => "text", :name => "email"
|
|
|
|
|
end
|
|
|
|
|
p do
|
|
|
|
|
input :type => "checkbox", :name => "prize", :checked => true
|
2010-05-31 19:01:51 +02:00
|
|
|
|
label "Ik wil meedingen naar de prijs.", :for => "prize"
|
2010-05-18 15:07:50 +02:00
|
|
|
|
end
|
|
|
|
|
p do
|
|
|
|
|
input :type => "checkbox", :name => "results", :checked => true
|
2010-05-31 13:25:58 +02:00
|
|
|
|
label "Ik wil de resultaten van het onderzoek ontvangen.", :for => "results"
|
2010-05-18 15:07:50 +02:00
|
|
|
|
end
|
|
|
|
|
|
2010-05-28 16:36:17 +02:00
|
|
|
|
p "Je e-mailadres wordt enkel gebruikt voor de enquête-resultaten en " \
|
2010-05-27 17:22:20 +02:00
|
|
|
|
"om je op de hoogte te stellen als je gewonnen hebt."
|
|
|
|
|
|
2010-06-08 08:41:29 +02:00
|
|
|
|
p do
|
|
|
|
|
label "Opmerkingen over dit onderzoek", :for => "comments"
|
|
|
|
|
br
|
|
|
|
|
textarea :name => "comments", :cols => 80, :rows => 5
|
|
|
|
|
end
|
|
|
|
|
|
2010-05-27 17:22:20 +02:00
|
|
|
|
input :type => "submit", :value => "Verstuur"
|
2010-05-18 15:07:50 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2010-05-18 23:54:15 +02:00
|
|
|
|
def thanks
|
2010-05-27 17:22:20 +02:00
|
|
|
|
h2 "Bedankt!"
|
|
|
|
|
|
|
|
|
|
p "Je antwoorden zijn verstuurd."
|
2010-05-18 23:54:15 +02:00
|
|
|
|
end
|
2010-05-18 15:07:50 +02:00
|
|
|
|
|
|
|
|
|
end
|
2010-05-18 15:42:54 +02:00
|
|
|
|
|
|
|
|
|
__END__
|
|
|
|
|
/* Style sheet for the Anne Survey Camping app */
|
2010-05-18 23:54:15 +02:00
|
|
|
|
|
2010-05-31 22:15:44 +02:00
|
|
|
|
html { background: #333; }
|
2010-05-31 19:01:51 +02:00
|
|
|
|
|
2010-05-18 23:54:15 +02:00
|
|
|
|
body {
|
2010-05-31 22:15:44 +02:00
|
|
|
|
margin: 10px auto;
|
2010-06-01 00:39:18 +02:00
|
|
|
|
padding: 10px;
|
2010-05-31 19:01:51 +02:00
|
|
|
|
width: 960px;
|
|
|
|
|
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
|
2010-05-18 23:54:15 +02:00
|
|
|
|
color: white;
|
|
|
|
|
background-color: black;
|
2010-05-31 22:15:44 +02:00
|
|
|
|
-webkit-border-radius: 12px;
|
|
|
|
|
-moz-border-radius: 12px;
|
|
|
|
|
border-radius: 12px;
|
2010-05-31 19:01:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-21 19:37:44 +02:00
|
|
|
|
#header { position: relative; height: 73px; }
|
|
|
|
|
#header span { bottom: 10px; }
|
2010-05-31 19:01:51 +02:00
|
|
|
|
|
2010-06-01 12:01:59 +02:00
|
|
|
|
#images { position: relative; height: 470px; }
|
2010-06-21 19:37:44 +02:00
|
|
|
|
.image { border: thin solid #888; }
|
|
|
|
|
.left { position: absolute; left: 0px; }
|
|
|
|
|
.right { position: absolute; right: 0px; }
|
2010-05-31 19:01:51 +02:00
|
|
|
|
|
|
|
|
|
#progressbar {
|
|
|
|
|
height: 6px;
|
2010-06-01 12:01:59 +02:00
|
|
|
|
margin-top: 8px;
|
2010-05-31 19:01:51 +02:00
|
|
|
|
background-color: #101073;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#progressbar #done {
|
2010-06-01 12:01:59 +02:00
|
|
|
|
height: 6px;
|
2010-05-31 19:01:51 +02:00
|
|
|
|
background-color: #d6007b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#footer {
|
2010-05-31 22:15:44 +02:00
|
|
|
|
padding: 0px 0px 0px 8px;
|
|
|
|
|
margin-top: 14px;
|
2010-05-31 19:01:51 +02:00
|
|
|
|
border-top: thin #eee solid;
|
2010-05-31 22:15:44 +02:00
|
|
|
|
font-size: 69.4%;
|
2010-05-18 23:54:15 +02:00
|
|
|
|
}
|