org.bolson.vote
Class NamedHistogram

java.lang.Object
  extended by org.bolson.vote.NameVotingSystem
      extended by org.bolson.vote.NamedHistogram

public class NamedHistogram
extends NameVotingSystem

The normal vote interface in this case accumulates the ratings into histograms per name.


Nested Class Summary
protected  class NamedHistogram.Choice
           
 
Nested classes/interfaces inherited from class org.bolson.vote.NameVotingSystem
NameVotingSystem.NameVote, NameVotingSystem.ReverseComparator
 
Field Summary
 java.lang.String barImgUrl
           
 float bucketscale
          bucketscale used at display time on bucket labels
 boolean disableWinners
          make getWinners return null
 boolean doscaleoffset
          doscaleoffset used at display time on bucket labels
protected static java.lang.String[] globalHistChoiceFormat
           
protected static java.lang.String[] globalHistRowFormat
           
static java.lang.String HIST_CHOICE_AVERAGE
           
static java.lang.String[] HIST_CHOICE_keys
           
static java.lang.String HIST_CHOICE_LABEL
           
static java.lang.String HIST_CHOICE_NAME
           
static java.lang.String HIST_CHOICE_ROWS
           
static java.lang.String HIST_CHOICE_SUM
           
static java.lang.String HIST_CHOICE_VOTES
           
static java.lang.String HIST_ROW_HVAL
           
static java.lang.String[] HIST_ROW_keys
           
static java.lang.String HIST_ROW_SCALED_HVAL
           
static java.lang.String HIST_ROW_VALUES_LABEL
           
 boolean intmode
           
 java.lang.String labelname
           
 boolean lowfirst
           
 float offset
          offset used at display time on bucket labels
 boolean printPercents
           
 boolean useSpan
           
 
Constructor Summary
NamedHistogram()
          equivalent to NamedHistogram( -10, 10 );
NamedHistogram(int numBuckets, float minRating, float maxRating)
          Constructor creates a histogram with some number of buckets evenly distributed with the min rating and max rating at the limits.
NamedHistogram(int minint, int maxint)
          Constructor creates a histogram with some number of buckets to contain the possible integer values including minint through maxint.
 
Method Summary
protected  int[][] counts(java.lang.String[] names)
           
 java.lang.StringBuffer formatChoice(java.lang.StringBuffer sb, NamedHistogram.Choice c, int minBucket, int maxBucket, double scale, java.lang.String[] format)
           
protected  void formatHistRow(java.lang.StringBuffer sb, int i, int hval, double scale)
           
protected  void formatHistRow(java.lang.StringBuffer sb, int i, int hval, double scale, java.lang.String[] histRowFormat)
           
protected  NamedHistogram.Choice[] getChoices()
           
 NameVotingSystem.NameVote[] getWinners()
           
protected  void histRow(java.lang.StringBuffer sb, int i, int hval, double scale)
           
 java.lang.StringBuffer htmlSummary(java.lang.StringBuffer sb)
          Makes HTML tables and CSS span bars to show the histogram.
 java.lang.StringBuffer htmlSummary(java.lang.StringBuffer sb, NameVotingSystem.NameVote[] winners)
          Makes HTML tables and CSS span bars to show the histogram.
 java.lang.StringBuffer htmlSummary(java.lang.StringBuffer sb, java.lang.String[] names)
          Makes HTML tables and CSS span bars to show the histogram.
 int init(java.lang.String[] argv)
          Set options for voting system.
static void main(java.lang.String[] argv)
           
 java.lang.String name()
           
protected  java.lang.String[] names()
           
protected static java.lang.String[] parseFormat(java.lang.String format, java.lang.String[] keys)
           
 java.lang.StringBuffer renderChoice(java.lang.StringBuffer sb, NamedHistogram.Choice c, int minBucket, int maxBucket, double scale)
           
static void setGlobalHistRowFormat(java.lang.String format)
          Set default format for histogram rows.
 void voteRating(NameVotingSystem.NameVote[] vote)
          The normal vote interface in this case accumulates the ratings into histograms per name.
 
Methods inherited from class org.bolson.vote.NameVotingSystem
defaultMain, denibble, depercentHexify, fromUrlEncoded, getDebug, getImplNames, getIpmlForName, htmlExplain, htmlExplain, htmlSummary, nameEqStrToVoteArray, nameEqStrToVoteArray, percentHexify, readVotes, registerImpl, resultsHTMLDisplay, sort, urlEncode, voteNameEqStr, voteOrderSpec, voteRating, voteSpecToNameVoteArray, winnerSummaryHTMLTable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

intmode

public boolean intmode

lowfirst

public boolean lowfirst

bucketscale

public float bucketscale
bucketscale used at display time on bucket labels


offset

public float offset
offset used at display time on bucket labels


doscaleoffset

public boolean doscaleoffset
doscaleoffset used at display time on bucket labels


disableWinners

public boolean disableWinners
make getWinners return null


labelname

public java.lang.String labelname

barImgUrl

public java.lang.String barImgUrl

useSpan

public boolean useSpan

printPercents

public boolean printPercents

HIST_ROW_VALUES_LABEL

public static final java.lang.String HIST_ROW_VALUES_LABEL
See Also:
Constant Field Values

HIST_ROW_SCALED_HVAL

public static final java.lang.String HIST_ROW_SCALED_HVAL
See Also:
Constant Field Values

HIST_ROW_HVAL

public static final java.lang.String HIST_ROW_HVAL
See Also:
Constant Field Values

HIST_ROW_keys

public static final java.lang.String[] HIST_ROW_keys

globalHistRowFormat

protected static java.lang.String[] globalHistRowFormat

HIST_CHOICE_NAME

public static final java.lang.String HIST_CHOICE_NAME
See Also:
Constant Field Values

