Fixes a part of issues
This commit is contained in:
parent
5bdb229b56
commit
caaff9d802
|
@ -117,13 +117,19 @@ module DemoDist = {
|
||||||
<div>
|
<div>
|
||||||
{switch (domain, unit, options) {
|
{switch (domain, unit, options) {
|
||||||
| (Some(domain), Some(unit), Some(options)) =>
|
| (Some(domain), Some(unit), Some(options)) =>
|
||||||
DistPlusIngredients.make(~guesstimatorString, ~domain, ~unit, ())
|
let distPlus =
|
||||||
|> DistPlusIngredients.toDistPlus(
|
DistPlusIngredients.make(~guesstimatorString, ~domain, ~unit, ())
|
||||||
~sampleCount=options.sampleCount,
|
|> DistPlusIngredients.toDistPlus(
|
||||||
~outputXYPoints=options.outputXYPoints,
|
~sampleCount=options.sampleCount,
|
||||||
~truncateTo=options.truncateTo,
|
~outputXYPoints=options.outputXYPoints,
|
||||||
)
|
~truncateTo=options.truncateTo,
|
||||||
|> E.O.React.fmapOrNull(distPlus => <DistPlusPlot distPlus />)
|
);
|
||||||
|
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."
|
"Nothing to show. Try to change the distribution description."
|
||||||
|> E.ste
|
|> E.ste
|
||||||
|
|
|
@ -163,6 +163,7 @@ export class CdfChartD3 {
|
||||||
this.addLollipopsChart(common);
|
this.addLollipopsChart(common);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
this._container.selectAll("*").remove();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -135,6 +135,7 @@ function get_final_pdf(pdf_vals, bst_pts_and_idxs, output_grid) {
|
||||||
var active_intervals = new Map();
|
var active_intervals = new Map();
|
||||||
var active_endpoints = new bst.AVLTree();
|
var active_endpoints = new bst.AVLTree();
|
||||||
var final_pdf_vals = [];
|
var final_pdf_vals = [];
|
||||||
|
|
||||||
for (
|
for (
|
||||||
let out_grid_idx = 0;
|
let out_grid_idx = 0;
|
||||||
out_grid_idx < output_grid.length;
|
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);
|
active_intervals.delete(interval_idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return final_pdf_vals;
|
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,
|
* Entrypoint. Pass user input strings to this function,
|
||||||
* get the corresponding pdf values and input points back.
|
* 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 {([]|*[])[]}
|
* @returns {([]|*[])[]}
|
||||||
*/
|
*/
|
||||||
function get_pdf_from_user_input(user_input_string) {
|
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 parsed = parse.parse_initial_string(user_input_string);
|
||||||
let mm_args = parse.separate_mm_args(parsed.mm_args_string);
|
let mm_args = parse.separate_mm_args(parsed.mm_args_string);
|
||||||
|
|
||||||
const is_mm = mm_args.distrs.length > 0;
|
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 tree = new bst.AVLTree();
|
||||||
let possible_start_pts = [];
|
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 output_grid = evenly_spaced_grid(start_pt, end_pt, OUTPUT_GRID_NUMEL);
|
||||||
let final_pdf_vals = get_final_pdf(all_vals, tree, output_grid);
|
let final_pdf_vals = get_final_pdf(all_vals, tree, output_grid);
|
||||||
|
|
||||||
return [final_pdf_vals, output_grid, false];
|
return [final_pdf_vals, output_grid, false];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return [[], [], true];
|
return [[], [], true];
|
||||||
|
|
|
@ -3,6 +3,7 @@ const math = _math.create(_math.all);
|
||||||
|
|
||||||
// Functions for parsing/processing user input strings are here
|
// Functions for parsing/processing user input strings are here
|
||||||
|
|
||||||
|
// @todo: Do not use objects.
|
||||||
const DISTR_REGEXS = [
|
const DISTR_REGEXS = [
|
||||||
/beta\(/g,
|
/beta\(/g,
|
||||||
/(log)?normal\(/g,
|
/(log)?normal\(/g,
|
||||||
|
@ -12,7 +13,6 @@ const DISTR_REGEXS = [
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param user_input_string
|
* @param user_input_string
|
||||||
* @returns {{mm_args_string: string, outer_string: 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 outer_output_string = "";
|
||||||
let mm_args_string = "";
|
let mm_args_string = "";
|
||||||
let idx = 0;
|
let idx = 0;
|
||||||
|
|
||||||
while (idx < user_input_string.length) {
|
while (idx < user_input_string.length) {
|
||||||
if (
|
if (
|
||||||
user_input_string.substring(idx - 11, idx) === "multimodal(" ||
|
user_input_string.substring(idx - 11, idx) === "multimodal(" ||
|
||||||
|
@ -42,6 +43,7 @@ function parse_initial_string(user_input_string) {
|
||||||
idx += 1;
|
idx += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
outer_string: outer_output_string,
|
outer_string: outer_output_string,
|
||||||
mm_args_string: mm_args_string
|
mm_args_string: mm_args_string
|
||||||
|
|
Loading…
Reference in New Issue
Block a user