Skip to content

Instantly share code, notes, and snippets.

@Hiestaa
Last active August 17, 2022 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hiestaa/0b459ada66d71eee4abf5468bd419768 to your computer and use it in GitHub Desktop.
Save Hiestaa/0b459ada66d71eee4abf5468bd419768 to your computer and use it in GitHub Desktop.
Dwell Time Test Suite - Test Chain Data Linking with Dummy Dwell Time Events
/** Data Link Configuration:
{
"dataLink": {
"details.scheduledActivity": {
"match": [
"cameras.$any.id"
],
"window": [
86400,
0
],
"ttlHours": 5000,
"invalidateOn": {
"state": "CLOSED"
},
"sourceWindow": [
0,
"details.scheduledActivity.duration"
]
},
"details.Vehicle menu board time": {
"window": [
3600,
3600
],
"ttlSeconds": 3600,
"consumeOnce": true,
"sourceField": "details.Vehicle menu board time link 2",
"sourceFilter": {
"details.Vehicle dwell time type": "service-window"
},
"targetFilter": {
"type": "transaction",
"subtype": "dummy-link-target"
},
"sourceTimestampField": "endTime",
"targetTimestampField": "startTime"
},
"details.Vehicle payment window time": {
"window": [
3600,
3600
],
"ttlSeconds": 3600,
"consumeOnce": true,
"sourceField": "details.Vehicle payment window time link 1",
"sourceFilter": {
"details.Vehicle dwell time type": "service-window"
},
"targetFilter": {
"type": "transaction",
"subtype": "dummy-link-target"
},
"sourceTimestampField": "endTime",
"targetTimestampField": "startTime"
},
"details.Vehicle service window time": {
"window": [
3600,
3600
],
"ttlSeconds": 3600,
"consumeOnce": true,
"sourceField": "details.Vehicle service window time",
"sourceFilter": {
"details.Vehicle dwell time type": "service-window"
},
"targetFilter": {
"type": "transaction",
"subtype": "dummy-link-target"
},
"sourceTimestampField": "endTime",
"targetTimestampField": "startTime"
},
"details.Vehicle menu board time link 1": {
"window": [
3600,
3600
],
"ttlSeconds": 3600,
"consumeOnce": true,
"sourceField": "details.Vehicle menu board time",
"sourceFilter": {
"details.Vehicle dwell time type": "menu-board"
},
"targetFilter": {
"details.Vehicle dwell time type": "payment-window"
},
"sourceTimestampField": "endTime",
"targetTimestampField": "startTime"
},
"details.Vehicle menu board time link 2": {
"window": [
3600,
3600
],
"ttlSeconds": 3600,
"consumeOnce": true,
"sourceField": "details.Vehicle menu board time link 1",
"sourceFilter": {
"details.Vehicle dwell time type": "payment-window"
},
"targetFilter": {
"details.Vehicle dwell time type": "service-window"
},
"sourceTimestampField": "endTime",
"targetTimestampField": "startTime"
},
"details.Vehicle payment window time link 1": {
"window": [
3600,
3600
],
"ttlSeconds": 3600,
"consumeOnce": true,
"sourceField": "details.Vehicle payment window time",
"sourceFilter": {
"details.Vehicle dwell time type": "payment-window"
},
"targetFilter": {
"details.Vehicle dwell time type": "service-window"
},
"sourceTimestampField": "endTime",
"targetTimestampField": "startTime"
}
}
}
*/
let count = 0;
const INTERVAL = 5 * 60 * 1000;
const INTERVAL_VARIATION_RANGE = 0; //120 * 1000;
const LAG = 10 * 60 * 1000;// Math.round((1 + Math.random() * 10) * 60 * 1000);
const EMPLOYEES = [
"Mana Kujawa",
"Carissa Ledesma",
"Beverly Murrow",
"Melodi Lovick",
"Jesusita Castleman",
"Maximina Desir",
"Leonard Childs",
"Donya Farley",
"Fatimah Arp",
"Emilie Lembo",
"Adelaida Nogle",
"Dayle Reddish",
"Alden Linhart",
"Thomasina Lauderback",
"Kandace Barnum",
"Matha Gros",
"Goldie Mix",
"Frida Duncan",
"Francoise Montalbano",
"Clemencia Flint",
"Janita Ishii",
"Hannah Lucero",
"Rosalba Durrell",
"Romona Milliman",
"Oma Noyola",
"Wendell Englert",
"Blair Endres",
"Clint Seamons",
"Maile Paff",
"Neville Brock",
"Johnetta Shepperd",
"Frederica Blakley",
"Krystina Nolte",
"Catrice Malan",
"Briana Gaudette",
"Tyrell Mina",
"Adaline Benefiel",
"Mercedez Kimes",
"Samuel Samuelson",
"Dino Riggle",
"Dessie Claar",
"Cheyenne Cambre",
"Jewell Wherry",
"Manuel Bluford",
"Darron Hout",
"Anh Luthy",
"Toccara Gattis",
"Bart Gobel",
"Tayna Darley",
"Caitlin Biggers",
];
dataReceived = function () {
};
function fakeEvents() {
count += 1;
fakeMenuBoardTime();
setTimeout(fakePaymentWindowTime, (15 + count) * 1000);
setTimeout(fakeServiceWindowTime, (15 + count + 30 + count) * 1000);
setTimeout(fakeTransaction, (15 + count + 30 + count + 60 + count) * 1000);
const interval = INTERVAL;// + Math.random() * INTERVAL_VARIATION_RANGE;
console.log(`[Dummy Transactions][fakeTransaction] next post in ${Math.round(interval / 1000)}s`);
setTimeout(fakeEvents, interval);
}
function fakeMenuBoardTime() {
postTransaction({
title: `Fake Menu Board Time #${count} ${15 + count}s`,
type: 'bookmark',
subtype: 'dwell time',
dataSource: 'dummy',
startTime: new Date(Date.now() - LAG).toISOString(),
endTime: new Date(Date.now() + (15 + count) * 1000 - LAG).toISOString(),
details: {
"Vehicle menu board time": 15 + count,
"Vehicle dwell time type": "menu-board"
},
}, {
postProcessMetadata: metadata.EVENT && metadata.EVENT.postProcessMetadata
});
}
function fakePaymentWindowTime() {
postTransaction({
title: `Fake Payment Window Time #${count} ${30 + count}s`,
type: 'bookmark',
subtype: 'dwell time',
dataSource: 'dummy',
startTime: new Date(Date.now() - LAG).toISOString(),
endTime: new Date(Date.now() + (30 + count) * 1000 - LAG).toISOString(),
details: {
"Vehicle payment window time": 30 + count,
"Vehicle dwell time type": "payment-window"
},
}, {
postProcessMetadata: metadata.EVENT && metadata.EVENT.postProcessMetadata
});
}
function fakeServiceWindowTime() {
postTransaction({
title: `Fake Service Window Time #${count} ${60 + count}s`,
type: 'bookmark',
subtype: 'dwell time',
dataSource: 'dummy',
startTime: new Date(Date.now() - LAG).toISOString(),
endTime: new Date(Date.now() + (60 + count) * 1000 - LAG).toISOString(),
details: {
"Vehicle service window time": 60 + count,
"Vehicle dwell time type": "service-window"
},
}, {
postProcessMetadata: metadata.EVENT && metadata.EVENT.postProcessMetadata
});
}
function fakeTransaction () {
console.log(`[Dummy Transactions][fakeTransaction] current lag: ${Math.round(LAG / 1000)}s`);
const employee = EMPLOYEES[Math.floor(Math.random() * EMPLOYEES.length)];
postTransaction({
title: `Fake Transaction #${count}`,
type: 'transaction',
subtype: 'dummy-link-target',
dataSource: 'dummy',
startTime: new Date(Date.now() - LAG - 120 * 1000).toISOString(),
endTime: new Date(Date.now() - LAG).toISOString(),
details: {
"Employee": employee,
"Receipt": `Employee: ${employee}\n`,
},
}, {
postProcessMetadata: metadata.EVENT && metadata.EVENT.postProcessMetadata
});
}
const interval = Math.random();// * INTERVAL_VARIATION_RANGE;
console.log(`[Dummy Transactions] first post in ${Math.round(interval / 1000)}s`);
setTimeout(fakeEvents, interval);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment