irie 0.0.5__py3-none-any.whl → 0.0.6__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/config.py +0 -1
- irie/apps/evaluation/identification.py +1 -1
- irie/apps/evaluation/models.py +3 -3
- irie/apps/evaluation/views.py +3 -3
- irie/apps/events/admin.py +2 -2
- irie/apps/events/migrations/0002_rename_event_eventrecord.py +19 -0
- irie/apps/events/migrations/0003_hazardevent.py +21 -0
- irie/apps/events/models.py +55 -5
- irie/apps/events/views.py +48 -3
- irie/apps/events/views_events.py +6 -10
- irie/apps/inventory/filters.py +37 -0
- irie/apps/inventory/models.py +7 -0
- irie/apps/inventory/urls.py +1 -0
- irie/apps/inventory/views.py +134 -227
- irie/apps/prediction/forms.py +4 -8
- irie/apps/prediction/metrics.py +0 -2
- irie/apps/prediction/migrations/0002_alter_predictormodel_protocol.py +18 -0
- irie/apps/prediction/models.py +4 -4
- irie/apps/prediction/predictor.py +18 -12
- irie/apps/prediction/runners/__init__.py +3 -398
- irie/apps/prediction/runners/hazus.py +579 -0
- irie/apps/prediction/runners/opensees/__init__.py +395 -0
- irie/apps/prediction/runners/{utilities.py → opensees/utilities.py} +7 -7
- irie/apps/prediction/runners/ssid.py +414 -0
- irie/apps/prediction/urls.py +1 -1
- irie/apps/prediction/views.py +45 -22
- irie/apps/site/view_sdof.py +2 -2
- irie/apps/templates/admin/base_site.html +3 -1
- irie/apps/templates/css/admin-extra.css +7 -0
- irie/apps/templates/includes/sidebar.html +17 -14
- irie/apps/templates/inventory/asset-event-summary.html +3 -2
- irie/apps/templates/inventory/asset-profile.html +126 -38
- irie/apps/templates/inventory/asset-table.html +191 -135
- irie/apps/templates/inventory/dashboard.html +105 -27
- irie/apps/templates/inventory/preamble.tex +131 -0
- irie/apps/templates/inventory/report.tex +59 -0
- irie/apps/templates/networks/corridor_table.html +2 -2
- irie/apps/templates/networks/networks.html +164 -0
- irie/apps/templates/prediction/asset-predictors.html +6 -6
- irie/apps/templates/prediction/form-submission.html +3 -3
- irie/apps/templates/prediction/hazus/event.html +33 -0
- irie/apps/templates/prediction/hazus/history.html +1 -0
- irie/apps/templates/prediction/hazus/history.js +44 -0
- irie/apps/templates/prediction/{new-predictor.html → new-runner.html} +12 -8
- irie/apps/templates/site/index.html +29 -47
- irie/core/urls.py +7 -2
- irie/init/__main__.py +2 -0
- irie/init/bridges.py +5 -3
- irie/init/management/commands/init_assets.py +24 -45
- irie/init/management/commands/init_corridors.py +3 -6
- irie/init/management/commands/init_predictors.py +23 -8
- irie/post/__main__.py +88 -0
- {irie-0.0.5.dist-info → irie-0.0.6.dist-info}/METADATA +5 -3
- {irie-0.0.5.dist-info → irie-0.0.6.dist-info}/RECORD +61 -47
- /irie/apps/prediction/runners/{metrics.py → opensees/metrics.py} +0 -0
- /irie/apps/prediction/runners/{xmlutils.py → opensees/xmlutils.py} +0 -0
- /irie/apps/prediction/runners/{zipped.py → opensees/zipped.py} +0 -0
- /irie/init/data/{04.tar → nbi/04.tar} +0 -0
- {irie-0.0.5.dist-info → irie-0.0.6.dist-info}/WHEEL +0 -0
- {irie-0.0.5.dist-info → irie-0.0.6.dist-info}/entry_points.txt +0 -0
- {irie-0.0.5.dist-info → irie-0.0.6.dist-info}/top_level.txt +0 -0
irie/apps/inventory/views.py
CHANGED
|
@@ -10,16 +10,21 @@
|
|
|
10
10
|
#----------------------------------------------------------------------------#
|
|
11
11
|
import os
|
|
12
12
|
import re
|
|
13
|
+
import json
|
|
14
|
+
import base64
|
|
15
|
+
import numpy as np
|
|
13
16
|
from django.core.paginator import Paginator
|
|
14
|
-
from django.template import loader
|
|
17
|
+
from django.template import loader
|
|
15
18
|
from django.http import HttpResponse
|
|
16
19
|
from django.contrib.auth.decorators import login_required
|
|
17
|
-
from django.core.exceptions import ObjectDoesNotExist
|
|
18
20
|
|
|
19
|
-
from irie.apps.events.models import
|
|
21
|
+
from irie.apps.events.models import EventRecord
|
|
20
22
|
from irie.apps.site.view_utils import raise404
|
|
21
23
|
from irie.apps.inventory.models import Asset
|
|
22
|
-
from
|
|
24
|
+
from .filters import AssetFilter
|
|
25
|
+
# Predictors
|
|
26
|
+
from irie.apps.prediction.runners.hazus import hazus_fragility
|
|
27
|
+
from irie.apps.prediction.runners.ssid import make_mountains, ssid_stats, ssid_event_plot
|
|
23
28
|
|
|
24
29
|
|
|
25
30
|
@login_required(login_url="/login/")
|
|
@@ -34,37 +39,13 @@ def fetch_rendering(request):
|
|
|
34
39
|
|
|
35
40
|
from irie.apps.prediction.models import PredictorModel
|
|
36
41
|
for p in PredictorModel.objects.filter(asset=asset):
|
|
37
|
-
if p.protocol == "
|
|
42
|
+
if p.protocol == "IRIE_PREDICTOR_T4":
|
|
38
43
|
return HttpResponse("html")
|
|
39
44
|
|
|
40
45
|
return HttpResponse("No rendering available for this asset.")
|
|
41
46
|
|
|
42
47
|
|
|
43
48
|
|
|
44
|
-
def _make_freq_plot(evaluation):
|
|
45
|
-
import numpy as np
|
|
46
|
-
from mdof.macro import FrequencyContent
|
|
47
|
-
|
|
48
|
-
plot = FrequencyContent(scale=True, period=True, xlabel="Period (s)", ylabel="Normalized Amplitude")
|
|
49
|
-
|
|
50
|
-
for name, mdata in evaluation["summary"].items():
|
|
51
|
-
periods = []
|
|
52
|
-
amplitudes = []
|
|
53
|
-
for i in mdata.get("data", []):
|
|
54
|
-
if "period" in i:
|
|
55
|
-
periods.append(i["period"])
|
|
56
|
-
if "amplitude" in i:
|
|
57
|
-
amplitudes.append(i["amplitude"])
|
|
58
|
-
|
|
59
|
-
if len(amplitudes) and (len(amplitudes) == len(periods)):
|
|
60
|
-
plot.add(np.array(periods), np.array(amplitudes), label=name)
|
|
61
|
-
else:
|
|
62
|
-
plot.add(np.array(periods), label=name)
|
|
63
|
-
|
|
64
|
-
fig = plot.get_figure()
|
|
65
|
-
return fig.to_json()
|
|
66
|
-
|
|
67
|
-
|
|
68
49
|
@login_required(login_url="/login/")
|
|
69
50
|
def asset_event_summary(request, cesmd, event):
|
|
70
51
|
from irie.apps.evaluation.models import Evaluation
|
|
@@ -74,7 +55,6 @@ def asset_event_summary(request, cesmd, event):
|
|
|
74
55
|
html_template = loader.get_template("inventory/asset-event-summary.html")
|
|
75
56
|
|
|
76
57
|
try:
|
|
77
|
-
|
|
78
58
|
segments = request.path.split("/")
|
|
79
59
|
_, _, is_nce = segments[-3:]
|
|
80
60
|
|
|
@@ -94,7 +74,7 @@ def asset_event_summary(request, cesmd, event):
|
|
|
94
74
|
|
|
95
75
|
if "SPECTRAL_SHIFT_IDENTIFICATION" in evaluation_data:
|
|
96
76
|
context["freq_plot_json"] = \
|
|
97
|
-
|
|
77
|
+
ssid_event_plot(evaluation_data["SPECTRAL_SHIFT_IDENTIFICATION"])
|
|
98
78
|
|
|
99
79
|
context["all_evaluations"] = evaluation_data
|
|
100
80
|
|
|
@@ -107,7 +87,7 @@ def asset_event_summary(request, cesmd, event):
|
|
|
107
87
|
}
|
|
108
88
|
context["asset"] = evaluation and evaluation.event.asset or None
|
|
109
89
|
context["nce_version"] = is_nce
|
|
110
|
-
context["event_data"] =
|
|
90
|
+
context["event_data"] = EventRecord.objects.get(pk=int(event)).motion_data
|
|
111
91
|
|
|
112
92
|
|
|
113
93
|
resp = html_template.render(context, request)
|
|
@@ -120,6 +100,7 @@ def asset_event_summary(request, cesmd, event):
|
|
|
120
100
|
html_template = loader.get_template("site/page-500.html")
|
|
121
101
|
return HttpResponse(html_template.render(context, request))
|
|
122
102
|
|
|
103
|
+
|
|
123
104
|
@login_required(login_url="/login/")
|
|
124
105
|
def dashboard(request):
|
|
125
106
|
from irie.apps.inventory.models import Asset
|
|
@@ -132,15 +113,18 @@ def dashboard(request):
|
|
|
132
113
|
context["demo_version"] = True
|
|
133
114
|
|
|
134
115
|
context["recent_evaluations"] = [
|
|
135
|
-
(evaluation,
|
|
116
|
+
(evaluation, EventRecord.objects.get(pk=evaluation.event_id))
|
|
136
117
|
for evaluation in reversed(list(Evaluation.objects.all())[-6:])
|
|
137
118
|
]
|
|
138
|
-
assets =
|
|
119
|
+
assets = list(set(
|
|
139
120
|
Asset.objects.get(cesmd=event[1].cesmd) for event in context["recent_evaluations"]
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
121
|
+
))
|
|
122
|
+
colors = {
|
|
123
|
+
asset.id: max(event[1].pga for event in context["recent_evaluations"] if event[1].cesmd == asset.cesmd)
|
|
124
|
+
for asset in assets
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
context["asset_map"] = AssetMap(assets, colors=colors, color_name="Peak Station Accel.").get_html()
|
|
144
128
|
context["calid"] = {b.cesmd: b.calid for b in assets}
|
|
145
129
|
|
|
146
130
|
html_template = loader.get_template("inventory/dashboard.html")
|
|
@@ -154,105 +138,36 @@ def dashboard(request):
|
|
|
154
138
|
|
|
155
139
|
|
|
156
140
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
mode_results = [
|
|
161
|
-
[
|
|
162
|
-
{
|
|
163
|
-
"period": ...,
|
|
164
|
-
"frequency": ...,
|
|
165
|
-
"damping": ...,
|
|
166
|
-
"emac": ...,
|
|
167
|
-
"mpc": ...,
|
|
168
|
-
},
|
|
169
|
-
...
|
|
170
|
-
],
|
|
171
|
-
...
|
|
172
|
-
]
|
|
141
|
+
@login_required(login_url="/login/")
|
|
142
|
+
def asset_event_report(request):
|
|
143
|
+
from irie.apps.evaluation.models import Evaluation
|
|
173
144
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
"R1": {"period": [1.2]}}
|
|
178
|
-
]
|
|
179
|
-
"""
|
|
180
|
-
mode_results = [_find_ssid(event.id) for event in events]
|
|
181
|
-
import numpy as np
|
|
182
|
-
|
|
183
|
-
filtered_results = [
|
|
184
|
-
{
|
|
185
|
-
method: [
|
|
186
|
-
result for result in event_results[method]
|
|
187
|
-
if key in result and result.get("emac", 1.0) > 0.5 and result.get("mpc", 1.0) > 0.5
|
|
188
|
-
] for method in event_results
|
|
189
|
-
} for event_results in mode_results
|
|
190
|
-
]
|
|
145
|
+
context = {}
|
|
146
|
+
context["segment"] = "events"
|
|
147
|
+
html_template = loader.get_template("inventory/report.tex")
|
|
191
148
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
for method in event:
|
|
196
|
-
for result in event[method]:
|
|
197
|
-
values[method].append(result[key])
|
|
198
|
-
|
|
199
|
-
mean = {method: np.mean(values[method]) for method in values}
|
|
200
|
-
std = {method: np.std(values[method]) for method in values}
|
|
201
|
-
|
|
202
|
-
def _first(method_results):
|
|
203
|
-
if method_results and len(method_results) > 0:
|
|
204
|
-
results = np.array([result[key] for result in method_results])
|
|
205
|
-
try:
|
|
206
|
-
idx = np.argmax([result["amplitude"] for result in method_results])
|
|
207
|
-
return results[idx]
|
|
208
|
-
except KeyError:
|
|
209
|
-
return np.max(results)
|
|
210
|
-
else:
|
|
211
|
-
return {}
|
|
212
|
-
|
|
213
|
-
return [
|
|
214
|
-
{method: {
|
|
215
|
-
# "distance": (closest_item[key]-mean)/std),
|
|
216
|
-
"nearest_mean": event_results[method][np.argmin(np.abs(mean[method] \
|
|
217
|
-
- [result[key] for result in event_results[method]]))] \
|
|
218
|
-
if event_results[method] and len(event_results[method]) > 0 else {} ,
|
|
219
|
-
"maximum": _first(event_results[method])
|
|
220
|
-
}
|
|
221
|
-
for method in event_results
|
|
222
|
-
}
|
|
223
|
-
for event_results in filtered_results
|
|
149
|
+
events = [
|
|
150
|
+
EventRecord.objects.get(pk=evaluation.event_id)
|
|
151
|
+
for evaluation in reversed(list(Evaluation.objects.all())[-6:])
|
|
224
152
|
]
|
|
153
|
+
assets = list(set(
|
|
154
|
+
Asset.objects.get(cesmd=event.cesmd) for event in events
|
|
155
|
+
))
|
|
156
|
+
context["events"] = events
|
|
157
|
+
context["assets"] = assets
|
|
225
158
|
|
|
159
|
+
context["mountains"] = []
|
|
226
160
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
Given an event ID, finds the results of the first configured
|
|
230
|
-
system ID run. This generally looks like a list of dicts,
|
|
231
|
-
each with fields "frequency", "damping", etc.
|
|
232
|
-
"""
|
|
233
|
-
from irie.apps.evaluation.models import Evaluation
|
|
161
|
+
if request.method == 'POST' and request.FILES.get('map_image'):
|
|
162
|
+
context["map"] = base64.b64encode(request.FILES['map_image'].read()).decode("utf-8")
|
|
234
163
|
|
|
235
|
-
|
|
236
|
-
|
|
164
|
+
for event in events:
|
|
165
|
+
context["mountains"].append(make_mountains(event.asset))
|
|
237
166
|
|
|
238
|
-
|
|
239
|
-
evaluation = [evaluation]
|
|
167
|
+
resp = html_template.render(context, request)
|
|
240
168
|
|
|
169
|
+
return HttpResponse(resp)
|
|
241
170
|
|
|
242
|
-
if len(evaluation) != 1:
|
|
243
|
-
return []
|
|
244
|
-
|
|
245
|
-
else:
|
|
246
|
-
evaluation_data = evaluation[0].evaluation_data
|
|
247
|
-
|
|
248
|
-
if "SPECTRAL_SHIFT_IDENTIFICATION" in evaluation_data:
|
|
249
|
-
return {
|
|
250
|
-
key: val.get("data", val.get("error", []))
|
|
251
|
-
for key,val in evaluation_data["SPECTRAL_SHIFT_IDENTIFICATION"]["summary"].items()
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
else:
|
|
255
|
-
return []
|
|
256
171
|
|
|
257
172
|
|
|
258
173
|
@login_required(login_url="/login/")
|
|
@@ -267,17 +182,41 @@ def asset_profile(request, calid):
|
|
|
267
182
|
try:
|
|
268
183
|
asset = Asset.objects.get(calid=calid)
|
|
269
184
|
|
|
270
|
-
except
|
|
185
|
+
except Asset.DoesNotExist:
|
|
271
186
|
return raise404(request, context)
|
|
272
187
|
|
|
273
188
|
context["asset"] = asset
|
|
274
189
|
|
|
190
|
+
# Compute Hazus fragility probabilities and curve
|
|
191
|
+
try:
|
|
192
|
+
hazus_results = hazus_fragility(asset.nbi_data, generate_plot=False, return_data=True)
|
|
193
|
+
|
|
194
|
+
# Add fragility probabilities and plot to the context
|
|
195
|
+
context["hazus"] = {
|
|
196
|
+
"probabilities": {
|
|
197
|
+
"Slight": hazus_results.get("Slight"),
|
|
198
|
+
"Moderate": hazus_results.get("Moderate"),
|
|
199
|
+
"Extensive": hazus_results.get("Extensive"),
|
|
200
|
+
"Complete": hazus_results.get("Complete"),
|
|
201
|
+
},
|
|
202
|
+
"sa_range": json.dumps(hazus_results["sa_range"]),
|
|
203
|
+
"curves": json.dumps(hazus_results["curves"])
|
|
204
|
+
# "plot_base64": hazus_results.get("plot_base64"),
|
|
205
|
+
}
|
|
206
|
+
except:
|
|
207
|
+
pass
|
|
208
|
+
|
|
209
|
+
try:
|
|
210
|
+
context["mountains"] = make_mountains(asset)
|
|
211
|
+
except:
|
|
212
|
+
pass
|
|
213
|
+
|
|
275
214
|
context["tables"] = _make_tables(asset)
|
|
276
215
|
|
|
277
216
|
if asset.cesmd:
|
|
278
217
|
cesmd = asset.cesmd
|
|
279
218
|
|
|
280
|
-
events = list(reversed(sorted(
|
|
219
|
+
events = list(reversed(sorted(EventRecord.objects.filter(cesmd=cesmd),
|
|
281
220
|
key=lambda x: x.motion_data["event_date"])))
|
|
282
221
|
|
|
283
222
|
evals = [
|
|
@@ -285,17 +224,13 @@ def asset_profile(request, calid):
|
|
|
285
224
|
"pga": event.pga, #abs(event.motion_data["peak_accel"])/980.,
|
|
286
225
|
"evaluation": ssid,
|
|
287
226
|
}
|
|
288
|
-
for i, (event, ssid) in enumerate(zip(events,
|
|
227
|
+
for i, (event, ssid) in enumerate(zip(events, ssid_stats(events, "period")))
|
|
289
228
|
]
|
|
290
229
|
context["evaluations"] = Paginator(evals, 5).get_page(1)
|
|
291
230
|
|
|
292
231
|
try:
|
|
293
232
|
return HttpResponse(html_template.render(context, request))
|
|
294
233
|
|
|
295
|
-
# except TemplateDoesNotExist:
|
|
296
|
-
# context["rendering"] = None
|
|
297
|
-
# return HttpResponse(html_template.render(context, request))
|
|
298
|
-
|
|
299
234
|
except Exception as e:
|
|
300
235
|
if "DEBUG" in os.environ and os.environ["DEBUG"]:
|
|
301
236
|
raise e
|
|
@@ -303,16 +238,16 @@ def asset_profile(request, calid):
|
|
|
303
238
|
return HttpResponse(html_template.render(context, request))
|
|
304
239
|
|
|
305
240
|
def _make_tables(asset):
|
|
306
|
-
if asset.cesmd:
|
|
241
|
+
if asset.cesmd and isinstance(asset.cgs_data, list):
|
|
307
242
|
tables = [
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
243
|
+
{k: v for k,v in group.items()
|
|
244
|
+
if k not in {
|
|
245
|
+
"Remarks",
|
|
246
|
+
"Instrumentation",
|
|
247
|
+
"Remarks/Notes",
|
|
248
|
+
"Construction Date"
|
|
249
|
+
}
|
|
250
|
+
} for group in asset.cgs_data[1:]
|
|
316
251
|
]
|
|
317
252
|
else:
|
|
318
253
|
tables = []
|
|
@@ -368,7 +303,6 @@ def asset_table(request):
|
|
|
368
303
|
|
|
369
304
|
context = {}
|
|
370
305
|
context["segment"] = "assets"
|
|
371
|
-
html_template = loader.get_template("inventory/asset-table.html")
|
|
372
306
|
|
|
373
307
|
page = request.GET.get("page", 1)
|
|
374
308
|
try:
|
|
@@ -376,12 +310,20 @@ def asset_table(request):
|
|
|
376
310
|
except:
|
|
377
311
|
page = 1
|
|
378
312
|
|
|
379
|
-
|
|
313
|
+
filter_set = AssetFilter(request.GET, queryset=Asset.objects.all())
|
|
314
|
+
assets = filter_set.qs
|
|
380
315
|
context["bridges"] = Paginator(assets, 10).get_page(page)
|
|
381
|
-
context["asset_map"] = AssetMap(assets=assets
|
|
382
|
-
|
|
383
|
-
layer_assets=True).get_html()
|
|
316
|
+
context["asset_map"] = AssetMap(assets=assets).get_html()
|
|
317
|
+
context["filter"] = filter_set
|
|
384
318
|
|
|
319
|
+
|
|
320
|
+
# Copy the GET parameters and remove the 'page' parameter
|
|
321
|
+
query_params = request.GET.copy()
|
|
322
|
+
query_params.pop('page', None) # Remove 'page' parameter if it exists
|
|
323
|
+
context["query_string"] = query_params.urlencode()
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
html_template = loader.get_template("inventory/asset-table.html")
|
|
385
327
|
try:
|
|
386
328
|
return HttpResponse(html_template.render(context, request))
|
|
387
329
|
|
|
@@ -394,54 +336,57 @@ def asset_table(request):
|
|
|
394
336
|
|
|
395
337
|
|
|
396
338
|
import folium
|
|
397
|
-
from folium import branca
|
|
398
339
|
|
|
399
340
|
class AssetMap:
|
|
400
|
-
def __init__(self,
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
341
|
+
def __init__(self, assets, name=None, colors=None, color_name=None):
|
|
342
|
+
if name is None:
|
|
343
|
+
name = "Assets"
|
|
344
|
+
|
|
345
|
+
if colors is not None:
|
|
346
|
+
cm = folium.branca.colormap.LinearColormap(colors=["green", "yellow", "orange", "red"],
|
|
347
|
+
vmin=0, vmax=max(colors.values()),
|
|
348
|
+
caption=color_name)
|
|
349
|
+
colors = {
|
|
350
|
+
k: cm.rgb_hex_str(v) for k,v in colors.items()
|
|
351
|
+
}
|
|
352
|
+
else:
|
|
353
|
+
cm = None
|
|
406
354
|
|
|
355
|
+
markers = self.add_bridges(assets, colors=colors)
|
|
407
356
|
|
|
408
|
-
|
|
357
|
+
if len(markers) > 0:
|
|
358
|
+
location = sum(np.array(m.location) for m in markers) / len(markers)
|
|
359
|
+
else:
|
|
360
|
+
location = [37.7735, -122.0993] # (self._preferences.latitude, self._preferences.longitude)
|
|
409
361
|
|
|
410
|
-
self._figure = figure = folium.Figure()
|
|
362
|
+
# self._figure = figure = folium.Figure()
|
|
411
363
|
self._map = m = folium.Map(
|
|
412
|
-
location=
|
|
364
|
+
location=location,
|
|
365
|
+
zoom_start=6,
|
|
366
|
+
tiles='cartodbpositron'
|
|
413
367
|
)
|
|
414
368
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
name='Instrumented Bridges'
|
|
418
|
-
).add_to(m)
|
|
419
|
-
m.add_to(figure)
|
|
369
|
+
if cm is not None:
|
|
370
|
+
cm.add_to(m)
|
|
420
371
|
|
|
421
|
-
|
|
422
|
-
|
|
372
|
+
for marker in markers:
|
|
373
|
+
marker.add_to(m)
|
|
423
374
|
|
|
424
|
-
if traffic:
|
|
425
|
-
self.add_traffic()
|
|
426
375
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
"partial": folium.FeatureGroup(name="Partial Digital Twins"),
|
|
431
|
-
"complete": folium.FeatureGroup(name="Full Digital Twins")
|
|
432
|
-
}
|
|
433
|
-
list(map(lambda i: i.add_to(self._map), self._asset_layers.values()))
|
|
434
|
-
self.add_twins(list(self._asset_layers.values()))
|
|
376
|
+
# CESMD
|
|
377
|
+
# Partial
|
|
378
|
+
# Full
|
|
435
379
|
|
|
436
380
|
|
|
437
381
|
def get_html(self, **kwargs):
|
|
438
|
-
folium.LayerControl(collapsed=False).add_to(self._map)
|
|
439
|
-
self._figure.render()
|
|
440
382
|
return self._map._repr_html_()
|
|
441
383
|
|
|
442
|
-
def
|
|
384
|
+
def add_bridges(self, assets, colors=None):
|
|
385
|
+
if colors is None:
|
|
386
|
+
colors = {}
|
|
443
387
|
|
|
444
|
-
|
|
388
|
+
markers = []
|
|
389
|
+
for b in assets:
|
|
445
390
|
lat, lon = b.coordinates
|
|
446
391
|
popup = folium.Popup(
|
|
447
392
|
folium.Html(
|
|
@@ -455,61 +400,23 @@ class AssetMap:
|
|
|
455
400
|
max_width=100
|
|
456
401
|
)
|
|
457
402
|
if b.is_complete:
|
|
458
|
-
folium.Marker(
|
|
403
|
+
markers.append(folium.Marker(
|
|
459
404
|
location=[lat, lon],
|
|
460
405
|
popup=popup,
|
|
461
406
|
icon=folium.Icon(icon="cloud", color="blue" if not b.is_complete else "beige"),
|
|
462
407
|
z_index_offset=1000
|
|
463
|
-
)
|
|
408
|
+
))
|
|
464
409
|
else:
|
|
465
|
-
folium.CircleMarker(
|
|
410
|
+
markers.append(folium.CircleMarker(
|
|
466
411
|
location=[lat, lon],
|
|
467
412
|
popup=popup,
|
|
468
|
-
color="
|
|
413
|
+
color="black",
|
|
414
|
+
fill_color=colors.get(b.id, "gray"),
|
|
469
415
|
fill=True,
|
|
470
416
|
opacity=1,
|
|
471
417
|
fill_opacity=1,
|
|
472
|
-
radius=
|
|
418
|
+
radius=4,
|
|
419
|
+
weight=1,
|
|
473
420
|
z_index_offset=800
|
|
474
|
-
)
|
|
475
|
-
return
|
|
476
|
-
|
|
477
|
-
def add_CESMD(self):
|
|
478
|
-
cesmdbridges = folium.FeatureGroup(name="Registered Bridges")
|
|
479
|
-
cesmdbridges.add_to(self._map)
|
|
480
|
-
|
|
481
|
-
for b in self._assets:
|
|
482
|
-
if not b.cesmd:
|
|
483
|
-
continue
|
|
484
|
-
lat, lon = b.coordinates
|
|
485
|
-
|
|
486
|
-
folium.Marker(
|
|
487
|
-
location=[lat, lon],
|
|
488
|
-
popup=b.cesmd,
|
|
489
|
-
icon=folium.Icon(icon="glyphicon-road", color="lightgray"),
|
|
490
|
-
).add_to(cesmdbridges)
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
def add_traffic(self):
|
|
494
|
-
# from irie.apps.inventory.traffic import TRAFFIC_LOW, TRAFFIC_MID, TRAFFIC_HIGH, TRAFFIC_ALL
|
|
495
|
-
from irie.apps.inventory.traffic import TRAFFIC_ALL
|
|
496
|
-
traffic = folium.FeatureGroup(name="Traffic")
|
|
497
|
-
traffic.add_to(self._map)
|
|
498
|
-
|
|
499
|
-
cm = branca.colormap.LinearColormap(colors=['green', 'yellow', 'orange', 'red'], vmin=10000, vmax=100000)
|
|
500
|
-
for loc in TRAFFIC_ALL:
|
|
501
|
-
folium.CircleMarker([loc["coords"][1],loc["coords"][0]],
|
|
502
|
-
radius=5,
|
|
503
|
-
popup=None,
|
|
504
|
-
color=cm.rgb_hex_str(loc["properties"]["AHEAD_AADT"]),
|
|
505
|
-
fill=True,
|
|
506
|
-
opacity=0.5,
|
|
507
|
-
weight=0,
|
|
508
|
-
).add_to(traffic)
|
|
509
|
-
|
|
510
|
-
cm = branca.colormap.LinearColormap(colors=['green', 'yellow', 'orange', 'red'],
|
|
511
|
-
vmin=10000, vmax=100000,
|
|
512
|
-
caption='Average Annual Daily Traffic Crossings')
|
|
513
|
-
cm.add_to(self._map)
|
|
514
|
-
|
|
515
|
-
return self
|
|
421
|
+
))
|
|
422
|
+
return markers
|
irie/apps/prediction/forms.py
CHANGED
|
@@ -6,15 +6,11 @@
|
|
|
6
6
|
from django import forms
|
|
7
7
|
from irie.apps.prediction.models import PredictorModel
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
# class CsiForm(forms.Form):
|
|
11
|
-
# option1 = forms.CharField(label='Option 1', max_length=100)
|
|
12
|
-
# option2 = forms.CharField(label='Option 2', max_length=100)
|
|
13
|
-
# file_upload = forms.FileField(label='Upload a file', required=True)
|
|
14
|
-
|
|
15
|
-
|
|
16
9
|
class PredictorForm(forms.ModelForm):
|
|
17
10
|
class Meta:
|
|
18
11
|
model = PredictorModel
|
|
19
12
|
fields = '__all__'
|
|
20
|
-
exclude = ['render_file', '
|
|
13
|
+
exclude = ['render_file', 'asset', 'metrics', 'active',
|
|
14
|
+
'entry_point',
|
|
15
|
+
'config',
|
|
16
|
+
'protocol']
|
irie/apps/prediction/metrics.py
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Generated by Django 5.1.2 on 2024-12-08 02:25
|
|
2
|
+
|
|
3
|
+
from django.db import migrations, models
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Migration(migrations.Migration):
|
|
7
|
+
|
|
8
|
+
dependencies = [
|
|
9
|
+
('apps_prediction', '0001_initial'),
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
operations = [
|
|
13
|
+
migrations.AlterField(
|
|
14
|
+
model_name='predictormodel',
|
|
15
|
+
name='protocol',
|
|
16
|
+
field=models.CharField(choices=[('IRIE_PREDICTOR_V1', 'Type1'), ('IRIE_PREDICTOR_T2', 'Type2'), ('IRIE_PREDICTOR_T3', 'Type3'), ('IRIE_PREDICTOR_T4', 'Type4')], default='IRIE_PREDICTOR_T2', max_length=25),
|
|
17
|
+
),
|
|
18
|
+
]
|
irie/apps/prediction/models.py
CHANGED
|
@@ -10,10 +10,10 @@ from irie.apps.inventory.models import Asset
|
|
|
10
10
|
class PredictorModel(models.Model):
|
|
11
11
|
# https://docs.djangoproject.com/en/4.2/ref/models/fields/
|
|
12
12
|
class Protocol(models.TextChoices):
|
|
13
|
-
TYPE1 = "
|
|
14
|
-
TYPE2 = "
|
|
15
|
-
TYPE3 = "
|
|
16
|
-
TYPE4 = "
|
|
13
|
+
TYPE1 = "IRIE_PREDICTOR_V1"
|
|
14
|
+
TYPE2 = "IRIE_PREDICTOR_T2"
|
|
15
|
+
TYPE3 = "IRIE_PREDICTOR_T3"
|
|
16
|
+
TYPE4 = "IRIE_PREDICTOR_T4"
|
|
17
17
|
|
|
18
18
|
id = models.BigAutoField(primary_key=True)
|
|
19
19
|
name = models.CharField(max_length=35)
|
|
@@ -16,8 +16,13 @@ import subprocess
|
|
|
16
16
|
from pathlib import Path
|
|
17
17
|
from typing import Dict
|
|
18
18
|
|
|
19
|
-
from .runners import
|
|
19
|
+
from .runners import (
|
|
20
|
+
Runner, RunID,
|
|
21
|
+
classproperty
|
|
22
|
+
)
|
|
23
|
+
from .runners.opensees import OpenSeesRunner
|
|
20
24
|
|
|
25
|
+
class Event: pass
|
|
21
26
|
|
|
22
27
|
|
|
23
28
|
class PredictorType1(Runner):
|
|
@@ -38,7 +43,7 @@ class PredictorType1(Runner):
|
|
|
38
43
|
predictor.name = data.pop("name")
|
|
39
44
|
predictor.config = data
|
|
40
45
|
predictor.asset = asset
|
|
41
|
-
predictor.protocol = "
|
|
46
|
+
predictor.protocol = "IRIE_PREDICTOR_T1"
|
|
42
47
|
predictor.active = False
|
|
43
48
|
return predictor
|
|
44
49
|
|
|
@@ -196,7 +201,7 @@ class PredictorType2(Runner):
|
|
|
196
201
|
predictor.name = data.pop("name")
|
|
197
202
|
predictor.config = data
|
|
198
203
|
predictor.asset = asset
|
|
199
|
-
predictor.protocol = "
|
|
204
|
+
predictor.protocol = "IRIE_PREDICTOR_T2"
|
|
200
205
|
predictor.active = True
|
|
201
206
|
return predictor
|
|
202
207
|
|
|
@@ -207,10 +212,11 @@ class PredictorType2(Runner):
|
|
|
207
212
|
|
|
208
213
|
def runPrediction(self, run_id: RunID) -> bool:
|
|
209
214
|
event_file = Path(self.event.event_file.path).resolve()
|
|
210
|
-
# if "config" in self.conf:
|
|
211
215
|
command = [*self.entry_point,
|
|
212
|
-
"--config",
|
|
216
|
+
"--config",
|
|
217
|
+
json.dumps(self.conf),
|
|
213
218
|
event_file]
|
|
219
|
+
|
|
214
220
|
if False:
|
|
215
221
|
command = [*self.entry_point,
|
|
216
222
|
event_file,
|
|
@@ -246,7 +252,7 @@ class PredictorType4(Runner):
|
|
|
246
252
|
predictor.name = config.pop("name")
|
|
247
253
|
predictor.config = config
|
|
248
254
|
predictor.asset = asset
|
|
249
|
-
predictor.protocol = "
|
|
255
|
+
predictor.protocol = "IRIE_PREDICTOR_T4"
|
|
250
256
|
predictor.active = True
|
|
251
257
|
return predictor
|
|
252
258
|
|
|
@@ -267,7 +273,7 @@ class PredictorType4(Runner):
|
|
|
267
273
|
*map(str, self.conf.get("argv", []))]
|
|
268
274
|
|
|
269
275
|
self.metric_details = subprocess.check_output(command).decode()
|
|
270
|
-
print(self.metric_details)
|
|
276
|
+
# print(self.metric_details)
|
|
271
277
|
return True
|
|
272
278
|
|
|
273
279
|
def getMetricData(self, run, metric):
|
|
@@ -277,10 +283,10 @@ class PredictorType4(Runner):
|
|
|
277
283
|
|
|
278
284
|
|
|
279
285
|
PREDICTOR_TYPES : Dict[str, Runner] = {
|
|
280
|
-
"
|
|
281
|
-
"
|
|
282
|
-
"" :
|
|
283
|
-
# "
|
|
284
|
-
"
|
|
286
|
+
"IRIE_PREDICTOR_V1" : PredictorType1,
|
|
287
|
+
"IRIE_PREDICTOR_T2" : PredictorType2,
|
|
288
|
+
"" : PredictorType2,
|
|
289
|
+
# "IRIE_PREDICTOR_T3" : PredictorType3,
|
|
290
|
+
"IRIE_PREDICTOR_T4" : OpenSeesRunner,
|
|
285
291
|
}
|
|
286
292
|
|