midas-civil 0.0.9__py3-none-any.whl → 0.1.1__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 midas-civil might be problematic. Click here for more details.

@@ -2,414 +2,418 @@ from ._mapi import *
2
2
 
3
3
  class CS:
4
4
 
5
- CSA = []
6
5
 
7
- def __init__(self,
8
- name: str,
9
- duration: float = 0,
10
- s_group: str = None,
11
- s_age: float = None,
12
- s_type: str= None,
13
- b_group: str = None,
14
- b_pos: str = None,
15
- b_type: str = None,
16
- l_group: str = None,
17
- l_day: str = None,
18
- l_type: str = None,
19
- id: int = None,
20
- sr_stage: bool = True,
21
- ad_stage: bool = False,
22
- load_in: bool = False,
23
- nl: int = 5,
24
- addstp: list = None):
25
- """
26
- Construction Stage define.
27
-
28
- Parameters:
29
- name: Name of Construction Stage
30
- duration: Duration of Construction Stage in days (default 0)
31
- s_group: Structure group name or list of group names (default None)
32
- s_age: Age of structure group in days and Redistribution value(%) win case of Deactivation (default 0)
33
- s_type: Structure activation type - "A" to activate, "D" to deactivate(default A)
34
- b_group: Boundary group name or list of group names (default None)
35
- b_pos: Boundary position type - "ORIGINAL" or "DEFORMED", or list (default DEFORMED)
36
- b_type: Boundary activation type - "A" to activate, "D" to deactivate (default A)
37
- l_group: Load group name or list of group names (default None)
38
- l_day: Load activation day - "FIRST" or "LAST" (default "FIRST")
39
- l_type: Load activation type - "A" to activate, "D" to deactivate (default A)
40
- id: The construction stage ID (optional)
41
- sr_stage: Save results of this stage (default True)
42
- ad_stage: Add additional step results (default False)
43
- load_in: Load incremental steps for material nonlinear analysis (default False)
44
- nl: Number of load incremental steps (default 5)
45
- addstp: List of additional steps (default None)
46
-
47
- Examples:
48
- ```python
49
- # Single group activation
50
- CS("CS1", 7, "S1", 7, "A", "B1", "DEFORMED", "A", "L1", "FIRST", "A")
6
+ class STAGE:
7
+ stages = []
8
+
9
+ def __init__(self,
10
+ name: str,
11
+ duration: float = 0,
12
+ s_group: str = None,
13
+ s_age: float = None,
14
+ s_type: str= None,
15
+ b_group: str = None,
16
+ b_pos: str = None,
17
+ b_type: str = None,
18
+ l_group: str = None,
19
+ l_day: str = None,
20
+ l_type: str = None,
21
+ id: int = None,
22
+ sv_result: bool = True,
23
+ sv_step: bool = False,
24
+ load_in: bool = False,
25
+ nl: int = 5,
26
+ addstp: list = None):
27
+ """
28
+ Construction Stage define.
29
+
30
+ Parameters:
31
+ name: Name of Construction Stage
32
+ duration: Duration of Construction Stage in days (default 0)
33
+ s_group: Structure group name or list of group names (default None)
34
+ s_age: Age of structure group in days and Redistribution value(%) win case of Deactivation (default 0)
35
+ s_type: Structure activation type - "A" to activate, "D" to deactivate(default A)
36
+ b_group: Boundary group name or list of group names (default None)
37
+ b_pos: Boundary position type - "ORIGINAL" or "DEFORMED", or list (default DEFORMED)
38
+ b_type: Boundary activation type - "A" to activate, "D" to deactivate (default A)
39
+ l_group: Load group name or list of group names (default None)
40
+ l_day: Load activation day - "FIRST" or "LAST" (default "FIRST")
41
+ l_type: Load activation type - "A" to activate, "D" to deactivate (default A)
42
+ id: The construction stage ID (optional)
43
+ sv_result: Save results of this stage (default True)
44
+ sv_step: Add additional step results (default False)
45
+ load_in: Load incremental steps for material nonlinear analysis (default False)
46
+ nl: Number of load incremental steps (default 5)
47
+ addstp: List of additional steps (default None)
51
48
 
