/* easter_demand.pl */


easter_demand_daily(BaseYear, TlStartDate, TlEndDate, Xs, Ys) :-
    easter_demand_key_points(BaseYear, KeyPoints),
    % A list of kp(Date,DI,Reason) keypoints.
    
    maplist({TlStartDate}/[kp(Date,DI,_Reason), Offset-DI]>>date_interval(Date, TlStartDate, days(Offset)),
            KeyPoints,
            OffsetsAndDIs),
    % Convert keypoints to offsets and demand increments.
    
    TlStartOffset = 0,
    date_interval(TlEndDate, TlStartDate, days(TlEndOffset)),
    time_series_segments_to_points(TlStartOffset, TlEndOffset, OffsetsAndDIs, Xs, Ys).
    % Generate a time series from segments to points.


easter_demand_key_points(BaseYear, KeyPoints) :-
    findall(kp(Date,DI,Reason),
            easter_demand_key_point(BaseYear, Date, DI, Reason),
            KeyPoints).


easter_demand_key_point(BaseYear, Date, DI, Reason) :-
    easter_demand(DR, DI, Reason),
    eval_daterel_easter(DR, BaseYear, Date).


easter_demand('Easter Sunday'-16, 0, "Just before start of school holidays. Slight increase in travel as families plan extended stays.").

easter_demand('Easter Sunday'-14, 5, "Start of school holidays. Slight increase in travel as families plan extended stays.").

easter_demand('Easter Sunday'-7, 10, "Increase in travel continues as more families start their holiday travels.").

easter_demand('Easter Sunday', 20, "Peak demand on Easter Sunday for both religious and non-religious travellers.").

easter_demand('Easter Sunday'+1, 15, "Slight decrease in demand after Easter Sunday as some travellers return home.").

easter_demand('Easter Monday', 10, "Last peak in demand due to public holiday before a gradual return to baseline.").

easter_demand('Easter Sunday'+7, 2, "Demand starts to normalize as school holidays come to an end and travellers return home.").

easter_demand('Easter Sunday'+8, 0, "End of school holidays.").


eval_daterel_easter('Easter Sunday', Year, Date) :-
    easter_sunday(Year, Date).

eval_daterel_easter('Easter Monday', Year, Date) :-
    easter_sunday(Year, EasterSunday),
    date_add(EasterSunday, days(1), Date).

eval_daterel_easter(DR+Offset, Year, Date) :-
    eval_daterel_easter(DR, Year, BaseDate),
    date_add(BaseDate, days(Offset), Date).

eval_daterel_easter(DR-Offset, Year, Date) :-
    eval_daterel_easter(DR, Year, BaseDate),
    date_add(BaseDate, days(-Offset), Date).


easter_sunday(2023, date(2023,4,9)).
easter_sunday(2024, date(2024,3,31)).
easter_sunday(2025, date(2025,4,20)).
easter_sunday(2026, date(2026,4,5)).