Lai,Risheng
2023-11-02 30c02e0c981b16be0918483543f4b812956c45d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Quintiq file version 2.0
#parent: #root
Method CalculateKpiRanks (
  shadow[KpiSnapshotSetData] data,
  structured[KpiMetaData] metadatas
) id:Method_GlobalStateKpiTracker_CalculateKpiRanks
{
  #keys: '[146874.0.1589191442]'
  Body:
  [*
    // Sets the IsBest/IsWorst attributes on the KpiValueData objects that are populating the Matrix and list.
    
    // Traverse through all the fetched KPIs and set the whole thing once.
    traverse( metadatas, Elements, kpi )
    {
      // only perform this routine if the kpi is max or min (not if it's a counter)
      if ( kpi.IsMaximize() or kpi.IsMinimize() )
      {
        values := selectset( data, SnapshotData.Value, val,
                             val.Name() = kpi.Name() );
    
    
        multiplier := ifexpr( kpi.IsMaximize(), 1, -1 )
        bestvalue  := max( values, Elements, val, true, val.Value() * multiplier ) * multiplier;
        worstvalue := min( values, Elements, val, true, val.Value() * multiplier ) * multiplier;
        traverse( values, Elements, val )
        {
          val.UI_IsBest( val.Value() = bestvalue );
          val.UI_IsWorst( val.Value() = worstvalue );
        }
      }
    }
  *]
}