Skip to content

Commit 0a11255

Browse files
author
Chow
committed
psql scripts
1 parent d6da6ae commit 0a11255

20 files changed

+756
-3
lines changed

scripts/Create_table_canada_exposure.psql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ CREATE TABLE canada_exposure(
3939

4040
-- import exposure from csv
4141
COPY canada_exposure (id, lon, lat, taxonomy, number, structural, nonstructural, contents, day, night, transit, landusetyp, GenOcc, hzOccType, eqOccType, BldgGen, hzTaxon, EqBldgType, EqDesLev, sauid, dauid, adauid, fsauid, csdname, cdname, SAC, prname, ername)
42-
FROM 'C:\Workspace\eRisk_CA\Canada.csv'
42+
FROM 'C:\Workspace\eRisk_CA\PSRA_sample_data\Canada.csv'
4343
WITH
4444
DELIMITER AS ','
4545
CSV HEADER ;

scripts/Create_table_SRisk_JdFM7p1_1.psql renamed to scripts/DSRA/Create_table_SRisk_JdFM7p1_1.psql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- script to generate the tables SRisk_JdFM7p1_1
2-
DROP TABLE IF EXISTS sRisk_JdFM7p1_1
2+
DROP TABLE IF EXISTS sRisk_JdFM7p1_1;
33

44
CREATE TABLE sRisk_JdFM7p1_1(
55
PRIMARY KEY (asset_ref),
@@ -137,5 +137,6 @@ CREATE TABLE sRisk_JdFM7p1_1(
137137
sc2_BusInt30 float,
138138
sc2_BusInt90 float,
139139
sc2_BusInt180 float,
140-
sc2_BusInt360 float,
140+
sc2_BusInt360 float
141+
141142
);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
DROP TABLE IF EXISTS dmg_by_asset_rlz_001_xxx;
2+
3+
CREATE TABLE dmg_by_asset_rlz_001_xxx(
4+
PRIMARY KEY (id),
5+
BldgGen varchar,
6+
EqBldgType varchar,
7+
EqDesLev varchar,
8+
GenOcc varchar,
9+
SAC varchar,
10+
adauid varchar,
11+
cdname varchar,
12+
csdname varchar,
13+
dauid varchar,
14+
eqOccType varchar,
15+
ername varchar,
16+
fsauid varchar,
17+
hzOccType varchar,
18+
hzTaxon varchar,
19+
id varchar,
20+
landusetyp varchar,
21+
prname varchar,
22+
sauid varchar,
23+
taxonomy varchar,
24+
lon float,
25+
lat float,
26+
structural_no_damage_mean float,
27+
structural_no_damage_stdv float,
28+
structural_slight_mean float,
29+
structural_slight_stdv float,
30+
structural_moderate_mean float,
31+
structural_moderate_stdv float,
32+
structural_extensive_mean float,
33+
structural_extensive_stdv float,
34+
structural_complete_mean float,
35+
structural_complete_stdv float
36+
37+
);
38+
39+
-- import results from csv
40+
COPY dmg_by_asset_rlz_001_xxx (BldgGen, EqBldgType, EqDesLev, GenOcc, SAC, adauid,cdname, csdname, dauid, eqOccType, ername, fsauid, hzOccType, hzTaxon, id, landusetyp, prname, sauid, taxonomy, lon, lat, structural_no_damage_mean, structural_no_damage_stdv, structural_slight_mean,
41+
structural_slight_stdv, structural_moderate_mean, structural_moderate_stdv, structural_extensive_mean, structural_extensive_stdv, structural_complete_mean, structural_complete_stdv)
42+
FROM 'C:\Workspace\eRisk_CA\DataForWill_DSRAInput\dmg_by_asset-rlz-001_454.csv'
43+
WITH
44+
DELIMITER AS ','
45+
CSV HEADER ;
46+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
-- create PSRA metric baseline view from source TABLES
2+
3+
4+
DROP VIEW IF EXISTS psra_metrics_baseline;
5+
6+
CREATE VIEW psra_metrics_baseline AS
7+
8+
9+
SELECT a.id,
10+
a.lon,
11+
a.lat,
12+
a.taxonomy AS "Taxonomy",
13+
a.number AS "BldgNum",
14+
a.structural AS "CostStr",
15+
a.nonstructural AS "CostNStr",
16+
a.contents AS "CostCont",
17+
a.structural + a.nonstructural AS "CostBldgT",
18+
a.structural + a.nonstructural + a.contents AS "CostAssetT",
19+
a.day AS "PopDay",
20+
a.night AS "PopNight",
21+
a.transit AS "PopTrnst",
22+
23+
--damage potential baseline - operational
24+
b.no_damage AS "pd0_None",
25+
b.slight AS "pd0_Slight",
26+
(b.no_damage + b.slight) AS "pd0_GreenTag",
27+
b.moderate AS "pd0_Moderate",
28+
(b.moderate/a.number) AS "pd0_YellowTag_r",
29+
b.extensive AS "pd0_Extensive",
30+
b.complete AS "pd0_Complete",
31+
(b.extensive + b.complete) AS "pd0_RedTag",
32+
(b.extensive + b.complete) / a.number AS "pd0_RedTag_r",
33+
e.collapse_pc AS "Collapse_pc",
34+
(b.complete * e.collapse_pc) AS "pd0_Collapse",
35+
(b.complete * e.collapse_pc) / a.number AS "pd0_Collapse_r",
36+
37+
--placeholder for life safety baseline
38+
0 AS "p10_Fatal50",
39+
0 AS "pl0_Fatal100",
40+
0 AS "pl0_Fatal1000",
41+
0 AS"pl0_Fatal2500",
42+
43+
--average_annual_loss_baseline
44+
d.structural AS "aal0_Str",
45+
d.nonstructural AS "aal0_NStr",
46+
d.contents AS "aal0_Cont",
47+
(d.structural + d.nonstructural) AS "aal0_Bldg",
48+
(d.structural + d.nonstructural + d.contents) AS "aal0_Asset",
49+
(d.structural + d.nonstructural)/(a.structural + a.nonstructural) AS "alr0_Bldg",
50+
(d.structural + d.nonstructural + d.contents)/(a.structural + a.nonstructural) AS "alr0_Asset",
51+
d.occupants AS "aal0_Fatal",
52+
53+
--placeholder for probable maximium loss baseline
54+
0 AS "pml0_50",
55+
0 AS "pml0_100",
56+
0 AS "pml0_500",
57+
0 AS "pml0_1000",
58+
0 AS "pml0_2500",
59+
60+
--physical exposure
61+
a.landusetyp AS "LandUse",
62+
a.genocc AS "OccGen",
63+
a.hzocctype AS "Occ_hzType",
64+
a.eqocctype AS "Occ_oqType",
65+
a.bldggen AS "BldgGen",
66+
a.hztaxon AS "hzTaxon",
67+
a.eqbldgtype AS "eqBldgType",
68+
a.eqdeslev AS "eqDesLev",
69+
a.sauid,
70+
a.dauid,
71+
a.adauid,
72+
a.fsauid,
73+
a.csdname,
74+
a.cdname,
75+
a.sac AS "SAC",
76+
a.ername,
77+
a.prname
78+
79+
FROM canada_exposure a
80+
INNER JOIN damages_structural_mean_baseline b ON a.id = b.id
81+
--INNER JOIN loss_curve_mean_merge_baseline c ON a.id = c.id
82+
INNER JOIN avg_losses_mean_merge_baseline d ON a.id = d.id
83+
RIGHT JOIN collapse_probability_lut e ON a.eqbldgtype = e.eqbldgtype
84+
85+
86+
87+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
-- script to generate the avg_losses-mean baseline table
2+
DROP TABLE IF EXISTS avg_losses_mean_merge_baseline;
3+
4+
5+
-- create tables
6+
CREATE TABLE avg_losses_mean_merge_baseline(
7+
PRIMARY KEY (id),
8+
BldgGen varchar,
9+
EqBldgType varchar,
10+
EqDesLev varchar,
11+
GenOcc varchar,
12+
SAC varchar,
13+
adauid varchar,
14+
cdname varchar,
15+
csdname varchar,
16+
dauid varchar,
17+
eqOccType varchar,
18+
ername varchar,
19+
fsauid varchar,
20+
hzOccType varchar,
21+
hzTaxon varchar,
22+
id varchar,
23+
landusetyp varchar,
24+
prname varchar,
25+
sauid varchar,
26+
taxonomy varchar,
27+
lon float,
28+
lat float,
29+
contents float,
30+
nonstructural float,
31+
occupants float,
32+
structural float
33+
34+
);
35+
36+
37+
38+
39+
-- copy test avg losses mean tables into one master baseline table (single OQ run)
40+
COPY avg_losses_mean_merge_baseline (BldgGen, EqBldgType, EqDesLev, GenOcc, SAC, adauid, cdname, csdname, dauid, eqOccType, ername, fsauid, hzOccType, hzTaxon, id, landusetyp, prname, sauid, taxonomy, lon, lat, contents, nonstructural, occupants, structural)
41+
FROM 'C:\Workspace\eRisk_CA\PSRA_sample_data\baseline\average-annual-loss\avg_losses-mean_merge_baseline.csv'
42+
WITH
43+
DELIMITER AS ','
44+
CSV HEADER ;
45+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- script to generate the collapse probability LUT
2+
DROP TABLE IF EXISTS collapse_probability_LUT;
3+
4+
5+
-- create tables
6+
CREATE TABLE collapse_probability_LUT(
7+
typology varchar,
8+
EqBldgType varchar,
9+
collapse_pc float
10+
11+
);
12+
13+
14+
-- import results from csv
15+
COPY collapse_probability_LUT (typology, EqBldgType, collapse_pc)
16+
FROM 'C:\Workspace\eRisk_CA\PSRA_sample_data\collapse_probability_LUT.csv'
17+
WITH
18+
DELIMITER AS ','
19+
CSV HEADER ;
20+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
-- script to generate the damages_structural-mean baseline table
2+
3+
DROP TABLE IF EXISTS damages_structural_mean_baseline;
4+
5+
-- create tables
6+
CREATE TABLE damages_structural_mean_baseline(
7+
PRIMARY KEY (id),
8+
BldgGen varchar,
9+
EqBldgType varchar,
10+
EqDesLev varchar,
11+
GenOcc varchar,
12+
SAC varchar,
13+
adauid varchar,
14+
cdname varchar,
15+
csdname varchar,
16+
dauid varchar,
17+
eqOccType varchar,
18+
ername varchar,
19+
fsauid varchar,
20+
hzOccType varchar,
21+
hzTaxon varchar,
22+
id varchar,
23+
landusetyp varchar,
24+
prname varchar,
25+
sauid varchar,
26+
taxonomy varchar,
27+
lon float,
28+
lat float,
29+
no_damage float,
30+
slight float,
31+
moderate float,
32+
extensive float,
33+
complete float
34+
35+
);
36+
37+
38+
-- import results from csv
39+
40+
COPY damages_structural_mean_baseline (BldgGen, EqBldgType, EqDesLev, GenOcc, SAC, adauid, cdname, csdname, dauid, eqOccType, ername, fsauid, hzOccType, hzTaxon,
41+
id, landusetyp, prname, sauid, taxonomy, lon, lat, no_damage, slight, moderate, extensive, complete)
42+
FROM 'C:\Workspace\eRisk_CA\PSRA_sample_data\baseline\c-damage\damages-structural-mean_merge_baseline.csv'
43+
WITH
44+
DELIMITER AS ','
45+
CSV HEADER ;
46+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- script to generate the retrofit costs LUT
2+
DROP TABLE IF EXISTS retrofit_costs_LUT;
3+
4+
5+
-- create tables
6+
CREATE TABLE retrofit_costs_LUT(
7+
Eq_Bldg_Type varchar,
8+
Description varchar,
9+
BldgArea_ft2 float,
10+
Unit_Retrofit_Cost_pre1917_USD_ft2 float,
11+
Unit_Retrofit_Cost_1917_1975_USD_ft2 float,
12+
Unit_Retrofit_Cost_1975_2019_USD_ft2 float,
13+
Retrofit_Cost_Bldg_pc float,
14+
Building_Retrofit_Cost_USD float,
15+
Building_Retrofit_Cost_CAD float
16+
17+
);
18+
19+
20+
-- import results from csv
21+
COPY retrofit_costs_LUT (Eq_Bldg_Type, Description, BldgArea_ft2, Unit_Retrofit_Cost_pre1917_USD_ft2, Unit_Retrofit_Cost_1917_1975_USD_ft2, Unit_Retrofit_Cost_1975_2019_USD_ft2, Retrofit_Cost_Bldg_pc, Building_Retrofit_Cost_USD, Building_Retrofit_Cost_CAD
22+
)
23+
FROM 'C:\Workspace\eRisk_CA\PSRA_sample_data\retrofit_costs_LUT.csv'
24+
WITH
25+
DELIMITER AS ','
26+
CSV HEADER ;
27+
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
-- create PSRA metric baseline view from source TABLES
2+
3+
4+
DROP VIEW IF EXISTS prsa_metrics_baseline;
5+
6+
CREATE VIEW prsa_metrics_baseline AS
7+
8+
9+
SELECT a.id,
10+
a.lon,
11+
a.lat,
12+
a.taxonomy AS "Taxonomy",
13+
a.number AS "BldgNum",
14+
a.structural AS "CostStr",
15+
a.nonstructural AS "CostNStr",
16+
a.contents AS "CostCont",
17+
a.structural + a.nonstructural AS "CostBldgT",
18+
a.structural + a.nonstructural + a.contents AS "CostAssetT",
19+
a.day AS "PopDay",
20+
a.night AS "PopNight",
21+
a.transit AS "PopTrnst",
22+
23+
--damage potential baseline - operational
24+
b.pd0_none AS "pd0_None",
25+
b.pd0_slight AS "pd0_Slight",
26+
--b.pd0_greentag AS "pd1_GreenTag",
27+
b.pd0_greentag AS "pd0_GreenTag",
28+
b.pd0_moderate AS "pd0_Moderate",
29+
--b.pd0_yellowtag_m AS "pd1_yellowtag_r" ??
30+
(b.pd0_moderate/a.number) AS "pd0_YellowTag_r",
31+
b.pd0_extensive AS "pd0_Extensive",
32+
b.pd0_complete AS "pd0_Complete",
33+
--b.pd0_redtag AS "pd0_RedTag",
34+
b.pd0_extensive + b.pd0_complete AS "pd0_RedTag",
35+
(b.pd0_extensive + b.pd0_complete) / a.number AS "pd0_RedTag_r",
36+
b.pd0_collapse AS "pd0_Collapse",
37+
b.pd0_collapse_m AS "pd0_Collapse_r",
38+
39+
--life safety avg_losses_mean_merge_baseline
40+
c.s0_occ_50 AS "pl0_Fatal50",
41+
c.s0_OCC_100 AS "pl0_Fatal100",
42+
c.s0_OCC_500 AS "pl0_Fatal1000",
43+
c.s0_OCC_2500 AS "pl0_Fatal2500",
44+
--pl_Fatality_r ??
45+
46+
--average_annual_loss_baseline
47+
d.s0_structural AS "aal0_Str",
48+
d.s0_nonstructural AS "aal0_NStr",
49+
d.s0_contents AS "aal0_Cont",
50+
d.s0_structural + d.s0_nonstructural AS "aal0_Bldg",
51+
d.s0_structural + d.s0_nonstructural + d.s0_contents AS "aal0_Asset",
52+
(d.s0_structural + d.s0_nonstructural)/(a.structural + a.nonstructural) AS "alr0_Bldg",
53+
(d.s0_structural + d.s0_nonstructural + d.s0_contents)/(a.structural + a.nonstructural) AS "alr0_Asset",
54+
d.s0_occupants AS "aal0_Fatal",
55+
56+
--probable maximium loss baseline
57+
c.s0_pml_50 AS "pml0_50",
58+
c.s0_pml_100 AS "pml0_100",
59+
c.s0_pml_500 AS "pml0_500",
60+
c.s0_pml_1000 AS "pml0_1000",
61+
c.s0_pml_2500 AS "pml0_2500",
62+
63+
--physical exposure
64+
a.landusetyp AS "LandUse",
65+
a.genocc AS "OccGen",
66+
a.hzocctype AS "Occ_hzType",
67+
a.eqocctype AS "Occ_oqType",
68+
a.bldggen AS "BldgGen",
69+
a.hztaxon AS "hzTaxon",
70+
a.eqbldgtype AS "eqBldgType",
71+
a.eqdeslev AS "eqDesLev",
72+
a.sauid,
73+
a.dauid,
74+
a.adauid,
75+
a.fsauid,
76+
a.csdname,
77+
a.cdname,
78+
a.sac AS "SAC",
79+
a.ername,
80+
a.prname
81+
82+
83+
FROM canada_exposure a
84+
INNER JOIN cdamage_ca_baseline b ON a.id = b.id
85+
INNER JOIN loss_curve_mean_merge_baseline c ON a.id = c.id
86+
INNER JOIN avg_losses_mean_merge_baseline d ON a.id = d.id
87+
88+

0 commit comments

Comments
 (0)