fix seeds; update models

This commit is contained in:
Deeman
2025-07-27 22:49:37 +02:00
parent c0d8f60d1c
commit 641f794d61
8 changed files with 363 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
MODEL (
name raw.psd_attribute_codes,
kind SEED (
path '$root/seeds/psd_attribute_codes.csv',
csv_settings (
delimiter = ';'
)
)
);

View File

@@ -0,0 +1,10 @@
MODEL (
name raw.psd_commodity_codes,
kind SEED (
path '$root/seeds/psd_commodity_codes.csv',
csv_settings (
delimiter = ';'
)
)
);

View File

@@ -0,0 +1,26 @@
MODEL (
name raw.psd_alldata,
kind FULL,
start '2006-08-01',
cron '@daily'
);
SELECT
*
--format('{}-{}-01',split(filename, '/')[-4],split(filename, '/')[-3])::date as ingest_date
FROM read_csv('zip:///home/deeman/projects/materia/extract/psdonline/src/psdonline/data/**/*.zip/*.csv', header=true, union_by_name=true, filename=true, names = ['commodity_code', 'commodity_description', 'country_code', 'country_name', 'market_year', 'calendar_year', 'month', 'attribute_id', 'attribute_description', 'unit_id', 'unit_description', 'value'], types=
{
'commodity_code' : 'VARCHAR',
'commodity_description' :'VARCHAR',
'country_code' : 'VARCHAR',
'country_name' : 'VARCHAR',
'market_year' : 'BIGINT' ,
'calendar_year' : 'BIGINT' ,
'month' : 'VARCHAR',
'attribute_id' : 'VARCHAR',
'attribute_description' :'VARCHAR',
'unit_id' : 'VARCHAR',
'unit_description' : 'VARCHAR',
'value' : 'DOUBLE'
}
)

View File

@@ -0,0 +1,10 @@
MODEL (
name raw.psd_unit_of_measure_codes,
kind SEED (
path '$root/seeds/psd_unit_of_measure_codes.csv',
csv_settings (
delimiter = ';'
)
)
);

View File

@@ -0,0 +1,67 @@
MODEL (
name staging.psd_alldata,
kind INCREMENTAL_BY_TIME_RANGE (
time_column ingest_date
),
start '2006-08-01',
cron '@daily'
);
SELECT
@GENERATE_SURROGATE_KEY(commodity_code, country_code, market_year, month, attribute_id) as hkey,
commodity_code,
coalesce(commodity_name, commodity_description) as commodity_name,
country_code,
country_name,
market_year,
calendar_year,
month,
attribute_id,
coalesce(attribute_name, attribute_description) as attribute_name,
unit_id,
coalesce(unit_name, unit_description) as unit_name,
value,
filename,
format('{}-{}-01',split(filename, '/')[-4],split(filename, '/')[-3])::date as ingest_date
FROM raw.psd_alldata
left join raw.psd_commodity_codes using (commodity_code)
left join raw.psd_unit_of_measure_codes using (unit_id)
left join raw.psd_attribute_codes using (attribute_id)
/*
MIssing commodities
│ 0579311 │ NULL │
│ 0411000 │ NULL │
│ 0545900 │ NULL │
│ 0577903 │ NULL │
│ 0572920 │ NULL │
│ 0114300 │ NULL │
│ 1211000 │ NULL │
│ 0585200 │ NULL │
│ 0565905 │ NULL │
│ 0589901 │ NULL │
│ 0579401 │ NULL │
│ 0585120 │ NULL │
│ 0585700 │ NULL │
│ 0566100 │ NULL │
│ 1222000 │ NULL │
│ 0589903 │ NULL │
│ 0585300 │ NULL │
│ 0579301 │ NULL │
│ 0586111 │ NULL │
│ 0579701 │ NULL │
│ 0575200 │ NULL │
│ 0579901 │ NULL │
│ 0579500 │ NULL │
│ 0565901 │ NULL │
│ 0577500 │ NULL │
│ 0565903 │ NULL │
│ 0577905 │ NULL │
--------------------
Missing Attributes
│ 221 │ NULL │
│ 219 │ NULL │
*/