52
- # Multiple group activation
53
- CS("CS1", 7, ["S1", "S2"], [7, 10], ["A", "A"], ["B1", "B2"],
54
- ["DEFORMED", "DEFORMED"], ["A", "A"], ["L1", "L2"], ["FIRST", "FIRST"], ["A", "A"])
49
+ Examples:
50
+ ```python
51
+ # Single group activation
52
+ CS("CS1", 7, "S1", 7, "A", "B1", "DEFORMED", "A", "L1", "FIRST", "A")
53
+
54
+ # Multiple group activation
55
+ CS("CS1", 7, ["S1", "S2"], [7, 10], ["A", "A"], ["B1", "B2"],
56
+ ["DEFORMED", "DEFORMED"], ["A", "A"], ["L1", "L2"], ["FIRST", "FIRST"], ["A", "A"])
57
+
58
+ # Mixed activation and deactivation
59
+ CS("CS1", 7, ["S1", "S2"], [7, 10], ["A", "D"], ["B1", "B2"],
60
+ ["DEFORMED", "DEFORMED"], ["A", "D"], "L1", "FIRST", "A")
61
+
62
+ # With additional options
63
+ CS("CS1", 7, "S1", 7, "A", "B1", "DEFORMED", "A", "L1", "FIRST", "A",
64
+ sv_result=True, sv_step=True, load_in=True, nl=6, addstp=[1, 2, 3])
65
+ ```
66
+ """
67
+
68
+ self.NAME = name
69
+ self.DURATION = duration
70
+ self.SV_Result = sv_result
71
+ self.SV_Step = sv_step
72
+ self.Load_IN = load_in
73
+ self.NL = nl
74
+ self.addstp = [] if addstp is None else addstp
55
75
 
56
- # Mixed activation and deactivation
57
- CS("CS1", 7, ["S1", "S2"], [7, 10], ["A", "D"], ["B1", "B2"],
58
- ["DEFORMED", "DEFORMED"], ["A", "D"], "L1", "FIRST", "A")
76
+ # Initialize group containers
77
+ self.act_structure_groups = []
78
+ self.deact_structure_groups = []
79
+ self.act_boundary_groups = []
80
+ self.deact_boundary_groups = []
81
+ self.act_load_groups = []
82
+ self.deact_load_groups = []
59
83
 
60
- # With additional options
61
- CS("CS1", 7, "S1", 7, "A", "B1", "DEFORMED", "A", "L1", "FIRST", "A",
62
- sr_stage=True, ad_stage=True, load_in=True, nl=6, addstp=[1, 2, 3])
63
- ```
64
- """
65
84
 
66
- self.NAME = name
67
- self.DURATION = duration
68
- self.SR_stage = sr_stage
69
- self.Ad_stage = ad_stage
70
- self.Load_IN = load_in
71
- self.NL = nl
72
- self.addstp = [] if addstp is None else addstp
73
-
74
- # Initialize group containers
75
- self.act_structure_groups = []
76
- self.deact_structure_groups = []
77
- self.act_boundary_groups = []
78
- self.deact_boundary_groups = []
79
- self.act_load_groups = []
80
- self.deact_load_groups = []
81
-
82
- # Set ID
83
- if id is None:
84
- self.ID = len(CS.CSA) + 1
85
- else:
86
- self.ID = id
87
-
88
- # Process structure groups
89
- if s_group:
90
- # Convert single values to lists for uniform processing
91
- if not isinstance(s_group, list):
92
- s_group = [s_group]
93
- s_age = [s_age if s_age is not None else 0]
94
- s_type = [s_type if s_type is not None else "A"]
85
+ # Set ID
86
+ if id is None:
87
+ self.ID = len(CS.STAGE.stages) + 1
95
88
  else:
96
- # Ensure other parameters are lists too
97
- if s_age is None:
98
- s_age = [0] * len(s_group)
99
- elif not isinstance(s_age, list):
100
- s_age = [s_age] * len(s_group)
101
-
102
- if s_type is None:
103
- s_type = ["A"] * len(s_group)
104
- elif not isinstance(s_type, list):
105
- s_type = [s_type] * len(s_group)
89
+ self.ID = id
106
90
 
