LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Writing own functions

    Employee
    Posted 10-02-2013 08:48

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: petrisila

    Hi,

    I need an own function like dateSubtract which accounts for Sundays and German public holidays.
    Is there any way to do that?

    Greetings,
    Ioannis


  • 2.  RE: Writing own functions

    Employee
    Posted 11-02-2013 08:56

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hey,

    Sorry for the delay in replying, but it turned out that this isn't as simple as first imagined...

    There isn't any function like that available in BRAINscript, and writing something of your own just using BRAINscript would be pretty difficult given problems of calculating Easter and other movable holidays.
    Even then, without lookup tables, it would need to be specific for a given country.

    However, with that in mind, I've put together something which should do what you want.
    It's not a function as such, but a node where you can either enter the start and end date as parameters, or specify the fields from an input record containing the start and end dates.
    Similarly, you can specify a parameter for the country who's holidays you want, or specify an input field in the input records which contains the country code.
    In addition, you can also specify a particular region (on the Optional tab) - from a field, or as a parameter value.

    Then you specify what you want the node to calculate (all in days) either:
    • Weekdays in Date Range
    • Weekends in Date Range
    • Workdays in Date Range
    • Holidays In Date Range
    • Non-Holidays in Date Range
    • Sundays and Public Holidays in Date Range
    • Non-Sundays and Public Holidays in Date Range
    Some quick web searching lead to the web service provided by kayaposoft (http://kayaposoft.com/enrico/) for retrieving public holiday information.
    Since this is hitting a web service, for the holiday information, this node won't have particularly good performance - assuming you have specified an operation where holidays are required.
    It will perform a separate query for each combination of country, year and region (if specified).

    Then, it will determine the number of days for the specified operation in the specified ranges.

    There are probably other things that could be fixed up performance-wise, but it should do the trick at least for not huge amounts of data - or over not huge date ranges.

    An example showing its usage is attached, which is parameterized to calculate the number of holidays there will be in in NRW, Germany for this year, next year, and during the world cup in Brazil next year.

    This makes use of the HTTP node from the Lavastorm Analytic Library (LAL) to perform the web service requests for holiday information.

    I couldn't see anything on the kayaposoft web site about terms of usage of their web service (except saying it's free) , so I assume that it's ok to use it in for such automated requests....

    Regards,
    Tim.
    Attachments:
    DateRangeCalculatorStuff.brg


  • 3.  RE: Writing own functions

    Employee
    Posted 05-15-2017 11:44

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ejones

    Thanks Tim,
    Nice example. I'm happy to see this still works.

    Building on what you did this makes it into Library nodes. And it adds a second library node where you can supply the list of holidays for cases where you cannot reach the web site.

    Edits:
    - There was a problem creating LXAs and BRXs when the library node used the {{? ?}} notation. These have been removed
    - There was a problem with extracting the year from the service. This parsing is now done with the JSON Data node.
    Attachments:
    DateRangeCalculatorStuff2.brg