irie 0.0.41__py3-none-any.whl → 0.0.43__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of irie might be problematic. Click here for more details.
- irie/apps/inventory/archive/CESMD.py +0 -0
- irie/apps/inventory/filters.py +1 -1
- irie/apps/inventory/models.py +27 -0
- irie/apps/inventory/services/render.py +0 -0
- irie/apps/inventory/urls.py +3 -0
- irie/apps/inventory/views.py +57 -0
- irie/apps/prediction/forms.py +2 -1
- irie/apps/prediction/models.py +24 -0
- irie/apps/prediction/runners/hazus.py +33 -19
- irie/apps/prediction/urls.py +5 -3
- irie/apps/prediction/views.py +101 -8
- irie/apps/static/assets/css/brace.css +0 -33
- irie/apps/static/assets/css/brace.css.map +1 -1
- irie/apps/static/assets/css/brace.min.css +1 -1
- irie/apps/static/assets/js/brace.js +2 -1
- irie/apps/templates/includes/scripts.html +10 -1
- irie/apps/templates/includes/sidebar.html +19 -11
- irie/apps/templates/inventory/asset-on-map.html +457 -0
- irie/apps/templates/inventory/asset-profile.html +1 -2
- irie/apps/templates/inventory/map-inventory.html +136 -0
- irie/apps/templates/inventory/map-inventory2.html +143 -0
- irie/apps/templates/inventory/map-single-asset.html +0 -0
- irie/apps/templates/inventory/map-single-asset2.html +618 -0
- irie/apps/templates/inventory/map-terrain.html +214 -0
- irie/apps/templates/inventory/sensor-upload.html +1 -0
- irie/apps/templates/inventory/three-maps.html +229 -0
- irie/apps/templates/layouts/base.html +2 -1
- irie/apps/templates/prediction/predictor-upload.html +68 -22
- irie/apps/templates/site/index.html +36 -27
- irie/apps/templates/site/page-400-sidebar.html +31 -0
- irie/apps/templates/site/page-400.html +29 -0
- irie/apps/templates/site/page-404-sidebar.html +1 -1
- irie/apps/templates/site/page-404.html +1 -1
- irie/fhwa/__init__.py +132 -0
- irie/fhwa/__main__.py +79 -0
- irie/fhwa/fields/nbi001.py +61 -0
- irie/fhwa/fields/nbi001b.py +1 -0
- irie/fhwa/fields/nbi002.py +0 -0
- irie/fhwa/fields.py +32 -0
- irie/init/__main__.py +0 -4
- irie/init/calid.py +86 -3
- irie/init/getNBIData.py +1 -1
- irie/init/getNBIData2.py +304 -0
- irie/init/management/commands/init_assets.py +11 -11
- irie/init/management/commands/init_predictors.py +1 -1
- irie/init/management/commands/make_asset.py +0 -0
- irie/pull/nbi.py +304 -0
- {irie-0.0.41.dist-info → irie-0.0.43.dist-info}/METADATA +1 -1
- {irie-0.0.41.dist-info → irie-0.0.43.dist-info}/RECORD +53 -36
- {irie-0.0.41.dist-info → irie-0.0.43.dist-info}/WHEEL +1 -1
- irie/apps/inventory/CESMD.py +0 -81
- irie/apps/inventory/archive/arcGIS.py +0 -1175
- irie/apps/inventory/traffic.py +0 -175052
- /irie/apps/inventory/{calid.py → archive/calid.py} +0 -0
- {irie-0.0.41.dist-info → irie-0.0.43.dist-info}/entry_points.txt +0 -0
- {irie-0.0.41.dist-info → irie-0.0.43.dist-info}/top_level.txt +0 -0
irie/init/calid.py
CHANGED
|
@@ -21,16 +21,16 @@ CESMD = {
|
|
|
21
21
|
"53-2795F": ("CE24694", "07-LA-5-24.5" , "Sylmar - I5/14 Interchange Bridge"),
|
|
22
22
|
"55-0225": ("CE13795", "07-ORA-5-6.62" , "Capistrano Beach - I5/Via Calif. Bridge"),
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
# "58-0215": ("CE01336", None, "El Centro - Hwy8/Meloland Overpass [Abandoned]"),
|
|
25
25
|
"47-0048": ("CE54730", None, "Lake Crowley - Hwy 395 Bridge"),
|
|
26
26
|
"04-0228": ("CE89686", None, "Eureka - Samoa Channel Bridge"),
|
|
27
27
|
"04-0236": ("CE89324", None, "Rio Dell - Hwy 101/Painter St. Overpass"),
|
|
28
28
|
"54-0823G": ("CE23631", None, "San Bernardino - I10/215 Interchange Br"),
|
|
29
29
|
"33-0214L": ("CE58658", None, "Hayward - Hwy 580/238 Interchange Bridge"),
|
|
30
|
-
}
|
|
30
|
+
# }
|
|
31
31
|
|
|
32
32
|
# TODO: Need to get NBI/CGS Data for these
|
|
33
|
-
{
|
|
33
|
+
# {
|
|
34
34
|
#-------------------------------------
|
|
35
35
|
|
|
36
36
|
"34-0006": ("CE58600", None, "Oakland - SF Bay Bridge/East: SAS"),
|
|
@@ -116,3 +116,86 @@ CESMD = {
|
|
|
116
116
|
"""
|
|
117
117
|
|
|
118
118
|
CALID = {v[0]: k for k, v in CESMD.items()}
|
|
119
|
+
|
|
120
|
+
CESMD_LONG_LAT = {
|
|
121
|
+
'89973': [40.5093, -124.1196],
|
|
122
|
+
'89324': [40.5031, -124.1009],
|
|
123
|
+
'89686': [40.8216, -124.1697],
|
|
124
|
+
'89736': [40.809, -124.1547],
|
|
125
|
+
'89735': [40.8136, -124.1594],
|
|
126
|
+
'47315': [36.8619, -121.5796],
|
|
127
|
+
'23631': [34.065, -117.2962],
|
|
128
|
+
'58700': [37.8198, -122.4788],
|
|
129
|
+
'25749': [34.4497, -119.735],
|
|
130
|
+
'14406': [33.7494, -118.2715],
|
|
131
|
+
'58632': [37.7982, -122.3774],
|
|
132
|
+
'58657': [37.8286, -122.2666],
|
|
133
|
+
'24775': [34.8663, -118.8836],
|
|
134
|
+
'58601': [37.8198, -122.3429],
|
|
135
|
+
'24706': [34.5463, -118.1301],
|
|
136
|
+
'33742': [35.6696, -117.8187],
|
|
137
|
+
'24704': [34.0368, -118.3762],
|
|
138
|
+
'24689': [34.1486, -118.1561],
|
|
139
|
+
'54730': [37.5733, -118.739],
|
|
140
|
+
'13705': [33.882, -117.5497],
|
|
141
|
+
'13795': [33.4659, -117.6674],
|
|
142
|
+
'68065': [38.1205, -122.2801],
|
|
143
|
+
'57595': [37.4639, -121.9302],
|
|
144
|
+
'68185': [38.061, -122.2265],
|
|
145
|
+
'68717': [38.3484, -122.713],
|
|
146
|
+
'58754': [37.3574, -122.397],
|
|
147
|
+
'58658': [37.6907, -122.0993],
|
|
148
|
+
'76741': [39.368, -120.1151],
|
|
149
|
+
'89708': [40.9563, -124.1161],
|
|
150
|
+
'24714': [34.2878, -118.4084],
|
|
151
|
+
'79421': [39.9213, -123.7634],
|
|
152
|
+
'68778': [38.1157, -122.5054],
|
|
153
|
+
'58602': [37.8126, -122.3627],
|
|
154
|
+
'68184': [38.061, -122.2252],
|
|
155
|
+
'12666': [33.9153, -116.6085],
|
|
156
|
+
'68682': [38.0414, -122.1238],
|
|
157
|
+
'12649': [33.9332, -116.9907],
|
|
158
|
+
'67771': [38.0278, -121.7514],
|
|
159
|
+
'57748': [37.4176, -121.9738],
|
|
160
|
+
'58600': [37.8152, -122.3589],
|
|
161
|
+
'69760': [38.955, -123.1051],
|
|
162
|
+
'47707': [36.9067, -121.7818],
|
|
163
|
+
'03679': [32.6891, -117.1538],
|
|
164
|
+
'24738': [34.2878, -118.865],
|
|
165
|
+
'36668': [35.7331, -120.2901],
|
|
166
|
+
'37728': [35.5955, -121.1256],
|
|
167
|
+
'03731': [32.838, -117.234],
|
|
168
|
+
'99190': [41.8797, -124.1373],
|
|
169
|
+
'25324': [34.2428, -119.1905],
|
|
170
|
+
'58258': [37.9344, -122.4346],
|
|
171
|
+
'79757': [39.8485, -123.7019],
|
|
172
|
+
'68322': [38.0441, -122.1229],
|
|
173
|
+
'58596': [37.505, -122.12],
|
|
174
|
+
'24694': [34.3349, -118.5084],
|
|
175
|
+
'79683': [39.2157, -123.7678],
|
|
176
|
+
'24670': [34.0314, -118.4354],
|
|
177
|
+
'69671': [38.4347, -123.1017],
|
|
178
|
+
'79761': [39.8471, -123.6967],
|
|
179
|
+
'58656': [37.7837, -122.1769],
|
|
180
|
+
'67972': [38.5728, -121.587],
|
|
181
|
+
'99710': [41.5174, -124.0307],
|
|
182
|
+
'23650': [34.2251, -117.4096],
|
|
183
|
+
'58677': [37.5836, -122.2515],
|
|
184
|
+
'25758': [34.9331, -119.5941],
|
|
185
|
+
'79296': [39.4274, -123.8068],
|
|
186
|
+
'58536': [37.6746, -122.3895],
|
|
187
|
+
'58501': [37.6708, -122.0885],
|
|
188
|
+
'58414': [37.584, -122.509],
|
|
189
|
+
'01571': [37.34105, -121.8514],
|
|
190
|
+
'05235': [33.96843, -117.44815],
|
|
191
|
+
'25725': [34.2622, -119.231],
|
|
192
|
+
'58799': [37.6083, -122.1842],
|
|
193
|
+
'47646': [36.2391, -121.7747],
|
|
194
|
+
'88638': [40.881, -122.3809],
|
|
195
|
+
'22503': [34.2419, -116.9775],
|
|
196
|
+
'88194': [40.7597, -122.3188],
|
|
197
|
+
'26917': [34.5215, -120.3369],
|
|
198
|
+
'34715': [35.0387, -118.1696],
|
|
199
|
+
'14690': [33.7865, -118.0939],
|
|
200
|
+
'58678': [37.5048, -122.3346]
|
|
201
|
+
}
|
irie/init/getNBIData.py
CHANGED
irie/init/getNBIData2.py
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
#===----------------------------------------------------------------------===#
|
|
2
|
+
#
|
|
3
|
+
# STAIRLab -- STructural Artificial Intelligence Laboratory
|
|
4
|
+
#
|
|
5
|
+
#===----------------------------------------------------------------------===#
|
|
6
|
+
#
|
|
7
|
+
# First run without arguments to generate list of structure numbers and
|
|
8
|
+
# save to JSON. Then run with that JSON as argv[1] to pull inventory data.
|
|
9
|
+
#
|
|
10
|
+
# Adapted from:
|
|
11
|
+
# https://github.com/psychogeekir/ScrapeNBIBridgeInfo/raw/master/getNBIClimateData.py
|
|
12
|
+
#
|
|
13
|
+
# Claudio M. Perez
|
|
14
|
+
#
|
|
15
|
+
# TODO:
|
|
16
|
+
#
|
|
17
|
+
# - Add option for "SELECTED_TAB": "NBETab",
|
|
18
|
+
#
|
|
19
|
+
# - Perhaps add something like:
|
|
20
|
+
# --filter-calid calids.txt
|
|
21
|
+
# This will be useful for testing, eg, (chrystal's first version)
|
|
22
|
+
# python getNBIData.py yearly.json --filter-calid <(echo "33 0214L")
|
|
23
|
+
#
|
|
24
|
+
# or
|
|
25
|
+
# python getNBIData.py | python getNBIData.py /dev/stdin <(echo "33 0214L")
|
|
26
|
+
#
|
|
27
|
+
import sys
|
|
28
|
+
import json
|
|
29
|
+
import requests
|
|
30
|
+
from tqdm import tqdm
|
|
31
|
+
from pathlib import Path
|
|
32
|
+
|
|
33
|
+
NAME = Path(__file__).name
|
|
34
|
+
|
|
35
|
+
EXAMPLES= """"
|
|
36
|
+
Examples:
|
|
37
|
+
run to obtain structure numbers list:
|
|
38
|
+
$ {NAME}
|
|
39
|
+
run to obtain data from JSON list:
|
|
40
|
+
$ {NAME} [structure_numbers]
|
|
41
|
+
run filtering for given structure 33 0214L:
|
|
42
|
+
$ {NAME} [structure_numbers] --filter-calid "33 0214L"
|
|
43
|
+
run filtering for given structures:
|
|
44
|
+
$ {NAME} [structure_numbers] --filter-list [list]
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
HELP=f"""
|
|
48
|
+
|
|
49
|
+
usage: $ {NAME}
|
|
50
|
+
$ {NAME} --help
|
|
51
|
+
$ {NAME} [structure_numbers] [options]
|
|
52
|
+
|
|
53
|
+
Two-step process to obtain data from the National Bridge Inventory.
|
|
54
|
+
|
|
55
|
+
Positional Arguments:
|
|
56
|
+
|
|
57
|
+
Options:
|
|
58
|
+
-fc, --filter-calid filter for specific structure.
|
|
59
|
+
-fl, --filter-list filter for specified structures in txt file.
|
|
60
|
+
-h, --help print this message and exit.
|
|
61
|
+
|
|
62
|
+
{EXAMPLES}
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
def getBridgeList(headers, start_page=1, totalpages=3, pagesize=10, totalbridges=24, page_nums=None, **kwds):
|
|
66
|
+
url = 'https://infobridge.fhwa.dot.gov/Data/GetAllBridges'
|
|
67
|
+
|
|
68
|
+
payload = {
|
|
69
|
+
"isShowBridgesApplied":True,
|
|
70
|
+
"gridParam": {
|
|
71
|
+
"isShowBridgesApplied":True, "IsFilterApplied":False, "SelectedFilters":None,
|
|
72
|
+
"SortOrder":"asc", "SortIndex": "STATE_CODE",
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
pages = []
|
|
77
|
+
def filter(row):
|
|
78
|
+
return int(row["STATE_CODE"]) > 0
|
|
79
|
+
|
|
80
|
+
if page_nums is None:
|
|
81
|
+
page_nums = range(start_page, totalpages + 1)
|
|
82
|
+
|
|
83
|
+
for pageno in page_nums:
|
|
84
|
+
try:
|
|
85
|
+
payload["gridParam"]["PageNumber"] = pageno
|
|
86
|
+
payload["gridParam"]["PageSize"] = pagesize
|
|
87
|
+
|
|
88
|
+
r = requests.post(url, headers=headers, data=json.dumps(payload))
|
|
89
|
+
|
|
90
|
+
if r.status_code == 200:
|
|
91
|
+
try:
|
|
92
|
+
resp = json.loads(eval(r.content.decode('utf-8'))) # [1:-1].replace("\\", ""))
|
|
93
|
+
except:
|
|
94
|
+
print(f"Failed to get page {pageno}", file=sys.stderr)
|
|
95
|
+
continue
|
|
96
|
+
|
|
97
|
+
bridges = [
|
|
98
|
+
{'BRIDGE_YEARLY_ID': row['BRIDGE_YEARLY_ID'],
|
|
99
|
+
'STRUCTURE_NUMBER': row['STRUCTURE_NUMBER'].strip()}
|
|
100
|
+
for row in resp["Results"]["rows"] # if filter(row)
|
|
101
|
+
]
|
|
102
|
+
pages.extend(bridges)
|
|
103
|
+
print(pageno, len(pages), len(bridges), resp["Results"]["rows"][-1]["STATE_NAME"], file=sys.stderr)
|
|
104
|
+
|
|
105
|
+
except KeyboardInterrupt:
|
|
106
|
+
break
|
|
107
|
+
|
|
108
|
+
return pages
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def getNBIData(headers, bridgeTable, years, tab="NBI",
|
|
112
|
+
keep_query=False):
|
|
113
|
+
|
|
114
|
+
url = 'https://infobridge.fhwa.dot.gov/Data/getBridgeInformation'
|
|
115
|
+
|
|
116
|
+
_headers = headers.copy()
|
|
117
|
+
# payload = {
|
|
118
|
+
# "requestModel": {
|
|
119
|
+
# "SELECTED_TAB": "OverviewTab",
|
|
120
|
+
# "SELECTED_YEAR_ID": None,
|
|
121
|
+
# "IS_NEW_RECORD": True,
|
|
122
|
+
# "IS_YEAR_SELECTED": False,
|
|
123
|
+
# "Is_Overview_Bridge_Selected": False,
|
|
124
|
+
# "SELECTED_YEAR": None,
|
|
125
|
+
# "CURRENT_YEARLY_ID": "25099893",
|
|
126
|
+
# "IS_NBI_TREE_SELECTED": False,
|
|
127
|
+
# "Folder_Name": None,
|
|
128
|
+
# "tabChange": False,
|
|
129
|
+
# "BRIDGE_YEARLY_ID": "25099893",
|
|
130
|
+
# "NEW_BRIDGE_ID": 58813,
|
|
131
|
+
# "SELECTED_NDE_TAB": "General"
|
|
132
|
+
# }
|
|
133
|
+
# }
|
|
134
|
+
|
|
135
|
+
payload = {
|
|
136
|
+
"requestModel":{
|
|
137
|
+
"SELECTED_TAB": f"{tab}Tab",
|
|
138
|
+
"SELECTED_YEAR_ID": None,
|
|
139
|
+
"IS_NEW_RECORD": False,
|
|
140
|
+
"IS_YEAR_SELECTED": False,
|
|
141
|
+
"Is_Overview_Bridge_Selected": False,
|
|
142
|
+
"NEW_BRIDGE_ID": 0,
|
|
143
|
+
"STRUCTURE_NUMBER": None,
|
|
144
|
+
"STATE_NAME": None,
|
|
145
|
+
"STATE_CODE": 0,
|
|
146
|
+
"IS_EXPERIMENTAL": False,
|
|
147
|
+
"SELECTED_NDE_TAB": "General",
|
|
148
|
+
#"MERRA_ID": 0,"IS_NBI_TREE_SELECTED": False,"Folder_Name": None,"tabChange": False,
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
referer = 'https://infobridge.fhwa.dot.gov/Data/BridgeDetail/'
|
|
154
|
+
data = {}
|
|
155
|
+
|
|
156
|
+
for i,bridge in enumerate(tqdm(bridgeTable)):
|
|
157
|
+
|
|
158
|
+
BRIDGE_YEARLY_ID = bridge['BRIDGE_YEARLY_ID']
|
|
159
|
+
STRUCTURE_NUMBER = bridge['STRUCTURE_NUMBER']
|
|
160
|
+
|
|
161
|
+
# data[STRUCTURE_NUMBER] = []
|
|
162
|
+
|
|
163
|
+
for year in years:
|
|
164
|
+
_headers['referer'] = referer + str(BRIDGE_YEARLY_ID)
|
|
165
|
+
|
|
166
|
+
payload["requestModel"].update({
|
|
167
|
+
"SELECTED_YEAR": year,
|
|
168
|
+
"CURRENT_YEARLY_ID": BRIDGE_YEARLY_ID,
|
|
169
|
+
"BRIDGE_YEARLY_ID": BRIDGE_YEARLY_ID,
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
r = requests.post(url, data=json.dumps(payload), headers=_headers)
|
|
173
|
+
|
|
174
|
+
if r.status_code == 200:
|
|
175
|
+
htmlcontent = r.content.decode('utf-8')
|
|
176
|
+
# print(data[STRUCTURE_NUMBER][0])
|
|
177
|
+
try:
|
|
178
|
+
data[STRUCTURE_NUMBER] = [{
|
|
179
|
+
k: (
|
|
180
|
+
v if k != "Results" else {
|
|
181
|
+
kk: vv for kk, vv in v.items() if (kk != "NBIDataQuery" or keep_query)
|
|
182
|
+
}
|
|
183
|
+
) for k, v in json.loads(htmlcontent).items()
|
|
184
|
+
}]
|
|
185
|
+
except Exception as e:
|
|
186
|
+
print(f">> Error: {e}", file=sys.stderr)
|
|
187
|
+
continue
|
|
188
|
+
|
|
189
|
+
else:
|
|
190
|
+
print(f">> Error ({year}) {r.status_code}: {r.content}", file=sys.stderr)
|
|
191
|
+
|
|
192
|
+
if i % 500 == 0:
|
|
193
|
+
with open(f"nbi_data-{i}.json", "w") as f:
|
|
194
|
+
json.dump(data, f, indent=2)
|
|
195
|
+
|
|
196
|
+
return data
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
if __name__ == '__main__':
|
|
200
|
+
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0"
|
|
201
|
+
request_verification_token = 'CfDJ8M6CuWz5hhxGnmUVXw2yDHQlfeNDzVoF03IbAJ0p3LdaDW7poklPvy74ykYda-qwcrtUXD4rnNzn583Ug7PWbR9IlomGzQh1OQIw_pa9d5TNwdN5p77SDfIfz3yq1nWPzxemEn_8bbh7TGGK9FIwcRY'
|
|
202
|
+
cookie = "_ga=GA1.1.478241025.1718907711; _ga_0623JYSC1Q=GS1.1.1718922743.2.0.1718922743.0.0.0; _ga_VW1SFWJKBB=GS1.1.1730789269.3.0.1730789272.0.0.0; _ga_CSLL4ZEK4L=GS1.1.1730789269.3.0.1730789272.0.0.0; _ga_NQ5ZN114SB=GS1.1.1730789269.3.0.1730789272.0.0.0; .AspNetCore.Session=CfDJ8M6CuWz5hhxGnmUVXw2yDHRQxNlIdqc8pBGKOJhMcHphMelhCyOQD7cnzYLVUWcsfCE8KOO8TNogarX5FbmvNQeSW1pTphWgR%2B6RLzPiUWuR4yPiDmb6rg82isfHqoEBhFoziXpFlU2o9pMgQICLsy7WbaeZbSgOl6FTg5Y0vLQ5; __RequestVerificationToken=CfDJ8M6CuWz5hhxGnmUVXw2yDHQXNjHWpjZ61I-CMSrl0yWsdWpCyt2QhUoeZ2L2aY0sqNpGy-wrD8ToMph6-wbfcRPpqORdlVci0ghxWu-3i4PCuWsiOkq90E1WupEYErSXnhsQVwHHGcD63WI7qyXZd7w; _ga_GNYE9X3V7H=GS1.1.1730825963.2.1.1730825988.0.0.0"
|
|
203
|
+
|
|
204
|
+
headers = {
|
|
205
|
+
'authority': 'infobridge.fhwa.dot.gov',
|
|
206
|
+
'origin': 'https://infobridge.fhwa.dot.gov',
|
|
207
|
+
'sec-fetch-site': 'same-origin',
|
|
208
|
+
'sec-fetch-mode': 'cors',
|
|
209
|
+
'accept-encoding': 'gzip, deflate, br',
|
|
210
|
+
'accept-language': 'en-US,en;q=0.9',
|
|
211
|
+
|
|
212
|
+
'__requestverificationtoken': request_verification_token,
|
|
213
|
+
'user-agent': user_agent,
|
|
214
|
+
'cookie': cookie
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if len(sys.argv) == 1:
|
|
218
|
+
|
|
219
|
+
headers.update({
|
|
220
|
+
'x-requested-with': 'XMLHttpRequest',
|
|
221
|
+
'content-type': 'application/json; charset=UTF-8',
|
|
222
|
+
'accept': 'application/json, text/javascript, */*; q=0.01',
|
|
223
|
+
'referer': 'https://infobridge.fhwa.dot.gov/Data',
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
bridgeTable = getBridgeList(headers, start_page=511, totalpages=808, pagesize=100)
|
|
227
|
+
print(json.dumps(bridgeTable, indent=2))
|
|
228
|
+
with open(f"nbi_codes-california-test.json","w") as f:
|
|
229
|
+
# with open(f"nbi_codes-california.json","w") as f:
|
|
230
|
+
json.dump(bridgeTable,f,indent=2)
|
|
231
|
+
sys.exit()
|
|
232
|
+
|
|
233
|
+
elif len(sys.argv) == 2:
|
|
234
|
+
headers.update({
|
|
235
|
+
'datatype': 'json',
|
|
236
|
+
'content-type': 'application/json; charset=UTF-8',
|
|
237
|
+
'accept': 'application/json, text/plain, */*'
|
|
238
|
+
})
|
|
239
|
+
bridgeTable = json.load(open(sys.argv[1]))
|
|
240
|
+
bridgeTable = [
|
|
241
|
+
i for i in bridgeTable
|
|
242
|
+
if " " in i["STRUCTURE_NUMBER"] and len(i["STRUCTURE_NUMBER"]) in {7, 8}
|
|
243
|
+
]
|
|
244
|
+
|
|
245
|
+
# calids = list(map(str.strip, open("init/calid.txt").readlines()))
|
|
246
|
+
# bridgeTable = [i for i in bridgeTable if i["STRUCTURE_NUMBER"] in calids]
|
|
247
|
+
|
|
248
|
+
nbi_data = getNBIData(headers, bridgeTable[:], years=(2024,)) #range(2020, 2024))
|
|
249
|
+
print(json.dumps(nbi_data, indent=2))
|
|
250
|
+
with open(f"nbi_data-california-test.json","w") as f:
|
|
251
|
+
# with open(f"nbi_data-california.json","w") as f:
|
|
252
|
+
json.dump(nbi_data,f,indent=2)
|
|
253
|
+
|
|
254
|
+
else:
|
|
255
|
+
arg1 = sys.argv[1]
|
|
256
|
+
args2 = iter(sys.argv[2:])
|
|
257
|
+
|
|
258
|
+
if arg1 in ["--help", "-h"]:
|
|
259
|
+
print(HELP)
|
|
260
|
+
sys.exit
|
|
261
|
+
else:
|
|
262
|
+
headers.update({
|
|
263
|
+
'datatype': 'json',
|
|
264
|
+
'content-type': 'application/json; charset=UTF-8',
|
|
265
|
+
'accept': 'application/json, text/plain, */*'
|
|
266
|
+
})
|
|
267
|
+
bridgeTable = json.load(open(sys.argv[1]))
|
|
268
|
+
for arg in args2:
|
|
269
|
+
if arg in ["--help", "-h"]:
|
|
270
|
+
print(HELP)
|
|
271
|
+
sys.exit
|
|
272
|
+
elif arg in ["--filter-calid", "-fc"]:
|
|
273
|
+
calid = next(args2)
|
|
274
|
+
bridgeTable = [
|
|
275
|
+
i for i in bridgeTable
|
|
276
|
+
if calid in i["STRUCTURE_NUMBER"]
|
|
277
|
+
]
|
|
278
|
+
file_ending = calid
|
|
279
|
+
elif arg in ["--filter-list", "-fl"]:
|
|
280
|
+
filename = next(args2)
|
|
281
|
+
with open(filename, 'r') as file:
|
|
282
|
+
# Check if this is dependent on a specific txt structure (currently 1 bridge/line)
|
|
283
|
+
calid = [line.strip() for line in file]
|
|
284
|
+
# print(calid)
|
|
285
|
+
bridgeTable = [
|
|
286
|
+
i for i in bridgeTable
|
|
287
|
+
if any(j in i["STRUCTURE_NUMBER"] for j in calid)
|
|
288
|
+
]
|
|
289
|
+
# print(bridgeTable)
|
|
290
|
+
file_ending = Path(filename).name
|
|
291
|
+
|
|
292
|
+
# calids = list(map(str.strip, open("init/calid.txt").readlines()))
|
|
293
|
+
# bridgeTable = [i for i in bridgeTable if i["STRUCTURE_NUMBER"] in calids]
|
|
294
|
+
|
|
295
|
+
nbi_data = getNBIData(headers, bridgeTable[:], years=(2024,)) #range(2020, 2024))
|
|
296
|
+
print(json.dumps(nbi_data, indent=2))
|
|
297
|
+
|
|
298
|
+
# TODO: remove this and replace with arg parsing
|
|
299
|
+
tab = ...
|
|
300
|
+
|
|
301
|
+
with open(f"{tab}_data-{file_ending}.json","w") as f:
|
|
302
|
+
# with open(f"nbi_data-california.json","w") as f:
|
|
303
|
+
json.dump(nbi_data,f,indent=2)
|
|
304
|
+
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"""
|
|
2
|
-
python manage.py shell < scripts/make_assets.py
|
|
3
|
-
"""
|
|
4
1
|
import irie
|
|
5
2
|
import lzma
|
|
6
3
|
import tarfile
|
|
@@ -47,6 +44,13 @@ SKIP_DESIGN = {
|
|
|
47
44
|
|
|
48
45
|
#-----------------------------------
|
|
49
46
|
|
|
47
|
+
def nbi_reshape(raw):
|
|
48
|
+
data = defaultdict(dict)
|
|
49
|
+
for row in raw["Results"]["NBIData"]["NBIDataList"]:
|
|
50
|
+
data[row["TABLE_NAME"]][row["EXPANDED_FIELD_ALIAS"]] = row["FIELD_VALUE"]
|
|
51
|
+
|
|
52
|
+
return dict(data)
|
|
53
|
+
|
|
50
54
|
|
|
51
55
|
def load_assets(NBI_DATA):
|
|
52
56
|
|
|
@@ -57,16 +61,12 @@ def load_assets(NBI_DATA):
|
|
|
57
61
|
return {}
|
|
58
62
|
|
|
59
63
|
def get_nbi(calid, missing_ok=False):
|
|
60
|
-
data = defaultdict(dict)
|
|
61
64
|
|
|
62
65
|
if missing_ok and calid not in NBI_DATA:
|
|
63
66
|
return None
|
|
64
67
|
|
|
65
|
-
blocks = NBI_DATA[calid]
|
|
66
|
-
|
|
67
|
-
data[row["TABLE_NAME"]][row["EXPANDED_FIELD_ALIAS"]] = row["FIELD_VALUE"]
|
|
68
|
-
|
|
69
|
-
return dict(data)
|
|
68
|
+
blocks = NBI_DATA[calid][-1]
|
|
69
|
+
return nbi_reshape(blocks)
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
def get_route(bridge):
|
|
@@ -101,10 +101,10 @@ def load_assets(NBI_DATA):
|
|
|
101
101
|
for calid in CESMD: #BRIDGES.values():
|
|
102
102
|
# if "calid" not in bridge:
|
|
103
103
|
try:
|
|
104
|
-
calid = Asset.objects.get(calid=calid).calid
|
|
104
|
+
calid = Asset.objects.get(calid=calid).calid
|
|
105
105
|
except:
|
|
106
106
|
continue
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
calid = calid.split(" ")[0].replace("-", " ")
|
|
109
109
|
nbi = get_nbi(calid, missing_ok=True)
|
|
110
110
|
if nbi is not None:
|
|
File without changes
|