107
- # Process each structure group
108
- for i, group in enumerate(s_group):
109
- if i < len(s_type) and s_type[i] == "A":
110
- # Activation: Check if already activated in previous stages
111
- for stage in CS.CSA:
112
- for existing_group in stage.act_structure_groups:
113
- if existing_group["name"] == group:
114
- raise ValueError(f"Structure group '{group}' has already been activated in stage '{stage.NAME}' (ID: {stage.ID})")
115
-
116
- age = s_age[i] if i < len(s_age) else 0
117
- self.act_structure_groups.append({"name": group, "age": age})
91
+
92
+ # Process structure groups
93
+ if s_group:
94
+ # Convert single values to lists for uniform processing
95
+ if not isinstance(s_group, list):
96
+ s_group = [s_group]
97
+ s_age = [s_age if s_age is not None else 0]
98
+ s_type = [s_type if s_type is not None else "A"]
118
99
  else:
119
- # Deactivation: Check if activated in previous stages
120
- activated = False
121
- for stage in CS.CSA:
122
- for existing_group in stage.act_structure_groups:
123
- if existing_group["name"] == group:
124
- activated = True
125
- break
126
- if activated:
127
- break
128
-
129
- if not activated:
130
- raise ValueError(f"Structure group '{group}' cannot be deactivated as it has not been activated in any previous stage")
100
+ # Ensure other parameters are lists too
101
+ if s_age is None:
102
+ s_age = [0] * len(s_group)
103
+ elif not isinstance(s_age, list):
104
+ s_age = [s_age] * len(s_group)
131
105
 
132
- # For deactivation, s_age value is used as redist percentage
133
- redist = s_age[i] if i < len(s_age) else 100
134
- self.deact_structure_groups.append({"name": group, "redist": redist})
135
-
136
- # Process boundary groups
137
- if b_group:
138
- # Convert single values to lists for uniform processing
139
- if not isinstance(b_group, list):
140
- b_group = [b_group]
141
- b_pos = [b_pos if b_pos is not None else "DEFORMED"]
142
- b_type = [b_type if b_type is not None else "A"]
143
- else:
144
- # Ensure other parameters are lists too
145
- if b_pos is None:
146
- b_pos = ["DEFORMED"] * len(b_group)
147
- elif not isinstance(b_pos, list):
148
- b_pos = [b_pos] * len(b_group)
106
+ if s_type is None:
107
+ s_type = ["A"] * len(s_group)
108
+ elif not isinstance(s_type, list):
109
+ s_type = [s_type] * len(s_group)
149
110
 
150
- if b_type is None:
151
- b_type = ["A"] * len(b_group)
152
- elif not isinstance(b_type, list):
153
- b_type = [b_type] * len(b_group)
111
+ # Process each structure group
112
+ for i, group in enumerate(s_group):
113
+ if i < len(s_type) and s_type[i] == "A":
114
+ # Activation: Check if already activated in previous stages
115
+ for stage in CS.STAGE.stages:
116
+ for existing_group in stage.act_structure_groups:
117
+ if existing_group["name"] == group:
118
+ raise ValueError(f"Structure group '{group}' has already been activated in stage '{stage.NAME}' (ID: {stage.ID})")
119
+
120
+ age = s_age[i] if i < len(s_age) else 0
121
+ self.act_structure_groups.append({"name": group, "age": age})
122
+ else:
123
+ # Deactivation: Check if activated in previous stages
124
+ activated = False
125
+ for stage in CS.STAGE.stages:
126
+ for existing_group in stage.act_structure_groups:
127
+ if existing_group["name"] == group:
128
+ activated = True
129
+ break
130
+ if activated:
131
+ break
132
+
133
+ if not activated:
134
+ raise ValueError(f"Structure group '{group}' cannot be deactivated as it has not been activated in any previous stage")
135
+
136
+ # For deactivation, s_age value is used as redist percentage
137
+ redist = s_age[i] if i < len(s_age) else 100
138
+ self.deact_structure_groups.append({"name": group, "redist": redist})
154
139
 
