Spaces:
Running
Running
Pranabesh Singh commited on
Commit ·
8a3694b
1
Parent(s): 71405d9
Implement 500 status combinations and 30-min auto decay reset
Browse files
server.js
CHANGED
|
@@ -138,9 +138,161 @@ async function updateHighScore(gameKey, score, player, lowerIsBetter) {
|
|
| 138 |
}
|
| 139 |
}
|
| 140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
// DB Helpers for Current Activity
|
| 142 |
async function getActivity() {
|
| 143 |
let activeMoodId = null;
|
|
|
|
| 144 |
let updatedAt = null;
|
| 145 |
|
| 146 |
if (useMongo) {
|
|
@@ -150,6 +302,7 @@ async function getActivity() {
|
|
| 150 |
const doc = await collection.findOne({ key: "current" });
|
| 151 |
if (doc) {
|
| 152 |
activeMoodId = doc.moodId;
|
|
|
|
| 153 |
updatedAt = doc.updatedAt;
|
| 154 |
}
|
| 155 |
} catch (err) {
|
|
@@ -161,6 +314,7 @@ async function getActivity() {
|
|
| 161 |
const data = JSON.parse(raw);
|
| 162 |
if (data.activity) {
|
| 163 |
activeMoodId = data.activity.moodId;
|
|
|
|
| 164 |
updatedAt = data.activity.updatedAt;
|
| 165 |
}
|
| 166 |
} catch (err) {
|
|
@@ -168,40 +322,43 @@ async function getActivity() {
|
|
| 168 |
}
|
| 169 |
}
|
| 170 |
|
| 171 |
-
//
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
];
|
| 178 |
// Rotate every 30 minutes (1800000ms)
|
| 179 |
const seed = Math.floor(Date.now() / 1800000);
|
| 180 |
-
const index = seed %
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
| 182 |
updatedAt = new Date(seed * 1800000).toISOString();
|
| 183 |
}
|
| 184 |
|
| 185 |
-
return { moodId: activeMoodId, updatedAt };
|
| 186 |
}
|
| 187 |
|
| 188 |
async function updateActivity(moodId) {
|
| 189 |
const updatedAt = new Date().toISOString();
|
|
|
|
| 190 |
if (useMongo) {
|
| 191 |
const db = dbClient.db(DB_NAME);
|
| 192 |
const collection = db.collection("activity");
|
| 193 |
await collection.updateOne(
|
| 194 |
{ key: "current" },
|
| 195 |
-
{ $set: { moodId, updatedAt } },
|
| 196 |
{ upsert: true }
|
| 197 |
);
|
| 198 |
} else {
|
| 199 |
const raw = fs.readFileSync(FILE_DB_PATH, "utf-8");
|
| 200 |
const data = JSON.parse(raw);
|
| 201 |
-
data.activity = { moodId, updatedAt };
|
| 202 |
fs.writeFileSync(FILE_DB_PATH, JSON.stringify(data, null, 2));
|
| 203 |
}
|
| 204 |
-
return { moodId, updatedAt };
|
| 205 |
}
|
| 206 |
|
| 207 |
// API Routes
|
|
|
|
| 138 |
}
|
| 139 |
}
|
| 140 |
|
| 141 |
+
const MOOD_LABELS = {
|
| 142 |
+
coding: "CODING",
|
| 143 |
+
coffee: "CAFFEINATING",
|
| 144 |
+
eating: "REGAINING HP",
|
| 145 |
+
sleeping: "SLEEP MODE",
|
| 146 |
+
thinking: "BRAINSTORMING",
|
| 147 |
+
music: "LOW-FI VIBES",
|
| 148 |
+
gaming: "GRINDING",
|
| 149 |
+
bug: "BUG HUNTING",
|
| 150 |
+
rocket: "DEPLOYING",
|
| 151 |
+
chill: "CHILLING",
|
| 152 |
+
fire: "ON FIRE",
|
| 153 |
+
bash: "SH_MODE",
|
| 154 |
+
reading: "LD_LEARNING",
|
| 155 |
+
writing: "ARCHITECTING",
|
| 156 |
+
search: "RESEARCHING",
|
| 157 |
+
battery: "RECHARGING",
|
| 158 |
+
cloud: "IN THE CLOUD",
|
| 159 |
+
heart: "OPTIMISTIC",
|
| 160 |
+
success: "ACHIEVING",
|
| 161 |
+
lock: "SECURE"
|
| 162 |
+
};
|
| 163 |
+
|
| 164 |
+
// Generates exactly 500 tech developer statuses
|
| 165 |
+
function getGeneratedStatuses() {
|
| 166 |
+
const actions = [
|
| 167 |
+
{ text: "Debugging", mood: "bug" },
|
| 168 |
+
{ text: "Refactoring", mood: "coding" },
|
| 169 |
+
{ text: "Compiling", mood: "bash" },
|
| 170 |
+
{ text: "Optimizing", mood: "fire" },
|
| 171 |
+
{ text: "Squashing", mood: "bug" },
|
| 172 |
+
{ text: "Reviewing", mood: "reading" },
|
| 173 |
+
{ text: "Architecting", mood: "writing" },
|
| 174 |
+
{ text: "Tuning", mood: "battery" },
|
| 175 |
+
{ text: "Monitoring", mood: "lock" },
|
| 176 |
+
{ text: "Deploying", mood: "rocket" },
|
| 177 |
+
{ text: "Rewriting", mood: "coding" },
|
| 178 |
+
{ text: "Analyzing", mood: "search" },
|
| 179 |
+
{ text: "Diagnosing", mood: "thinking" },
|
| 180 |
+
{ text: "Fixing", mood: "bug" },
|
| 181 |
+
{ text: "Tracing", mood: "search" },
|
| 182 |
+
{ text: "Testing", mood: "success" },
|
| 183 |
+
{ text: "Securing", mood: "lock" },
|
| 184 |
+
{ text: "Scaling", mood: "cloud" },
|
| 185 |
+
{ text: "Patching", mood: "rocket" },
|
| 186 |
+
{ text: "Mocking", mood: "coding" }
|
| 187 |
+
];
|
| 188 |
+
|
| 189 |
+
const subjects = [
|
| 190 |
+
"null pointers",
|
| 191 |
+
"memory leaks",
|
| 192 |
+
"legacy spaghetti",
|
| 193 |
+
"Docker containers",
|
| 194 |
+
"Kubernetes pods",
|
| 195 |
+
"SQL injections",
|
| 196 |
+
"CORS policies",
|
| 197 |
+
"Git merge conflicts",
|
| 198 |
+
"500 Internal Errors",
|
| 199 |
+
"flaky unit tests",
|
| 200 |
+
"API specifications",
|
| 201 |
+
"CSS flexbox centering",
|
| 202 |
+
"TypeScript type errors",
|
| 203 |
+
"WebSocket handlers",
|
| 204 |
+
"out of memory crashes",
|
| 205 |
+
"CI/CD pipelines",
|
| 206 |
+
"Redis cache misses",
|
| 207 |
+
"expired JWT tokens",
|
| 208 |
+
"infinite loops",
|
| 209 |
+
"YAML configurations",
|
| 210 |
+
"microservices mesh",
|
| 211 |
+
"garbage collection runs",
|
| 212 |
+
"DNS resolution failures",
|
| 213 |
+
"Webpack configurations",
|
| 214 |
+
"auth middleware"
|
| 215 |
+
];
|
| 216 |
+
|
| 217 |
+
const contexts = [
|
| 218 |
+
"in production",
|
| 219 |
+
"at 3:00 AM",
|
| 220 |
+
"fueled by espresso",
|
| 221 |
+
"in slow motion",
|
| 222 |
+
"for the final release",
|
| 223 |
+
"to hit five nines",
|
| 224 |
+
"without any comments",
|
| 225 |
+
"using stack overflow",
|
| 226 |
+
"like a 10x developer",
|
| 227 |
+
"inside Docker container",
|
| 228 |
+
"locally on my machine",
|
| 229 |
+
"on Cloudflare edge",
|
| 230 |
+
"while listening to lo-fi",
|
| 231 |
+
"to prevent page collapse",
|
| 232 |
+
"for a client demo",
|
| 233 |
+
"without dev testing",
|
| 234 |
+
"using experimental flags",
|
| 235 |
+
"hoping it doesn't break",
|
| 236 |
+
"with fingers crossed",
|
| 237 |
+
"under extreme pressure"
|
| 238 |
+
];
|
| 239 |
+
|
| 240 |
+
const list = [];
|
| 241 |
+
|
| 242 |
+
// Create 500 distinct combinations
|
| 243 |
+
for (let i = 0; i < 500; i++) {
|
| 244 |
+
const actionIdx = (i * 7) % actions.length;
|
| 245 |
+
const subjectIdx = (i * 13) % subjects.length;
|
| 246 |
+
const contextIdx = (i * 17) % contexts.length;
|
| 247 |
+
|
| 248 |
+
const action = actions[actionIdx];
|
| 249 |
+
const subject = subjects[subjectIdx];
|
| 250 |
+
const context = contexts[contextIdx];
|
| 251 |
+
|
| 252 |
+
list.push({
|
| 253 |
+
label: `${action.text} ${subject} ${context}`.toUpperCase(),
|
| 254 |
+
moodId: action.mood
|
| 255 |
+
});
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
// Pre-seed high quality overrides
|
| 259 |
+
const staticStatuses = [
|
| 260 |
+
{ label: "CAFFEINATING HARD", moodId: "coffee" },
|
| 261 |
+
{ label: "SIP OF HOT ESPRESSO", moodId: "coffee" },
|
| 262 |
+
{ label: "REGAINING HP (RAMEN)", moodId: "eating" },
|
| 263 |
+
{ label: "RELOADING CARBS", moodId: "eating" },
|
| 264 |
+
{ label: "SLEEP MODE ENABLED", moodId: "sleeping" },
|
| 265 |
+
{ label: "DREAMING OF SYNTAX", moodId: "sleeping" },
|
| 266 |
+
{ label: "BRAINSTORMING V2", moodId: "thinking" },
|
| 267 |
+
{ label: "THINKING IN BINARY", moodId: "thinking" },
|
| 268 |
+
{ label: "LOW-FI MUSIC VIBES", moodId: "music" },
|
| 269 |
+
{ label: "SYNTHWAVE PLAYLIST", moodId: "music" },
|
| 270 |
+
{ label: "GAMING (GRINDING)", moodId: "gaming" },
|
| 271 |
+
{ label: "CLEARING SIDE QUESTS", moodId: "gaming" },
|
| 272 |
+
{ label: "CHILLING BY THE POOL", moodId: "chill" },
|
| 273 |
+
{ label: "DOING ABSOLUTELY NOTHING", moodId: "chill" },
|
| 274 |
+
{ label: "ON FIRE (1000 WPM)", moodId: "fire" },
|
| 275 |
+
{ label: "UNSTOPPABLE CODING", moodId: "fire" },
|
| 276 |
+
{ label: "READING RFC SPECS", moodId: "reading" },
|
| 277 |
+
{ label: "LEARNING RUST GEMS", moodId: "reading" },
|
| 278 |
+
{ label: "SECURE NODE NETWORKS", moodId: "lock" },
|
| 279 |
+
{ label: "ROTATING TLS CERTIFICATES", moodId: "lock" }
|
| 280 |
+
];
|
| 281 |
+
|
| 282 |
+
staticStatuses.forEach((status, idx) => {
|
| 283 |
+
const targetIdx = (idx * 23) % 500;
|
| 284 |
+
list[targetIdx] = status;
|
| 285 |
+
});
|
| 286 |
+
|
| 287 |
+
return list;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
const generatedStatuses = getGeneratedStatuses();
|
| 291 |
+
|
| 292 |
// DB Helpers for Current Activity
|
| 293 |
async function getActivity() {
|
| 294 |
let activeMoodId = null;
|
| 295 |
+
let activeLabel = null;
|
| 296 |
let updatedAt = null;
|
| 297 |
|
| 298 |
if (useMongo) {
|
|
|
|
| 302 |
const doc = await collection.findOne({ key: "current" });
|
| 303 |
if (doc) {
|
| 304 |
activeMoodId = doc.moodId;
|
| 305 |
+
activeLabel = doc.label;
|
| 306 |
updatedAt = doc.updatedAt;
|
| 307 |
}
|
| 308 |
} catch (err) {
|
|
|
|
| 314 |
const data = JSON.parse(raw);
|
| 315 |
if (data.activity) {
|
| 316 |
activeMoodId = data.activity.moodId;
|
| 317 |
+
activeLabel = data.activity.label;
|
| 318 |
updatedAt = data.activity.updatedAt;
|
| 319 |
}
|
| 320 |
} catch (err) {
|
|
|
|
| 322 |
}
|
| 323 |
}
|
| 324 |
|
| 325 |
+
// 30 minute manual override decay check (1800000ms)
|
| 326 |
+
const DECAY_MS = 30 * 60 * 1000;
|
| 327 |
+
const isExpired = updatedAt && (Date.now() - new Date(updatedAt).getTime() > DECAY_MS);
|
| 328 |
+
|
| 329 |
+
// If no manual override is set, if set to "auto", or if manual status has expired (>30 mins)
|
| 330 |
+
if (!activeMoodId || activeMoodId === "auto" || isExpired) {
|
|
|
|
| 331 |
// Rotate every 30 minutes (1800000ms)
|
| 332 |
const seed = Math.floor(Date.now() / 1800000);
|
| 333 |
+
const index = seed % generatedStatuses.length;
|
| 334 |
+
const status = generatedStatuses[index];
|
| 335 |
+
|
| 336 |
+
activeMoodId = status.moodId;
|
| 337 |
+
activeLabel = status.label;
|
| 338 |
updatedAt = new Date(seed * 1800000).toISOString();
|
| 339 |
}
|
| 340 |
|
| 341 |
+
return { moodId: activeMoodId, label: activeLabel, updatedAt };
|
| 342 |
}
|
| 343 |
|
| 344 |
async function updateActivity(moodId) {
|
| 345 |
const updatedAt = new Date().toISOString();
|
| 346 |
+
const label = MOOD_LABELS[moodId] || "AUTO ROTATE";
|
| 347 |
if (useMongo) {
|
| 348 |
const db = dbClient.db(DB_NAME);
|
| 349 |
const collection = db.collection("activity");
|
| 350 |
await collection.updateOne(
|
| 351 |
{ key: "current" },
|
| 352 |
+
{ $set: { moodId, label, updatedAt } },
|
| 353 |
{ upsert: true }
|
| 354 |
);
|
| 355 |
} else {
|
| 356 |
const raw = fs.readFileSync(FILE_DB_PATH, "utf-8");
|
| 357 |
const data = JSON.parse(raw);
|
| 358 |
+
data.activity = { moodId, label, updatedAt };
|
| 359 |
fs.writeFileSync(FILE_DB_PATH, JSON.stringify(data, null, 2));
|
| 360 |
}
|
| 361 |
+
return { moodId, label, updatedAt };
|
| 362 |
}
|
| 363 |
|
| 364 |
// API Routes
|