Fixes the vector

This commit is contained in:
Roman Galochkin 2020-02-19 15:06:41 +03:00
parent 8f2cb18edc
commit 36cc3ec61a
6 changed files with 19 additions and 41 deletions

View File

@ -18,16 +18,7 @@ let timeDist =
~generationSource=GuesstimatorString("mm(3, normal(5,1), [.5,.5])"),
~probabilityType=Pdf,
~domain=Complete,
~unit=
TimeDistribution({
zero: MomentRe.momentNow(),
step: `years,
length:
MomentRe.Moment.add(
~duration=MomentRe.duration(5., `years),
MomentRe.momentNow(),
),
}),
~unit=TimeDistribution({zero: MomentRe.momentNow(), unit: `years}),
(),
)
|> GenericDistribution.renderIfNeeded(~sampleCount=3000);

View File

@ -181,17 +181,19 @@ export class CdfChartD3 {
// Axis generator.
if (!!this.attrs.timeScale) {
const zero = _.get(this.attrs.timeScale, 'zero', moment());
const step = _.get(this.attrs.timeScale, 'step', 'years');
const length = _.get(this.attrs.timeScale, 'length', moment());
const unit = _.get(this.attrs.timeScale, 'unit', 'years');
const diff = Math.abs(xMax - xMin);
const left = zero.clone().add(xMin, unit);
const right = left.clone().add(diff, unit);
const xScaleTime = d3.scaleTime()
.domain([zero.toDate(), length.toDate()])
.domain([left.toDate(), right.toDate()])
.nice()
.range([0, calc.chartWidth]);
this.xAxis = d3.axisBottom()
.scale(xScaleTime)
.ticks(this.getTimeTicksByStr(step))
.ticks(this.getTimeTicksByStr(unit))
.tickFormat(this.formatDates);
} else {
this.xAxis = d3.axisBottom(this.xScale)
@ -339,11 +341,11 @@ export class CdfChartD3 {
}
/**
* @param {string} step
* @param {string} unit
* @returns {*}
*/
getTimeTicksByStr(step) {
switch (step) {
getTimeTicksByStr(unit) {
switch (unit) {
case "months":
return d3.timeMonth.every(1);
case "quarters":

View File

@ -51,13 +51,9 @@ type genericDistribution = {
module DistributionUnit = {
let toJson = (distributionUnit: distributionUnit) =>
switch (distributionUnit) {
| TimeDistribution({zero, step, length}) =>
| TimeDistribution({zero, unit}) =>
Js.Null.fromOption(
Some({
"zero": zero,
"step": step |> TimeTypes.TimeUnit.toString,
"length": length,
}),
Some({"zero": zero, "unit": unit |> TimeTypes.TimeUnit.toString}),
)
| _ => Js.Null.fromOption(None)
};

View File

@ -12,8 +12,7 @@ type timeUnit = [
type timeVector = {
zero: MomentRe.Moment.t,
length: MomentRe.Moment.t,
step: timeUnit,
unit: timeUnit,
};
type timePoint = {
@ -43,12 +42,12 @@ module TimePoint = {
timePoint.timeVector.zero
|> MomentRe.Moment.add(
~duration=
MomentRe.duration(timePoint.value, timePoint.timeVector.step),
MomentRe.duration(timePoint.value, timePoint.timeVector.unit),
);
};
let fromMoment = (timeVector: timeVector, moment: MomentRe.Moment.t) =>
MomentRe.diff(timeVector.zero, moment, timeVector.step);
MomentRe.diff(timeVector.zero, moment, timeVector.unit);
};
module RelativeTimePoint = {
@ -61,7 +60,7 @@ module RelativeTimePoint = {
| Time(r) => r
| XValue(r) =>
timeVector.zero
|> MomentRe.Moment.add(~duration=MomentRe.duration(r, timeVector.step))
|> MomentRe.Moment.add(~duration=MomentRe.duration(r, timeVector.unit))
};
let _timeToX = (time, timeStart, timeUnit) =>
@ -69,7 +68,7 @@ module RelativeTimePoint = {
let toXValue = (timeVector: timeVector, timeInVector: timeInVector) =>
switch (timeInVector) {
| Time(r) => _timeToX(r, timeVector.zero, timeVector.step)
| Time(r) => _timeToX(r, timeVector.zero, timeVector.unit)
| XValue(r) => r
};
};

View File

@ -154,12 +154,7 @@ module Model = {
),
~probabilityType=Cdf,
~domain=RightLimited({xPoint: 100., excludingProbabilityMass: 0.3}),
~unit=
TimeDistribution({
zero: currentDateTime,
step: `years,
length: currentDateTime,
}),
~unit=TimeDistribution({zero: currentDateTime, unit: `years}),
(),
),
)

View File

@ -7,12 +7,7 @@ module Model = {
~generationSource=GuesstimatorString(guesstimatorString),
~probabilityType=Cdf,
~domain=RightLimited({xPoint: 200., excludingProbabilityMass: 0.3}),
~unit=
TimeDistribution({
zero: currentDateTime,
step: `years,
length: currentDateTime,
}),
~unit=TimeDistribution({zero: currentDateTime, unit: `years}),
(),
);
Prop.Value.GenericDistribution(genericDistribution);