Fixes a part of issues

This commit is contained in:
Roman Galochkin 2020-03-04 12:55:01 +03:00
parent 5bdb229b56
commit caaff9d802
4 changed files with 39 additions and 11 deletions

View File

@ -117,13 +117,19 @@ module DemoDist = {
<div>
{switch (domain, unit, options) {
| (Some(domain), Some(unit), Some(options)) =>
DistPlusIngredients.make(~guesstimatorString, ~domain, ~unit, ())
|> DistPlusIngredients.toDistPlus(
~sampleCount=options.sampleCount,
~outputXYPoints=options.outputXYPoints,
~truncateTo=options.truncateTo,
)
|> E.O.React.fmapOrNull(distPlus => <DistPlusPlot distPlus />)
let distPlus =
DistPlusIngredients.make(~guesstimatorString, ~domain, ~unit, ())
|> DistPlusIngredients.toDistPlus(
~sampleCount=options.sampleCount,
~outputXYPoints=options.outputXYPoints,
~truncateTo=options.truncateTo,
);
switch (distPlus) {
| Some(distPlus) => <DistPlusPlot distPlus />
| _ =>
"Correct Guesstimator string input to show a distribution."
|> E.ste
};
| _ =>
"Nothing to show. Try to change the distribution description."
|> E.ste

View File

@ -163,6 +163,7 @@ export class CdfChartD3 {
this.addLollipopsChart(common);
}
} catch (e) {
this._container.selectAll("*").remove();
throw e;
}
return this;

View File

@ -135,6 +135,7 @@ function get_final_pdf(pdf_vals, bst_pts_and_idxs, output_grid) {
var active_intervals = new Map();
var active_endpoints = new bst.AVLTree();
var final_pdf_vals = [];
for (
let out_grid_idx = 0;
out_grid_idx < output_grid.length;
@ -179,9 +180,19 @@ function get_final_pdf(pdf_vals, bst_pts_and_idxs, output_grid) {
active_intervals.delete(interval_idx);
}
}
return final_pdf_vals;
}
/**
* @param {string} str
* @param {string} char
* @returns {number}
*/
function get_count_of_chars(str, char) {
return str.split(char).length - 1;
}
/**
* Entrypoint. Pass user input strings to this function,
* get the corresponding pdf values and input points back.
@ -194,12 +205,19 @@ function get_final_pdf(pdf_vals, bst_pts_and_idxs, output_grid) {
* @returns {([]|*[])[]}
*/
function get_pdf_from_user_input(user_input_string) {
try{
try {
const count_opened_bracket = get_count_of_chars(user_input_string, '(');
const count_closed_bracket = get_count_of_chars(user_input_string, ')');
if (count_opened_bracket !== count_closed_bracket) {
throw new Error('Count of brackets are not equal.');
}
let parsed = parse.parse_initial_string(user_input_string);
let mm_args = parse.separate_mm_args(parsed.mm_args_string);
const is_mm = mm_args.distrs.length > 0;
if (!parsed.outer_string) return [[], [], true];
if (!parsed.outer_string) {
throw new Error('Parse string is empty.');
}
let tree = new bst.AVLTree();
let possible_start_pts = [];
@ -232,6 +250,7 @@ function get_pdf_from_user_input(user_input_string) {
let output_grid = evenly_spaced_grid(start_pt, end_pt, OUTPUT_GRID_NUMEL);
let final_pdf_vals = get_final_pdf(all_vals, tree, output_grid);
return [final_pdf_vals, output_grid, false];
} catch (e) {
return [[], [], true];

View File

@ -3,6 +3,7 @@ const math = _math.create(_math.all);
// Functions for parsing/processing user input strings are here
// @todo: Do not use objects.
const DISTR_REGEXS = [
/beta\(/g,
/(log)?normal\(/g,
@ -12,7 +13,6 @@ const DISTR_REGEXS = [
];
/**
*
* @param user_input_string
* @returns {{mm_args_string: string, outer_string: string}}
*/
@ -20,6 +20,7 @@ function parse_initial_string(user_input_string) {
let outer_output_string = "";
let mm_args_string = "";
let idx = 0;
while (idx < user_input_string.length) {
if (
user_input_string.substring(idx - 11, idx) === "multimodal(" ||
@ -42,6 +43,7 @@ function parse_initial_string(user_input_string) {
idx += 1;
}
}
return {
outer_string: outer_output_string,
mm_args_string: mm_args_string