-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.js
43 lines (34 loc) · 1.39 KB
/
sample.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Function to generate a random number between min (inclusive) and max (inclusive)
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// Function to generate a random timestamp within a given range
function getRandomTimestamp(start, end) {
return new Date(
start.getTime() + Math.random() * (end.getTime() - start.getTime())
);
}
// Function to generate an array of JSON objects with random timestamps
function generateRandomJSONs(numJSONs, startTime, endTime) {
const jsons = [];
const timeInterval = 15 * 60 * 1000; // 15 minutes in milliseconds
for (let i = 0; i < numJSONs; i++) {
const randomExecutionTime = getRandomInt(1000, 25000); // Example random execution time
const randomTimestamp = getRandomTimestamp(startTime, endTime);
const formattedTimestamp = randomTimestamp.toISOString();
const json = {
Identifier: `ID-${i}`,
ExecutionTime: randomExecutionTime,
Timestamp: formattedTimestamp,
};
jsons.push(json);
}
return jsons;
}
// Calculate start and end time for the range (current time to 12 hours back)
const currentTime = new Date();
const twelveHoursAgo = new Date(currentTime.getTime() - 12 * 60 * 60 * 1000);
// Generate 30 JSONs with random timestamps within the range
const numJSONs = 100;
const jsons = generateRandomJSONs(numJSONs, twelveHoursAgo, currentTime);
// console.log(jsons);