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.
我试图在数据库中表示复杂的计划数据时遇到了一个有趣的问题。作为指导,我需要能够代表iCalendar - ics - 格式的全部内容,但在数据库中。我实际上并没有实现与ic相关的任何内容,但它提供了我需要能够为我的特定项目建模的规则类型的良好范围。
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.
我需要允许基于每天多次,一周中的几天,一个月的一周,一个月,一年或这些的某些组合来允许表示单个事件或重复事件。例如,每年11月的第三个星期四,或每年的12月25日,或从11月2日开始的每两周一直持续到次年的9月8日。
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.)
我不关心插入效率,但查询效率至关重要。我最常做的操作是提供单个日期/时间或日期/时间范围,并尝试确定定义的时间表是否与日期/时间范围的任何部分相匹配。其他操作可能会更慢。例如,在2010年1月15日上午10:00到2010年1月15日上午11:00,查找至少部分时间匹配的所有计划。 (即10:30 - 11:00的时间表仍然匹配。)
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.
有什么建议么?我看一下如何在RDBMS中表示预定事件?但它不包括我想建模的重复规则类型的范围。
3 个解决方案
#1
4
In the end, this post was most helpful:
最后,这篇文章最有帮助:
iCal "Field" list (for database schema based on iCal standard)
iCal“字段”列表(适用于基于iCal标准的数据库模式)
We decided to follow the iCal model pretty exactly since the guys who wrote that standard had a great feel for the problem domain.
我们决定完全遵循iCal模型,因为编写该标准的人对问题域有很好的感觉。
#2
1
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.
对于重复发生的事件,我不太熟悉iCalendar如何存储重复,但是如果您按周中存储每个事件(如果一个事件每周重复超过一天,则可能必须有多行) ,然后搜索它几乎与上表相同。对于像本周第三个星期二那样的陌生人复发,你可以有一个额外的列来描述具体情况。如果你能告诉我更多关于ics如何代表那种复发的话,我或许可以给你一个更好的答案。
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.
我希望有所帮助。我现在没有太多时间。如果您想讨论这个问题,可以稍后与我联系。我目前在密苏里州,所以我下周的可用性将变得不稳定。
#3
-1
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?
这可能是一个简单的解决方案,但添加一个定义事件重现的列(即每x周,每年,每周等)并将其用作结果标准会有什么缺点呢?
#1
4
In the end, this post was most helpful:
最后,这篇文章最有帮助:
iCal "Field" list (for database schema based on iCal standard)
iCal“字段”列表(适用于基于iCal标准的数据库模式)
We decided to follow the iCal model pretty exactly since the guys who wrote that standard had a great feel for the problem domain.
我们决定完全遵循iCal模型,因为编写该标准的人对问题域有很好的感觉。
#2
1
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.
对于重复发生的事件,我不太熟悉iCalendar如何存储重复,但是如果您按周中存储每个事件(如果一个事件每周重复超过一天,则可能必须有多行) ,然后搜索它几乎与上表相同。对于像本周第三个星期二那样的陌生人复发,你可以有一个额外的列来描述具体情况。如果你能告诉我更多关于ics如何代表那种复发的话,我或许可以给你一个更好的答案。
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.
我希望有所帮助。我现在没有太多时间。如果您想讨论这个问题,可以稍后与我联系。我目前在密苏里州,所以我下周的可用性将变得不稳定。
#3
-1
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?
这可能是一个简单的解决方案,但添加一个定义事件重现的列(即每x周,每年,每周等)并将其用作结果标准会有什么缺点呢?