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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
Quintiq file version 2.0
#parent: #root
StaticMethod CreateExcelFromSnapshot (KpiSnapshotSetData snapshotSetData, KpiTracker kpitracker) as BinaryValue
{
  Description: 'Creates a Excel string out of the specified KpiSnapshotDatas'
  TextBody:
  [*
    // Render header line.
    lines := construct( Strings );
    
    conversion := ConversionOptions::System();
    
    lines.Add( '<?xml version="1.0" encoding="UTF-16"?>' );
    lines.Add( '<table>' );
    lines.Add( '<name>KpiValue</name>' );
    
    lines.Add( '<column>' );
    lines.Add( '<name>PlanDateTime</name>' );
    lines.Add( '<type>String</type>' );
    traverse( snapshotSetData, SnapshotData, snapshot ) 
    {
      lines.Add( '<cell value="' + snapshot.PlanDateTime().Format( 'Y-M2-D2TH2:m:sZ', conversion ) + '" />' );
    }
    lines.Add( '</column>' );
    
    lines.Add( '<column>' );
    lines.Add( '<name>ServerDateTime</name>' );
    lines.Add( '<type>String</type>' );
    traverse( snapshotSetData, SnapshotData, snapshot ) 
    {
      lines.Add( '<cell value="' + snapshot.ServerDateTime().Format( 'Y-M2-D2TH2:m:sZ', conversion ) + '" />' );
    }
    lines.Add( '</column>' );
    
    lines.Add( '<column>' );
    lines.Add( '<name>RetentionPolicyID</name>' );
    lines.Add( '<type>String</type>' );
    traverse( snapshotSetData, SnapshotData, snapshot ) 
    {
      lines.Add( '<cell value="' + snapshot.RetentionPolicyIdentification() + '" />' );
    }
    lines.Add( '</column>' );
    
    // -- Label 
    sortedLabels := selectsortedset( kpitracker, Label, label, true, label.Name() );
    traverse( sortedLabels, Elements, label )
    {
      lines.Add( '<column>' );
      lines.Add( '<name>' + "label_" + label.Name() + '</name>' );
      lines.Add( '<type>String</type>' );
      traverse( snapshotSetData, SnapshotData, snapshot ) 
      {
        labelValue := select( snapshot, Label, labelV, label.Name() = labelV.Name() );
        lines.Add( '<cell value="' + guard( labelValue.Value(), "" ) + '" />' );
      }
      lines.Add( '</column>' );
    }
    
    
    // -- Value 
    sortedKpis   := selectsortedset( kpitracker, MetaData, kpi, true, kpi.Name() );
    traverse( sortedKpis, Elements, kpi )
    {
      lines.Add( '<column>' );
      lines.Add( '<name>' + "kpi_" + kpi.Name() + '</name>' );
      lines.Add( '<type>String</type>' );
      traverse( snapshotSetData, SnapshotData, snapshot )
      {
        kpiValue := select( snapshot, Value, value, kpi.Name() = value.Name() );
        lines.Add( '<cell value="' + guard( [String]kpiValue.Value(), "" ) + '" />' );
      }
      lines.Add( '</column>' );
    }
    
    // Send result.
    lines.Add( '</table>' );
    binary := BinaryValue::Construct( lines.Concatenate( String::NewLine() ) );
    return binary;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}