表示数据库中复杂的计划重复

发布于 2024-09-05 06:57:13 字数 666 浏览 8 评论 0原文

我有一个有趣的问题,试图在数据库中表示复杂的计划数据。作为指导原则,我需要能够表示 iCalendar -- ics -- 格式可以表示的全部内容,但在数据库中。我实际上并没有实现与 ics 相关的任何内容,但它提供了我需要能够为我的特定项目建模的规则类型的良好范围。

我需要允许根据每天的多次、一周中的几天、一个月中的一周、一个月、一年或这些的某种组合来表示单个事件或重复事件。例如,每年 11 月的第三个星期四,或每年 12 月 25 日,或从 11 月 2 日开始每两周一次,一直持续到次年 9 月 8 日。

我不关心插入效率,但查询效率很关键。我最常执行的操作是提供单个日期/时间或日期/时间范围,并尝试确定定义的计划是否与日期/时间范围的任何部分匹配。其他操作可能会更慢。例如,给定 2010 年 1 月 15 日上午 10:00 到 2010 年 1 月 15 日上午 11:00,查找至少匹配该时间部分时间的所有时间表。 (即涵盖 10:30 - 11:00 的时间表仍然匹配。)

有什么建议吗?我查看了 如何在 RDBMS 中表示计划事件?< /a> 但它不涵盖我想要建模的重复规则类型的范围。

I have an interesting problem trying to represent complex schedule data in a database. As a guideline, I need to be able to represent the entirety of what the iCalendar -- ics -- format can represent, but in a database. I'm not actually implementing anything relating to ics, but it gives a good scope of the type of rules I need to be able to model for my particular project.

I need to allow allow representation of a single event or a recurring event based on multiple times per day, days of the week, week of a month, month, year, or some combination of those. For example, the third Thursday in November annually, or the 25th of December annually, or every two weeks starting November 2 and continuing until September 8 the following year.

I don't care about insertion efficiency but query efficiency is critical. The operation I will be doing most often is providing either a single date/time or a date/time range, and trying to determine if the defined schedule matches any part of the date/time range. Other operations can be slower. For example, given January 15, 2010 at 10:00 AM through January 15, 2010 at 11:00 AM, find all schedules that match at least part of that time. (i.e. a schedule that covers 10:30 - 11:00 still matches.)

Any suggestions? I looked at How would one represent scheduled events in an RDBMS? but it doesn't cover the scope of the type of recurrence rules I'd like to model.

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

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

发布评论

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

评论(3

无人接听 2024-09-12 06:57:13

最后,这篇文章最有帮助:

iCal ” Field”列表(基于 iCal 标准的数据库模式)

我们决定完全遵循 iCal 模型,因为编写该标准的人对问题领域有很好的感觉。

In the end, this post was most helpful:

iCal "Field" list (for database schema based on iCal standard)

We decided to follow the iCal model pretty exactly since the guys who wrote that standard had a great feel for the problem domain.

£冰雨忧蓝° 2024-09-12 06:57:13

我做类似事情的方法是有两张桌子。如果事件没有重复发生模式,则只需存储日期、开始时间和结束时间。您的查询会检查您搜索的时间是否大于任何条目的开始时间并且小于或等于同一事件的结束时间。

对于重复事件,我不太熟悉 iCalendar 如何存储重复事件,但如果您按一周中的某一天存储每个事件(如果单个事件每周重复超过一天,则可能需要为单个事件拥有多行) ,然后按照与上表几乎相同的方式进行搜索。对于陌生人重复出现的情况,例如一周的第三个星期二,您可以有一个额外的列来描述具体情况。如果你能告诉我更多关于 ics 如何代表这种复发的信息,我也许可以给你一个更好的答案。

我希望这有帮助。我现在没有太多时间。如果您想讨论这个问题,可以稍后联系我。我目前在密苏里州,因此下周的空闲时间会不稳定。

The way I did something similar to this was to have two tables. If an event had no recurring pattern, then just store the date, start time, and end time. Your query checks if the time your searching for is greater than the start time of any entry and less than or equal to the end time of that same event.

For recurring events, I'm not too familiar with how iCalendar stores recurrences, but if you store each event by day of the week (you might have to have multiple rows for a single event if it repeats on more than one day a week), then search it almost the same way as the above table. For stranger recurrences like the third Tuesday of the week, you could have an extra column describing the specific condition. I might be able to give you a better answer for this if you could tell me more about how ics represents that kind of recurrence.

I hope that helps. I don't have much time right now. You can contact me later if you want to discuss this. I'm currently in Missouri so my availability for the next week is going to be erratic.

一抹苦笑 2024-09-12 06:57:13

这可能是一个微不足道的解决方案,但是添加定义事件重复发生的列(即每x周、每年、每周等)并将其用作结果标准会有什么缺点?

This might be a trivial solution, but what would be the drawbacks of adding a column that defines the recurrence of the event (i.e. every x weeks, annually, weekly, etc) and using that as the result criterion?

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