这就是我们最终做的。我在http://etherpad.com/sugarorgy(修订版25,为防万一因为添加此公共链接而被破坏)中收集了大家的评分,然后使用以下Perl脚本将数据解析为CSV文件:
#!/usr/bin/env perl
# Grabs the cupcake data from etherpad and parses it into a CSV file.
use LWP::Simple qw(get);
$content = get("http://etherpad.com/ep/pad/export/sugarorgy/latest?format=txt");
$content =~ s/^.*BEGIN_MAGIC\s*//s;
$content =~ s/END_MAGIC.*$//s;
$bakery = "none";
for $line (split('\n', $content)) {
next if $line =~ /sar kri and deb/;
if ($line =~ s/bakery\s+(\w+)//) { $bakery = $1; }
$line =~ s/\([^\)]*\)//g; # strip out stuff in parens.
$line =~ s/^\s+(\w)(\w)/$1 $2/;
$line =~ s/\-/\-1/g;
$line =~ s/^\s+//;
$line =~ s/\s+$//;
$line =~ s/\s+/\,/g;
print "$bakery,$line\n";
}
然后我做数学中的平均和诸如此类的东西:
data = Import["!~/svn/sugar.pl", "CSV"];
(* return a bakery's list of ratings for the given type of cupcake *)
tratings[bak_, t_] := Select[Drop[[email protected][data,
#[[1]]==bak && #[[2]]==t && #[[3]]=="g" &], 3], #!=-1&]
(* return a bakery's list of ratings for the given cupcake attribute *)
aratings[bak_, a_] := Select[Flatten[Drop[#,3]& /@
Select[data, #[[1]]==bak && #[[3]]==a&]], #!=-1&]
(* overall rating for a bakery *)
oratings[bak_] := Join @@ (tratings[bak, #] & /@ {"V", "C", "R", "W"})
bakeries = [email protected][[All, 1]]
SortBy[{#, [email protected]#, Round[[email protected][#], .01]}& /@ bakeries, -#[[3]]&]
的结果是在http://etherpad.com/sugarorgy底部。
我担心有人会认为这是作业,所以我讲了有关派对的全部故事。我死得很严肃;我们真的有这个派对! – dreeves 2009-08-01 06:13:52
这与编程有什么关系? – 2009-08-01 06:16:41
那么,一个理想的答案会推广它,并将其编码为一个程序,该程序将个人评级和输出排名,甚至可能计算统计显着性水平。这可能是一个有趣的小问题! – dreeves 2009-08-01 06:22:50