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
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
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
Forms
ratio_to_report(DS over (partition by Id)) 🟢 · number → number
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
ratio_to_reportat data set level, partitioned byId_1andId_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 inYY: from 3 / 20 = 0.15 to 14 / 40 = 0.35 forMe_1, and from 1 / 10 = 0.1 to -3 / 10 = -0.3 forMe_2, as Numbers.
script.vtl
DS_r := ratio_to_report ( DS_1 over ( partition by Id_1, Id_2 ) );
| Id_1 | Id_2 | Id_3 | Me_1 | Me_2 |
|---|---|---|---|---|
| A | XX | 2000 | 3 | 1 |
| A | XX | 2001 | 4 | 3 |
| A | XX | 2002 | 7 | 5 |
| A | XX | 2003 | 6 | 1 |
| A | YY | 2000 | 12 | 0 |
| A | YY | 2001 | 8 | 8 |
| A | YY | 2002 | 6 | 5 |
| A | YY | 2003 | 14 | -3 |
| Id_1 | Id_2 | Id_3 | Me_1 | Me_2 |
|---|---|---|---|---|
| A | XX | 2000 | 0.15 | 0.1 |
| A | XX | 2001 | 0.2 | 0.3 |
| A | XX | 2002 | 0.35 | 0.5 |
| A | XX | 2003 | 0.3 | 0.1 |
| A | YY | 2000 | 0.3 | 0 |
| A | YY | 2001 | 0.2 | 0.8 |
| A | YY | 2002 | 0.15 | 0.5 |
| A | YY | 2003 | 0.35 | -0.3 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