這就是我們最終做的。我在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