UNPKG

rjweb-server

Version:

Easy and Robust Way to create a Web Server with Many Easy-to-use Features in NodeJS

63 lines (62 loc) 1.15 kB
const getPreviousHours = () => { return Array.from({ length: 7 }, (_, i) => ((/* @__PURE__ */ new Date()).getHours() - (4 - i) + 24) % 24); }; class DataStat { /** * Create a new Data Stat * @since 7.3.0 */ constructor() { this.secondStat = 0; this.stats = { total: 0, perSecond: 0, 0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0, 17: 0, 18: 0, 19: 0, 20: 0, 21: 0, 22: 0, 23: 0 }; setInterval(() => { this.stats.perSecond = this.secondStat; this.secondStat = 0; }, 1e3); setInterval(() => { const previousHours = getPreviousHours(); this.stats[previousHours[6]] = 0; }, 3e5); } /** * Increase a Stat * @since 7.3.0 */ increase(amount = 1) { this.secondStat += amount; this.stats.total += amount; this.stats[(/* @__PURE__ */ new Date()).getHours()] += amount; return this; } } export { DataStat as default, getPreviousHours };