155
- # Process each boundary group
156
- for i, group in enumerate(b_group):
157
- if i < len(b_type) and b_type[i] == "A":
158
- # Activation: Check if already activated in previous stages
159
- for stage in CS.CSA:
160
- for existing_group in stage.act_boundary_groups:
161
- if existing_group["name"] == group:
162
- raise ValueError(f"Boundary group '{group}' has already been activated in stage '{stage.NAME}' (ID: {stage.ID})")
163
-
164
- pos = b_pos[i] if i < len(b_pos) else "DEFORMED"
165
- self.act_boundary_groups.append({"name": group, "pos": pos})
140
+ # Process boundary groups
141
+ if b_group:
142
+ # Convert single values to lists for uniform processing
143
+ if not isinstance(b_group, list):
144
+ b_group = [b_group]
145
+ b_pos = [b_pos if b_pos is not None else "DEFORMED"]
146
+ b_type = [b_type if b_type is not None else "A"]
166
147
  else:
167
- # Deactivation: Check if activated in previous stages
168
- activated = False
169
- for stage in CS.CSA:
170
- for existing_group in stage.act_boundary_groups:
171
- if existing_group["name"] == group:
172
- activated = True
173
- break
174
- if activated:
175
- break
176
-
177
- if not activated:
178
- raise ValueError(f"Boundary group '{group}' cannot be deactivated as it has not been activated in any previous stage")
148
+ # Ensure other parameters are lists too
149
+ if b_pos is None:
150
+ b_pos = ["DEFORMED"] * len(b_group)
151
+ elif not isinstance(b_pos, list):
152
+ b_pos = [b_pos] * len(b_group)
179
153
 
180
- self.deact_boundary_groups.append(group)
181
-
182
- # Process load groups
183
- if l_group:
184
- # Convert single values to lists for uniform processing
185
- if not isinstance(l_group, list):
186
- l_group = [l_group]
187
- l_day = [l_day if l_day is not None else "FIRST"]
188
- l_type = [l_type if l_type is not None else "A"]
189
- else:
190
- # Ensure other parameters are lists too
191
- if l_day is None:
192
- l_day = ["FIRST"] * len(l_group)
193
- elif not isinstance(l_day, list):
194
- l_day = [l_day] * len(l_group)
154
+ if b_type is None:
155
+ b_type = ["A"] * len(b_group)
156
+ elif not isinstance(b_type, list):
157
+ b_type = [b_type] * len(b_group)
195
158
 
196
- if l_type is None:
197
- l_type = ["A"] * len(l_group)
198
- elif not isinstance(l_type, list):
199
- l_type = [l_type] * len(l_group)
159
+ # Process each boundary group
160
+ for i, group in enumerate(b_group):
161
+ if i < len(b_type) and b_type[i] == "A":
162
+ # Activation: Check if already activated in previous stages
163
+ for stage in CS.STAGE.stages:
164
+ for existing_group in stage.act_boundary_groups:
165
+ if existing_group["name"] == group:
166
+ raise ValueError(f"Boundary group '{group}' has already been activated in stage '{stage.NAME}' (ID: {stage.ID})")
167
+
168
+ pos = b_pos[i] if i < len(b_pos) else "DEFORMED"
169
+ self.act_boundary_groups.append({"name": group, "pos": pos})
170
+ else:
171
+ # Deactivation: Check if activated in previous stages
172
+ activated = False
173
+ for stage in CS.STAGE.stages:
174
+ for existing_group in stage.act_boundary_groups:
175
+ if existing_group["name"] == group:
176
+ activated = True
177
+ break
178
+ if activated:
179
+ break
180
+
181
+ if not activated:
182
+ raise ValueError(f"Boundary group '{group}' cannot be deactivated as it has not been activated in any previous stage")
183
+
184
+ self.deact_boundary_groups.append(group)
200
185
 
201
- # Process each load group
202
- for i, group in enumerate(l_group):
203
- if i < len(l_type) and l_type[i] == "A":
204
- # Activation: Check if already activated in previous stages
205
- for stage in CS.CSA:
206
- for existing_group in stage.act_load_groups:
207
- if existing_group["name"] == group:
208
- raise ValueError(f"Load group '{group}' has already been activated in stage '{stage.NAME}' (ID: {stage.ID})")
209
-
210
- day = l_day[i] if i < len(l_day) else "FIRST"
211
- self.act_load_groups.append({"name": group, "day": day})
186
+ # Process load groups
187
+ if l_group:
188
+ # Convert single values to lists for uniform processing
189
+ if not isinstance(l_group, list):
190
+ l_group = [l_group]
191
+ l_day = [l_day if l_day is not None else "FIRST"]
192
+ l_type = [l_type if l_type is not None else "A"]
212
193
  else:
