mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Make it possible to edit case group statistics
This commit is contained in:
@@ -169,6 +169,7 @@ if (PYTHON_EXECUTABLE)
|
||||
"rips/View.py"
|
||||
"rips/examples/InstanceExample.py"
|
||||
"rips/examples/CommandExample.py"
|
||||
"rips/examples/CaseGridGroup.py"
|
||||
"rips/examples/CaseInfoStreamingExample.py"
|
||||
"rips/examples/SoilPorvAsync.py"
|
||||
"rips/examples/SoilPorvSync.py"
|
||||
|
||||
@@ -26,10 +26,9 @@ class PdmObject:
|
||||
listOfKeywords.append(keyword)
|
||||
return listOfKeywords
|
||||
|
||||
def getValue(self, keyword):
|
||||
value = self.pb2Object.parameters[keyword]
|
||||
def __toValue(self, value):
|
||||
if value.lower() == 'false':
|
||||
return False
|
||||
return False
|
||||
elif value.lower() == 'true':
|
||||
return True
|
||||
else:
|
||||
@@ -43,18 +42,43 @@ class PdmObject:
|
||||
except ValueError:
|
||||
# We may have a string. Strip internal start and end quotes
|
||||
value = value.strip('\"')
|
||||
if self.__islist(value):
|
||||
return self.__makelist(value)
|
||||
return value
|
||||
|
||||
def setValue(self, keyword, value):
|
||||
def __fromValue(self, value):
|
||||
if isinstance(value, bool):
|
||||
if value:
|
||||
self.pb2Object.parameters[keyword] = "true"
|
||||
return "true"
|
||||
else:
|
||||
self.pb2Object.parameters[keyword] = "false"
|
||||
return "false"
|
||||
elif isinstance(value, list):
|
||||
listofstrings = []
|
||||
for val in value:
|
||||
listofstrings.append(self.__fromValue(val))
|
||||
return "[" + ", ".join(listofstrings) + "]"
|
||||
elif isinstance(value, str):
|
||||
self.pb2Object.parameters[keyword] = "\"" + str(value) + "\""
|
||||
return "\"" + str(value) + "\""
|
||||
else:
|
||||
self.pb2Object.parameters[keyword] = str(value)
|
||||
return str(value)
|
||||
|
||||
def getValue(self, keyword):
|
||||
value = self.pb2Object.parameters[keyword]
|
||||
return self.__toValue(value)
|
||||
|
||||
def __islist(self, value):
|
||||
return value.startswith("[") and value.endswith("]")
|
||||
|
||||
def __makelist(self, liststring):
|
||||
liststring = liststring.lstrip("[")
|
||||
liststring = liststring.rstrip("]")
|
||||
strings = liststring.split(", ")
|
||||
values = []
|
||||
for string in strings:
|
||||
values.append(self.__toValue(string))
|
||||
return values
|
||||
|
||||
def setValue(self, keyword, value):
|
||||
self.pb2Object.parameters[keyword] = self.__fromValue(value)
|
||||
|
||||
def descendants(self, classKeyword):
|
||||
request = PdmObject_pb2.PdmChildObjectRequest(object=self.pb2Object, child_keyword=classKeyword)
|
||||
|
||||
@@ -11,4 +11,17 @@ casePaths.append("../../../../TestModels/Case_with_10_timesteps/Real0/BRUGGE_000
|
||||
casePaths.append("../../../../TestModels/Case_with_10_timesteps/Real10/BRUGGE_0010.EGRID")
|
||||
groupId, groupName = resInsight.commands.createGridCaseGroup(casePaths=casePaths)
|
||||
print("Group id = " + str(groupId))
|
||||
print("Group name = " + groupName)
|
||||
print("Group name = " + groupName)
|
||||
|
||||
caseGroups = resInsight.project.descendants("RimIdenticalGridCaseGroup");
|
||||
for caseGroup in caseGroups:
|
||||
print ("#### Case Group ####")
|
||||
for kw in caseGroup.keywords():
|
||||
print (kw, caseGroup.getValue(kw))
|
||||
statCases = caseGroup.descendants("RimStatisticalCalculation")
|
||||
for statCase in statCases:
|
||||
print(" ## Stat Case ##")
|
||||
for skw in statCase.keywords():
|
||||
print(" ", skw, statCase.getValue(skw))
|
||||
statCase.setValue("DynamicPropertiesToCalculate", statCase.getValue("DynamicPropertiesToCalculate") + ["SWAT"])
|
||||
statCase.update()
|
||||
Reference in New Issue
Block a user