activity-simulator / src /utils /humanSchedule.js
abedelbahnasy55's picture
feat: cloud simulator - Docker, dashboard, auto-start
ccb6b75
import { toZonedTime } from 'date-fns-tz';
class HumanSchedule {
constructor(config) {
this.config = config;
this.timezone = config.schedule.timezone;
}
isWorkHours(date = new Date()) {
return true;
}
isWeekend(date = new Date()) {
return false;
}
isLunchTime(date = new Date()) {
return false;
}
getNextWorkTime(date = new Date()) {
return date;
}
getRandomWorkInterval() {
const minMs = this.config.activity.minIntervalMinutes * 60 * 1000;
const maxMs = this.config.activity.maxIntervalMinutes * 60 * 1000;
const baseDelay = Math.random() * (maxMs - minMs) + minMs;
const intensity = this.getEnergyLevel();
const intensityFactor = 1 - (intensity - 0.5);
return Math.floor(baseDelay * intensityFactor);
}
getEnergyLevel(date = new Date()) {
const localTime = toZonedTime(date, this.timezone);
const hour = localTime.getHours();
const dayOfWeek = localTime.getDay();
let baseEnergy = 0.7;
if (hour >= 7 && hour < 11) baseEnergy = 0.8;
else if (hour >= 11 && hour < 14) baseEnergy = 0.9;
else if (hour >= 14 && hour < 17) baseEnergy = 0.7;
else if (hour >= 17 && hour < 20) baseEnergy = 0.6;
else if (hour >= 20 && hour < 23) baseEnergy = 0.5;
else baseEnergy = 0.4;
const dayEnergy = {
0: 0.7, 1: 0.85, 2: 0.95, 3: 0.9, 4: 0.8, 5: 0.6, 6: 0.5
}[dayOfWeek] || 0.7;
return Math.max(0.1, Math.min(1, baseEnergy * dayEnergy + (Math.random() - 0.5) * 0.2));
}
getDayOfWeekName(date = new Date()) {
const localTime = toZonedTime(date, this.timezone);
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
return days[localTime.getDay()];
}
getWorkPeriod(date = new Date()) {
const localTime = toZonedTime(date, this.timezone);
const hour = localTime.getHours();
if (hour >= 4 && hour < 7) return 'earlyMorning';
if (hour >= 7 && hour < 11) return 'morning';
if (hour >= 11 && hour < 14) return 'midday';
if (hour >= 14 && hour < 17) return 'afternoon';
if (hour >= 17 && hour < 20) return 'evening';
if (hour >= 20 && hour < 23) return 'night';
return 'lateNight';
}
}
export default HumanSchedule;