yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
35
36
Quintiq file version 2.0
#parent: #root
Method CalculateKpiRanks (
  shadow[KpiSnapshotSetData] snapshotSetData,
  structured[KpiMetaData] metadatas
) id:Method_Kpi_GlobalState_CalculateKpiRanks
{
  #keys: '[146874.0.1590402520]'
  Body:
  [*
    // Sets the IsBest/IsWorst attributes on the KpiValueData objects that are populating the Matrix and list.
    
    data := snapshotSetData;
    
    // 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 );
        }
      }
    }
  *]
}