Design pattern: Generating daily and weekly tasks based on specifications - algorithm

I am working on a project that has some inputs like task type and frequency.
For example
if task type = Daily and frequency =2 then create 5 task every alternate day.
if task type = Daily and frequency =3 then create 5 task on today and 3rd and sixth days.
If task type = Weekly and frequency =2 then create 2 tasks every alternate week.
More over I have a calendar table so I need to check working day, if that is a weekend, that task should be generated on next working day. I have calendar_Holidays table as well so check and skin that date as well.
Can I use design pattern for this problem? can somebody show me how?

You might be interested in a paper about recurring events in calendars by Martin Fowler. It describes few very interesting techniques and patterns to use while dealing with scheduling events.

You are trying to apply design patterns too early in your implementation. Design patterns help when you have identified important classes and want to adjust their relationships, for example to reduce coupling and enable extension.
Here you have not yet identified any classes, and I would say that you haven't even got your requirements completely clear. On which days will weekly tasks be generated? What will you do for alternate days when you have a long weekend - in UK we could have Friday as public holiday, Sat, Sun as weekend, and Monday as public holiday - what's your rule now. Can you have monthly events? what other intervals? Again in UK we pay council tax monthly, but not in February and March, do you have cases like that?
So I'd recommend firs getting very clear the corner cases of your requirements. Then produce a natural OO design, and then look to see what patterns may help.

Related

Is the day of the week for a date the same everywhere in the world?

Part of my program requires checking the day of the week that a file was created. I have an input attribute which gives the date of creation in US form (month/day/year). However I do not have the day of the week.
As per the sadism of the legal department I am also restricted to only the time modules within python's standard library so unfortunately the obvious solution of PYTZ is not an option.
My current approach is to use the date to reference the Gregorian calendar. On the assumption that a the same date is always the same day i.e. 1st September 2022 is a Thursday everywhere in the world. However, I have not been able to validate this assumption.
If you know if this assumption is correct/incorrect and/or know of somewhere I can find out I would be very grateful.
Thanks.

PBCS: Custom rules to aggregate Period members

I have an input account (never share) in which the user types a parameter for each month, I want that into aggregate members of Period dimension, for example on YearTotal, the value will be the weighted average between two other accounts representing the cost and the quantity.
With the account properties I can rollup my account in addition or as simple average between months, obviously in this way I get wrong data in both cases.
Anyone know a solution to my question?
Thanks a lot,
Daniele
Not sure exactly what you are asking. But I assume the following in my answer:
data entry for user on account Parameter (from the context, I think it is a price)
data entry for user on level0 Period, i.e. the months
you want Essbase to show the Parameter value as typed in at the month level (Jan .. Dec)
you want Essbase to show Costs / Quantity for Q1/2/3/4 and the YearTotal
the Account and Period dimension are of density: dense
You did not specify if you are also reporting on YTD values and how you have implemented this in Essbase. I assume you do, but the preferred solution depends on how you have implemented this, so I take the "safe" solution here:
solution 1
This is the most straightforward solution:
Implement a "parameter_inp" account on which the user keys in the data. Set the account to "never consolidate".
Create a new "parameter" account, dynamic calc, and give it the formula "Costs/Quantity;".
Refer to "parameter" in your reports, and to "parameter_inp" for user entry
solution 2 - alternative
If you have a lot of these parameters, you'll end up with a system making it unpleasant for data entry and reporting for the end-users. To solve it using data entry and reporting on the same "parameter" account, you need to tune your implementation for Quarter and YearTotal calculation, including the YTD calculation. I see no way of getting this correct if you are using DTS.
This is the way to go forward:
Make use of a new dimension called "View", data entry on PER (= periodic), additional dynamic calc member "YTD", density: dense, place it after Period (so Account, Period, View)
Add a UDA to the "parameter", for example "WA"
Set custom dynamic calculations on Quarter and YearTotal level, something like: IF (#ISUDA("WA")) THEN ELSIF <check on FLOW/BALANCE> ... logic for regular aggregation of FLOW and BALANCE items hereby overriding Essbase's native time logic)
Set custom dynamic calculations for YTD (overiding DTS), and make an exception for UDA "WA"

Power BI - Calculate Difference between previous day volume and the next day volume

I have got a table that only contains two column Legend (for Dates) and EOD Volume (for volume) as shown below.
I need to calculate the difference between the previous date volume. For example to calculate the difference between Feb 29 to March 2nd, it will be ((1469-1877) / 1469) * 100%. How to do create this measure in power BI. And the data also contains weekends and weekdays and i will need the analysis for all dates regardless of weekends and/or weekdays. Could someone please help me on this. Thank you in advance.
My propose solution works in a table at day granularity. Additionally, to handle working day the best-practice is to manage it as a binary attribute in the back-end because working days differ country by country so there is no standard dynamic way to handle them.
Possible Solution:=
VAR _YESTERDAY = CALCULATE(MAX('Fact'[EOD Volume]), PREVIOUSDAY('Calendar'[CalendarKey]))
VAR _TODAY = CALCULATE(MAX('Fact'[EOD Volume]))
RETURN
DIVIDE(_TODAY - _YESTERDAY, ABS(_YESTERDAY))

Can I generate the number of business days in a month in Visual Studio?

I have a report that takes sales data from a few tables. I want to add a field that will divide the total sales for the given month by the total number of business days in that same month. Is there a way I can calculate that in an expression? Do I need to create a new table in the database specifically for months and their number of business days? How should I go about this?
Thank you
Intuitively, I would say that you need a simple function and a table.
The table is to host the exceptions like Independence day, labor day, etc.
The function will get two parameters: Month and Year (I'm not providing any sample code since you haven't specified which language you are using).
It will then build a date as yyyy-mm-01 (meaning, first day of the month). If will then loop from 2 to 31 and:
Create a new date by adding the index of the loop to the initial date,
Check if the resulting date is still within the month,
Check if it is a working or not working day (e.g. Sunday),
Check if it is found within the table of exceptions.
If the created date passes all the above tests, you add 1 to the counter.
Though it might look complex, it is not and it will provide you the correct answer regardless of the month (e.g. Feb.) and the year (leap or not).

How to data-model dynamic open/close times for booking a room

this is my first post. I have been searching for the best way to do this but have not had much success so I decided to post here.
I have a database model that is going to be used to book rooms in a complex. These rooms need to have open and close times to determine when they can be booked. For example, one room may be open from 8am to 10pm but another might be open from 10am to 5pm etc.
One of the requirements, and the part I'm stuck on, is that the open/close times for rooms needs to changed based on a time period similar to a "season" but this time period is manually set by an admin unlike a season.
So, from Jan-11 to March-28, a specific room may to open from 10am to 5pm but from March-29 to July-17 it may be open from 8am to 7pm.
I'm guessing that I need another table or two to store the "time periods" as well as the open/close time of the room during those periods.
Can anyone point me in the right direction or show me an example?
Thanks.
It highly depends on logic of your application, but in the simplest case you can save it inside additional table of the following structure:
room_id INT
period_from DATE
period_to DATE
open_from INT
open_to INT
You can select open time for a room on particular day using:
SELECT open_from, open_to
FROM intervals
WHERE room_id = 4 AND period_from > '2015-08-19' AND period_to < '2015-08-19'
NOTE When you add new period, you should validate, that time periods don't intersect for a given room.

Resources