Skip to content

Commit 7f18495

Browse files
committed
Got units conversion working and small edits to restore code runnability:
- Fixed/finished unifyUnits function -- it now (seems to) work... - Uncommented the call to unifyUnits so it's now applied to vessel yamls. - action.py: Commented out a syntax issue and made it so that assignObjects method doesn't also figure out the required capacities (so that code will run, and that could be a separate step anyway). - Moved the test call to evaluateAssets in Irma.py to later in the script after all the actions are set up. More organized order, and lets the existing code still run.
1 parent 5434acd commit 7f18495

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

famodel/irma/action.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ def getMetrics(self, cap, met, obj):
331331
# object logic checked
332332
vol = 0
333333
length = 0
334+
'''
334335
if objType == 'cable':
335336
for cable in cables: # TODO: figure out this iteration
336337
if cable is cable and not other thing in cables object: # TODO figure out how to only check cables, not j-tubes or any other parts
@@ -339,7 +340,7 @@ def getMetrics(self, cap, met, obj):
339340
else:
340341
vol = -1
341342
length = -1
342-
343+
'''
343344
# Assign the capabilties metrics
344345
metrics['volume_m3'] = vol if vol > metrics.get('volume_m3') else metrics.get('volume_m3')
345346
metrics['cable_capacity_m'] = length if length > metrics.get('cable_capacity_m') else metrics.get('cable_capacity_m')
@@ -760,14 +761,15 @@ def assignObjects(self, objects):
760761
else:
761762
if obj in self.objectList:
762763
print(f"Warning: Object '{obj}' is already in the action's object list. Capabilities will be overwritten.")
763-
764+
'''
764765
# Set capability requirements based on object
765766
for role, caplist in self.requirements.items():
766767
for cap in caplist:
767768
metrics = self.getMetrics(cap, caplist[cap], obj) # pass in the metrics dict for the cap and the obj
768769
769770
self.requirements[role][cap] = metrics # assign metric of capability cap based on value required by obj
770-
771+
# MH: commenting our for now just so the code will run, but it may be better to make the above a separate step anyway
772+
'''
771773
self.objectList.append(obj)
772774

773775

famodel/irma/irma.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,24 +110,30 @@ def unifyUnits(d):
110110
# >>> dcopy = deepcopy(d)
111111

112112
for asset in d.values(): # loop through each asset's dict
113-
for capability in asset['capabilities'].values():
114-
for key, val in capability.items(): # look at each capability metric
113+
114+
capabilities = {} # new dict of capabilities to built up
115+
116+
for cap_key, cap_val in asset['capabilities'].items():
117+
118+
# make the capability type sub-dictionary
119+
capabilities[cap_key] = {}
120+
121+
for key, val in cap_val.items(): # look at each capability metric
115122
try:
116123
i = keys1.index(key) # find if key is on the list to convert
117124

118125

119-
if keys2[i] in capability.keys():
126+
if keys2[i] in cap_val.keys():
120127
raise Exception(f"Specification '{keys2[i]}' already exists")
121128

122-
capability[keys2[i]] = val * facts[i] # create a new SI entry
123-
124-
breakpoint()
125-
126-
del capability[keys1[i]] # remove the original?
129+
capabilities[cap_key][keys2[i]] = val * facts[i] # make converted entry
130+
#capability[keys2[i]] = val * facts[i] # create a new SI entry
131+
#del capability[keys1[i]] # remove the original?
127132

128133
except:
129-
print('not found')
130-
134+
135+
capabilities[cap_key][key] = val # copy over original form
136+
131137

132138
class Scenario():
133139

@@ -144,7 +150,7 @@ def __init__(self):
144150
vessels = loadYAMLtoDict('vessels.yaml', already_dict=True)
145151
objects = loadYAMLtoDict('objects.yaml', already_dict=True)
146152

147-
#unifyUnits(vessels) # (function doesn't work yet!) <<<
153+
unifyUnits(vessels) # (function doesn't work yet!) <<<
148154

149155
# ----- Validate internal cross references -----
150156

@@ -378,7 +384,6 @@ def findCompatibleVessels(self):
378384

379385
# add and register anchor install action(s)
380386
a1 = sc.addAction('install_anchor', f'install_anchor-{akey}', objects=[anchor])
381-
a1.evaluateAssets({'carrier' : sc.vessels["MPSV_01"]})
382387

383388
# register the actions as necessary for the anchor <<< do this for all objects??
384389
anchor.install_dependencies = [a1]
@@ -436,6 +441,10 @@ def findCompatibleVessels(self):
436441

437442
# ----- Check tasks for suitable vessels and the associated costs/times -----
438443

444+
# preliminary/temporary test of anchor install asset suitability
445+
for akey, anchor in project.anchorList.items():
446+
for a in anchor.install_dependencies: # go through required actions (should just be the anchor install)
447+
a.evaluateAssets({'carrier' : sc.vessels["MPSV_01"]}) # see if this example vessel can do it
439448

440449

441450
# ----- Call the scheduler -----

0 commit comments

Comments
 (0)