Skip to content

Instantly share code, notes, and snippets.

@themakshter
Created April 30, 2020 20:34
Show Gist options
  • Save themakshter/73dc419b50fcc442566390e2ac9bce5c to your computer and use it in GitHub Desktop.
Save themakshter/73dc419b50fcc442566390e2ac9bce5c to your computer and use it in GitHub Desktop.
export default function dummyDataGenerator(updateReadingStateFunction) {
let intervalFunction;
function getRandomValue(range, valueToSubtract = 0) {
return Math.round(Math.random() * range - valueToSubtract);
}
function generateDummyReadings() {
return {
peep: getRandomValue(10),
peakPressure: getRandomValue(100, 100),
patientRate: getRandomValue(220),
vte: getRandomValue(700),
inspiratoryTime: getRandomValue(3),
expiratoryTime: getRandomValue(5).toFixed(1),
oxygen: getRandomValue(100),
flow: getRandomValue(30, 10),
};
}
function startGenerating() {
intervalFunction = setInterval(() => {
const newReadings = generateDummyReadings();
updateReadingStateFunction(newReadings);
});
}
function stopGenerating() {
clearInterval(intervalFunction);
}
return {
startGenerating,
stopGenerating,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment