## LESSWRONGMetaLW

awk is made for this, but it took me a few minutes to whip this up in java. I figured if numeric polls are used in the future, this can be used as a code-base. The indentation isn't coming through, but any IDE will fix that for you.

This doesn't work on arbitrary numeric entry polls, but for those, you can gather the statistics as you go along, putting it in the GATHER loop

EDITED to fix serious bug.

usage: paste this into PollStat.java, compile it. then run

``````java PollStat < poll.csv.txt
``````

So far, the winners are endoself and army1987. I wasn't far off.

~~~~~

``````import java.io.*;
import java.util.*;

public class PollStat {
public static void main(String[] args) {
try {
int[] counts = new int[12]; // PUT NUMBER OF POLL OPTIONS HERE
int end, begin;
int linen = 0;
while (line != null && line.charAt(0) == '#') {
linen++;
}
while (line != null) { // GATHER LOOP
linen++;
end = line.lastIndexOf("\",\"");
begin = line.lastIndexOf("\",\"", end-1);
try {
line = line.substring(begin+3, end);
} catch (Exception e) {
System.out.println("At line number "+linen+":");
e.printStackTrace();
System.exit(1);
}
Integer c = Integer.parseInt(line);
counts[c]++;
// For arbitrary numeric responses, don't use counts.
// just continuously gather your statistics. Alternately, make a list of Doubles or something.

}
br.close();

int total = 0;
int resp = 0;

int[] numbers = new int[]{100, 64, 41, 26, 17, 11, 7, 4, 3, 2, 1, 0}; // PUT POLL OPTIONS HERE
for (int i = 0; i < c.length; i++) {
System.out.println(numbers[i]+": "+counts[i]);
total += numbers[i] * counts[i];
resp += counts[i];
}
System.out.println("total: "+total);
System.out.println("average: "+((double)total)/resp);

} catch (IOException ioe) {
ioe.printStackTrace();
System.exit(2);
}
}
}
``````

# 79

You can now write Less Wrong comments that contain polls! John Simon picked up and finished some code I had written back in 2010 but never finished, and our admins Wesley Moore and Matt Fallshaw have deployed it. You can use it right now, so let's give it some testing here in this thread.

The polls work through the existing Markdown comment formatting, similar to the syntax used for links. Full documentation is in the wiki; the short version is that you can write comments like this:

What is your favorite color? [poll]{Red}{Green}{Blue}{Other}

How long has it been your favorite color, in years? [poll:number]

Red is a nice color [poll:Agree....Disagree]

Will your favorite color change? [poll:probability]

To see the results of the poll, you have to vote (you can leave questions blank if you want). The results include a link to the raw poll data, including the usernames of people who submitted votes with the "Vote anonymously" box unchecked. After you submit the comment, if you go back and edit your comment all those poll tags will have turned into [pollid:123]. You can edit the rest of the comment without resetting the poll, but you can't change the options.

It works right now, but it's also new and could be buggy. Let's give it some testing; what have you always wanted to know about Less Wrongers?

Pingbacks