Ratio to report · ratio_to_report

🟢 2 of 2 forms all ok · VTL 2.2 Reference Manual ↗ · vtlengine 1.10.0rc3 (9e1c81a6) · pandas 2.3.3 · DuckDB 1.5.5
🟢 all ok🟡 partially implemented🛡️ refused with an error🔴 not implemented or crash🔵 engines differ ✅ match · ❌ wrong result · 🛡 guarded error (code) · 💥 crash · 📌 team decision
Dataset formsComponent formsScalar forms
        ---
config:
  flowchart:
    useMaxWidth: false

---
flowchart TB
    classDef ok fill:#d4edda,stroke:#28a745,color:#000
    classDef partial fill:#fff3cd,stroke:#ffc107,color:#000
    classDef refused fill:#d4edda,stroke:#28a745,stroke-width:3px,stroke-dasharray: 2 2,color:#000
    classDef missing fill:#f8d7da,stroke:#dc3545,color:#000
    classDef diverge fill:#cce5ff,stroke:#007bff,color:#000
    classDef block fill:#2b3a4a,stroke:#2b3a4a,color:#fff,font-weight:bold
    classDef ext fill:#fff,stroke:#666,color:#000,stroke-dasharray: 5 5
    O["Ratio to report · ratio_to_report<br/>🟢2"]:::ok
    subgraph G_ds["Dataset"]
        direction LR
        v_ds["ratio_to_report(DS over (partition by Id))"]:::ok
    end
    subgraph G_comp["Component"]
        direction LR
        v_comp["DS#91;calc Me #58;#61; ratio_to_report(Me over (partition by Id))#93;"]:::ok
    end
    subgraph G_use["Used with"]
        direction LR
        used__clause__calc["calc ↗<br/><small>used in over()</small>"]:::ext
    end
    O --- G_ds
    O --- G_comp
    O -.- G_use
    style G_ds fill:#f8f9fa,stroke:#495057,stroke-width:2px
    style G_comp fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 8 5
    style G_use fill:#ffffff,stroke:#868e96,stroke-width:1px,stroke-dasharray: 1 4
    click v_ds href "#form-ds"
    click v_comp href "#form-comp"
    click used__clause__calc href "../clause/calc.html" "Calculation of a Component · calc"
    

Types

Takes number · Gives number

Viral attributes: combined with the propagation rules → Viral propagation

Comes from · number — 44 operators in 6 blocks 🟢44
General purpose operators (2) 🟢2
String operators (3) 🟢3
Numeric operators (18) 🟢18
Time operators (9) 🟢9
Aggregate and Analytic operators (9) 🟢9
Data validation operators (3) 🟢3
Comes from · operators that return any type (their input's) — 37 operators in 8 blocks 🟢37
General purpose operators (5) 🟢5
Join operators (4) 🟢4
Time operators (3) 🟢3
Set operators (4) 🟢4
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (8) 🟢8
Conditional operators (3) 🟢3
Clause operators (9) 🟢9
Goes to · number — 33 operators in 7 blocks 🟢33
General purpose operators (1) 🟢1
Numeric operators (18) 🟢18
Time operators (2) 🟢2
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (7) 🟢7
Data validation operators (2) 🟢2
Definitions (VTL-DL) (2) 🟢2
Goes to · operators that take any scalar — 48 operators in 8 blocks 🟢48
General purpose operators (6) 🟢6
Join operators (4) 🟢4
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (10) 🟢10
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Clause operators (9) 🟢9

Forms

ratio_to_report(DS over (partition by Id)) 🟢 · number → number

Manual example 1 🟢 pandas ✅ · DuckDB ✅
Tests:

ratio_to_report at data set level, partitioned by Id_1 and Id_2.

Manual:

Ratio to report, Example 1, output verbatim: “The operator returns the ratio between the value of the current Data Point and the sum of the values of the partition which the current Data Point belongs to.”

Expected:

the sums are 20 and 10 in XX, 40 and 10 in YY: from 3 / 20 = 0.15 to 14 / 40 = 0.35 for Me_1, and from 1 / 10 = 0.1 to -3 / 10 = -0.3 for Me_2, as Numbers.

script.vtl
DS_r := ratio_to_report ( DS_1 over ( partition by Id_1, Id_2 ) );
Input DS_1
Id_1Id_2Id_3Me_1Me_2
AXX200031
AXX200143
AXX200275
AXX200361
AYY2000120
AYY200188
AYY200265
AYY200314-3
Expected DS_r
Id_1Id_2Id_3Me_1Me_2
AXX20000.150.1
AXX20010.20.3
AXX20020.350.5
AXX20030.30.1
AYY20000.30
AYY20010.20.8
AYY20020.150.5
AYY20030.35-0.3

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

DS[calc Me := ratio_to_report(Me over (partition by Id))] 🟢 · number → number

Share of partition sum 🟢 pandas ✅ · DuckDB ✅
Tests:

ratio_to_report in calc, partitioned by Id_1.

Manual:

Ratio to report: “The operator returns the ratio between the value of the current Data Point and the sum of the values of the partition which the current Data Point belongs to.”

Expected:

the sums of Me_1 are 10 in A and 12 in B: Me_3 is 0.3, 0.1, 0.5, 0.1 in A, and 4 / 12 = 0.333333 and 8 / 12 = 0.666667 in B.

script.vtl
DS_r := DS_1 [ calc Me_3 := ratio_to_report ( Me_1 over ( partition by Id_1 ) ) ];
Input DS_1
Id_1Id_2Me_1Me_2
A2020Q131.500000
A2020Q213.500000
A2021Q152.500000
A2021Q210.500000
B2020Q146.500000
B2020Q284.500000
Expected DS_r
Id_1Id_2Me_1Me_2Me_3
A2020Q131.5000000.300000
A2020Q213.5000000.100000
A2021Q152.5000000.500000
A2021Q210.5000000.100000
B2020Q146.5000000.333333
B2020Q284.5000000.666667

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