Skip to content

Commit

Permalink
Initial ability to go from dataframe metadata to variable class
Browse files Browse the repository at this point in the history
  • Loading branch information
IKCAP committed Jul 5, 2024
1 parent a0a60d4 commit 7fd6e35
Show file tree
Hide file tree
Showing 23 changed files with 1,036 additions and 196 deletions.
68 changes: 68 additions & 0 deletions pylipd/classes/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,74 @@ def to_json(self):

return data

@staticmethod
def from_json(data) -> 'Calibration':
self = Calibration()
for key in data:
pvalue = data[key]
if key == "@id":
self.id = pvalue
elif key == "datasetRange":
value = pvalue
obj = value
self.datasetRange = obj
elif key == "doi":
value = pvalue
obj = value
self.dOI = obj
elif key == "equation":
value = pvalue
obj = value
self.equation = obj
elif key == "equationIntercept":
value = pvalue
obj = value
self.datasetRange = obj
elif key == "equationR2":
value = pvalue
obj = value
self.datasetRange = obj
elif key == "equationSlope":
value = pvalue
obj = value
self.datasetRange = obj
elif key == "equationSlopeUncertainty":
value = pvalue
obj = value
self.datasetRange = obj
elif key == "hasSeasonality":
value = pvalue
obj = value
self.seasonality = obj
elif key == "method":
value = pvalue
obj = value
self.datasetRange = obj
elif key == "methodDetail":
value = pvalue
obj = value
self.datasetRange = obj
elif key == "notes":
value = pvalue
obj = value
self.notes = obj
elif key == "proxyDataset":
value = pvalue
obj = value
self.proxyDataset = obj
elif key == "targetDataset":
value = pvalue
obj = value
self.targetDataset = obj
elif key == "uncertainty":
value = pvalue
obj = value
self.uncertainty = obj
else:
self.set_non_standard_property(key, pvalue)

return self

def set_non_standard_property(self, key, value):
if key not in self.misc:
self.misc[key] = value
Expand Down
20 changes: 20 additions & 0 deletions pylipd/classes/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ def to_json(self):

return data

@staticmethod
def from_json(data) -> 'ChangeLog':
self = ChangeLog()
for key in data:
pvalue = data[key]
if key == "@id":
self.id = pvalue
elif key == "changes":
value = pvalue
obj = value
self.changes = obj
elif key == "notes":
value = pvalue
obj = value
self.notes = obj
else:
self.set_non_standard_property(key, pvalue)

return self

def set_non_standard_property(self, key, value):
if key not in self.misc:
self.misc[key] = value
Expand Down
30 changes: 22 additions & 8 deletions pylipd/classes/chrondata.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,13 @@ def to_json(self):
if len(self.measurementTables):
data["measurementTable"] = []
for value_obj in self.measurementTables:
if hasattr(value_obj, "to_json"):
obj = value_obj.to_json()
else:
obj = value_obj
obj = value_obj.to_json()
data["measurementTable"].append(obj)

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

for key in self.misc:
Expand All @@ -141,6 +135,26 @@ def to_json(self):

return data

@staticmethod
def from_json(data) -> 'ChronData':
self = ChronData()
for key in data:
pvalue = data[key]
if key == "@id":
self.id = pvalue
elif key == "measurementTable":
for value in pvalue:
obj = DataTable.from_json(value)
self.measurementTables.append(obj)
elif key == "model":
for value in pvalue:
obj = Model.from_json(value)
self.modeledBy.append(obj)
else:
self.set_non_standard_property(key, pvalue)

return self

def set_non_standard_property(self, key, value):
if key not in self.misc:
self.misc[key] = value
Expand Down
20 changes: 20 additions & 0 deletions pylipd/classes/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,26 @@ def to_json(self):

return data

@staticmethod
def from_json(data) -> 'Compilation':
self = Compilation()
for key in data:
pvalue = data[key]
if key == "@id":
self.id = pvalue
elif key == "compilationName":
value = pvalue
obj = value
self.name = obj
elif key == "compilationVersion":
value = pvalue
obj = value
self.version = obj
else:
self.set_non_standard_property(key, pvalue)

