Skip to content

Commit

Permalink
Bugfixes to schema, and to/from json code
Browse files Browse the repository at this point in the history
  • Loading branch information
IKCAP committed Jul 7, 2024
1 parent d8c1f24 commit 469eb2a
Show file tree
Hide file tree
Showing 15 changed files with 428 additions and 879 deletions.
184 changes: 161 additions & 23 deletions pylipd/classes/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def __init__(self):
self.dOI: str = None
self.datasetRange: str = None
self.equation: str = None
self.equationIntercept: str = None
self.equationR2: str = None
self.equationSlope: str = None
self.equationSlopeUncertainty: str = None
self.method: str = None
self.methodDetail: str = None
self.notes: str = None
self.proxyDataset: str = None
self.seasonality: str = None
Expand Down Expand Up @@ -53,6 +59,42 @@ def from_data(id, data) -> 'Calibration':
obj = val["@value"]
self.equation = obj

elif key == "hasEquationIntercept":
for val in value:
if "@value" in val:
obj = val["@value"]
self.equationIntercept = obj

elif key == "hasEquationR2":
for val in value:
if "@value" in val:
obj = val["@value"]
self.equationR2 = obj

elif key == "hasEquationSlope":
for val in value:
if "@value" in val:
obj = val["@value"]
self.equationSlope = obj

elif key == "hasEquationSlopeUncertainty":
for val in value:
if "@value" in val:
obj = val["@value"]
self.equationSlopeUncertainty = obj

elif key == "hasMethod":
for val in value:
if "@value" in val:
obj = val["@value"]
self.method = obj

elif key == "hasMethodDetail":
for val in value:
if "@value" in val:
obj = val["@value"]
self.methodDetail = obj

elif key == "hasNotes":
for val in value:
if "@value" in val:
Expand Down Expand Up @@ -132,6 +174,66 @@ def to_data(self, data={}):
data[self.id]["hasEquation"] = [obj]


