/* skiing_season_demand.pl */
  

skiing_season_demand_daily( BaseYear, TlStartDate, TlEndDate, Xs, Ys ) :-
  skiing_season_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
         ),
  % A list of Date-DI keypoints.
  
  TlStartOffset = 0,
  date_interval( TlEndDate, TlStartDate, days(TlEndOffset) ), 
  time_series_segments_to_points( TlStartOffset, TlEndOffset, OffsetsAndDIs, Xs, Ys ).
  % A list of date offsets Xs, and a list of demand increments Ys.
  
  
skiing_season_demand_key_points( BaseYear, KeyPoints ) :-
  findall( kp(Date,DI,Reason)
         , skiing_season_demand_key_point( BaseYear, Date, DI, Reason )
         , KeyPoints
         ).


skiing_season_demand_key_point( BaseYear, Date, DI, Reason ) :-
  skiing_season_demand( DR, DI, Reason ),
  skiing_season_demand_eval_daterel( DR, BaseYear, Date ).


skiing_season_demand( 'start', 0, "Just before early season skiing, before holiday peaks." ).
skiing_season_demand( 'start', 10, "Early season skiing, before holiday peaks." ).
skiing_season_demand( 'start'+32, 30, "Sustained skiing interest post-holidays, including school vacation peaks." ).
skiing_season_demand( 'start'+75, 15, "Late season and spring skiing interest." ).
skiing_season_demand( 'start'+125, 15, "Late season and spring skiing interest." ).
skiing_season_demand( 'start'+145, 0, "Late season and spring skiing interest finishes." ).


skiing_season_demand_eval_daterel( 'start', Y, Date ) :-
  Date = date(Y,12,1).

skiing_season_demand_eval_daterel( DR+Offset, Y, Date ) :-
  skiing_season_demand_eval_daterel( DR, Y, BaseDate ),
  date_add( BaseDate, days(Offset), Date ).
  
skiing_season_demand_eval_daterel( DR-Offset, Y, Date ) :-
  skiing_season_demand_eval_daterel( DR, Y, BaseDate ),
  date_add( BaseDate, days(-Offset), Date ).