HIST_CHOICE_LABEL

public static final java.lang.String HIST_CHOICE_LABEL
See Also:
Constant Field Values

HIST_CHOICE_ROWS

public static final java.lang.String HIST_CHOICE_ROWS
See Also:
Constant Field Values

HIST_CHOICE_SUM

public static final java.lang.String HIST_CHOICE_SUM
See Also:
Constant Field Values

HIST_CHOICE_VOTES

public static final java.lang.String HIST_CHOICE_VOTES
See Also:
Constant Field Values

HIST_CHOICE_AVERAGE

public static final java.lang.String HIST_CHOICE_AVERAGE
See Also:
Constant Field Values

HIST_CHOICE_keys

public static final java.lang.String[] HIST_CHOICE_keys

globalHistChoiceFormat

protected static java.lang.String[] globalHistChoiceFormat
Constructor Detail

NamedHistogram

public NamedHistogram()
equivalent to NamedHistogram( -10, 10 );


NamedHistogram

public NamedHistogram(int numBuckets,
                      float minRating,
                      float maxRating)
Constructor creates a histogram with some number of buckets evenly distributed with the min rating and max rating at the limits.
   0    1    2    3    4
 |----|----|----|----|----|
min                      max
5 buckets each with a width of (buckets/(max-min))
Values less than min are accumulated in the min bucket and values greater than max are accumulated in the max bucket.

Parameters:
numBuckets - number of buctets to accumulate histogram data in
minRating - value of the lowest edge of the lowest bucket
maxRating - value of the highest edge of the highest bucket

NamedHistogram

public NamedHistogram(int minint,
                      int maxint)
Constructor creates a histogram with some number of buckets to contain the possible integer values including minint through maxint.
   0    1    2    3    4
 |----|----|----|----|----|
min                      max
5 buckets
minint 0, maxint 4
min = -0.5, max = 4.5

Parameters:
minint - value of lowest bucket
maxint - value of highest bucket
Method Detail

init

public int init(java.lang.String[] argv)
Description copied from class: NameVotingSystem
Set options for voting system. Default implementation sets debug to true if it sees "debug". Skip pass null entries, which may have been yanked by a subclass. Unless there's an error, last line should be "return super.init( argv );" Multi-seat capable implementations should accept an option pair ("seats", <int>) to set the number of seats.

Overrides:
init in class NameVotingSystem
Parameters:
argv - array of options, just like main()
Returns:
0 on success

voteRating

public void voteRating(NameVotingSystem.NameVote[] vote)
The normal vote interface in this case accumulates the ratings into histograms per name.

Specified by:
voteRating in class NameVotingSystem
Parameters:
vote - a set of (name,rating) pairs
See Also:
NameVotingSystem.voteRating(Map)

names

protected java.lang.String[] names()

getChoices

protected NamedHistogram.Choice[] getChoices()

counts

protected int[][] counts(java.lang.String[] names)

getWinners

public NameVotingSystem.NameVote[] getWinners()
Specified by:
getWinners in class NameVotingSystem
Returns:
average ratings for each name

setGlobalHistRowFormat

public static void setGlobalHistRowFormat(java.lang.String format)
Set default format for histogram rows.

row template:
%valueslabel n,>=n, %hval
%scaledhval

default is:
<tr><td>%valuesLabel</td><td><div style="background-color: #bb99ff; width: %scaledhval">%hval</div></td></tr>\n

Parameters:
format - string which will be parsed with above %keys to set histogram row format

parseFormat

protected static java.lang.String[] parseFormat(java.lang.String format,
                                                java.lang.String[] keys)

formatHistRow

protected void formatHistRow(java.lang.StringBuffer sb,
                             int i,
                             int hval,
                             double scale)

formatHistRow

protected void formatHistRow(java.lang.StringBuffer sb,
                             int i,
                             int hval,
                             double scale,
                             java.lang.String[] histRowFormat)

histRow

protected void histRow(java.lang.StringBuffer sb,
                       int i,
                       int hval,
                       double scale)

formatChoice

public java.lang.StringBuffer formatChoice(java.lang.StringBuffer sb,
                                           NamedHistogram.Choice c,
                                           int minBucket,
                                           int maxBucket,
                                           double scale,
                                           java.lang.String[] format)

renderChoice

public java.lang.StringBuffer renderChoice(java.lang.StringBuffer sb,
                                           NamedHistogram.Choice c,
                                           int minBucket,
                                           int maxBucket,
                                           double scale)

htmlSummary

public java.lang.StringBuffer htmlSummary(java.lang.StringBuffer sb)
Makes HTML tables and CSS span bars to show the histogram.

Specified by:
htmlSummary in class NameVotingSystem
Parameters:
sb - gets HTML summary appended to it.
Returns:
sb with HTML summary appended to it.

htmlSummary

public java.lang.StringBuffer htmlSummary(java.lang.StringBuffer sb,
                                          NameVotingSystem.NameVote[] winners)
Makes HTML tables and CSS span bars to show the histogram.

Parameters:
sb - gets HTML summary appended to it.
winners - Histogram will present the choices in the order they are in this array of winners (typically sorted winningest first).
Returns:
sb with HTML summary appended to it.

htmlSummary

public java.lang.StringBuffer htmlSummary(java.lang.StringBuffer sb,
                                          java.lang.String[] names)
Makes HTML tables and CSS span bars to show the histogram.

Parameters:
sb - gets HTML summary appended to it.
names - which names to get histogram for, in that order.
Returns:
sb with HTML summary appended to it.

name

public java.lang.String name()
Specified by:
name in class NameVotingSystem
Returns:
name of this voting system (may be modified by settings from init)

main

public static void main(java.lang.String[] argv)