if self.equationIntercept:
value_obj = self.equationIntercept
obj = {
"@value": value_obj,
"@type": "literal",
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["hasEquationIntercept"] = [obj]


if self.equationR2:
value_obj = self.equationR2
obj = {
"@value": value_obj,
"@type": "literal",
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["hasEquationR2"] = [obj]


if self.equationSlope:
value_obj = self.equationSlope
obj = {
"@value": value_obj,
"@type": "literal",
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["hasEquationSlope"] = [obj]


if self.equationSlopeUncertainty:
value_obj = self.equationSlopeUncertainty
obj = {
"@value": value_obj,
"@type": "literal",
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["hasEquationSlopeUncertainty"] = [obj]


if self.method:
value_obj = self.method
obj = {
"@value": value_obj,
"@type": "literal",
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["hasMethod"] = [obj]


if self.methodDetail:
value_obj = self.methodDetail
obj = {
"@value": value_obj,
"@type": "literal",
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["hasMethodDetail"] = [obj]


if self.notes:
value_obj = self.notes
obj = {
Expand Down Expand Up @@ -221,41 +323,41 @@ def to_json(self):
obj = value_obj
data["datasetRange"] = obj

if self.datasetRange:
value_obj = self.datasetRange
if self.equation:
value_obj = self.equation
obj = value_obj
data["equation"] = obj

if self.equationIntercept:
value_obj = self.equationIntercept
obj = value_obj
data["equationIntercept"] = obj

if self.datasetRange:
value_obj = self.datasetRange
if self.equationR2:
value_obj = self.equationR2
obj = value_obj
data["equationR2"] = obj

if self.datasetRange:
value_obj = self.datasetRange
if self.equationSlope:
value_obj = self.equationSlope
obj = value_obj
data["equationSlope"] = obj

if self.datasetRange:
value_obj = self.datasetRange
if self.equationSlopeUncertainty:
value_obj = self.equationSlopeUncertainty
obj = value_obj
data["equationSlopeUncertainty"] = obj

if self.datasetRange:
value_obj = self.datasetRange
if self.method:
value_obj = self.method
obj = value_obj
data["method"] = obj

if self.datasetRange:
value_obj = self.datasetRange
if self.methodDetail:
value_obj = self.methodDetail
obj = value_obj
data["methodDetail"] = obj

if self.equation:
value_obj = self.equation
obj = value_obj
data["equation"] = obj

if self.notes:
value_obj = self.notes
obj = value_obj
Expand Down Expand Up @@ -309,31 +411,31 @@ def from_json(data) -> 'Calibration':
elif key == "equationIntercept":
value = pvalue
obj = value
self.datasetRange = obj
self.equationIntercept = obj
elif key == "equationR2":
value = pvalue
obj = value
self.datasetRange = obj
self.equationR2 = obj
elif key == "equationSlope":
value = pvalue
obj = value
self.datasetRange = obj
self.equationSlope = obj
elif key == "equationSlopeUncertainty":
value = pvalue
obj = value
self.datasetRange = obj
self.equationSlopeUncertainty = obj
elif key == "hasSeasonality":
value = pvalue
obj = value
self.seasonality = obj
elif key == "method":
value = pvalue
obj = value
self.datasetRange = obj
self.method = obj
elif key == "methodDetail":
value = pvalue
obj = value
self.datasetRange = obj
self.methodDetail = obj
elif key == "notes":
value = pvalue
obj = value
Expand Down Expand Up @@ -388,6 +490,42 @@ def getEquation(self) -> str:
def setEquation(self, equation:str):
self.equation = equation

def getEquationIntercept(self) -> str:
return self.equationIntercept

def setEquationIntercept(self, equationIntercept:str):
self.equationIntercept = equationIntercept

def getEquationR2(self) -> str:
return self.equationR2

def setEquationR2(self, equationR2:str):
self.equationR2 = equationR2

def getEquationSlope(self) -> str:
return self.equationSlope

def setEquationSlope(self, equationSlope:str):
self.equationSlope = equationSlope

def getEquationSlopeUncertainty(self) -> str:
return self.equationSlopeUncertainty

def setEquationSlopeUncertainty(self, equationSlopeUncertainty:str):
self.equationSlopeUncertainty = equationSlopeUncertainty

def getMethod(self) -> str:
return self.method

def setMethod(self, method:str):
self.method = method

def getMethodDetail(self) -> str:
return self.methodDetail

def setMethodDetail(self, methodDetail:str):
self.methodDetail = methodDetail

def getNotes(self) -> str:
return self.notes

Expand Down
20 changes: 16 additions & 4 deletions pylipd/classes/chrondata.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,19 @@ def to_json(self):
if len(self.measurementTables):
data["measurementTable"] = []
for value_obj in self.measurementTables:
obj = value_obj.to_json()
if hasattr(value_obj, "to_json"):
obj = value_obj.to_json()
else:
obj = value_obj
data["measurementTable"].append(obj)

if len(self.modeledBy):
data["model"] = []
for value_obj in self.modeledBy:
obj = value_obj.to_json()
if hasattr(value_obj, "to_json"):
obj = value_obj.to_json()
else:
obj = value_obj
data["model"].append(obj)

for key in self.misc:
Expand All @@ -158,11 +164,17 @@ def from_json(data) -> 'ChronData':
self.id = pvalue
elif key == "measurementTable":
for value in pvalue:
obj = DataTable.from_json(value)
if type(value) is dict:
obj = DataTable.from_json(value)
else:
obj = value
self.measurementTables.append(obj)
elif key == "model":
for value in pvalue:
obj = Model.from_json(value)
if type(value) is dict:
obj = Model.from_json(value)
else:
obj = value
self.modeledBy.append(obj)
else:
self.set_non_standard_property(key, pvalue)
Expand Down
Loading

0 comments on commit 469eb2a

Please sign in to comment.