-
Notifications
You must be signed in to change notification settings - Fork 3
/
init_dynamodb.sh
executable file
·344 lines (323 loc) · 13.8 KB
/
init_dynamodb.sh
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#!/bin/bash
apt update && apt install -y jq
script_dir=$(dirname "$0")
entries_dir="${script_dir}/dynamo-entries"
if [[ -f "${script_dir}/dynamo-entries.tgz" ]]; then
tar -xzf "${script_dir}/dynamo-entries.tgz" -C "${script_dir}"
fi
batch_write_entries () {
table_name="$1"
entries_file="$2"
num_items="$(jq -r length "${entries_file}")"
# `batch-write-item` only supports 25 items at a time, so we use the `_nwise` operator
# to chunk things out into batches of that size, which we then loop over and write to dynamo
request_items_batches="$(jq -c "map({ PutRequest: { Item: . }}) | _nwise(25)" "${entries_file}")"
if [[ "${num_items}" -lt 1000 ]]; then
echo "Seeding ${num_items} item(s) into the ${table_name} table..."
else
echo "Seeding ${num_items} items into the ${table_name} table. This may take a few minutes..."
fi
start_time="$(date +%s)"
echo "${request_items_batches}" | while read -r items
do
awslocal dynamodb batch-write-item \
--request-items "{ \"${table_name}\": ${items} }" \
--region us-west-2 > /dev/null
done
end_time="$(date +%s)"
echo "done in $(( ${end_time} - ${start_time} )) seconds"
}
# **** APPLIANCE TABLE ****
awslocal dynamodb create-table \
--table-name appliance_table \
--attribute-definitions AttributeName=_id,AttributeType=S \
--key-schema AttributeName=_id,KeyType=HASH \
--billing-mode PAY_PER_REQUEST \
--region us-west-2
if [[ -f "${entries_dir}/Appliances.json" ]]; then
batch_write_entries "appliance_table" "${entries_dir}/Appliances.json"
else
awslocal dynamodb put-item \
--table-name appliance_table \
--item '{
"unit": {"S": "kwh"} ,
"lifespan": {"N": "12"},
"_id": {"S": "6572424b530d7b4310456b76"},
"per_year": {"N": "139"},
"appliance": {"S": "stove"},
"unique_id": {"S": "1662765633488x566876457883010750"},
"avg_price": {"N": "691"},
"fuel_type": {"S": "electricity"}
}' \
--region us-west-2
fi
# **** BIOMASS TABLE ****
awslocal dynamodb create-table \
--table-name biomass_table \
--attribute-definitions AttributeName=_id,AttributeType=S \
--key-schema AttributeName=_id,KeyType=HASH \
--billing-mode PAY_PER_REQUEST \
--region us-west-2
if [[ -f "${entries_dir}/Densified_Biomass_Prices.json" ]]; then
batch_write_entries "biomass_table" "${entries_dir}/Densified_Biomass_Prices.json"
else
awslocal dynamodb put-item \
--table-name biomass_table \
--item '{
"_id": {"S": "65a97f9b7032768b5f429a08"},
"date": {"S": "2023-10"},
"usd-ton": {"S": "228.75"},
"name": {"S": "wood"}
}' \
--region us-west-2
fi
# **** HOMEDECADE TABLE
awslocal dynamodb create-table \
--table-name home_decade_table \
--attribute-definitions AttributeName=_id,AttributeType=S \
--key-schema AttributeName=_id,KeyType=HASH \
--billing-mode PAY_PER_REQUEST \
--region us-west-2
if [[ -f "${entries_dir}/Home_Decades.json" ]]; then
batch_write_entries "home_decade_table" "${entries_dir}/Home_Decades.json"
else
awslocal dynamodb put-item \
--table-name home_decade_table \
--item '{
"_id": { "S": "6572421f5c6f3247a090be0c" },
"decade": { "S": "1940-1949" },
"prob_of_insulation": { "N": "0.7" },
"insulation": { "S": "Fiberglass" },
"insulation_r/in": { "N": "3.14" },
"wall_insulation_r": { "N": "10.99" },
"wall_construction": { "N": "4.38" },
"wall_siding": { "N": "1.4" },
"wall_r": { "N": "13.47" },
"attic_insulation_r": { "N": "23.55" },
"joist": { "N": "4.38" },
"roof": { "N": "1.4" },
"attic_r": { "N": "22.265" },
"ach": { "N": "0.75" }
}' \
--region us-west-2
fi
# **** HOMETYPE TABLE ****
awslocal dynamodb create-table \
--table-name home_type_table \
--attribute-definitions AttributeName=_id,AttributeType=S \
--key-schema AttributeName=_id,KeyType=HASH \
--billing-mode PAY_PER_REQUEST \
--region us-west-2
if [[ -f "${entries_dir}/Home_Type.json" ]]; then
batch_write_entries "home_type_table" "${entries_dir}/Home_Type.json"
else
awslocal dynamodb put-item \
--table-name home_type_table \
--item '{
"_id": { "S": "657241ebd1671b78e5d355f9" },
"home_type": { "S": "Apartment or Condo" },
"shared_walls": { "N": "3" },
"shared_ceilings": { "N": "1" }
}' \
--region us-west-2
fi
# **** HVAC TABLE ****
awslocal dynamodb create-table \
--table-name hvac_table \
--attribute-definitions AttributeName=_id,AttributeType=S \
--key-schema AttributeName=_id,KeyType=HASH \
--billing-mode PAY_PER_REQUEST \
--region us-west-2
if [[ -f "${entries_dir}/HVAC_Appliances.json" ]]; then
batch_write_entries "hvac_table" "${entries_dir}/HVAC_Appliances.json"
else
awslocal dynamodb put-item \
--table-name hvac_table \
--item '{
"_id": { "S": "65737d7c936e49e28f2fc3cc" },
"cost": { "N": "300" },
"default_unit-type": { "S": "" },
"description": {
"S": "A portable AC unit is a portable air conditioning system that can be moved from room to room. It consists of an evaporator, a compressor, and a condenser, and it is designed to cool a single room or small area."
},
"efficiency": { "N": "2.64" },
"external_link": { "S": "https://zwellhome.com/learn/hvac/" },
"fuel": { "S": "electricity" },
"function": { "S": "cooling" },
"icon": {
"S": "//s3.amazonaws.com/appforest_uf/f1672980104589x542622914672405300/Icon_PortableAC_Grey.svg"
},
"lifespan": { "N": "6" },
"system": { "S": "portable ac unit" },
"creation_date": { "S": "########" },
"modified_date": { "S": "########" },
"slug": { "S": "" },
"creator": { "S": "(App admin)" },
"unique_id": { "S": "1673572752154x986440559365401700" },
"display_name": { "S": "Portable AC Unit" }
}' \
--region us-west-2
fi
# **** STATE TABLE ****
awslocal dynamodb create-table \
--table-name state_table \
--attribute-definitions AttributeName=_id,AttributeType=S \
--key-schema AttributeName=_id,KeyType=HASH \
--billing-mode PAY_PER_REQUEST \
--region us-west-2
if [[ -f "${entries_dir}/State_Data.json" ]]; then
batch_write_entries "state_table" "${entries_dir}/State_Data.json"
else
awslocal dynamodb put-item \
--table-name state_table \
--item '{
"_id": { "S": "659c6233d61ba4e1468b5321" },
"state": { "S": "Alabama" },
"abbreviation": { "S": "AL" },
"state_emissions": {
"L": [
{
"M": {
"co2_lbs/mhw": { "N": "794" },
"co2_lbs/btu": { "N": "0.00023270808909730363" },
"co2_net_emission_estimate": { "S": "9,977" },
"date": { "S": "2022" }
}
}
]
},
"state_energy_costs": {
"L": [
{
"M": {
"usd/btu_electricity": { "N": "0.0000044021101992966004" },
"usd/btu_natural_gas": { "N": "0.00002789" },
"usd/btu_propane": { "N": "0.00003464112321217688" },
"usd/btu_fuel_oil": { "N": "0.00001952346570397112" },
"date": { "S": "2023-12-27" }
}
}
]
},
"state_energy_breakdown": {
"L": [
{
"M": {
"all_fuels": { "N": "67.8007" },
"natural_gas": { "N": "12.6686" },
"petroleum": { "N": "0.00217" },
"coal": { "N": "14.11617" },
"nuclear": { "N": "37.69161" },
"hydro": { "N": "3.31545" },
"wind": { "N": "0" },
"solar": { "N": "0.00671" },
"other_renewable": { "N": "0" },
"date": { "S": "2023-10" },
"units": { "S": "million MMBtu" }
}
}
]
}
}' \
--region us-west-2
awslocal dynamodb put-item \
--table-name state_table \
--item '{
"_id": { "S": "659c6233d61ba4e1468b5340" },
"state": { "S": "New York" },
"abbreviation": { "S": "NY" },
"state_emissions": {
"L": [
{
"M": {
"co2_lbs/mhw": { "N": "541" },
"co2_lbs/btu": { "N": "0.00015855803048065651" },
"co2_net_emission_estimate": { "S": "11,534" },
"date": { "S": "2022" }
}
}
]
},
"state_energy_costs": {
"L": [
{
"M": {
"usd/btu_electricity": { "N": "0.000006652989449003517" },
"usd/btu_natural_gas": { "N": "0.000020969999999999997" },
"usd/btu_propane": { "N": "0.00003582207059441018" },
"usd/btu_fuel_oil": { "N": "0.000030122743682310467" },
"date": { "S": "2023-12-27" }
}
}
]
},
"state_energy_breakdown": {
"L": [
{
"M": {
"all_fuels": { "N": "15.6124" },
"natural_gas": { "N": "8.82411" },
"petroleum": { "N": "0.07999" },
"coal": { "N": "0" },
"nuclear": { "N": "0" },
"hydro": { "N": "6.62945" },
"wind": { "N": "0.07885" },
"solar": { "N": "0" },
"other_renewable": { "N": "0" },
"date": { "S": "2023-10" },
"units": { "S": "million MMBtu" }
}
}
]
}
}' \
--region us-west-2
fi
# **** ZIPCODE TABLE ****
awslocal dynamodb create-table \
--table-name zipcode_table \
--attribute-definitions AttributeName=_id,AttributeType=S AttributeName=zipcode,AttributeType=S \
--key-schema AttributeName=_id,KeyType=HASH AttributeName=zipcode,KeyType=RANGE \
--global-secondary-indexes 'IndexName=zipcode-index,KeySchema=[{AttributeName=zipcode,KeyType=HASH}],Projection={ProjectionType=ALL}' \
--billing-mode PAY_PER_REQUEST \
--region us-west-2
if [[ -f "${entries_dir}/Zip_Code_Data.json" ]]; then
batch_write_entries "zipcode_table" "${entries_dir}/Zip_Code_Data.json"
else
awslocal dynamodb put-item \
--table-name zipcode_table \
--item '{
"_id": { "S": "659c61fe32efd4163615703d" },
"state": { "S": "NY" },
"zipcode": { "S": "10001" },
"primary_city": { "S": "New York" },
"latitude": { "N": "40.75" },
"longitude": { "N": "-74" },
"degree_days": {
"M": {
"heating_degree_days": { "N": "4131" },
"cooling_degree_days": { "N": "1479" },
"site": {
"M": {
"site_id": { "S": "GHCND:USW00014732" },
"site_name": { "S": "LAGUARDIA AIRPORT, NY US" },
"station_distance": { "N": "0.1232987242" }
}
}
}
},
"water_temperature_data": {
"M": {
"water_temperature": { "N": "56.84641096" },
"site": {
"M": {
"site_id": { "N": "1302250" },
"site_name": { "S": "EAST CREEK AT SANDS POINT NY" },
"station_distance": { "N": "0.31224171" }
}
}
}
}
}' \
--region us-west-2
fi