make-mp-data 1.3.4 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +11 -3
- package/.vscode/settings.json +11 -1
- package/README.md +2 -2
- package/chart.js +180 -0
- package/index.js +443 -301
- package/package.json +59 -52
- package/{models → schemas}/complex.js +18 -18
- package/{models → schemas}/foobar.js +1 -1
- package/schemas/funnels.js +222 -0
- package/{models → schemas}/simple.js +10 -10
- package/scratch.mjs +20 -0
- package/testCases.mjs +229 -0
- package/testSoup.mjs +27 -0
- package/tests/e2e.test.js +27 -20
- package/tests/jest.config.js +30 -0
- package/tests/unit.test.js +346 -14
- package/tmp/.gitkeep +0 -0
- package/tsconfig.json +1 -1
- package/types.d.ts +74 -15
- package/utils.js +590 -151
- package/timesoup.js +0 -92
- /package/{models → schemas}/deepNest.js +0 -0
package/timesoup.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
const Chance = require("chance");
|
|
2
|
-
const chance = new Chance();
|
|
3
|
-
const dayjs = require("dayjs");
|
|
4
|
-
const utc = require("dayjs/plugin/utc");
|
|
5
|
-
dayjs.extend(utc);
|
|
6
|
-
const { integer } = require('./utils');
|
|
7
|
-
const NOW = dayjs().unix();
|
|
8
|
-
|
|
9
|
-
const PEAK_DAYS = [
|
|
10
|
-
dayjs().subtract(2, "day").unix(),
|
|
11
|
-
dayjs().subtract(3, "day").unix(),
|
|
12
|
-
dayjs().subtract(5, "day").unix(),
|
|
13
|
-
dayjs().subtract(7, "day").unix(),
|
|
14
|
-
dayjs().subtract(11, "day").unix(),
|
|
15
|
-
dayjs().subtract(13, "day").unix(),
|
|
16
|
-
dayjs().subtract(17, "day").unix(),
|
|
17
|
-
dayjs().subtract(19, "day").unix(),
|
|
18
|
-
dayjs().subtract(23, "day").unix(),
|
|
19
|
-
dayjs().subtract(29, "day").unix(),
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* essentially, a timestamp generator with a twist
|
|
25
|
-
* @param {number} [earliestTime] - The earliest timestamp in Unix format.
|
|
26
|
-
* @param {number} [latestTime] - The latest timestamp in Unix format.
|
|
27
|
-
* @param {Array} [peakDays] - Array of Unix timestamps representing the start of peak days.
|
|
28
|
-
* @returns {string} - The generated event timestamp in Unix format.
|
|
29
|
-
*/
|
|
30
|
-
function AKsTimeSoup(earliestTime, latestTime = NOW, peakDays = PEAK_DAYS) {
|
|
31
|
-
let chosenTime;
|
|
32
|
-
let eventTime;
|
|
33
|
-
let validTime = false;
|
|
34
|
-
|
|
35
|
-
if (typeof earliestTime !== "number") {
|
|
36
|
-
if (parseInt(earliestTime) > 0) earliestTime = parseInt(earliestTime);
|
|
37
|
-
if (dayjs(earliestTime).isValid()) earliestTime = dayjs(earliestTime).unix();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
while (!validTime) {
|
|
41
|
-
|
|
42
|
-
// Define business hours
|
|
43
|
-
const peakStartHour = 4; // 4 AM
|
|
44
|
-
const peakEndHour = 23; // 11 PM
|
|
45
|
-
const likelihoodOfPeakDay = chance.integer({ min: integer(5, 42), max: integer(43, 69) }); // Randomize likelihood with CHAOS!~~
|
|
46
|
-
|
|
47
|
-
// Select a day, with a preference for peak days
|
|
48
|
-
let selectedDay;
|
|
49
|
-
if (chance.bool({ likelihood: likelihoodOfPeakDay })) { // Randomized likelihood to pick a peak day
|
|
50
|
-
selectedDay = peakDays.length > 0 ? chance.pickone(peakDays) : integer(earliestTime, latestTime);
|
|
51
|
-
} else {
|
|
52
|
-
// Introduce minor peaks by allowing some events to still occur during business hours
|
|
53
|
-
selectedDay = chance.bool({ likelihood: integer(1, 42) })
|
|
54
|
-
? chance.pickone(peakDays)
|
|
55
|
-
: integer(earliestTime, latestTime);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Normalize selectedDay to the start of the day
|
|
59
|
-
selectedDay = dayjs.unix(selectedDay).startOf('day').unix();
|
|
60
|
-
|
|
61
|
-
// Generate a random time within business hours with a higher concentration in the middle of the period
|
|
62
|
-
const businessStart = dayjs.unix(selectedDay).hour(peakStartHour).minute(0).second(0).unix();
|
|
63
|
-
const businessEnd = dayjs.unix(selectedDay).hour(peakEndHour).minute(0).second(0).unix();
|
|
64
|
-
|
|
65
|
-
if (selectedDay === peakDays[0]) {
|
|
66
|
-
// Use a skewed distribution for peak days
|
|
67
|
-
eventTime = chance.normal({ mean: (businessEnd + businessStart) / integer(1, 4), dev: (businessEnd - businessStart) / integer(2, 8) });
|
|
68
|
-
} else {
|
|
69
|
-
// For non-peak days, use a uniform distribution to add noise
|
|
70
|
-
eventTime = integer(integer(businessStart, businessEnd), integer(businessStart, businessEnd));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// usually, ensure the event time is within business hours
|
|
74
|
-
if (chance.bool({ likelihood: 42 })) eventTime = Math.min(Math.max(eventTime, businessStart), businessEnd);
|
|
75
|
-
|
|
76
|
-
if (eventTime > 0) validTime = true;
|
|
77
|
-
const parsedTime = dayjs.unix(eventTime).toISOString();
|
|
78
|
-
if (!parsedTime.startsWith('20')) validTime = false;
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
chosenTime = dayjs.unix(eventTime).toISOString();
|
|
82
|
-
|
|
83
|
-
//should never get here
|
|
84
|
-
if (eventTime < 0) debugger;
|
|
85
|
-
if (!chosenTime.startsWith('20')) debugger;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return chosenTime;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
module.exports = AKsTimeSoup;
|
|
File without changes
|