A Deno-powered backend service for Plants vs. Zombies: MODDED. [Read-only GitHub mirror] docs.pvzm.net
express typescript expressjs plant deno jspvz pvzm game online backend plants-vs-zombies zombie javascript plants modded vs plantsvszombies openapi pvz noads
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

0.6.3 - 🛠️ Simplified featured sort

Clay 41d11a59 2bae40ce

+11 -58
+4
CHANGELOG.md
··· 1 1 # Changelog 2 2 3 + ## 0.6.3 4 + 5 + - 🛠️ Simplified featured sort 6 + 3 7 ## 0.6.2 4 8 5 9 - 🛠️ Cache game images used for thumbnail rendering
+1 -1
README.md
··· 1 - # PVZM Backend ![v0.6.2](https://img.shields.io/badge/version-v0.6.2-darklime) 1 + # PVZM Backend ![v0.6.3](https://img.shields.io/badge/version-v0.6.3-darklime) 2 2 3 3 > A Deno-powered backend service for [Plants vs. Zombies: MODDED](https://github.com/roblnet13/pvz). This service provides APIs for uploading, downloading, listing, favoriting, and reporting user-created _I, Zombie_ levels. 4 4
+1 -1
deno.json
··· 1 1 { 2 - "version": "0.6.2", 2 + "version": "0.6.3", 3 3 "tasks": { 4 4 "dev": "deno run --watch -P=dev --env-file=.env main.ts", 5 5 "start": "deno run -P --env-file=.env main.ts",
+2 -53
modules/routes/levels.ts
··· 346 346 const orderDirection = reversedOrder ? "ASC" : "DESC"; 347 347 348 348 let orderClause: string; 349 - let useDiversitySort = false; 350 349 if (sort === "featured") { 351 - // recency weight: 1 point per day, quality: favorites * 10 + plays / 10 352 - // this makes recency ~100x more important than in the mature formula 353 - orderClause = `(created_at / 86400.0 + favorites * 10 + plays / 10.0) DESC`; 354 - useDiversitySort = true; 350 + orderClause = `featured_at DESC`; 355 351 } else { 356 352 const orderColumn = sort === "recent" ? "created_at" : sort === "favorites" ? "favorites" : "plays"; 357 353 orderClause = `${orderColumn} ${orderDirection}, id ${orderDirection}`; ··· 393 389 query += " WHERE " + filters.join(" AND "); 394 390 } 395 391 396 - // for featured sort with diversity, fetch more results to allow for re-ranking 397 - const shouldApplyDiversity = useDiversitySort && tokenLevelId === null; 398 - const fetchLimit = shouldApplyDiversity ? limit * 3 : limit; 399 - const fetchOffset = shouldApplyDiversity ? offset : offset; 400 - 401 392 query += ` ORDER BY ${orderClause} LIMIT ? OFFSET ?`; 402 - params.push(fetchLimit, fetchOffset); 393 + params.push(limit, offset); 403 394 404 395 let levels = dbCtx.db.prepare(query).all(...params); 405 - 406 - // apply author diversity algorithm for featured sort 407 - if (shouldApplyDiversity && Array.isArray(levels) && levels.length > 0) { 408 - type LevelWithScore = { 409 - id: number; 410 - author: string; 411 - created_at: number; 412 - favorites: number; 413 - plays: number; 414 - featured: number; 415 - score: number; 416 - [key: string]: unknown; 417 - }; 418 - 419 - const authorCounts = new Map<string, number>(); 420 - 421 - // calculate scores and apply diversity penalties 422 - const levelsWithScores = (levels as LevelWithScore[]).map((level) => { 423 - // Calculate base score (same formula as SQL) 424 - let baseScore: number; 425 - 426 - baseScore = level.created_at / 86400.0 + level.favorites * 10 + level.plays / 10.0; 427 - 428 - // Apply diversity penalty 429 - const authorCount = authorCounts.get(level.author) || 0; 430 - authorCounts.set(level.author, authorCount + 1); 431 - 432 - // Penalty increases exponentially: 0, -500, -1500, -3500, -7500... 433 - const diversityPenalty = authorCount === 0 ? 0 : -500 * (Math.pow(2, authorCount) - 1); 434 - 435 - return { 436 - ...level, 437 - score: baseScore + diversityPenalty, 438 - }; 439 - }); 440 - 441 - // Re-sort by adjusted scores 442 - levelsWithScores.sort((a, b) => b.score - a.score); 443 - 444 - // Take only the requested limit 445 - levels = levelsWithScores.slice(0, limit); 446 - } 447 396 448 397 type LevelRow = { 449 398 id: number;
+3 -3
openapi.yaml
··· 2 2 info: 3 3 title: PVZM Backend API 4 4 description: "API for the Plants vs. Zombies: MODDED level sharing platform. Supports level uploading, downloading, browsing, favoriting, reporting, and admin management." 5 - version: 0.6.2 5 + version: 0.6.3 6 6 contact: 7 7 url: https://pvzm.net 8 8 ··· 45 45 format: date-time 46 46 version: 47 47 type: string 48 - example: 0.6.2 48 + example: 0.6.3 49 49 50 50 /api/config: 51 51 get: ··· 73 73 get: 74 74 tags: [Levels] 75 75 summary: List levels 76 - description: Retrieve a paginated, filterable list of levels. When `sort=featured`, an author diversity algorithm is applied. 76 + description: Retrieve a paginated, filterable list of levels. 77 77 operationId: getLevels 78 78 parameters: 79 79 - name: page