213
- # Deactivation: Check if activated in previous stages
214
- activated = False
215
- for stage in CS.CSA:
216
- for existing_group in stage.act_load_groups:
217
- if existing_group["name"] == group:
218
- activated = True
219
- break
220
- if activated:
221
- break
222
-
223
- if not activated:
224
- raise ValueError(f"Load group '{group}' cannot be deactivated as it has not been activated in any previous stage")
194
+ # Ensure other parameters are lists too
195
+ if l_day is None:
196
+ l_day = ["FIRST"] * len(l_group)
197
+ elif not isinstance(l_day, list):
198
+ l_day = [l_day] * len(l_group)
225
199
 
226
- day = l_day[i] if i < len(l_day) else "FIRST"
227
- self.deact_load_groups.append({"name": group, "day": day})
228
-
229
- CS.CSA.append(self)
230
-
231
- @classmethod
232
- def json(cls):
233
- """
234
- Converts Construction Stage data to JSON format
235
- Example:
236
- # Get the JSON data for all construction stages
237
- json_data = CS.json()
238
- print(json_data)
239
- """
240
- json = {"Assign": {}}
241
-
242
- for csa in cls.CSA:
243
- stage_data = {
244
- "NAME": csa.NAME,
245
- "DURATION": csa.DURATION,
246
- "bSV_RSLT": csa.SR_stage,
247
- "bSV_STEP": csa.Ad_stage,
248
- "bLOAD_STEP": csa.Load_IN
249
- }
250
-
251
- # Add incremental steps if load step is enabled
252
- if csa.Load_IN:
253
- stage_data["INCRE_STEP"] = csa.NL
254
-
255
- # Add additional steps if specified
256
- if csa.addstp:
257
- stage_data["ADD_STEP"] = csa.addstp
258
- else:
259
- stage_data["ADD_STEP"] = []
260
-
261
- # Handle structure group activation
262
- if csa.act_structure_groups:
263
- stage_data["ACT_ELEM"] = []
264
- for group in csa.act_structure_groups:
265
- stage_data["ACT_ELEM"].append({
266
- "GRUP_NAME": group["name"],
267
- "AGE": group["age"]
268
- })
269
-
270
- # Handle structure group deactivation
271
- if csa.deact_structure_groups:
272
- stage_data["DACT_ELEM"] = []
273
- for group in csa.deact_structure_groups:
274
- stage_data["DACT_ELEM"].append({
275
- "GRUP_NAME": group["name"],
276
- "REDIST": group["redist"]
277
- })
278
-
279
- # Handle boundary group activation
280
- if csa.act_boundary_groups:
281
- stage_data["ACT_BNGR"] = []
282
- for group in csa.act_boundary_groups:
283
- stage_data["ACT_BNGR"].append({
284
- "BNGR_NAME": group["name"],
285
- "POS": group["pos"]
286
- })
287
-
288
- # Handle boundary group deactivation
289
- if csa.deact_boundary_groups:
290
- stage_data["DACT_BNGR"] = []
291
- for group_name in csa.deact_boundary_groups:
292
- stage_data["DACT_BNGR"].append(group_name)
293
-
294
- # Handle load group activation
295
- if csa.act_load_groups:
296
- stage_data["ACT_LOAD"] = []
297
- for group in csa.act_load_groups:
298
- stage_data["ACT_LOAD"].append({
299
- "LOAD_NAME": group["name"],
300
- "DAY": group["day"]
301
- })
302
-
303
- # Handle load group deactivation
304
- if csa.deact_load_groups:
305
- stage_data["DACT_LOAD"] = []
306
- for group in csa.deact_load_groups:
307
- stage_data["DACT_LOAD"].append({
308
- "LOAD_NAME": group["name"],
309
- "DAY": group["day"]
310
- })
200
+ if l_type is None:
201
+ l_type = ["A"] * len(l_group)
202
+ elif not isinstance(l_type, list):
203
+ l_type = [l_type] * len(l_group)
204
+
205
+ # Process each load group
206
+ for i, group in enumerate(l_group):
207
+ if i < len(l_type) and l_type[i] == "A":
208
+ # Activation: Check if already activated in previous stages
209
+ for stage in CS.STAGE.stages:
210
+ for existing_group in stage.act_load_groups:
211
+ if existing_group["name"] == group:
212
+ raise ValueError(f"Load group '{group}' has already been activated in stage '{stage.NAME}' (ID: {stage.ID})")
213
+
214
+ day = l_day[i] if i < len(l_day) else "FIRST"
215
+ self.act_load_groups.append({"name": group, "day": day})
216
+ else:
217
+ # Deactivation: Check if activated in previous stages
218
+ activated = False
219
+ for stage in CS.STAGE.stages:
220
+ for existing_group in stage.act_load_groups:
221
+ if existing_group["name"] == group:
222
+ activated = True
223
+ break
224
+ if activated:
225
+ break
226
+
227
+ if not activated:
228
+ raise ValueError(f"Load group '{group}' cannot be deactivated as it has not been activated in any previous stage")
229
+
230
+ day = l_day[i] if i < len(l_day) else "FIRST"
231
+ self.deact_load_groups.append({"name": group, "day": day})
311
232
 
