I'm building a system that needs to store/manage different types of events. For simplicity, I will focus on designing a calendar (I'm building something slightly different, but calendar is a good analogy and it's easy to reason about). I'd like to hear about possible database/schema design ideas.
Problem Description
I have a calendar with different types of events (for simplicity sake, say there is only 1 type of event: Task). User can add new event for a particular date, edit (change some details, like title or move to another date) or delete. There can be one-time events and recurring events (with different types of recurrence: every X days, every 15th day of the month, every week on Monday; kind of like simple cron). When user moves recurring event, all other instances of this event are moved in the same manner (e.g: +3 days). Important part: recurring events can have exceptions. So, for example, let's say I have an recurring event A which is repeated every 7 days. But I want to change it's date for next week, so instead of Tuesday, it's be assigned to Friday, after that it'll still occur on Tuesday. This "exception" event shouldn't be affected when "parent" event is moved.
Also, every recurring event can have additional info, that is related only to 1 particular instance, e.g: I have the same recurring event A repeated every 7 days, I want to add a note for this week instance that says "X", and I want to add another note for the event A next month that says "Y" - those fields are only visible to that single instances.
Ideas
System with regular, one-time events is pretty straightforward so I won't discuss that and focus only on recurring events.
1. One possible solution is the one that resembles OOP: I can have an Event "class" with fields such as start_date, end_date (can be null), recurrence_type (something like enum with possible values of EVERY_X_DAYS, DAY_OF_WEEK, DAY_OF_MONTH) and recurrence_value (say 7). When user adds new recurring event, I just create such Event in the database. When user wants to change 1 occurrence of this event, I add new entry to the DB of the type/class MovedEvent that "inherits" from Event with different date and has additional field related_to that points to the ID (or UUID, if you will) of the Event that it's related to. But at the same time, I need to keep track of all the MovedEvents (otherwise I'd have 2 events displayed in the same week), so I need to have an array moved_events of IDs that point to all MovedEvents.
Disadvantage: every time I want to display the calendar I need to get Event and select all events from the moved_events, which is not optimal if I'll have a lot of moved events.
2. Another idea is to store every event as a separate record. IMO it's a terrible idea, but I just mentioning it because it's a possibility. Disadvantages: every time I want to edit the main event (e.g: I want to change the event from occurring "every 7 days" to "every 9 days") I need to change every single occurrence of the event. "Exceptions" (changing single instance) is easier, though.
SQL/NoSQL? Scale details
I'm using PostgreSQL in my project, but I have basic knowledge in NoSQL databases and if they are better suited for this kind of a problem, I can use it.
Scale: Let's say I have 5k users, and each will have on average 150 events/week, 40% of which can be "exceptions". Therefore I want to design this system to be efficient.
Similar Questions & Other Resources
I've just started reading Martin Fowler's "Recurring Events for Calendars" (http://martinfowler.com/apsupp/recurring.pdf) but I'm not sure if it applies to my problem and if so, how one would design database schema according to this document (suggestions are welcome).
There are similar questions, but I didn't see any mention of "exceptions" (changing 1 event instance without affecting other), but maybe someone will find these links useful:
Design question: How would you design a recurring event system?
Optimal design for a Database with recurring event
Design option for 'recurring tasks'
Calendar Recurring/Repeating Events - Best Storage Method
What is the best way to represent "Recurring Events" in database?
Sorry for a long question, I wanted to describe the problem well. Yet, I feel that's pretty chaotic, so if you have additional questions, I will happily provide more details. Again, I'd like to hear about possible database/schema design ideas plus any other suggestions. Thank you!
Use iCalendar RRules and ExDates
If it's a recurring event, just store the start/end datetimes and RRules and ExDates for the event.
Use a Materialized View to pre-calculate upcoming actual events, say for the next 30 days or 365 days.
As you are using Postgres, you can use existing python, perl, or javascript RRule libraries (such as dateutil) inside pg function for calculating future events based on the rrules and exdates
UPDATE: check out pg_rrule extension: https://github.com/petropavel13/pg_rrule
Related
Hi everyone and I new to complex SQL and to Clickhouse both. So sorry if this seems like a simple question, but I still can't figure it out.
Challenge:
I want to build an event path that leads to a specific event.
You probably have seen these types of analysis in Google Analytics, for instance:
Basically, based on a target "end event", I am looking to build the path taken by the user to arrive at that event.
Suppose I have a table like this:
date
event_name (purchase, add_to_cart, search, browse)
user_id
Now, given the final event, let's say "purchase", I want to understand what are the common paths for users to arrive at that event, just like the picture above.
How would you go about accomplishing that?
I am using Clickhouse for this analysis.
Thanks
I am not sure if this is the correct Community ''folder'' where to post this, but I have a question relating to the wonderful workflow as demonstrated in this video Inspection Workflows Part 2: Web Map Creation & Dynamic Symbology
Two questions:
Is it possible to Access the water utilities Symbology also on the new Map Viewer? I see it neatly in the Classic..
Is it just me or when using the same method of IIF+DateDiff as to define symbology for points that have been inspected recently and those that have to be inspected - it works only in the Map Viewer Classic? Is it because the Layer View is added to the map? I tried a workaround - created layer view by Join Analysis and added it to the Map Viewer Map. Used the same Arcade that is in the demonstration. Worked great for the Map Viewer Classic Map. Ignores the second part of the expression in Map Viewer.
I would be happy if anyone could give a comment if this is how it's supposed to be for now.
Glad we're making progress on the first point! But I think I know the error for the second point, it's a tricky one!
According to your Arcade expression, you have two values, right?
"Inspected more than a year ago"
"Recent inspection"
Even though you put these two values correctly into the arcade expression, the map still doesn't technically know that these two values exist... until inpsection records are submitted that meet each of the provided criteria (inspection within the last year OR inspection not in the last year).
So, if you built the arcade epxression and all of your inspections are within the last year, you can symbolize everything by "Recent inspection" because the map has data that supports this first part fo the expression. Until you add an inspection record that occured "more than a year ago", the map won't register this value in the symbology and it will ignore that second part fo the arcade expression. However, once you add an inspection record that meets the second criteria, you'll still have to go into the symbology and manually turn on the "Inspected more than a year ago" symbology. But it will work since a record meeting this criteria is available for the arcade expression to consume.
I ran through the symbology workflow and when I had no inspection records submitted, I couldn't use either of your two values. I got a generic "Other" value. I added an inspection record with today's date and was able to add the "Recent inspection" value. Then, I added an inspection record and falsified the date to be three years ago; this allowed me to add the "Inspected more than a year ago" symbology color.
Here's my suggestion: when using an arcade expression like this to drive symbology, create "fake" inspections records that will trick the map to thinking that all of your different criteria are met. This way you can apply your: "Inspected more than a year ago" and "Recent inspection" symbologies.
Finally, it makes sense that the symbology from the Map Viewer Classic pulled into the New Map Viewer. Just like the utility symbology, the New Map Viewer will pull on that Map Viewer Classic's symbology.
I am using HP Project and Portfolio Management(PPM) tool and I am adding a custom field in my request type which has date as value. Now my requirement is to send the email notifications to the users once the date mentioned in the custom field crosses the system date.
I had tried to set the notification for field level from Notification tab but not getting the custom fields in the list. All the fields, which is available, are pre-configured fields.
So, can anyone suggest me how to implement this requirement? And also where the changes need to be done If any required to implement this?
Please answer in detail and also reply soon.
Thanks in advance!!
PPM notifications can be configured on pre-defined events, like a certain transition, or timeout etc...
One possible solution for this scenario is to have timeouts on your decision step. Time out goes to an execution step, which checks for the date condition. If the condition is met it fires the notification. Else it just returns to the original decision step.
The downside of this work around is that there will be transaction details added once daily. Also the last update date of the request keeps updating daily, which is not ideal if you want to track what was the last time an end user update the request.
It is a workaround cause of the restrictions around notification events.
And if you have a large workflow, I would not recommend this work around.
I'm having this issue:
I'm using VBS to extract all meetings from our conference rooms.
Sometimes I get from the same room 2 meetings that overlap each other for a certain amount of time. But, outlook shows only one of them.
I've tried to check all the item.fields to see what seems to be the criteria by which a meeting is shown in shared calendar, or not, but all seems to be the same for both.
I would have uploaded my code here, but it is very long, about 350 code lines.
So, my question is, what property is used by outlook to show to other people in a shared calendar, a meeting, if it overlaps with another one?
I`ve found the answer.
Microsoft uses this model for recurrent appointments:
When a recurring event is created, the item.isRecurring is set to True.
then the colection occurrences is added to item, and reccuring pattern object.
If you delete or modify one or more occurrences, anther object is added to occurences, exception. All deleted, or modified occurrences can be found here.
the strange thing is that even if an occurence is deleted, you can still find it as active, and thus, overlaying with the appointments created afterwards.
The trick is to check all the way, even in exceptions, in order to be able to get same view as in Outlook.
if you need additional details, pm me.
I'm looking for an example where + autoupdatingCurrentCalendar would be used instead of + currentCalendar. More specifically where the values based on the calendar are automatically changed when the calendar changes. Do I need bindings for this or something like that?
The docs state:
Note that if you cache values based on
the calendar or related information
those caches will of course not be
automatically updated by the updating
of the calendar object.
Thanks in advance
currentCalendar returns cached version of current system calendar, while autoupdatingCurrentCalendar always returns most recent version of system calendar.
That is important, when you are presenting data based on the various parameters of a calendar like number of days in a month, number of a weeks in year or number of hours in a day.
To be honest, I don't know why Apple gives you an opportunity to get outdated value by using currentCalendar.
It looks like they have internal API that allows you to manipulate caches of NSCalendar, so you can achieve better performance. But since it is not public, there is no reason to use currentCalendar.
That is, always use autoupdatingCurrentCalendar.
Well, on OS X you can be running multiple processes simultaneous. One could be your process that uses the autoupdatingCurrentCalendar. The other could be System Preferences.
System Preferences allows you to customize your calendar settings. You can choose the first day of the week to be something other than the default (Sunday). Or you can choose a whole different calendar altogether. If you use the autoupdatingCurrentCalendar, these changes will be picked up automatically. If you don't use it, they won't.
I guess that it is only usefull if you store the calendar in memory for further use. Doing that way, if the calendar settings change, your stored calendar will take account of those changes if you used autoupdatingCurrentCalendar. If you only used currentCalendar, it wil stay at the state it was at your first call.