Adds jsDoc
This commit is contained in:
parent
a2c5eaac89
commit
5ee9a6d227
|
@ -34,15 +34,29 @@ const ratioSize = samples => {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param values
|
||||||
|
* @param outputResolutionCount
|
||||||
|
* @param min
|
||||||
|
* @param max
|
||||||
|
* @returns {{discrete: {ys: *, xs: *}, continuous: {ys: [], xs: []}}}
|
||||||
|
*/
|
||||||
const toPdf = (values, outputResolutionCount, min, max) => {
|
const toPdf = (values, outputResolutionCount, min, max) => {
|
||||||
let duplicateSamples = _(values).groupBy().pickBy(x => x.length > 1).keys().value();
|
let duplicateSamples = _(values).groupBy().pickBy(x => x.length > 1).keys().value();
|
||||||
let totalLength = _.size(values);
|
let totalLength = _.size(values);
|
||||||
let frequencies = duplicateSamples.map(s => ({value: parseFloat(s), percentage: _(values).filter(x => x ==s).size()/totalLength}));
|
let frequencies = duplicateSamples.map(s => ({
|
||||||
|
value: parseFloat(s),
|
||||||
|
percentage: _(values).filter(x => x == s).size() / totalLength
|
||||||
|
}));
|
||||||
let continuousSamples = _.difference(values, frequencies.map(f => f.value));
|
let continuousSamples = _.difference(values, frequencies.map(f => f.value));
|
||||||
|
|
||||||
let discrete = {xs: frequencies.map(f => f.value), ys: frequencies.map(f => f.percentage)};
|
let discrete = {
|
||||||
let continuous = {ys: [], xs: []};
|
xs: frequencies.map(f => f.value),
|
||||||
if (continuousSamples.length > 20){
|
ys: frequencies.map(f => f.percentage)
|
||||||
|
};
|
||||||
|
let continuous = { ys: [], xs: [] };
|
||||||
|
|
||||||
|
if (continuousSamples.length > 20) {
|
||||||
const samples = new Samples(continuousSamples);
|
const samples = new Samples(continuousSamples);
|
||||||
|
|
||||||
const ratioSize$ = ratioSize(samples);
|
const ratioSize$ = ratioSize(samples);
|
||||||
|
@ -51,38 +65,53 @@ const toPdf = (values, outputResolutionCount, min, max) => {
|
||||||
const pdf = samples.toPdf({ size: outputResolutionCount, width, min, max });
|
const pdf = samples.toPdf({ size: outputResolutionCount, width, min, max });
|
||||||
continuous = pdf;
|
continuous = pdf;
|
||||||
}
|
}
|
||||||
return {continuous, discrete};
|
|
||||||
|
return { continuous, discrete };
|
||||||
};
|
};
|
||||||
|
|
||||||
let run = (text, sampleCount, outputResolutionCount, inputs=[], min=false, max=false) => {
|
/**
|
||||||
let [_error, item] = Guesstimator.parse({ text: "=" + text });
|
* @param text
|
||||||
const { parsedInput } = item;
|
* @param sampleCount
|
||||||
const { guesstimateType } = parsedInput;
|
* @param outputResolutionCount
|
||||||
|
* @param inputs
|
||||||
|
* @param min
|
||||||
|
* @param max
|
||||||
|
* @returns {{discrete: {ys: *, xs: *}, continuous: {ys: *[], xs: *[]}}}
|
||||||
|
*/
|
||||||
|
const run = (
|
||||||
|
text,
|
||||||
|
sampleCount,
|
||||||
|
outputResolutionCount,
|
||||||
|
inputs = [],
|
||||||
|
min = false,
|
||||||
|
max = false,
|
||||||
|
) => {
|
||||||
|
const [_error, item] = Guesstimator.parse({ text: "=" + text });
|
||||||
|
const { parsedInput } = item;
|
||||||
|
|
||||||
const guesstimator = new Guesstimator({ parsedInput });
|
const guesstimator = new Guesstimator({ parsedInput });
|
||||||
const value = guesstimator.sample(
|
const value = guesstimator.sample(
|
||||||
sampleCount,
|
sampleCount,
|
||||||
inputs,
|
inputs,
|
||||||
);
|
);
|
||||||
const samplerType = guesstimator.samplerType();
|
|
||||||
|
|
||||||
const values = _.filter(value.values, _.isFinite);
|
const values = _.filter(value.values, _.isFinite);
|
||||||
|
|
||||||
let update;
|
let update;
|
||||||
let blankResponse = {
|
let blankResponse = {
|
||||||
continuous: {ys: [], xs: []},
|
continuous: { ys: [], xs: [] },
|
||||||
discrete: {ys: [], xs: []}
|
discrete: { ys: [], xs: [] }
|
||||||
};
|
};
|
||||||
if (values.length === 0) {
|
if (values.length === 0) {
|
||||||
update = blankResponse;
|
update = blankResponse;
|
||||||
} else if (values.length === 1) {
|
} else if (values.length === 1) {
|
||||||
update = blankResponse;
|
update = blankResponse;
|
||||||
} else {
|
} else {
|
||||||
update = toPdf(values, outputResolutionCount, min, max);
|
update = toPdf(values, outputResolutionCount, min, max);
|
||||||
}
|
}
|
||||||
return update;
|
return update;
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
run,
|
run,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user