Introduce slight bias towards positive trend in cost insights mock data

This commit is contained in:
Mārtiņš Kalvāns
2020-12-28 11:34:56 +01:00
parent 246281b6e3
commit 37b28bad44
+14 -4
View File
@@ -234,14 +234,24 @@ export function aggregationFor(
'day',
);
function nextDelta(): number {
const varianceFromBaseline = 0.15;
// Let's give positive vibes in trendlines - higher change for positive delta with >0.5 value
const positiveTrendChance = 0.55;
const normalization = positiveTrendChance - 1;
return baseline * (Math.random() + normalization) * varianceFromBaseline;
}
return [...Array(days).keys()].reduce(
(values: DateAggregation[], i: number): DateAggregation[] => {
const last = values.length ? values[values.length - 1].amount : baseline;
const date = dayjs(inclusiveStartDateOf(duration, endDate))
.add(i, 'day')
.format(DEFAULT_DATE_FORMAT);
const amount = Math.max(0, last + nextDelta());
values.push({
date: dayjs(inclusiveStartDateOf(duration, endDate))
.add(i, 'day')
.format(DEFAULT_DATE_FORMAT),
amount: Math.max(0, last + (baseline / 20) * (Math.random() * 2 - 1)),
date: date,
amount: amount,
});
return values;
},