return self

def set_non_standard_property(self, key, value):
if key not in self.misc:
self.misc[key] = value
Expand Down
138 changes: 98 additions & 40 deletions pylipd/classes/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,71 +436,47 @@ def to_json(self):
if len(self.chronData):
data["chronData"] = []
for value_obj in self.chronData:
if hasattr(value_obj, "to_json"):
obj = value_obj.to_json()
else:
obj = value_obj
obj = value_obj.to_json()
data["chronData"].append(obj)

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

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

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

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

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

if self.archiveType:
value_obj = self.archiveType
if hasattr(value_obj, "to_json"):
obj = value_obj.to_json()
else:
obj = value_obj
obj = value_obj.to_json()
data["archiveType"] = obj

if self.changeLog:
value_obj = self.changeLog
if hasattr(value_obj, "to_json"):
obj = value_obj.to_json()
else:
obj = value_obj
obj = value_obj.to_json()
data["changelog"] = obj

if self.collectionName:
Expand All @@ -515,10 +491,7 @@ def to_json(self):

if self.contributor:
value_obj = self.contributor
if hasattr(value_obj, "to_json"):
obj = value_obj.to_json()
else:
obj = value_obj
obj = value_obj.to_json()
data["dataContributor"] = obj

if self.dataSource:
Expand All @@ -533,10 +506,7 @@ def to_json(self):

if self.location:
value_obj = self.location
if hasattr(value_obj, "to_json"):
obj = value_obj.to_json()
else:
obj = value_obj
obj = value_obj.to_json()
data["geo"] = obj

if self.name:
Expand Down Expand Up @@ -570,6 +540,94 @@ def to_json(self):

return data

@staticmethod
def from_json(data) -> 'Dataset':
self = Dataset()
for key in data:
pvalue = data[key]
if key == "@id":
self.id = pvalue
elif key == "archiveType":
value = pvalue
obj = ArchiveType.from_synonym(re.sub("^.*?#", "", value))
self.archiveType = obj
elif key == "changelog":
value = pvalue
obj = ChangeLog.from_json(value)
self.changeLog = obj
elif key == "chronData":
for value in pvalue:
obj = ChronData.from_json(value)
self.chronData.append(obj)
elif key == "collectionName":
value = pvalue
obj = value
self.collectionName = obj
elif key == "collectionYear":
value = pvalue
obj = value
self.collectionYear = obj
elif key == "creator":
for value in pvalue:
obj = Person.from_json(value)
self.creators.append(obj)
elif key == "dataContributor":
value = pvalue
obj = Person.from_json(value)
self.contributor = obj
elif key == "dataSetName":
value = pvalue
obj = value
self.name = obj
elif key == "dataSetVersion":
value = pvalue
obj = value
self.version = obj
elif key == "dataSource":
value = pvalue
obj = value
self.dataSource = obj
elif key == "datasetId":
value = pvalue
obj = value
self.datasetId = obj
elif key == "funding":
for value in pvalue:
obj = Funding.from_json(value)
self.fundings.append(obj)
elif key == "geo":
value = pvalue
obj = Location.from_json(value)
self.location = obj
elif key == "googleSpreadSheetKey":
value = pvalue
obj = value
self.spreadsheetLink = obj
elif key == "investigator":
for value in pvalue:
obj = Person.from_json(value)
self.investigators.append(obj)
elif key == "notes":
value = pvalue
obj = value
self.notes = obj
elif key == "originalDataURL":
value = pvalue
obj = value
self.originalDataUrl = obj
elif key == "paleoData":
for value in pvalue:
obj = PaleoData.from_json(value)
self.paleoData.append(obj)
elif key == "pub":
for value in pvalue:
obj = Publication.from_json(value)
self.publications.append(obj)
else:
self.set_non_standard_property(key, pvalue)

return self

def set_non_standard_property(self, key, value):
if key not in self.misc:
self.misc[key] = value
Expand Down
Loading

0 comments on commit 7fd6e35

Please sign in to comment.