Skip to content

Commit

Permalink
Issue #78 removed default decimals in fact constructor, removed 'unit…
Browse files Browse the repository at this point in the history
…s=pure' edge case.
  • Loading branch information
jonoxia committed Feb 7, 2019
1 parent cd69e9f commit 32b1d05
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions oblib/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,9 @@ def __init__(self, concept, context, unit, value, decimals=None, precision=None)
raise OBException("Fact given both precision and decimals - use only one.")
self.decimals = decimals
self.precision = precision
if decimals is None and precision is None:
# Default to 2 decimals:
self.decimals = 2
# FUTURE TODO: decide if the Concept is numeric or non-numeric. If numeric,
# either require a decimals/precision or provide a default. If non-numeric,
# don't allow decimals/precision to be set.

# Fill in the id property with a UUID:
self.id = identifier.identifier() # Only used when exporting JSON
Expand All @@ -478,17 +478,13 @@ def _toXML(self):
Return the Fact as an XML element.
"""
attribs = {"contextRef": self.context.get_id()}
# TODO the "pure" part is probably wrong now.
# also the self.unit may not be correct unitRef? not sure
# TODO the self.unit may not be correct unitRef? not sure
if self.unit is not None:
attribs["unitRef"] = self.unit
if self.unit == "pure":
attribs["decimals"] = "0"
else:
if self.decimals is not None:
attribs["decimals"] = str(self.decimals)
elif self.precision is not None:
attribs["precision"] = str(self.precision)
if self.decimals is not None:
attribs["decimals"] = str(self.decimals)
elif self.precision is not None:
attribs["precision"] = str(self.precision)
elem = Element(self.concept, attrib=attribs)
if self.unit == "pure":
elem.text = "%d" % self.value
Expand All @@ -505,13 +501,10 @@ def _toJSON(self):
aspects["concept"] = self.concept
if self.unit is not None:
aspects["unit"] = self.unit
if self.unit == "pure":
aspects["decimals"] = "0"
else:
if self.decimals is not None:
aspects["decimals"] = str(self.decimals)
elif self.precision is not None:
aspects["precision"] = str(self.precision)
if self.decimals is not None:
aspects["decimals"] = str(self.decimals)
elif self.precision is not None:
aspects["precision"] = str(self.precision)

if isinstance( self.value, datetime.datetime):
value_str = self.value.strftime("%Y-%m-%dT%H:%M:%S")
Expand Down

0 comments on commit 32b1d05

Please sign in to comment.