View File

@@ -0,0 +1,133 @@
attribute_id;attribute_name
1;Area Planted
4;Area Harvested
5;Catch For Reduction
6;Cows In Milk
7;Crush
10;Total Grape Crush
13;Deliv. To Processors
16;Total Trees
17;Bearing Trees
19;Non-Bearing Trees
20;Beginning Stocks
22;Sow Beginning Stocks
23;Dairy Cows Beg. Stocks
24;Begin Stock (Ctrl App)
25;Beef Cows Beg. Stocks
26;Begin Stock (Other)
28;Production
29;Arabica Production
30;Beet Sugar Production
31;Commercial Production
32;Cows Milk Production
33;Farm Sales Weight Prod
34;Filter Production
40;Prod. from Wine Grapes
43;Cane Sugar Production
47;Non-Comm. Production
48;Non-Filter Production
49;Other Milk Production
51;Prod. from Tabl Grapes
53;Robusta Production
54;Rough Production
56;Other Production
57;Imports
58;Bean Imports
62;Intra-EU Imports
63;MY Imp. from U.S.
64;Raw Imports
65;U.S. Leaf Imports
70;MY Imp. from EU
71;Other Imports
74;Refined Imp.(Raw Val)
75;Roast & Ground Imports
78;CY Imports
81;TY Imports
82;Soluble Imports
83;CY Imp. from U.S.
84;TY Imp. from U.S.
86;Total Supply
87;CY Exp. to U.S.
88;Exports
89;Raw Exports
90;Bean Exports
94;Intra EU Exports
95;Intra-EU Exports
97;MY Exp. to EU
99;Refined Exp.(Raw Val)
104;Other Exports
107;Roast & Ground Exports
110;CY Exports
113;TY Exports
114;Soluble Exports
116;Slaughter (Reference)
117;Total Slaughter
118;Cow Slaughter
120;Inventory (Reference)
121;Sow Slaughter
122;Calf Slaughter
124;Other Slaughter
125;Domestic Consumption
126;Total Disappearance
128;Dom. Leaf Consumption
129;Dom.Consump(Cntrl App)
130;Feed Dom. Consumption
131;Fluid Use Dom. Consum.
132;For Processing
133;Fresh Dom. Consumption
135;Fresh Dom. Consumption
138;Human Consumption
139;Human Dom. Consumption
140;Industrial Dom. Cons.
141;Rst,Ground Dom. Consum
142;Domestic Use
143;Utilization for Sugar
145;Dom.Consump(Other)
147;Factory Use Consum.
149;Food Use Dom. Cons.
150;Loss
151;Other Disappearance
152;Other Use, Losses
154;Soluble Dom. Cons.
155;U.S. Leaf Dom. Cons.
157;Utilizatn for Alcohol
158;Feed Use Dom. Consum.
161;Feed Waste Dom. Cons.
167;Other Foreign Cons.
169;Withdrawal From Market
172;Loss and Residual
173;Total Disappearance
174;Total Use
175;Total Utilization
176;Ending Stocks
177;End Stocks (Cntrl App)
178;Total Distribution
179;End Stocks (Other)
181;Extr. Rate, 999.9999
182;Milling Rate (.9999)
183;Seed to Lint Ratio
184;YieldYield (Rough)
192;FSI Consumption
194;SME
195;Stocks-to-UseStock to Use %
196;Exportable Production
198;Balance
199;Inventory Balance
200;Inventory Change
201;Import Change
202;Export Change
203;Consumption Change
204;Production Change
205;Sow Change
206;Cow Change
207;Production to Cows
208;Production to Sows
209;Slaughter to Inventory
210;Weights
211;Population
212;Per Capita Consumption
213;Slaughter to Total Supply
214;Imports Percent Consumption
215;Exports Percent Production
220;Annual % Change Per Cap. Cons.
223;Stocks to Use (Months)
1 attribute_id attribute_name
2 1 Area Planted
3 4 Area Harvested
4 5 Catch For Reduction
5 6 Cows In Milk
6 7 Crush
7 10 Total Grape Crush
8 13 Deliv. To Processors
9 16 Total Trees
10 17 Bearing Trees
11 19 Non-Bearing Trees
12 20 Beginning Stocks
13 22 Sow Beginning Stocks
14 23 Dairy Cows Beg. Stocks
15 24 Begin Stock (Ctrl App)
16 25 Beef Cows Beg. Stocks
17 26 Begin Stock (Other)
18 28 Production
19 29 Arabica Production
20 30 Beet Sugar Production
21 31 Commercial Production
22 32 Cows Milk Production
23 33 Farm Sales Weight Prod
24 34 Filter Production
25 40 Prod. from Wine Grapes
26 43 Cane Sugar Production
27 47 Non-Comm. Production
28 48 Non-Filter Production
29 49 Other Milk Production
30 51 Prod. from Tabl Grapes
31 53 Robusta Production
32 54 Rough Production
33 56 Other Production
34 57 Imports
35 58 Bean Imports
36 62 Intra-EU Imports
37 63 MY Imp. from U.S.
38 64 Raw Imports
39 65 U.S. Leaf Imports
40 70 MY Imp. from EU
41 71 Other Imports
42 74 Refined Imp.(Raw Val)
43 75 Roast & Ground Imports
44 78 CY Imports
45 81 TY Imports
46 82 Soluble Imports
47 83 CY Imp. from U.S.
48 84 TY Imp. from U.S.
49 86 Total Supply
50 87 CY Exp. to U.S.
51 88 Exports
52 89 Raw Exports
53 90 Bean Exports
54 94 Intra EU Exports
55 95 Intra-EU Exports
56 97 MY Exp. to EU
57 99 Refined Exp.(Raw Val)
58 104 Other Exports
59 107 Roast & Ground Exports
60 110 CY Exports
61 113 TY Exports
62 114 Soluble Exports
63 116 Slaughter (Reference)
64 117 Total Slaughter
65 118 Cow Slaughter
66 120 Inventory (Reference)
67 121 Sow Slaughter
68 122 Calf Slaughter
69 124 Other Slaughter
70 125 Domestic Consumption
71 126 Total Disappearance
72 128 Dom. Leaf Consumption
73 129 Dom.Consump(Cntrl App)
74 130 Feed Dom. Consumption
75 131 Fluid Use Dom. Consum.
76 132 For Processing
77 133 Fresh Dom. Consumption
78 135 Fresh Dom. Consumption
79 138 Human Consumption
80 139 Human Dom. Consumption
81 140 Industrial Dom. Cons.
82 141 Rst,Ground Dom. Consum
83 142 Domestic Use
84 143 Utilization for Sugar
85 145 Dom.Consump(Other)
86 147 Factory Use Consum.
87 149 Food Use Dom. Cons.
88 150 Loss
89 151 Other Disappearance
90 152 Other Use, Losses
91 154 Soluble Dom. Cons.
92 155 U.S. Leaf Dom. Cons.
93 157 Utilizatn for Alcohol
94 158 Feed Use Dom. Consum.
95 161 Feed Waste Dom. Cons.
96 167 Other Foreign Cons.
97 169 Withdrawal From Market
98 172 Loss and Residual
99 173 Total Disappearance
100 174 Total Use
101 175 Total Utilization
102 176 Ending Stocks
103 177 End Stocks (Cntrl App)
104 178 Total Distribution
105 179 End Stocks (Other)
106 181 Extr. Rate, 999.9999
107 182 Milling Rate (.9999)
108 183 Seed to Lint Ratio
109 184 YieldYield (Rough)
110 192 FSI Consumption
111 194 SME
112 195 Stocks-to-UseStock to Use %
113 196 Exportable Production
114 198 Balance
115 199 Inventory Balance
116 200 Inventory Change
117 201 Import Change
118 202 Export Change
119 203 Consumption Change
120 204 Production Change
121 205 Sow Change
122 206 Cow Change
123 207 Production to Cows
124 208 Production to Sows
125 209 Slaughter to Inventory
126 210 Weights
127 211 Population
128 212 Per Capita Consumption
129 213 Slaughter to Total Supply
130 214 Imports Percent Consumption
131 215 Exports Percent Production
132 220 Annual % Change Per Cap. Cons.
133 223 Stocks to Use (Months)

