半静态数据设计问题
我正在设计一个将在 Django 中开发的项目,并且我有一个设计哲学问题。在我的应用程序中,我需要跟踪本周等信息。这与 NFL 中的当前周 (1-17) 相关,并且可以根据系统中的其他模型(例如时间表和当天)进行计算。由于此信息每周更新一次,并且会在应用程序中经常使用,因此将此信息存储在其自己的模型(数据库表)中并每周运行更新是否有意义?
还有其他信息可能也有助于存储(本周第一场和最后一场比赛的日期/时间),因此“当前几周信息”之类的模型是否适合于此,即使可以计算数据在飞行中?
I'm designing a project that will be developed in Django and I had a design philosophy question. In my app I need to track information like current week. This is related to the current week in the NFL (1-17) and can be calculated based on other models in the system (schedule and the current day for example). Since this information gets updated once a week, and will be used quite often in the app, does it make sense to store this information in a model (db table) of its own and just run the update weekly?
There is other information that might be useful to store as well (date/time of first and last games of the current week) so would a model of something like "current weeks information" be appropriate for this, even though the data can be calculated on the fly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是这样。您可以计算复活节的日期,但很少有应用程序能够做到这一点。计算远非简单,任何错误都必须被视为错误修复。但是,如果您将复活节日期存储在表中,则任何可以更新日历数据的人都可以修复任何错误。
计算美国假期很简单,例如马丁·路德·金日(1 月第 3 个星期一)、总统日(2 月第 3 个星期一)和劳动节(9 月第 1 个星期一)。计算工厂生产周数也很容易,这在某些方面与您的问题相似。
但是,当我为企业构建用于计划、估算、流程控制等的表时,我喜欢将对业务重要的日期(例如假期)存储在表中而不是存储在程序(计算)代码。主要优点是它们可以由相对不熟练的员工收集、审查、批准或纠正,而不需要程序员。
所以,如果我处于你的立场,我可能会将几周存储在表中。第二个优点(或者在您的情况下可能是主要优点)是大多数涉及周的查询可能会利用开始日期和结束日期的索引。
It might be. You can calculate the date Easter falls on, but few applications do that. The calculation is far from dead simple, and any error would have to be treated as a bug fix. But if you store Easter dates in a table, any error can be fixed by anyone who can update calendar data.
It's simple to calculate USA holidays like Martin Luther King Day (observed on the 3rd Monday in January), President's Day (observed on the 3rd Monday in February), and Labor Day (observed on the 1st Monday in September). It's also pretty easy to calculate factory production weeks, which parallels your problem in some ways.
But when I'm building tables for businesses to use for scheduling, estimating, process control, and so on, I like to have the dates that are important to the business--holidays, for example--stored in a table rather than in procedural (calculating) code. The main advantage is that they can be collected, reviewed, and approved or corrected by relatively unskilled employees instead of needing a programmer.
So, if I were in your shoes, I would probably store the weeks in a table. A secondary advantage (or maybe the main advantage, in your case) is that most queries involving weeks might take advantage of indexes on the start and end dates.