irie 0.0.0__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.

Files changed (145) hide show
  1. irie/__main__.py +24 -0
  2. irie/apps/__init__.py +5 -0
  3. irie/apps/authentication/__init__.py +1 -0
  4. irie/apps/authentication/admin.py +1 -0
  5. irie/apps/authentication/config.py +6 -0
  6. irie/apps/authentication/forms.py +41 -0
  7. irie/apps/authentication/migrations/__init__.py +1 -0
  8. irie/apps/authentication/models.py +1 -0
  9. irie/apps/authentication/tests.py +1 -0
  10. irie/apps/authentication/urls.py +9 -0
  11. irie/apps/authentication/views.py +53 -0
  12. irie/apps/config.py +8 -0
  13. irie/apps/context_processors.py +5 -0
  14. irie/apps/documents/__init__.py +0 -0
  15. irie/apps/documents/apps.py +7 -0
  16. irie/apps/documents/documents.py +61 -0
  17. irie/apps/documents/migrations/__init__.py +0 -0
  18. irie/apps/documents/tests.py +3 -0
  19. irie/apps/documents/urls.py +12 -0
  20. irie/apps/documents/views.py +27 -0
  21. irie/apps/evaluation/__init__.py +0 -0
  22. irie/apps/evaluation/admin.py +43 -0
  23. irie/apps/evaluation/apps.py +18 -0
  24. irie/apps/evaluation/daemon.py +107 -0
  25. irie/apps/evaluation/identification.py +196 -0
  26. irie/apps/evaluation/migrations/0001_initial.py +25 -0
  27. irie/apps/evaluation/migrations/0002_remove_evaluation_cesmd.py +17 -0
  28. irie/apps/evaluation/migrations/0003_evaluation_asset.py +20 -0
  29. irie/apps/evaluation/migrations/__init__.py +0 -0
  30. irie/apps/evaluation/models.py +72 -0
  31. irie/apps/evaluation/urls.py +16 -0
  32. irie/apps/evaluation/views.py +68 -0
  33. irie/apps/events/__init__.py +0 -0
  34. irie/apps/events/admin.py +9 -0
  35. irie/apps/events/apps.py +12 -0
  36. irie/apps/events/migrations/0001_initial.py +27 -0
  37. irie/apps/events/migrations/0002_alter_event_id.py +18 -0
  38. irie/apps/events/migrations/0003_event_cesmd.py +19 -0
  39. irie/apps/events/migrations/0004_event_record_identifier.py +19 -0
  40. irie/apps/events/migrations/0005_event_asset.py +21 -0
  41. irie/apps/events/migrations/0006_alter_event_event_file.py +18 -0
  42. irie/apps/events/migrations/__init__.py +0 -0
  43. irie/apps/events/models.py +70 -0
  44. irie/apps/events/tests.py +1 -0
  45. irie/apps/events/tests_events.py +240 -0
  46. irie/apps/events/urls.py +29 -0
  47. irie/apps/events/views.py +55 -0
  48. irie/apps/events/views_events.py +215 -0
  49. irie/apps/inventory/CESMD.py +81 -0
  50. irie/apps/inventory/__init__.py +5 -0
  51. irie/apps/inventory/admin.py +10 -0
  52. irie/apps/inventory/apps.py +12 -0
  53. irie/apps/inventory/archive/arcGIS.py +1175 -0
  54. irie/apps/inventory/calid.py +65 -0
  55. irie/apps/inventory/fields.py +5 -0
  56. irie/apps/inventory/forms.py +12 -0
  57. irie/apps/inventory/migrations/0001_initial.py +31 -0
  58. irie/apps/inventory/migrations/0002_assetevaluationmodel_cesmd.py +19 -0
  59. irie/apps/inventory/migrations/0003_auto_20230520_2030.py +23 -0
  60. irie/apps/inventory/migrations/0004_asset.py +27 -0
  61. irie/apps/inventory/migrations/0005_auto_20230731_1802.py +23 -0
  62. irie/apps/inventory/migrations/0006_auto_20230731_1816.py +28 -0
  63. irie/apps/inventory/migrations/0007_auto_20230731_1827.py +24 -0
  64. irie/apps/inventory/migrations/0008_asset_is_complete.py +19 -0
  65. irie/apps/inventory/migrations/0009_auto_20230731_1842.py +29 -0
  66. irie/apps/inventory/migrations/0010_auto_20230801_0025.py +23 -0
  67. irie/apps/inventory/migrations/0011_alter_asset_cgs_data.py +18 -0
  68. irie/apps/inventory/migrations/0012_corridor.py +22 -0
  69. irie/apps/inventory/migrations/0013_alter_asset_cesmd.py +18 -0
  70. irie/apps/inventory/migrations/0014_alter_asset_cesmd.py +18 -0
  71. irie/apps/inventory/migrations/__init__.py +0 -0
  72. irie/apps/inventory/models.py +70 -0
  73. irie/apps/inventory/tables.py +584 -0
  74. irie/apps/inventory/traffic.py +175052 -0
  75. irie/apps/inventory/urls.py +25 -0
  76. irie/apps/inventory/views.py +515 -0
  77. irie/apps/management/__init__.py +0 -0
  78. irie/apps/management/commands/__init__.py +0 -0
  79. irie/apps/networks/__init__.py +0 -0
  80. irie/apps/networks/apps.py +5 -0
  81. irie/apps/networks/forms.py +64 -0
  82. irie/apps/networks/migrations/0001_initial.py +26 -0
  83. irie/apps/networks/migrations/__init__.py +0 -0
  84. irie/apps/networks/models.py +14 -0
  85. irie/apps/networks/networks.py +782 -0
  86. irie/apps/networks/tests.py +1 -0
  87. irie/apps/networks/urls.py +18 -0
  88. irie/apps/networks/views.py +89 -0
  89. irie/apps/prediction/__init__.py +0 -0
  90. irie/apps/prediction/admin.py +9 -0
  91. irie/apps/prediction/apps.py +12 -0
  92. irie/apps/prediction/forms.py +20 -0
  93. irie/apps/prediction/metrics.py +61 -0
  94. irie/apps/prediction/migrations/0001_initial.py +32 -0
  95. irie/apps/prediction/migrations/0002_auto_20230731_1801.py +27 -0
  96. irie/apps/prediction/migrations/0003_rename_assetevaluationmodel_evaluation.py +18 -0
  97. irie/apps/prediction/migrations/0004_delete_evaluation.py +16 -0
  98. irie/apps/prediction/migrations/0005_predictormodel_protocol.py +18 -0
  99. irie/apps/prediction/migrations/0006_alter_predictormodel_protocol.py +18 -0
  100. irie/apps/prediction/migrations/0007_predictormodel_active.py +19 -0
  101. irie/apps/prediction/migrations/0008_predictormodel_description.py +18 -0
  102. irie/apps/prediction/migrations/0009_predictormodel_entry_point.py +19 -0
  103. irie/apps/prediction/migrations/0010_alter_predictormodel_entry_point.py +18 -0
  104. irie/apps/prediction/migrations/0011_remove_predictormodel_entry_point.py +17 -0
  105. irie/apps/prediction/migrations/0012_predictormodel_entry_point.py +18 -0
  106. irie/apps/prediction/migrations/0013_predictormodel_metrics.py +18 -0
  107. irie/apps/prediction/migrations/0014_auto_20240930_0004.py +28 -0
  108. irie/apps/prediction/migrations/0015_alter_predictormodel_render_file.py +18 -0
  109. irie/apps/prediction/migrations/__init__.py +0 -0
  110. irie/apps/prediction/models.py +37 -0
  111. irie/apps/prediction/predictor.py +286 -0
  112. irie/apps/prediction/runners/__init__.py +450 -0
  113. irie/apps/prediction/runners/metrics.py +168 -0
  114. irie/apps/prediction/runners/opensees/__init__.py +0 -0
  115. irie/apps/prediction/runners/opensees/schemas/__init__.py +39 -0
  116. irie/apps/prediction/runners/utilities.py +277 -0
  117. irie/apps/prediction/runners/xmlutils.py +232 -0
  118. irie/apps/prediction/runners/zipped.py +27 -0
  119. irie/apps/prediction/templatetags/__init__.py +0 -0
  120. irie/apps/prediction/templatetags/predictor.py +20 -0
  121. irie/apps/prediction/urls.py +19 -0
  122. irie/apps/prediction/views.py +184 -0
  123. irie/apps/prediction/views_api.py +216 -0
  124. irie/apps/site/__init__.py +0 -0
  125. irie/apps/site/admin.py +1 -0
  126. irie/apps/site/config.py +6 -0
  127. irie/apps/site/migrations/__init__.py +1 -0
  128. irie/apps/site/models.py +2 -0
  129. irie/apps/site/templatetags/__init__.py +0 -0
  130. irie/apps/site/templatetags/indexing.py +7 -0
  131. irie/apps/site/tests.py +1 -0
  132. irie/apps/site/urls.py +8 -0
  133. irie/apps/site/view_sdof.py +40 -0
  134. irie/apps/site/view_utils.py +13 -0
  135. irie/apps/site/views.py +88 -0
  136. irie/core/__init__.py +5 -0
  137. irie/core/asgi.py +12 -0
  138. irie/core/settings.py +223 -0
  139. irie/core/urls.py +39 -0
  140. irie/core/wsgi.py +12 -0
  141. irie-0.0.0.dist-info/METADATA +48 -0
  142. irie-0.0.0.dist-info/RECORD +145 -0
  143. irie-0.0.0.dist-info/WHEEL +5 -0
  144. irie-0.0.0.dist-info/entry_points.txt +2 -0
  145. irie-0.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,184 @@
