Spaces:
Sleeping
Sleeping
File size: 2,240 Bytes
ccb6b75 | 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | 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;
|