Merge remote-tracking branch 'origin/master' into feature/1081

# Conflicts:
#	src/components/charts/GenericDistributionChart.re
This commit is contained in:
Roman Galochkin 2020-02-20 14:10:40 +03:00
commit 3ddf3561ca
5 changed files with 27 additions and 50 deletions

View File

@ -18,7 +18,10 @@ let mixedDist =
let timeDist =
GenericDistribution.make(
~generationSource=GuesstimatorString("mm(3, normal(5,1), [.5,.5])"),
~generationSource=
GuesstimatorString(
"mm(floor(uniform(40, 50)), normal(50,10), [.5,.5])",
),
~probabilityType=Pdf,
~domain=Complete,
~unit=TimeDistribution({zero: MomentRe.momentNow(), unit: `years}),
@ -41,6 +44,7 @@ let distributions = () =>
<div>
<h2> {"Basic Mixed Distribution" |> ReasonReact.string} </h2>
{timeDist
|> E.O.bind(_, GenericDistribution.normalize)
|> E.O.React.fmapOrNull(dist => <GenericDistributionChart dist />)}
<h2> {"Simple Continuous" |> ReasonReact.string} </h2>
</div>

View File

@ -7,11 +7,7 @@ module Mixed = {
React.useMemo1(
() =>
<CdfChart__Plain
primaryDistribution={
data.continuous
|> Shape.Continuous.normalizePdf
|> E.O.toExt("")
}
primaryDistribution={data.continuous}
discrete={data.discrete}
color={`hex("333")}
timeScale
@ -77,6 +73,7 @@ module Cont = {
primaryDistribution=continuous
color={`hex("333")}
onHover
timeScale
/>,
[|continuous|],
);
@ -129,9 +126,7 @@ module GenericDist = {
{x |> E.Float.toString |> ReasonReact.string}
</th>
<th className="px-4 py-2 border ">
{genericDistribution
|> DistributionTypes.shape
|> E.O.bind(_, r => Shape.Any.yIntegral(r, x))
{genericDistribution->GenericDistribution.yIntegral(x)
|> E.O.fmap(E.Float.with2DigitsPrecision)
|> E.O.default("")
|> ReasonReact.string}
@ -147,34 +142,8 @@ module GenericDist = {
[@react.component]
let make = (~dist) => {
switch ((dist: DistributionTypes.genericDistribution)) {
| {
unit,
generationSource:
Shape(
Mixed({
continuous: n,
discrete: d,
discreteProbabilityMassFraction: f,
}),
),
} =>
<div>
<GenericDist genericDistribution=dist />
<Mixed
unit
data={
continuous:
n
|> Shape.XYShape.Range.integrateWithTriangles
|> E.O.toExt("")
|> Shape.XYShape.scaleCdfTo
|> Shape.Continuous.toPdf
|> E.O.toExt(""),
discrete: d,
discreteProbabilityMassFraction: f,
}
/>
</div>
| {generationSource: Shape(_)} =>
<div> <GenericDist genericDistribution=dist /> </div>
| _ => <div />
};
};

View File

@ -398,25 +398,25 @@ export class CdfChartD3 {
getTimeTicksByStr(unit) {
switch (unit) {
case "months":
return d3.timeMonth.every(1);
return d3.timeMonth.every(4);
case "quarters":
return d3.timeMonth.every(3);
case "hours":
return d3.timeHour.every(1);
return d3.timeHour.every(10);
case "days":
return d3.timeDay.every(1);
return d3.timeDay.every(7);
case "seconds":
return d3.timeSecond.every(1);
return d3.timeSecond.every(10);
case "years":
return d3.timeYear.every(1);
return d3.timeYear.every(10);
case "minutes":
return d3.timeMinute.every(1);
return d3.timeMinute.every(10);
case "weeks":
return d3.timeWeek.every(1);
return d3.timeWeek.every(10);
case "milliseconds":
return d3.timeMillisecond.every(1);
return d3.timeMillisecond.every(10);
default:
return d3.timeYear.every(1);
return d3.timeYear.every(10);
}
}

View File

@ -68,10 +68,12 @@ let normalizePdf = (t: DistributionTypes.pointsType) => {
};
};
let normalize = (t: genericDistribution): genericDistribution => {
let normalize = (t: genericDistribution): option(genericDistribution) => {
switch (t.generationSource) {
| Shape(shape) => t
| GuesstimatorString(_) => t
| Shape(shape) =>
normalizePdf(shape)
|> E.O.fmap(shape => {...t, generationSource: Shape(shape)})
| GuesstimatorString(_) => Some(t)
};
};

View File

@ -107,7 +107,9 @@ module Continuous = {
let toCdf = XYShape.Range.integrateWithTriangles;
let findX = CdfLibrary.Distribution.findX;
let findY = CdfLibrary.Distribution.findY;
let findIntegralY = (f, r) => r |> toCdf |> E.O.fmap(findY(f));
let findIntegralY = (f, r) => {
r |> toCdf |> E.O.fmap(findY(f));
};
let normalizeCdf = (continuousShape: continuousShape) =>
continuousShape |> XYShape.scaleCdfTo(~scaleTo=1.0);