在 Node.js 后端确定星期和自动函数的实用方法

发布于 2025-01-11 10:33:56 字数 932 浏览 0 评论 0原文

我正在开发一个后端服务器,使用 Postgres 作为朋友游戏项目的数据库。一切都很顺利,但有一些我想添加的功能我还不了解。

游戏需要等级。人们每天都可能会进行简短的比赛。每个玩它的人都会为目标得分。有月排名、周排名、日排名之分。每场比赛都会对各自的排名做出贡献。周是通过从星期一开始到星期日结束来衡量的。

月和日衡量很简单,但我想知道在更务实的一天来进行每周排名。如何确保我可以使用各种 JavaScript 函数轻松地逐月描绘一周等?例如,我们处于 2022 年的第 10 周,或第 15 周等。

另外,我想制作一个函数,该函数将在每天 00:00 每 24 小时自动运行一次,并通过电子邮件发送每日排名以及每周排名周日(“每周排名重置时”)和每个月底。在此过程中可能会删除旧的且无用的过去排名。

因此,目标是:

  • 检测当前弱势的最佳方法,即使是从月份过渡时也是如此 每月,并跟踪每个排名
  • 如何通过电子邮件将此类排名发送给游戏所有者(我的朋友)
  • 如何创建一个每 24 小时在服务器上自动运行的功能 在 00:00 标记此类排名。

我希望我已经足够清楚地阐述了这个问题。我将不胜感激的帮助,如果我可以帮助使问题更清楚,请询问我任何问题

项目的依赖关系:

jest:“^27.4.1”, bcryptjs: "^2.4.3", csv 解析:“^5.0.4”, 表达:“^4.17.2”, 表达异步错误:“^3.1.1”, 开玩笑:“^27.5.1”, jsonwebtoken: "^8.5.1", 乘法器:“^1.4.4”, 页码:“^8.7.3”, 反映元数据:“^0.1.13”, swagger-ui-express: "^4.3.0", ts-笑话:“^27.1.3”, tsyringe: "^4.6.0", 类型:“^0.2.43”, uuid: "^8.3.2"

还有一些更多的开发依赖项,但我不确定它们是否相关。

先谢谢大家了!

I’m developing a backend server, using Postgres as my database for a friend’s game project. Everything is going well but there are a couple of features that I want to add which I’m not knowledgeable about yet.

The game works with ranks. Every day people may play short matches. Everyone who plays it will score ranks toward goals. There is a monthly rank, weekly rank and daily rank. Every game contributes to each respective rank. Weeks are measured by starting on Mondays and ending on Sundays.

Month and daily measures are easy but I’m wondering on a more pragmatic day to make the weekly rank. How to make sure I can easily delineate a week from month to month and etc with the various JavaScript functions? For example, we are in the 10th week of 2022, or 15th and etc.

Also, I would like to make a function that will automatically run every 24 hours at 00:00 of each day and email the daily ranks, and also the weekly ones on Sundays(‘when the weekly ranks resets’) and by the end of each month. Possibly deleting the old and non-useful past ranks in this process.

So the goals are:

  • Best ways to detect present weak, even when transitioning from month
    to month, and keeping track of each rank
  • How to email such ranks to the game owner (my friend)
  • How to make a function that will autorun on the server every 24 hours
    at 00:00 to tab such ranks.

I hope I’ve elaborated the question clearly enough. I would appreciate the help, please ask me anything if I can help make the question clearer

Dependencies of the projects:

jest: "^27.4.1",
bcryptjs: "^2.4.3",
csv-parse: "^5.0.4",
express: "^4.17.2",
express-async-errors: "^3.1.1",
jest: "^27.5.1",
jsonwebtoken: "^8.5.1",
multer: "^1.4.4",
pg: "^8.7.3",
reflect-metadata: "^0.1.13",
swagger-ui-express: "^4.3.0",
ts-jest: "^27.1.3",
tsyringe: "^4.6.0",
typeorm: "^0.2.43",
uuid: "^8.3.2"

There are also some more dev-dependencies but I'm not sure if they are relevant.

Thanks in advance everybody!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尝蛊 2025-01-18 10:33:56

Postgres 提供了一种直接计算周数的方法,让您可以忍受 ISO 8601 周定义的年末特性。使用提取函数。但是,它不考虑特定月份。
不幸的是,就调度任务而言,Postgres 没有提供内置调度程序。不过,请参阅此处了解一些选项。

Postgres provides a direct method for week number, providing you can put up with the year end idiosyncrasies of the ISO 8601 week definition. Use the extract function. However, it does not take account the particular month.
As far as scheduling tasks it is unfortunate but Postgres does not provide a built in scheduler. However see here for a few options.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文