Skip to content

Commit

Permalink
Attempting to update .bithoundrc
Browse files Browse the repository at this point in the history
  • Loading branch information
lmaccherone committed Feb 25, 2016
1 parent 6eeea31 commit 9430620
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .bithoundrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"ignore": [
"**/docs/**"
]
],
"dependencies": {
"mute": ["browserify", "uglify-js", "marked", "bower", "istanbul", "wrench", "async"]
}
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/lumenize-docs/output/Lumenize.table (1).js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 39 additions & 5 deletions src/histogram.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ justHereForDocsAndDoctest = () ->
## Piecemeal usage ##
Sometimes you don't actually want a histogram. You want a way to create constantWidth or constantDepth or v-optimal buckets
Sometimes you don't actually want a histogram. You want a way to create constantWidth, constantDepth, log, or v-optimal buckets
and you want a tool to know which bucket a particular value falls into. The cannonical example of this is for calculating
percentiles for standardized testing... or for grading on a curve. The documentation for the `percentileBuckets()`
function walks you through an example like this.
Expand Down Expand Up @@ -101,6 +101,40 @@ setParameters = (rows, valueField, firstStartOn, lastEndBelow, bucketCount, sign

return {values, bucketCount, firstStartOn, lowerBase, lastEndBelow, upperBase}

histogram.bucketsLog = (rows, valueField, significance, firstStartOn, lastEndBelow, bucketCount) ->
if significance?
throw new Error("Significance not supported for bucketsLog.")

{values, bucketCount, firstStartOn, lowerBase, lastEndBelow, upperBase} = setParameters(rows, valueField, firstStartOn, lastEndBelow, bucketCount, significance)

if lowerBase < 0
throw new Error("bucketsLog do not support values below zero. Strip those out if you want to use this.")

if lowerBase is 0
firstStartOn = 0
else
firstStartOnExponent = Math.floor(Math.log10(lowerBase))
firstStartOn = Math.pow(10, firstStartOnExponent)
lastEndBelowExponent = Math.floor(Math.log10(upperBase)) + 1
lastEndBelow = Math.pow(10, lastEndBelowExponent)

index = 0
startOn = firstStartOn
if startOn is 0
endBelow = 1
else
endBelow = Math.pow(10, firstStartOnExponent + 1)

buckets = [] # each row is {index, startOn, endBelow} meaning bucket startOn <= x < endBelow

while endBelow <= lastEndBelow
buckets.push({index, startOn, endBelow})
startOn = endBelow
endBelow = endBelow * 10
index++

return buckets

histogram.bucketsConstantWidth = (rows, valueField, significance, firstStartOn, lastEndBelow, bucketCount) ->

{values, bucketCount, firstStartOn, lowerBase, lastEndBelow, upperBase} = setParameters(rows, valueField, firstStartOn, lastEndBelow, bucketCount, significance)
Expand Down Expand Up @@ -275,8 +309,8 @@ histogram.buckets = (rows, valueField, type = histogram.bucketsConstantWidth, si
assumed to be an Array of Numbers representing the values to bucket. Otherwise, it is assumed to be an Array of Objects
with a bunch of fields.
@param {String} [valueField] Specifies the field containing the values to calculate the histogram on
@param {function} [type = histogram.constantWidth] Specifies how to pick the edges of the buckets. Three standard schemes
are provided: histogram.bucketsConstantWidth, histogram.bucketsConstantDepth, and histogram.bucketsVOptimal.
@param {function} [type = histogram.constantWidth] Specifies how to pick the edges of the buckets. Four schemes
are provided: histogram.bucketsConstantWidth, histogram.bucketsConstantDepth, histogram.bucketsLog, and histogram.bucketsVOptimal.
You could inject your own but this function simply calls that so you may as well just create the buckets yourself.
@param {Number} [significance] The multiple to which you want to round the bucket edges. 1 means whole numbers.
0.1 means to round to tenths. 0.01 to hundreds. Etc. If you provide all of these last four parameters, ensure
Expand Down Expand Up @@ -437,8 +471,8 @@ histogram.histogram = (rows, valueField, type = histogram.constantWidth, signifi
assumed to be an Array of Numbers representing the values to bucket. Otherwise, it is assumed to be an Array of Objects
with a bunch of fields.
@param {String} [valueField] Specifies the field containing the values to calculate the histogram on
@param {function} [type = histogram.constantWidth] Specifies how to pick the edges of the buckets. Three standard schemes
are provided: histogram.bucketsConstantWidth, histogram.bucketsConstantDepth, and histogram.bucketsVOptimal.
@param {function} [type = histogram.constantWidth] Specifies how to pick the edges of the buckets. Four schemes
are provided: histogram.bucketsConstantWidth, histogram.bucketsConstantDepth, histogram.bucketsLog, and histogram.bucketsVOptimal.
However, you can inject your own.
@param {Number} [significance] The multiple to which you want to round the bucket edges. 1 means whole numbers.
0.1 means to round to tenths. 0.01 to hundreds. Etc. If you provide all of these last four parameters, ensure
Expand Down
31 changes: 31 additions & 0 deletions test/histogramTest.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,37 @@ exports.histogramTest =

test.done()

testLog: (test) ->
values = [0.05, 0.5, 5, 50, 500, 5000]

h = histogram.histogram(values, null, histogram.bucketsLog)

counts = (row.count for row in h)
test.deepEqual([1, 1, 1, 1, 1, 1], counts)

test.done()

testLogZero: (test) ->
values = [0, 5, 50, 500, 5000]

h = histogram.histogram(values, null, histogram.bucketsLog)

counts = (row.count for row in h)
test.deepEqual([1, 1, 1, 1, 1], counts)

test.done()

testLogHigher: (test) ->
values = [500, 5000, 50000]

h = histogram.histogram(values, null, histogram.bucketsLog)
console.log(h)

counts = (row.count for row in h)
test.deepEqual([1, 1, 1], counts)

test.done()

testPercentile: (test) ->
values = []
for i in [1..50]
Expand Down

0 comments on commit 9430620

Please sign in to comment.