/* concert_demand.pl */


concert_demand_daily( Level, ConcertStartDate, ConcertEndDate, TlStartDate, TlEndDate, Xs, Ys ) :-
  concert_demand_key_points( Level, ConcertStartDate, ConcertEndDate, KeyPoints),
  
  maplist( {TlStartDate} / [kp(Date,DI,_Reason), Offset-DI] >> date_interval(Date, TlStartDate, days(Offset))
         , KeyPoints
         , OffsetsAndDIs
         ),
  
  TlStartOffset = 0,
  date_interval(TlEndDate, TlStartDate, days(TlEndOffset)), 
  time_series_segments_to_points(TlStartOffset, TlEndOffset, OffsetsAndDIs, Xs, Ys).


concert_demand_key_points( Level, ConcertStartDate, ConcertEndDate, KeyPoints ) :-
  findall( kp( Date, DI, Reason )
         , concert_demand_key_point( Level, ConcertStartDate, ConcertEndDate, Date, DI, Reason )
         , KeyPoints
		 ).


concert_demand_key_point( l1, ConcertStartDate, ConcertEndDate, Date, DI, Reason ) :-
  world_famous_concert_demand( DR, DI, Reason ),
  eval_daterel_concert( DR, ConcertStartDate, ConcertEndDate, Date ).
 
concert_demand_key_point( l2, ConcertStartDate, ConcertEndDate, Date, DI, Reason ) :-
  regionally_known_concert_demand( DR, DI, Reason ),
  eval_daterel_concert( DR, ConcertStartDate, ConcertEndDate, Date ).

concert_demand_key_point( l3, ConcertStartDate, ConcertEndDate, Date, DI, Reason ) :-
  fun_night_concert_demand( DR, DI, Reason ),
  eval_daterel_concert( DR, ConcertStartDate, ConcertEndDate, Date ).
  
  
world_famous_concert_demand( 'start'-9, 0, "Just before early arrivals for the concert." ).
world_famous_concert_demand( 'start'-7, 10, "Early arrivals for the concert." ).
world_famous_concert_demand( 'start'-3, 20, "Increased arrivals, including international fans." ).
world_famous_concert_demand( 'start', 50, "Peak demand on concert day." ).
world_famous_concert_demand( 'end', 5, "A bit of demand as visitors fly in to meet stars, staff or friends who were there." ).
world_famous_concert_demand( 'end'+3, 0, "End of concert-related demand." ).
.
regionally_known_concert_demand( 'start'-7, 0, "Just before early arrivals, mostly local and regional fans" ).
regionally_known_concert_demand( 'start'-5, 5, "Early arrivals, mostly local and regional fans" ).
regionally_known_concert_demand( 'start'-2, 10, "Increase in arrivals as the concert approaches" ).
regionally_known_concert_demand( 'start', 30, "Peak demand on concert day" ).
regionally_known_concert_demand( 'end', 1, "A bit of demand as visitors fly in to meet stars, staff or friends who were there." ).
regionally_known_concert_demand( 'end'+2, 0, "End of concert-related demand" ).

fun_night_concert_demand( 'start'-1, 0, "Slight increase in demand due to local attendees." ).
fun_night_concert_demand( 'start', 2, "Slight increase in demand due to local attendees." ).
fun_night_concert_demand( 'end', 1, "Minimal post-event demand, primarily local." ).
fun_night_concert_demand( 'end'+1, 0, "Minimal post-event demand, primarily local." ).


eval_daterel_concert( 'start', ConcertStartDate, _ConcertEndDate, ConcertStartDate ).
eval_daterel_concert( 'end', _ConcertStartDate, ConcertEndDate, ConcertEndDate ). 
eval_daterel_concert( DR+Offset, ConcertStartDate, ConcertEndDate, Date ) :-
  eval_daterel_concert( DR, ConcertStartDate, ConcertEndDate, DRDate ),
  date_add( DRDate, days(Offset), Date ).
eval_daterel_concert( DR-Offset, ConcertStartDate, ConcertEndDate, Date ) :-
  eval_daterel_concert( DR, ConcertStartDate, ConcertEndDate, DRDate ),
  date_add( DRDate, days(-Offset), Date ).