2
# rating.rb: ʣ�����ˤ�뵭��ɾ���ȥ����ɽ��
6
# ���Τޤ� plugin �ǥ��쥯�ȥ���֤��ޤ���
7
# '����' -> 'rating.rb Configuration' �ǡ�ɾ������
10
# http://www.maripo.jp/diary/?date=20071019
12
# Copyright (c) 2007 Mariko/Maripo GODA <god@maripo.jp>
13
# http://www.maripo.jp/
14
# You can redistribute it and/or modify it under GPL.
19
@dbase = "#{@cache_path}/rating.db"
21
#########################################
23
#########################################
25
add_conf_proc('rating', 'rating.rb Configuration') do
26
rating_config = RatingConfig.new(@dbase)
29
if @mode == 'saveconf'
35
rating_config.each { |axis_config|
37
if (@cgi.params["label" + index.to_s][0] != "" && (@cgi.params["range" + index.to_s][0]).to_i > 0)
38
axis_config.edit(@cgi.params["label" + index.to_s][0], @cgi.params["label_max" + index.to_s][0],@cgi.params["label_min" + index.to_s][0],@cgi.params["range" + index.to_s][0].to_i,@cgi.params["order" + index.to_s][0].to_i,@cgi.params["display" + index.to_s][0]!=nil)
42
if (@cgi.params["label_new"][0] != "" && @cgi.params["range_new"][0].to_i > 0)
44
rating_config.add_axis(@cgi.params["label_new"][0], @cgi.params["label_max_new"][0], @cgi.params["label_min_new"][0], @cgi.params["range_new"][0].to_i)
46
rating_config.save_to_db
54
�ե����ɥХå��ե����������ޤ������Ϥ����ĤǤ�������뤳�Ȥ��Ǥ��ޤ���
57
<a href="http://www.maripo.jp/">���</a>�� <a href="http://www.maripo.jp/diary/?date=20071019">blog</a> ���ɲþ��Ƥ��뤫�⤷��ޤ���
61
<li>�� �� ɽ���������֤Ǥ����������ۤ��������¤Ӥޤ����ֹ椬����Ǥ�OK��</li>
62
<li>ɽ�� �� ����ʤ����ϥ����å����Ƥ��ޤäƤ���������
63
<li>����̾�� �� (��) "���ε����ϻ��ͤˤʤ�ޤ�����"</li>
64
<li>�����٥� �� �� "�ޤä������ͤˤʤ�ʤ�"</li>
65
<li>�ǹ��٥� �� �� "�ȤƤ⻲�ͤˤʤä�"</li>
66
<li>������ �� �� : 1��5��5�ʳ��ʤ� "5"</li>
74
rating_config.each { |axis_config|
77
<td>��:<input type="text" size="2" name="order#{index}" value="#{axis_config.order}"></td>
79
����̾��:<input type="text" size="16" name="label#{index}" value="#{axis_config.label}">��
80
�����٥�:<input type="text" size="10" name="label_min#{index}" value="#{axis_config.label_min}">��
81
�ǹ��٥�:<input type="text" size="10" name="label_max#{index}" value="#{axis_config.label_max}">��
82
������:<input type="text" size="4" name="range#{index}" value="#{axis_config.range.to_s}">��
83
ɽ��:<input type="checkbox" name="display#{index}" value="#{axis_config.label_max}" #{axis_config.check_label}>
93
����̾��:<input type="text" size="16" name="label_new">
94
�����٥�:<input type="text" size="10" name="label_min_new">
95
�ǹ��٥�:<input type="text" size="10" name="label_max_new">
96
������:<input type="text" size="4" name="range_new">
101
form_string += '</form>'
102
form_string #evaluate
106
#########################################
108
#########################################
110
add_body_leave_proc do |date|
115
#initialize DateEval object
116
todays_eval = DateEval.new(date.strftime('%Y%m%d'), @dbase)
118
#initialize RatingConfig object
119
@rating_config = RatingConfig.new(@dbase)
121
graph_string += <<HTML
122
<!-- Generated by plugin "rating.rb" -->
123
<div class="ratingGraphContainer" style="overflow:hidden;height:18px;">
125
onclick="with(this.parentNode.style){if(overflow=='hidden'){overflow='visible';}else{overflow='hidden';}}"
127
class="ratingGraphOpener">
130
<div class="ratingGraphContent">
132
form_string += '<!-- Generated by plugin "rating.rb" -->' + "\n"
133
form_string += ('<form action="./"><input type="hidden" name="comment" value="submit"><input type="hidden" name="body" value="rating"><input type="hidden" name="body" value="rating"><input type="hidden" name="name" value=""><input type="hidden" value="' + date.strftime('%Y%m%d') + '"><div class="ratingForm">')
134
@rating_config.each{|axis_config|
136
if !axis_config.display
141
form_string += ('<div class="ratingQuestion"><span class="ratingLabel">' + axis_config.label + '</span>')
144
form_string += ('<span class="ratingRadioButtons"><span class="ratingLabelMin">' + axis_config.label_min + '</span>')
146
# append graph string
149
graph_string += '<div class="ratingGraphBox">' #begin "graphBox"
150
graph_string += '<span class="ratingGraphAverage">average : ' + sprintf("%10.2f", todays_eval.get_average(axis_config.id)) +'</span><br>'
151
while current_rank < axis_config.range
152
graph_string += ('<div style="clear:both"><div
153
class="ratingGraphRank">' + (current_rank + 1).to_s + '</div><div
154
class="ratingGraphBar" style="width:' +
155
todays_eval.get_graph_length(axis_config.id, current_rank).to_s +
156
'px"></div><span class="ratingGraphValue"> (' + todays_eval.get_value(axis_config.id, current_rank).to_s + 'ɼ)</span></div>')
159
graph_string += '</div>' #end "graphBox"
161
for current_rank in 0..axis_config.range - 1
162
form_string += " " + '<input type="radio" name="axis' + axis_config.id.to_s + '" value="' + current_rank.to_s + '">' + (current_rank + 1).to_s
164
form_string += ('<span class="ratingLabelMax">' + axis_config.label_max + '</span></span>')
165
form_string += '</div>'
167
graph_string += <<HTML
170
<div style="clear:both;height:0px;"></div>
172
form_string += '<input type="hidden" name="date" value="' + date.strftime('%Y%m%d') + '">'
173
form_string += '<input type="submit" value="ɾ������"></div></form>'+"\n"
174
(form_string + graph_string)
178
#########################################
180
#########################################
187
def initialize (dbase)
189
db = PStore.new(@dbase)
192
if db.root?("config")
195
@max_axis_id = obj[0]
198
@axes[id] = AxisConfig.new(ary[0],ary[1],ary[2],ary[3],ary[4],ary[5],ary[6])
209
save_array = Array.new
210
db = PStore.new(@dbase)
211
save_array.push(@max_axis_id)
213
save_array.push(axis_config.to_array)
217
db["config"] = save_array
222
def add_axis (label, label_max, label_min, range)
224
new_axis = AxisConfig.new(label, label_max, label_min, range, @max_axis_id, 0, true)
225
@axes[@max_axis_id] = new_axis
228
def edit_axis (axis_id, label, label_max, label_min, range, order,display)
229
target_axis = @axes[axis_id]
230
target_axis.edit(label, label_max, label_min, range, order,display)
238
@axes.to_a.sort {|a, b| a[1].order <=> b[1].order}.each {|key ,axis_conf|
244
#########################################
246
#########################################
258
attr_reader :label, :label_max, :label_min, :range, :id, :order, :display
260
def initialize (label, label_max, label_min, range, id,order,display)
262
@label_max = label_max
263
@label_min = label_min
270
def edit (label, label_max, label_min, range, order, display)
272
@label_max = label_max
273
@label_min = label_min
280
return [@label, @label_max, @label_min, @range, @id, @order,@display]
292
return @display? "checked":""
297
#########################################
299
#########################################
302
@axes #axes[id][rank]
305
@average #average[id]
307
GRAPH_PIXEL_LENGTH = 300
309
attr_reader :axes, :average, :total
312
def initialize (date_string, dbase)
314
@date_string = date_string
315
db = PStore.new(@dbase)
318
if db.root?(date_string)
320
@axes = db[date_string]
331
def get_value(id, rank)
332
if @axes.key?(id) && @axes[id][rank] != nil
333
return @axes[id][rank]
342
unless @axes.key?(id)
345
for index in 0..@axes[id].length - 1
346
if @axes.key?(id) && @axes[id][index] != nil
347
vote += @axes[id][index]
348
sum += @axes[id][index] * index
351
if @axes[id].length == 0
354
return sum.to_f/vote + 1
359
unless @axes.key?(id)
360
@axes[id] = Array.new
362
if @axes[id][rank] != nil
370
db = PStore.new(@dbase)
374
db[@date_string] = @axes
379
def get_graph_length (id, rank)
380
unless @axes.key?(id)
383
if @axes[id][rank] != nil
385
@axes[id].each {|val|
390
return (@axes[id][rank] * GRAPH_PIXEL_LENGTH / total).to_i
396
end # class dateEval end
398
#########################################
400
#########################################
402
if (@mode == 'comment')
404
if @cgi.params["body"][0] != 'rating'
407
@dbase = "#{@cache_path}/rating.db"
408
#initialize RatingConfig object
409
rating_config = RatingConfig.new(@dbase)
410
#initialize DateEval object
411
todays_eval = DateEval.new(@cgi.params['date'][0], @dbase)
413
rating_config.each { |axis_config|
414
if @cgi.params["axis" + axis_config.id.to_s][0]!= nil
415
todays_eval.vote(axis_config.id, @cgi.params["axis" + axis_config.id.to_s][0].to_i)
418
todays_eval.save_to_db