View File

@@ -0,0 +1,65 @@
commodity_code; commodity_name
0577400;Almonds, Shelled Basis
0011000;Animal Numbers, Cattle
0013000;Animal Numbers, Swine
0574000;Apples, Fresh
0430000;Barley
0579305;Cherries (Sweet&Sour), Fresh
0711100;Coffee, Green
0440000;Corn
2631000;Cotton
0000000;Cotton (Metric Tons)
0230000;Dairy, Butter
0240000;Dairy, Cheese
0224400;Dairy, Dry Whole Milk Powder
0223000;Dairy, Milk, Fluid
0224200;Dairy, Milk, Nonfat Dry
0572220;Grapefruit, Fresh
0575100;Grapes, Fresh Table
0572120;Lemons/Limes, Fresh
0813700;Meal, Copra
0813300;Meal, Cottonseed
0814200;Meal, Fish
0813800;Meal, Palm Kernel
0813200;Meal, Peanut
0813600;Meal, Rapeseed
0813100;Meal, Soybean
0813101;Meal, Soybean (Local)
0813500;Meal, Sunflowerseed
0111000;Meat, Beef and Veal
0115000;Meat, Chicken
0113000;Meat, Swine
0459100;Millet
0459900;Mixed Grain
0452000;Oats
4242000;Oil, Coconut
4233000;Oil, Cottonseed
4235000;Oil, Olive
4243000;Oil, Palm
4244000;Oil, Palm Kernel
4234000;Oil, Peanut
4239100;Oil, Rapeseed
4232000;Oil, Soybean
4232001;Oil, Soybean (Local)
4236000;Oil, Sunflowerseed
2231000;Oilseed, Copra
2223000;Oilseed, Cottonseed
2232000;Oilseed, Palm Kernel
2221000;Oilseed, Peanut
2226000;Oilseed, Rapeseed
2222000;Oilseed, Soybean
2222001;Oilseed, Soybean (Local)
2224000;Oilseed, Sunflowerseed
0585100;Orange Juice
0571120;Oranges, Fresh
0579309;Peaches & Nectarines, Fresh
0579220;Pears, Fresh
0577907;Pistachios, Inshell Basis
0114200;Poultry, Meat, Broiler
0422110;Rice, Milled
0451000;Rye
0459200;Sorghum
0612000;Sugar, Centrifugal
0571220;Tangerines/Mandarins, Fresh
0577901;Walnuts, Inshell Basis
0410000;Wheat
1 commodity_code commodity_name
2 0577400 Almonds, Shelled Basis
3 0011000 Animal Numbers, Cattle
4 0013000 Animal Numbers, Swine
5 0574000 Apples, Fresh
6 0430000 Barley
7 0579305 Cherries (Sweet&Sour), Fresh
8 0711100 Coffee, Green
9 0440000 Corn
10 2631000 Cotton
11 0000000 Cotton (Metric Tons)
12 0230000 Dairy, Butter
13 0240000 Dairy, Cheese
14 0224400 Dairy, Dry Whole Milk Powder
15 0223000 Dairy, Milk, Fluid
16 0224200 Dairy, Milk, Nonfat Dry
17 0572220 Grapefruit, Fresh
18 0575100 Grapes, Fresh Table
19 0572120 Lemons/Limes, Fresh
20 0813700 Meal, Copra
21 0813300 Meal, Cottonseed
22 0814200 Meal, Fish
23 0813800 Meal, Palm Kernel
24 0813200 Meal, Peanut
25 0813600 Meal, Rapeseed
26 0813100 Meal, Soybean
27 0813101 Meal, Soybean (Local)
28 0813500 Meal, Sunflowerseed
29 0111000 Meat, Beef and Veal
30 0115000 Meat, Chicken
31 0113000 Meat, Swine
32 0459100 Millet
33 0459900 Mixed Grain
34 0452000 Oats
35 4242000 Oil, Coconut
36 4233000 Oil, Cottonseed
37 4235000 Oil, Olive
38 4243000 Oil, Palm
39 4244000 Oil, Palm Kernel
40 4234000 Oil, Peanut
41 4239100 Oil, Rapeseed
42 4232000 Oil, Soybean
43 4232001 Oil, Soybean (Local)
44 4236000 Oil, Sunflowerseed
45 2231000 Oilseed, Copra
46 2223000 Oilseed, Cottonseed
47 2232000 Oilseed, Palm Kernel
48 2221000 Oilseed, Peanut
49 2226000 Oilseed, Rapeseed
50 2222000 Oilseed, Soybean
51 2222001 Oilseed, Soybean (Local)
52 2224000 Oilseed, Sunflowerseed
53 0585100 Orange Juice
54 0571120 Oranges, Fresh
55 0579309 Peaches & Nectarines, Fresh
56 0579220 Pears, Fresh
57 0577907 Pistachios, Inshell Basis
58 0114200 Poultry, Meat, Broiler
59 0422110 Rice, Milled
60 0451000 Rye
61 0459200 Sorghum
62 0612000 Sugar, Centrifugal
63 0571220 Tangerines/Mandarins, Fresh
64 0577901 Walnuts, Inshell Basis
65 0410000 Wheat