1
+ #===----------------------------------------------------------------------===#
2
+ #
3
+ # STAIRLab -- STructural Artificial Intelligence Laboratory
4
+ #
5
+ #===----------------------------------------------------------------------===#
6
+ #
7
+ # This module implements the "Configure Predictors" page
8
+ #
9
+ # Author: Claudio Perez
10
+ #
11
+ #----------------------------------------------------------------------------#
12
+ import os
13
+ import json
14
+
15
+ from django.shortcuts import HttpResponse
16
+ from django.template import loader, TemplateDoesNotExist
17
+ from django.contrib.auth.decorators import login_required
18
+ from django.core.exceptions import ObjectDoesNotExist
19
+
20
+ from django.shortcuts import render
21
+
22
+ from rest_framework.decorators import api_view, permission_classes
23
+ from rest_framework.permissions import IsAuthenticated
24
+
25
+ from apps.site.view_utils import raise404
26
+ from apps.inventory.models import Asset
27
+ from apps.prediction.predictor import PREDICTOR_TYPES, OpenSeesRunner
28
+ from apps.prediction.models import PredictorModel
29
+ from .forms import PredictorForm
30
+
31
+ @login_required(login_url="/login/")
32
+ def new_prediction(request):
33
+ context = {}
34
+
35
+ page_template = "form-submission.html" #request.path.split("/")[-1]
36
+ context["segment"] = page_template
37
+ html_template = loader.get_template("prediction/" + page_template)
38
+ return HttpResponse(html_template.render(context, request))
39
+
40
+
41
+ #@login_required(login_url="/login/")
42
+ @api_view(["GET", "POST", "PUT"])
43
+ @permission_classes([IsAuthenticated])
44
+ def predictor_api(request):
45
+
46
+ context = {"segment": "assets"}
47
+
48
+ context["predictor_types"] = list(reversed([
49
+ {"schema": json.dumps(cls.schema),
50
+ "name": cls.__name__,
51
+ "title": cls.schema["title"]}
52
+ for cls in set(PREDICTOR_TYPES.values())
53
+ ]))
54
+
55
+ calid = request.path.split("/")[-3]
56
+
57
+ try:
58
+ context["asset"] = Asset.objects.get(calid=calid)
59
+
60
+ except:
61
+ return HttpResponse(
62
+ loader.get_template("home/page-404-sidebar.html").render(context, request)
63
+ )
64
+
65
+ if request.method == "POST":
66
+ PREDICTOR_TYPES["BRACE2_CLI_PREDICTOR_T2"].create(context["asset"],request).save()
67
+
68
+ html_template = loader.get_template("prediction/asset-predictors.html")
69
+ return HttpResponse(html_template.render(context, request))
70
+
71
+
72
+ # @api_view(["GET", "POST", "PUT"])
73
+ @login_required(login_url="/login/")
74
+ # @permission_classes([IsAuthenticated])
75
+ def asset_predictors(request):
76
+
77
+ context = {"segment": "assets"}
78
+
79
+ context["predictor_types"] = list(reversed([
80
+ {"schema": json.dumps(cls.schema),
81
+ "name": cls.__name__,
82
+ "title": cls.schema.get("title", "NO TITLE")}
83
+ for cls in set(PREDICTOR_TYPES.values())
84
+ ]))
85
+
86
+ calid = request.path.split("/")[-3]
87
+ try:
88
+ context["asset"] = Asset.objects.get(calid=calid)
89
+ except:
90
+ return HttpResponse(
91
+ loader.get_template("home/page-404-sidebar.html").render(context, request)
92
+ )
93
+
94
+ if request.method == "POST":
95
+ PREDICTOR_TYPES["BRACE2_CLI_PREDICTOR_T2"].create(context["asset"],request).save()
96
+
97
+ html_template = loader.get_template("prediction/asset-predictors.html")
98
+ return HttpResponse(html_template.render(context, request))
99
+
100
+
101
+ @login_required(login_url="/login/")
102
+ def predictor_profile(request):
103
+
104
+ context = {}
105
+ html_template = loader.get_template("prediction/predictor-profile.html")
106
+ context["segment"] = "assets"
107
+
108
+ url_segs = request.path.split("/")
109
+ if len(url_segs) < 5:
110
+ return raise404(request, context)
111
+ else:
112
+ calid = url_segs[2]
113
+ preid = url_segs[4]
114
+
115
+ try:
116
+ asset = Asset.objects.get(calid=calid)
117
+ except ObjectDoesNotExist:
118
+ return raise404(request, context)
119
+
120
+ try:
121
+ predictor = PredictorModel.objects.get(pk=int(preid))
122
+ except ObjectDoesNotExist:
123
+ return raise404(request, context)
124
+
125
+ context["asset"] = asset
126
+ context["predictor"] = PREDICTOR_TYPES[predictor.protocol](predictor)
127
+
128
+
129
+ try:
130
+ return HttpResponse(html_template.render(context, request))
131
+
132
+ except TemplateDoesNotExist:
133
+ context["rendering"] = None
134
+ return HttpResponse(html_template.render(context, request))
135
+
136
+ except Exception as e:
137
+ if "DEBUG" in os.environ and os.environ["DEBUG"]:
138
+ raise e
139
+ html_template = loader.get_template("site/page-500.html")
140
+ return HttpResponse(html_template.render(context, request))
141
+
142
+
143
+ @login_required(login_url="/login/")
144
+ def predictor_upload(request):
145
+
146
+ context = {}
147
+ html_template = loader.get_template("prediction/predictor-upload.html")
148
+ context["segment"] = "assets"
149
+
150
+ context["title"] = "The Title"
151
+
152
+ if request.method == 'POST':
153
+ form = PredictorForm(request.POST, request.FILES) # include request.FILES
154
+ if form.is_valid():
155
+ # Process the form data and uploaded file
156
+ asset = form.cleaned_data['asset']
157
+ uploaded_file = request.FILES['config_file']
158
+
159
+ with open(uploaded_file.name, 'wb+') as destination:
160
+ for chunk in uploaded_file.chunks():
161
+ destination.write(chunk)
162
+
163
+ # Save the predictor
164
+ OpenSeesRunner.create(asset,None,form).save()
165
+
166
+ context = {}
167
+
168
+ return render(request, 'prediction/predictor-upload.html',
169
+ context)
170
+ else:
171
+ form = PredictorForm()
172
+
173
+
174
+ try:
175
+ return render(request, 'prediction/predictor-upload.html', {'form': form})
176
+
177
+
178
+ except Exception as e:
179
+ if "DEBUG" in os.environ and os.environ["DEBUG"]:
180
+ raise e
181
+ html_template = loader.get_template("site/page-500.html")
182
+ return HttpResponse(html_template.render(context, request))
183
+
184
+
@@ -0,0 +1,216 @@
1
+ #===----------------------------------------------------------------------===#
2
+ #
3
+ # STAIRLab -- STructural Artificial Intelligence Laboratory
4
+ #
5
+ #===----------------------------------------------------------------------===#
6
+ #
7
+ # This module is responsible for implementing the API endpoint for
8
+ # scraping evaluation data
9
+ #
10
+ # Author: Claudio Perez
11
+ #
12
+ #----------------------------------------------------------------------------#
13
+ import json
14
+ import datetime
15
+ from threading import Thread
16
+ from django.shortcuts import render
17
+ from django.core.exceptions import ObjectDoesNotExist
18
+ from django.shortcuts import HttpResponse
19
+ from django.forms.models import model_to_dict
20
+
21
+ from rest_framework.parsers import JSONParser,MultiPartParser,FormParser
22
+ from rest_framework.decorators import api_view, permission_classes, parser_classes
23
+ from rest_framework import status
24
+ from rest_framework.permissions import IsAuthenticated
25
+
26
+ from .models import Event
27
+ from apps.inventory.models import Asset
28
+ # from apps.evaluation.evaluation import (run_evaluation,
29
+ # add_evaluation)
30
+ from apps.evaluation.models import Evaluation
31
+ import quakeio
32
+
33
+
34
+ def serialize_event(event):
35
+ serialized = model_to_dict(event)
36
+ serialized["upload_date"] = str(event.upload_date)
37
+
38
+ if event.event_file:
39
+ serialized["event_file"] = event.event_file.path
40
+ else:
41
+ serialized["event_file"] = None
42
+
43
+ #serialized["data_str"] = json.loads(event.data_str) if event.data_str else {}
44
+ return serialized
45
+
46
+
47
+ def save_event(request, event, success_status):
48
+ errors = []
49
+
50
+ # DATE
51
+ upload_date = datetime.datetime.now()
52
+
53
+ # UPLOAD DATA
54
+ upload_data = request.data.get("upload_data", "{}")
55
+ if upload_data == "":
56
+ errors.append({"upload_data": "This field is required"})
57
+
58
+ # EVENT FILE
59
+ try:
60
+ event_file = request.FILES["event_file"]
61
+ except KeyError:
62
+ event_file = None
63
+ # errors.append({"event_file": "This field is required"})
64
+ except Exception as e:
65
+ errors.append({"event_file": str(e)})
66
+
67
+
68
+ if len(errors) > 0:
69
+ return HttpResponse(json.dumps(
70
+ {
71
+ "errors": errors
72
+ }), status=status.HTTP_400_BAD_REQUEST)
73
+
74
+ # MOTION DATA
75
+ if event_file is not None:
76
+ try:
77
+ motion_data = (
78
+ quakeio.read(
79
+ event_file.temporary_file_path(), input_format="csmip.zip"
80
+ ).serialize(serialize_data=False, summarize=True)
81
+ )
82
+ except:
83
+ return HttpResponse(json.dumps(
84
+ {
85
+ "errors": ["Failed to parse ground motion file."]
86
+ }), status=status.HTTP_400_BAD_REQUEST)
87
+ elif "motion_data" in request.data:
88
+ motion_data = json.loads(request.data.get("motion_data"))
89
+
90
+ else:
91
+ return HttpResponse(json.dumps(
92
+ {
93
+ "errors": ["No motion_data provided."]
94
+ }), status=status.HTTP_400_BAD_REQUEST)
95
+
96
+ # RECORD ID
97
+ rec_id = motion_data.get("record_identifier", "")
98
+
99
+
100
+ # CREATE EVENT
101
+ if event is None:
102
+ # Doing a PUT
103
+ event = Event.objects.filter(record_identifier=rec_id).first()
104
+ if event is None:
105
+ print("PUT: creating", rec_id, "\n\n")
106
+ event = Event()
107
+ else:
108
+ print("PUT: updating", rec_id, "\n\n")
109
+ upload_date = event.upload_date
110
+
111
+
112
+ event.upload_date = upload_date
113
+ event.upload_data = json.loads(upload_data)
114
+ event.record_identifier = rec_id
115
+ event.motion_data = motion_data
116
+ event.cesmd = "CE" + event.motion_data["station_number"]
117
+ event.asset = Asset.objects.get(cesmd="CE" + event.motion_data["station_number"])
118
+ event.event_file = event_file
119
+ # if event_file is not None:
120
+
121
+ event.save()
122
+
123
+
124
+ # CREATE EVALUATION
125
+ if "evaluation" in request.data:
126
+ # TODO: check for parse error
127
+ eval_data = json.loads(request.data["evaluation"])
128
+ else:
129
+ eval_data = None
130
+
131
+
132
+ Evaluation.create(event, event.asset, eval_data)
133
+
134
+
135
+
136
+
137
+ # EMAIL
138
+ # Get users
139
+ from django.contrib.auth import get_user_model
140
+ User = get_user_model()
141
+ users = User.objects.all()
142
+
143
+ station_name = event.motion_data["station_name"]
144
+
145
+ event.email_notify(
146
+ subject = f"BRACE2: New event at '{station_name}'",
147
+
148
+ message = ("A new event has been sent to the BRACE2 platform. "
149
+ 'visit https://brace2-peer.ist.berkeley.edu/static/dmp/index.html for details.'),
150
+ html_message = ("A new event has been sent to the BRACE2 platform. "
151
+ 'visit <a href="https://brace2-peer.ist.berkeley.edu/static/dmp/index.html">here</a> for details.'),
152
+ fail_silently=True,
153
+ recipients=[user.email for user in users] + ["brace2-peer@mailinator.com"]
154
+ )
155
+
156
+ return HttpResponse(json.dumps({"data": serialize_event(event)}), status=success_status)
157
+
158
+
159
+
160
+ def index(request):
161
+ context = {}
162
+ return render(request, "events/events.html", context=context)
163
+
164
+
165
+ @api_view(["GET", "POST", "PUT"])
166
+ @permission_classes([IsAuthenticated])
167
+ def events(request):
168
+ # if request.user.is_anonymous:
169
+ # return HttpResponse(json.dumps({"detail": "Not authorized"}), status=status.HTTP_401_UNAUTHORIZED)
170
+
171
+ if request.method == "GET":
172
+ events_data = Event.objects.all()
173
+
174
+ events_count = events_data.count()
175
+
176
+ page_size = int(request.GET.get("page_size", events_count))
177
+ page_no = int(request.GET.get("page_no", 0))
178
+ events_data = list(events_data[page_no * page_size:page_no * page_size + page_size])
179
+
180
+ events_data = [serialize_event(event) for event in events_data]
181
+ return HttpResponse(json.dumps({"count": events_count, "data": events_data}), status=status.HTTP_200_OK)
182
+
183
+ elif request.method == "POST":
184
+ event = Event()
185
+ return save_event(request, event, status.HTTP_201_CREATED)
186
+
187
+ elif request.method == "PUT":
188
+ return save_event(request, None, status.HTTP_201_CREATED)
189
+
190
+ return HttpResponse(json.dumps({"detail": "Wrong method"}), status=status.HTTP_501_NOT_IMPLEMENTED)
191
+
192
+
193
+ @api_view(['GET', 'PUT', 'DELETE'])
194
+ @parser_classes([JSONParser,MultiPartParser])
195
+ @permission_classes([IsAuthenticated])
196
+ def event(request, event_id):
197
+ #if request.user.is_anonymous:
198
+ # return HttpResponse(json.dumps({"detail": "Not authorized"}), status=status.HTTP_401_UNAUTHORIZED)
199
+
200
+ try:
201
+ event = Event.objects.get(pk=event_id)
202
+ except ObjectDoesNotExist:
203
+ return HttpResponse(json.dumps({"detail": "Not found"}), status=status.HTTP_404_NOT_FOUND)
204
+
205
+ if request.method == "GET":
206
+ return HttpResponse(json.dumps({"data": serialize_event(event)}), status=status.HTTP_200_OK)
207
+
208
+ if request.method == "PUT":
209
+ return save_event(request, event, status.HTTP_200_OK)
210
+
211
+ if request.method == "DELETE":
212
+ event.delete()
213
+ return HttpResponse(json.dumps({"detail": "deleted"}), status=status.HTTP_410_GONE)
214
+
215
+ return HttpResponse(json.dumps({"detail": "Wrong method"}), status=status.HTTP_501_NOT_IMPLEMENTED)
216
+
File without changes
@@ -0,0 +1 @@
1
+ from django.contrib import admin
@@ -0,0 +1,6 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class MyConfig(AppConfig):
5
+ name = "apps.site"
6
+ label = "apps_site"
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,2 @@
1
+ from django.db import models
2
+ from django.contrib.auth.models import User
File without changes
@@ -0,0 +1,7 @@
1
+ from django import template
2
+ register = template.Library()
3
+
4
+ @register.filter
5
+ def index(indexable, i):
6
+ return indexable[i]
7
+
@@ -0,0 +1 @@
1
+ from django.test import TestCase
irie/apps/site/urls.py ADDED
@@ -0,0 +1,8 @@
1
+ from django.urls import path, re_path
2
+ from apps.site import views, view_sdof
3
+
4
+ urlpatterns = [
5
+ path("", views.index, name="home"),
6
+ path("about/", views.about, name="about"),
7
+ re_path(r"^sdof/.*", view_sdof.earthquake_fitter, name="sdof"),
8
+ ]
@@ -0,0 +1,40 @@
1
+ import os
2
+ import json
3
+
4
+ from django import template
5
+ from django.contrib.auth.decorators import login_required
6
+ from django.http import HttpResponse, HttpResponseRedirect
7
+ from django.template import loader
8
+ from django.urls import reverse
9
+
10
+ import quakeio
11
+
12
+ from apps.events.models import Event
13
+
14
+
15
+ @login_required(login_url="/login/")
16
+ def earthquake_fitter(request):
17
+ try:
18
+ load_template = "EarthquakeResponse.html"
19
+
20
+ pk = request.path.split("/")[2]
21
+
22
+ context = {}
23
+
24
+ context["event"] = Event.objects.filter(pk=pk)[0]
25
+
26
+ try:
27
+ context["event_data"] = quakeio.read(
28
+ context["event"].event_file.path, input_format="csmip.zip"
29
+ ).serialize(serialize_data=True, summarize=False)
30
+ except:
31
+ context["event_data"] = {}
32
+
33
+ html_template = loader.get_template("events/" + load_template)
34
+ return HttpResponse(html_template.render(context, request))
35
+
36
+ except Exception as e:
37
+ if "DEBUG" in os.environ and os.environ["DEBUG"]:
38
+ raise e
39
+ html_template = loader.get_template("home/page-500.html")
40
+ return HttpResponse(html_template.render(context, request))
@@ -0,0 +1,13 @@
1
+ import os
2
+ from django.http import HttpResponse, HttpResponseRedirect
3
+ from django.template import loader
4
+
5
+ def raise404(request, context={}, error=None):
6
+ "Convenience function for responding with a 404 code (page not found)"
7
+ if error is not None and "DEBUG" in os.environ and os.environ["DEBUG"]:
8
+ raise error
9
+ if "segment" in context:
10
+ html_template = loader.get_template("home/page-404-sidebar.html")
11
+ else:
12
+ html_template = loader.get_template("home/page-404.html")
13
+ return HttpResponse(html_template.render(context, request))
@@ -0,0 +1,88 @@
1
+ #===----------------------------------------------------------------------===#
2
+ #
3
+ # STAIRLab -- STructural Artificial Intelligence Laboratory
4
+ #
5
+ #===----------------------------------------------------------------------===#
6
+ #
7
+ # Each function in this file is responsible
8
+ # for rendering a web page. This generally
9
+ # consists of the following:
10
+ #
11
+ # - Extracting information from the URL (available from
12
+ # the `request` variable. For example, the URL may contain
13
+ # the CALID of the bridge that the page is about.
14
+ # - Collecting neccessary data into a `context` dictionary.
15
+ # This typically involves a database querry, or reading from
16
+ # a static record like the inventory.bridges.BRIDGES dictionary.
17
+ # - Finally, selecting an HTML template and rendering it against
18
+ # the assembled `context` dictionary.
19
+ #
20
+ # NOTE: In the future, the static data in the inventory app should
21
+ # be moved to the database. However, given the active pace of
22
+ # research and development that would require changes to this
23
+ # model, it is currently better as implemented.
24
+ #
25
+ #----------------------------------------------------------------------------#
26
+ #
27
+ # Fall 2022, BRACE2 Team
28
+ # Berkeley, CA
29
+ #
30
+ #----------------------------------------------------------------------------#
31
+
32
+ import os
33
+ from django import template
34
+ from django.contrib.auth.decorators import login_required
35
+ from django.http import HttpResponse, HttpResponseRedirect
36
+ from django.template import loader
37
+ from django.urls import reverse
38
+
39
+
40
+ def index(request):
41
+ "Return the primary landing page."
42
+ context = {
43
+ "segment": "index",
44
+ "authenticated": request.user.is_authenticated
45
+ }
46
+ html_template = loader.get_template("site/index.html")
47
+ return HttpResponse(html_template.render(context, request))
48
+
49
+
50
+ def about(request):
51
+ "Return the About page."
52
+ context = {
53
+ "segment": "about",
54
+ "authenticated": request.user.is_authenticated
55
+ }
56
+ html_template = loader.get_template("site/about.html")
57
+ return HttpResponse(html_template.render(context, request))
58
+
59
+
60
+ @login_required(login_url="/login/")
61
+ def admin(request):
62
+ """
63
+ Return the administrator's dashboard page
64
+ """
65
+ context = {}
66
+
67
+ try:
68
+ page_template = request.path.split("/")[-1]
69
+ context["segment"] = page_template
70
+
71
+ if page_template == "admin":
72
+ return HttpResponseRedirect(reverse("admin:index"))
73
+
74
+ html_template = loader.get_template("site/" + page_template)
75
+ return HttpResponse(html_template.render(context, request))
76
+
77
+ except template.TemplateDoesNotExist as e:
78
+ return raise404(request, context, e)
79
+
80
+ except Exception as e:
81
+ if "DEBUG" in os.environ and os.environ["DEBUG"]:
82
+ raise e
83
+ html_template = loader.get_template("site/page-500.html")
84
+ return HttpResponse(html_template.render(context, request))
85
+
86
+
87
+
88
+
irie/core/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ #===----------------------------------------------------------------------===#
2
+ #
3
+ # STAIRLab -- STructural Artificial Intelligence Laboratory
4
+ #
5
+ #===----------------------------------------------------------------------===#
irie/core/asgi.py ADDED
@@ -0,0 +1,12 @@
1
+ #===----------------------------------------------------------------------===#
2
+ #
3
+ # STAIRLab -- STructural Artificial Intelligence Laboratory
4
+ #
5
+ #===----------------------------------------------------------------------===#
6
+
7
+ import os
8
+ from django.core.asgi import get_asgi_application
9
+
10
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
11
+
12
+ application = get_asgi_application()