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/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