312
- json["Assign"][str(csa.ID)] = stage_data
233
+ CS.STAGE.stages.append(self)
313
234
 
314
- return json
315
-
316
- @classmethod
317
- def create(cls):
318
- """Creates construction stages in the database"""
319
- MidasAPI("PUT", "/db/stag", CS.json())
320
-
321
- @classmethod
322
- def get(cls):
323
- """Gets construction stage data from the database"""
324
- return MidasAPI("GET", "/db/stag")
325
-
326
- @classmethod
327
- def sync(cls):
328
- """Updates the CS class with data from the database"""
329
- cls.CSA = []
330
- a = CS.get()
331
- if a != {'message': ''}:
332
- if "STAG" in a:
333
- stag_data_dict = a["STAG"]
334
- else:
335
- return
235
+ @classmethod
236
+ def json(cls):
237
+ """
238
+ Converts Construction Stage data to JSON format
239
+ Example:
240
+ # Get the JSON data for all construction stages
241
+ json_data = CS.json()
242
+ print(json_data)
243
+ """
244
+ json = {"Assign": {}}
245
+
246
+ for csa in cls.stages:
247
+ stage_data = {
248
+ "NAME": csa.NAME,
249
+ "DURATION": csa.DURATION,
250
+ "bSV_RSLT": csa.SV_Result,
251
+ "bSV_STEP": csa.SV_Step,
252
+ "bLOAD_STEP": csa.Load_IN
253
+ }
336
254
 
337
- for stag_id, stag_data in stag_data_dict.items():
338
- # Basic stage data
339
- name = stag_data.get("NAME")
340
- duration = stag_data.get("DURATION")
341
- sr_stage = stag_data.get("bSV_RSLT")
342
- ad_stage = stag_data.get("bSV_STEP")
343
- load_in = stag_data.get("bLOAD_STEP")
344
- nl = stag_data.get("INCRE_STEP")
345
- addstp = stag_data.get("ADD_STEP")
255
+ # Add incremental steps if load step is enabled
256
+ if csa.Load_IN:
257
+ stage_data["INCRE_STEP"] = csa.NL
346
258
 
347
- # Create a new CS object with basic properties
348
- new_cs = CS(
349
- name=name,
350
- duration=duration,
351
- id=int(stag_id),
352
- sr_stage=sr_stage,
353
- ad_stage=ad_stage,
354
- load_in=load_in,
355
- nl=nl,
356
- addstp=addstp
357
- )
259
+ # Add additional steps if specified
260
+ if csa.addstp:
261
+ stage_data["ADD_STEP"] = csa.addstp
262
+ else:
263
+ stage_data["ADD_STEP"] = []
358
264
 
359
- CS.CSA.pop()
265
+ # Handle structure group activation
266
+ if csa.act_structure_groups:
267
+ stage_data["ACT_ELEM"] = []
268
+ for group in csa.act_structure_groups:
269
+ stage_data["ACT_ELEM"].append({
270
+ "GRUP_NAME": group["name"],
271
+ "AGE": group["age"]
272
+ })
360
273
 
