Adds jsDoc

This commit is contained in:
Roman Galochkin 2020-03-02 10:05:39 +03:00
parent a2c5eaac89
commit 5ee9a6d227

View File

@ -34,14 +34,28 @@ 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 = {
xs: frequencies.map(f => f.value),
ys: frequencies.map(f => f.percentage)
};
let continuous = { ys: [], xs: [] }; let continuous = { ys: [], xs: [] };
if (continuousSamples.length > 20) { if (continuousSamples.length > 20) {
const samples = new Samples(continuousSamples); const samples = new Samples(continuousSamples);
@ -51,20 +65,35 @@ 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
* @param sampleCount
* @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 { parsedInput } = item;
const { guesstimateType } = parsedInput;
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);
@ -81,7 +110,7 @@ let run = (text, sampleCount, outputResolutionCount, inputs=[], min=false, max=f
update = toPdf(values, outputResolutionCount, min, max); update = toPdf(values, outputResolutionCount, min, max);
} }
return update; return update;
} };
module.exports = { module.exports = {
run, run,