Public
Edited
Jan 16
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function getActivityDistribution(profile) {
const distributions = {
Inactive: {
sedentary: 0.90,
light: 0.10,
moderate: 0.00,
vigorous: 0.00
},
"Sporadic low intensity": {
sedentary: 0.70,
light: 0.25,
moderate: 0.05,
vigorous: 0.00
},
"Sporadic low/mod": {
sedentary: 0.60,
light: 0.25,
moderate: 0.13,
vigorous: 0.02
},
"Sporadic mod/high": {
sedentary: 0.50,
light: 0.20,
moderate: 0.20,
vigorous: 0.10
},
"Semi-structured mod": {
sedentary: 0.55,
light: 0.25,
moderate: 0.18,
vigorous: 0.02
},
"Semi-structured high": {
sedentary: 0.45,
light: 0.20,
moderate: 0.25,
vigorous: 0.10
}
};
return distributions[profile] || distributions.inactive;
}
Insert cell
function generateStructuredPeriods(profile) {
const periods = [];
const isHighIntensity = profile === "Semi-structured high";
const activeDaysPerWeek = isHighIntensity ? 5 : 3;
const sessionsPerDay = isHighIntensity ? 2 : 1;
// Generate active days
const activeDays = new Set();
while (activeDays.size < activeDaysPerWeek) {
activeDays.add(Math.floor(Math.random() * DAYS_PER_WEEK));
}
// For each active day, generate session times
for (const day of activeDays) {
for (let i = 0; i < sessionsPerDay; i++) {
// Assuming active periods are between 7AM and 9PM (minutes 7*60-1260)
const startMinute = Math.floor(random(7*60, 1260));
const duration = Math.floor(random(30, 60)); // 30-60 minute sessions
periods.push({
day,
startMinute,
duration,
intensity: isHighIntensity ? 'vigorous' : 'moderate'
});
}
}
return periods;
}
Insert cell
metValues = new Array(TOTAL_MINUTES);
Insert cell
distribution = getActivityDistribution(profile);
Insert cell
isStructured = profile.includes('structured');
Insert cell
structuredPeriods = isStructured ? generateStructuredPeriods(profile) : [];
Insert cell
function generateWeeklyMETs(profile = 'inactive') {

// Generate base activity levels
for (let minute = 0; minute < TOTAL_MINUTES; minute++) {
const currentDay = Math.floor(minute / MINUTES_PER_DAY);
const dayMinute = minute % MINUTES_PER_DAY;
// Check if this minute falls within a structured period
const structuredPeriod = structuredPeriods.find(period =>
period.day === currentDay &&
dayMinute >= period.startMinute &&
dayMinute < (period.startMinute + period.duration)
);
if (structuredPeriod) {
// Generate MET value for structured activity
const range = MET_RANGES[structuredPeriod.intensity];
metValues[minute] = random(range.min, range.max);
} else {
metValues[minute] = random(1.0, 1.2);
}
}
// Add time-based patterns
const sleepHours = [0, 1, 2, 3, 4, 5, 6]; // midnight to 5am
for (let day = 0; day < DAYS_PER_WEEK; day++) {
for (let hour of sleepHours) {
const startMinute = day * MINUTES_PER_DAY + hour * 60;
for (let i = 0; i < 60; i++) {
metValues[startMinute + i] = random(0.9, 1.1); // Sleep METs
}
}
}
return metValues;
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more