361
- # Process activation elements
362
- if "ACT_ELEM" in stag_data and stag_data["ACT_ELEM"]:
363
- for elem in stag_data["ACT_ELEM"]:
364
- group_name = elem.get("GRUP_NAME")
365
- age = elem.get("AGE")
366
- new_cs.act_structure_groups.append({"name": group_name, "age": age})
274
+ # Handle structure group deactivation
275
+ if csa.deact_structure_groups:
276
+ stage_data["DACT_ELEM"] = []
277
+ for group in csa.deact_structure_groups:
278
+ stage_data["DACT_ELEM"].append({
279
+ "GRUP_NAME": group["name"],
280
+ "REDIST": group["redist"]
281
+ })
367
282
 
368
- # Process deactivation elements
369
- if "DACT_ELEM" in stag_data and stag_data["DACT_ELEM"]:
370
- for elem in stag_data["DACT_ELEM"]:
371
- if isinstance(elem, dict):
372
- group_name = elem.get("GRUP_NAME")
373
- redist = elem.get("REDIST")
374
- else:
375
- group_name = elem
376
- redist = 0
377
- new_cs.deact_structure_groups.append({"name": group_name, "redist": redist})
283
+ # Handle boundary group activation
284
+ if csa.act_boundary_groups:
285
+ stage_data["ACT_BNGR"] = []
286
+ for group in csa.act_boundary_groups:
287
+ stage_data["ACT_BNGR"].append({
288
+ "BNGR_NAME": group["name"],
289
+ "POS": group["pos"]
290
+ })
378
291
 
379
- # Process activation boundary groups
380
- if "ACT_BNGR" in stag_data and stag_data["ACT_BNGR"]:
381
- for bngr in stag_data["ACT_BNGR"]:
382
- group_name = bngr.get("BNGR_NAME")
383
- pos = bngr.get("POS")
384
- new_cs.act_boundary_groups.append({"name": group_name, "pos": pos})
292
+ # Handle boundary group deactivation
293
+ if csa.deact_boundary_groups:
294
+ stage_data["DACT_BNGR"] = []
295
+ for group_name in csa.deact_boundary_groups:
296
+ stage_data["DACT_BNGR"].append(group_name)
385
297
 
386
- # Process deactivation boundary groups
387
- if "DACT_BNGR" in stag_data and stag_data["DACT_BNGR"]:
388
- for bngr in stag_data["DACT_BNGR"]:
389
- new_cs.deact_boundary_groups.append(bngr)
298
+ # Handle load group activation
299
+ if csa.act_load_groups:
300
+ stage_data["ACT_LOAD"] = []
301
+ for group in csa.act_load_groups:
302
+ stage_data["ACT_LOAD"].append({
303
+ "LOAD_NAME": group["name"],
304
+ "DAY": group["day"]
305
+ })
390
306
 
391
- # Process activation loads
392
- if "ACT_LOAD" in stag_data and stag_data["ACT_LOAD"]:
393
- for load in stag_data["ACT_LOAD"]:
394
- group_name = load.get("LOAD_NAME")
395
- day = load.get("DAY")
396
- new_cs.act_load_groups.append({"name": group_name, "day": day})
307
+ # Handle load group deactivation
308
+ if csa.deact_load_groups:
309
+ stage_data["DACT_LOAD"] = []
310
+ for group in csa.deact_load_groups:
311
+ stage_data["DACT_LOAD"].append({
312
+ "LOAD_NAME": group["name"],
313
+ "DAY": group["day"]
314
+ })
397
315
 