View File

@@ -0,0 +1,43 @@
unit_id; unit_name
1;(1000 BUSHES)
2;(1000 60 KG BAGS)
3;(1000 COLONIES)
4;(1000 HA)
5;(1000 HEAD)
6;(1000 HL)
7;(1000 MT CWE)
8;(1000 MT)
9;(1000 PCS)
10;(1000 TREES)
11;(Dec. Fraction)
12;(HA)
13;(HECTARES)
14;(KG)
15;(MIL HEAD)
16;(MIL PCS)
17;(MILLION TREES)
18;(MT RAW EQ)
19;(MT RAW EW)
20;(MT RE)
21;(MT)
22;(MT, Net Weight)
23;(PERCENT)
24;(RATIO)
25;(1000 CUBIC METERS)
26;(MT/HA)
27;1000 480 lb. Bales
28;(Bales/HA)
29;(KG/HA)
30;ACRES
31;BUSHELS
32;HUNDREDWEIGHT
33;MILLING RATE
34;BUSHELS/TON
35;IMPORT MILLING RATE
36;Bushels
37;SHORT TONS
38;MILLION LBS
39;BILLION LBS
40;(HEAD)
41;(PEOPLE)
42;(MONTHS)
1 unit_id unit_name
2 1 (1000 BUSHES)
3 2 (1000 60 KG BAGS)
4 3 (1000 COLONIES)
5 4 (1000 HA)
6 5 (1000 HEAD)
7 6 (1000 HL)
8 7 (1000 MT CWE)
9 8 (1000 MT)
10 9 (1000 PCS)
11 10 (1000 TREES)
12 11 (Dec. Fraction)
13 12 (HA)
14 13 (HECTARES)
15 14 (KG)
16 15 (MIL HEAD)
17 16 (MIL PCS)
18 17 (MILLION TREES)
19 18 (MT RAW EQ)
20 19 (MT RAW EW)
21 20 (MT RE)
22 21 (MT)
23 22 (MT, Net Weight)
24 23 (PERCENT)
25 24 (RATIO)
26 25 (1000 CUBIC METERS)
27 26 (MT/HA)
28 27 1000 480 lb. Bales
29 28 (Bales/HA)
30 29 (KG/HA)
31 30 ACRES
32 31 BUSHELS
33 32 HUNDREDWEIGHT
34 33 MILLING RATE
35 34 BUSHELS/TON
36 35 IMPORT MILLING RATE
37 36 Bushels
38 37 SHORT TONS
39 38 MILLION LBS
40 39 BILLION LBS
41 40 (HEAD)
42 41 (PEOPLE)
43 42 (MONTHS)