Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Function CalcAvailableCapacityRatio 
 | 
{ 
 | 
  Description: 'calculates a value between 0 and 1 corresponding to how much the campaign and period overlap' 
 | 
  TextBody: 
 | 
  [* 
 | 
    // lauri Apr-14-2014 (created) 
 | 
     
 | 
    value := 0.0; 
 | 
    period := this.UnitPeriod().Period_MP(); 
 | 
    duration := period.Duration().HoursAsReal(); 
 | 
     
 | 
    if( duration > 0 ) 
 | 
    { 
 | 
      start := maxvalue( period.Start(), this.Campaign_MP_DELETED_Q320().Start() ); 
 | 
      end := minvalue( period.End(), this.Campaign_MP_DELETED_Q320().End() ); 
 | 
     
 | 
      value := ( end - start ).HoursAsReal() / duration; 
 | 
      value := maxvalue( value, 0.0 ); 
 | 
    } 
 | 
     
 | 
    this.AvailableCapacityRatio( value ); 
 | 
  *] 
 | 
} 
 |