398
- # Process deactivation loads
399
- if "DACT_LOAD" in stag_data and stag_data["DACT_LOAD"]:
400
- for load in stag_data["DACT_LOAD"]:
401
- if isinstance(load, dict):
316
+ json["Assign"][str(csa.ID)] = stage_data
317
+
318
+ return json
319
+
320
+ @classmethod
321
+ def create(cls):
322
+ """Creates construction stages in the database"""
323
+ MidasAPI("PUT", "/db/stag", cls.json())
324
+
325
+ @classmethod
326
+ def get(cls):
327
+ """Gets construction stage data from the database"""
328
+ return MidasAPI("GET", "/db/stag")
329
+
330
+ @classmethod
331
+ def sync(cls):
332
+ """Updates the CS class with data from the database"""
333
+ cls.stages = []
334
+ a = cls.get()
335
+ if a != {'message': ''}:
336
+ if "STAG" in a:
337
+ stag_data_dict = a["STAG"]
338
+ else:
339
+ return
340
+
341
+ for stag_id, stag_data in stag_data_dict.items():
342
+ # Basic stage data
343
+ name = stag_data.get("NAME")
344
+ duration = stag_data.get("DURATION")
345
+ sv_result = stag_data.get("bSV_RSLT")
346
+ sv_step = stag_data.get("bSV_STEP")
347
+ load_in = stag_data.get("bLOAD_STEP")
348
+ nl = stag_data.get("INCRE_STEP")
349
+ addstp = stag_data.get("ADD_STEP")
350
+
351
+ # Create a new CS object with basic properties
352
+ new_cs = CS.STAGE(
353
+ name=name,
354
+ duration=duration,
355
+ id=int(stag_id),
356
+ sv_result=sv_result,
357
+ sv_step=sv_step,
358
+ load_in=load_in,
359
+ nl=nl,
360
+ addstp=addstp
361
+ )
362
+
363
+ CS.STAGE.stages.pop()
364
+
365
+ # Process activation elements
366
+ if "ACT_ELEM" in stag_data and stag_data["ACT_ELEM"]:
367
+ for elem in stag_data["ACT_ELEM"]:
368
+ group_name = elem.get("GRUP_NAME")
369
+ age = elem.get("AGE")
370
+ new_cs.act_structure_groups.append({"name": group_name, "age": age})
371
+
372
+ # Process deactivation elements
373
+ if "DACT_ELEM" in stag_data and stag_data["DACT_ELEM"]:
374
+ for elem in stag_data["DACT_ELEM"]:
375
+ if isinstance(elem, dict):
376
+ group_name = elem.get("GRUP_NAME")
377
+ redist = elem.get("REDIST")
378
+ else:
379
+ group_name = elem
380
+ redist = 0
381
+ new_cs.deact_structure_groups.append({"name": group_name, "redist": redist})
382
+
383
+ # Process activation boundary groups
384
+ if "ACT_BNGR" in stag_data and stag_data["ACT_BNGR"]:
385
+ for bngr in stag_data["ACT_BNGR"]:
386
+ group_name = bngr.get("BNGR_NAME")
387
+ pos = bngr.get("POS")
388
+ new_cs.act_boundary_groups.append({"name": group_name, "pos": pos})
389
+
390
+ # Process deactivation boundary groups
391
+ if "DACT_BNGR" in stag_data and stag_data["DACT_BNGR"]:
392
+ for bngr in stag_data["DACT_BNGR"]:
393
+ new_cs.deact_boundary_groups.append(bngr)
394
+
395
+ # Process activation loads
396
+ if "ACT_LOAD" in stag_data and stag_data["ACT_LOAD"]:
397
+ for load in stag_data["ACT_LOAD"]:
402
398
  group_name = load.get("LOAD_NAME")
403
399
  day = load.get("DAY")
404
- else:
405
- group_name = load
406
- day = "FIRST"
407
- new_cs.deact_load_groups.append({"name": group_name, "day": day})
408
-
409
- CS.CSA.append(new_cs)
410
-
411
- @classmethod
412
- def delete(cls):
413
- """Deletes all construction stages from the database and resets the class"""
414
- cls.CSA = []
415
- return MidasAPI("DELETE", "/db/stag")
400
+ new_cs.act_load_groups.append({"name": group_name, "day": day})
401
+
402
+ # Process deactivation loads
403
+ if "DACT_LOAD" in stag_data and stag_data["DACT_LOAD"]:
404
+ for load in stag_data["DACT_LOAD"]:
405
+ if isinstance(load, dict):
406
+ group_name = load.get("LOAD_NAME")
407
+ day = load.get("DAY")
408
+ else:
409
+ group_name = load
410
+ day = "FIRST"
411
+ new_cs.deact_load_groups.append({"name": group_name, "day": day})
412
+
413
+ CS.STAGE.stages.append(new_cs)
414
+
415
+ @classmethod
416
+ def delete(cls):
417
+ """Deletes all construction stages from the database and resets the class"""
418
+ cls.stages = []
419
+ return MidasAPI("DELETE", "/db/stag")