Пример #1
0
    def factAspects(fact):
        aspects = OrderedDict()
        if hasId and fact.id:
            aspects["id"] = fact.id
        elif (fact.isTuple or footnotesRelationshipSet.toModelObject(fact) or
              (isCSVorXL and footnotesRelationshipSet.fromModelObject(fact))):
            aspects["id"] = "f{}".format(fact.objectIndex)
        parent = fact.getparent()
        concept = fact.concept
        _csvType = "Value"
        if not fact.isTuple:
            if concept is not None:
                _baseXsdType = concept.baseXsdType
                if _baseXsdType == "XBRLI_DATEUNION":
                    if getattr(fact.xValue, "dateOnly", False):
                        _baseXsdType = "date"
                    else:
                        _baseXsdType = "dateTime"
                aspects["baseType"] = "xsd:{}".format(_baseXsdType)
                _csvType = baseTypes.get(_baseXsdType, _baseXsdType) + "Value"
                if concept.baseXbrliType in ("string", "normalizedString",
                                             "token") and fact.xmlLang:
                    aspects[qnOimLangAspect] = fact.xmlLang
        if fact.isItem:
            if fact.isNil:
                _value = None
                _strValue = "nil"
            else:
                _inferredDecimals = inferredDecimals(fact)
                _value = oimValue(fact.xValue, _inferredDecimals)
                _strValue = str(_value)
            if not isCSVorXL:
                aspects["value"] = _strValue
            if fact.concept is not None and fact.concept.isNumeric:
                _numValue = fact.xValue
                if isinstance(_numValue, Decimal) and not isinf(
                        _numValue) and not isnan(_numValue):
                    if _numValue == _numValue.to_integral():
                        _numValue = int(_numValue)
                    else:
                        _numValue = float(_numValue)
                if isCSVorXL:
                    aspects[_csvType] = _numValue
                else:
                    aspects["numericValue"] = _numValue
                if not fact.isNil:
                    if isinf(_inferredDecimals):
                        if isJSON: _accuracy = "infinity"
                        elif isCSVorXL: _accuracy = "INF"
                    else:
                        _accuracy = _inferredDecimals
                    aspects["accuracy"] = _accuracy
            elif isinstance(_value, bool):
                aspects["booleanValue"] = _value
            elif isCSVorXL:
                aspects[_csvType] = _strValue
        aspects[qnOimConceptAspect] = oimValue(fact.qname)
        cntx = fact.context
        if cntx is not None:
            if cntx.entityIdentifierElement is not None:
                aspects[qnOimEntityAspect] = oimValue(
                    qname(*cntx.entityIdentifier))
            if cntx.period is not None:
                if isJSON:
                    aspects[qnOimPeriodAspect] = oimPeriodValue(cntx)
                elif isCSVorXL:
                    _periodValue = oimPeriodValue(cntx)
                    aspects[qnOimPeriodStartAspect] = _periodValue["start"]
                    aspects[qnOimPeriodEndAspect] = _periodValue["end"]
            for _qn, dim in sorted(cntx.qnameDims.items(),
                                   key=lambda item: item[0]):
                aspects[dim.dimensionQname] = (
                    oimValue(dim.memberQname)
                    if dim.isExplicit else None if dim.typedMember.get(
                        "{http://www.w3.org/2001/XMLSchema-instance}nil") in (
                            "true", "1") else dim.typedMember.stringValue)
        unit = fact.unit
        if unit is not None:
            _mMul, _mDiv = unit.measures
            _sMul = '*'.join(
                oimValue(m) for m in sorted(_mMul, key=lambda m: oimValue(m)))
            if _mDiv:
                _sDiv = '*'.join(
                    oimValue(m)
                    for m in sorted(_mDiv, key=lambda m: oimValue(m)))
                if len(_mDiv) > 1:
                    if len(_mMul) > 1:
                        _sUnit = "({})/({})".format(_sMul, _sDiv)
                    else:
                        _sUnit = "{}/({})".format(_sMul, _sDiv)
                else:
                    if len(_mMul) > 1:
                        _sUnit = "({})/{}".format(_sMul, _sDiv)
                    else:
                        _sUnit = "{}/{}".format(_sMul, _sDiv)
            else:
                _sUnit = _sMul
            aspects[qnOimUnitAspect] = _sUnit
        if parent.qname != XbrlConst.qnXbrliXbrl:
            aspects[
                qnOimTupleParentAspect] = parent.id if parent.id else "f{}".format(
                    parent.objectIndex)
            aspects[qnOimTupleOrderAspect] = elementIndex(fact)

        if isJSON:
            _footnotes = factFootnotes(fact)
            if _footnotes:
                aspects["footnotes"] = _footnotes
        return aspects
Пример #2
0
 def factAspects(fact): 
     aspects = OrderedDict()
     if hasId and fact.id:
         aspects["id"] = fact.id
     elif (fact.isTuple or 
           footnotesRelationshipSet.toModelObject(fact) or
           (isCSVorXL and footnotesRelationshipSet.fromModelObject(fact))):
         aspects["id"] = "f{}".format(fact.objectIndex)
     parent = fact.getparent()
     concept = fact.concept
     _csvType = "Value"
     if not fact.isTuple:
         if concept is not None:
             _baseXsdType = concept.baseXsdType
             if _baseXsdType == "XBRLI_DATEUNION":
                 if getattr(fact.xValue, "dateOnly", False):
                     _baseXsdType = "date"
                 else:
                     _baseXsdType = "dateTime"
             aspects["baseType"] = "xs:{}".format(_baseXsdType)
             _csvType = baseTypes.get(_baseXsdType,_baseXsdType) + "Value"
             if concept.baseXbrliType in ("string", "normalizedString", "token") and fact.xmlLang:
                 aspects[qnOimLangAspect] = fact.xmlLang
     if fact.isItem:
         if fact.isNil:
             _value = None
             _strValue = "nil"
         else:
             _inferredDecimals = inferredDecimals(fact)
             _value = oimValue(fact.xValue, _inferredDecimals)
             _strValue = str(_value)
         if not isCSVorXL:
             aspects["value"] = _strValue
         if fact.concept is not None and fact.concept.isNumeric:
             _numValue = fact.xValue
             if isinstance(_numValue, Decimal) and not isinf(_numValue) and not isnan(_numValue):
                 if _numValue == _numValue.to_integral():
                     _numValue = int(_numValue)
                 else:
                     _numValue = float(_numValue)
             if isCSVorXL:
                 aspects[_csvType] = _numValue
             else:
                 aspects["numericValue"] = _numValue
             if not fact.isNil:
                 if isinf(_inferredDecimals):
                     if isJSON: _accuracy = "infinity"
                     elif isCSVorXL: _accuracy = "INF"
                 else:
                     _accuracy = _inferredDecimals
                 aspects["accuracy"] = _accuracy
         elif isinstance(_value, bool):
             aspects["booleanValue"] = _value
         elif isCSVorXL:
             aspects[_csvType] = _strValue
     aspects[qnOimConceptAspect] = oimValue(fact.qname)
     cntx = fact.context
     if cntx is not None:
         if cntx.entityIdentifierElement is not None:
             aspects[qnOimEntityAspect] = oimValue(qname(*cntx.entityIdentifier))
         if cntx.period is not None:
             if isJSON:
                 aspects[qnOimPeriodAspect] = oimPeriodValue(cntx)
             elif isCSVorXL:
                 _periodValue = oimPeriodValue(cntx)
                 aspects[qnOimPeriodStartAspect] = _periodValue["start"]
                 aspects[qnOimPeriodEndAspect] = _periodValue["end"]
         for _qn, dim in sorted(cntx.qnameDims.items(), key=lambda item: item[0]):
             aspects[dim.dimensionQname] = (oimValue(dim.memberQname) if dim.isExplicit
                                            else None if dim.typedMember.get("{http://www.w3.org/2001/XMLSchema-instance}nil") in ("true", "1")
                                            else dim.typedMember.stringValue)
     unit = fact.unit
     if unit is not None:
         _mMul, _mDiv = unit.measures
         _sMul = '*'.join(oimValue(m) for m in sorted(_mMul, key=lambda m: str(m)))
         if _mDiv:
             _sDiv = '*'.join(oimValue(m) for m in sorted(_mDiv, key=lambda m: str(m)))
             if len(mDiv) > 1:
                 if len(mMul) > 1:
                     _sUnit = "({})/({})".format(_sMul,_sDiv)
                 else:
                     _sUnit = "{}/({})".format(_sMul,_sDiv)
             else:
                 if len(mMul) > 1:
                     _sUnit = "({})/{}".format(_sMul,_sDiv)
                 else:
                     _sUnit = "{}/{}".format(_sMul,_sDiv)
         else:
             _sUnit = _sMul
         aspects[qnOimUnitAspect] = _sUnit
     if parent.qname != XbrlConst.qnXbrliXbrl:
         aspects[qnOimTupleParentAspect] = parent.id if parent.id else "f{}".format(parent.objectIndex)
         aspects[qnOimTupleOrderAspect] = elementIndex(fact)
         
     if isJSON:
         _footnotes = factFootnotes(fact)
         if _footnotes:
             aspects["footnotes"] = _footnotes
     return aspects
Пример #3
0
 def factAspects(fact):
     aspects = OrderedDict()
     if hasId and fact.id:
         aspects["id"] = fact.id
     elif fact.isTuple or footnotesRelationshipSet.toModelObject(fact):
         aspects["id"] = "f{}".format(fact.objectIndex)
     parent = fact.getparent()
     concept = fact.concept
     if not fact.isTuple:
         if concept is not None:
             _baseXsdType = concept.baseXsdType
             if _baseXsdType == "XBRLI_DATEUNION":
                 if getattr(fact.xValue, "dateOnly", False):
                     _baseXsdType = "date"
                 else:
                     _baseXsdType = "dateTime"
             aspects["baseType"] = "xs:{}".format(_baseXsdType)
             if concept.baseXbrliType in ("string", "normalizedString", "token") and fact.xmlLang:
                 aspects[qnOimLangAspect] = fact.xmlLang
             aspects[qnOimTypeAspect] = concept.baseXbrliType
     if fact.isItem:
         if fact.isNil:
             _value = None
             _strValue = "nil"
         else:
             _inferredDecimals = inferredDecimals(fact)
             _value = oimValue(fact.xValue, _inferredDecimals)
             _strValue = str(_value)
         aspects["value"] = _strValue
         if fact.concept is not None and fact.concept.isNumeric:
             _numValue = fact.xValue
             if isinstance(_numValue, Decimal) and not isinf(_numValue) and not isnan(_numValue):
                 if _numValue == _numValue.to_integral():
                     _numValue = int(_numValue)
                 else:
                     _numValue = float(_numValue)
             aspects["numericValue"] = _numValue
             if not fact.isNil:
                 aspects["accuracy"] = "infinity" if isinf(_inferredDecimals) else _inferredDecimals
         elif isinstance(_value, bool):
             aspects["booleanValue"] = _value
     aspects[qnOimConceptAspect] = oimValue(fact.qname)
     cntx = fact.context
     if cntx is not None:
         if cntx.entityIdentifierElement is not None:
             aspects[qnOimEntityAspect] = oimValue(qname(*cntx.entityIdentifier))
         if cntx.period is not None:
             aspects[qnOimPeriodAspect] = oimPeriodValue(cntx)
         for _qn, dim in sorted(cntx.qnameDims.items(), key=lambda item: item[0]):
             aspects[dim.dimensionQname] = (oimValue(dim.memberQname) if dim.isExplicit
                                            else None if dim.typedMember.get("{http://www.w3.org/2001/XMLSchema-instance}nil") in ("true", "1")
                                            else dim.typedMember.stringValue)
     unit = fact.unit
     if unit is not None:
         _mMul, _mDiv = unit.measures
         if isJSON:
             aspects[qnOimUnitAspect] = { # use tuple instead of list for hashability
                 "numerators": tuple(oimValue(m) for m in sorted(_mMul, key=lambda m: oimValue(m)))
             }
             if _mDiv:
                 aspects[qnOimUnitAspect]["denominators"] = tuple(oimValue(m) for m in sorted(_mDiv, key=lambda m: oimValue(m)))
         else: # CSV
             if _mMul:
                 aspects[qnOimUnitMulAspect] = ",".join(oimValue(m)
                                                     for m in sorted(_mMul, key=lambda m: q(m)))
             if _mDiv:
                 aspects[qnOimUnitDivAspect] = ",".join(oimValue(m)
                                                     for m in sorted(_mDiv, key=lambda m: str(m)))
     if parent.qname != XbrlConst.qnXbrliXbrl:
         aspects[qnOimTupleParentAspect] = parent.id if parent.id else "f{}".format(parent.objectIndex)
         aspects[qnOimTupleOrderAspect] = elementIndex(fact)
                 
     footnotes = []
     for footnoteRel in footnotesRelationshipSet.fromModelObject(fact):
         footnote = {"group": footnoteRel.arcrole}
         footnotes.append(footnote)
         toObj = footnoteRel.toModelObject
         if isinstance(toObj, ModelFact):
             footnote["factRef"] = toObj.id if toObj.id else "f{}".format(toObj.objectIndex)
         else:
             footnote["footnoteType"] = toObj.role
             footnote["footnote"] = xmlstring(toObj, stripXmlns=True, contentsOnly=True, includeText=True)
             if toObj.xmlLang:
                 footnote["language"] = toObj.xmlLang
     if footnotes:
         aspects["footnotes"] = footnotes
     return aspects
Пример #4
0
 def factAspects(fact): 
     aspects = OrderedDict()
     if hasId and fact.id:
         aspects["id"] = fact.id
     elif (fact.isTuple or 
           footnotesRelationshipSet.toModelObject(fact) or
           (isCSV and footnotesRelationshipSet.fromModelObject(fact))):
         aspects["id"] = "f{}".format(fact.objectIndex)
     parent = fact.getparent()
     concept = fact.concept
     if not fact.isTuple:
         if concept is not None:
             _baseXsdType = concept.baseXsdType
             if _baseXsdType == "XBRLI_DATEUNION":
                 if getattr(fact.xValue, "dateOnly", False):
                     _baseXsdType = "date"
                 else:
                     _baseXsdType = "dateTime"
             aspects["baseType"] = "xs:{}".format(_baseXsdType)
             if concept.baseXbrliType in ("string", "normalizedString", "token") and fact.xmlLang:
                 aspects[qnOimLangAspect] = fact.xmlLang
             aspects[qnOimTypeAspect] = concept.baseXbrliType
     if fact.isItem:
         if fact.isNil:
             _value = None
             _strValue = "nil"
         else:
             _inferredDecimals = inferredDecimals(fact)
             _value = oimValue(fact.xValue, _inferredDecimals)
             _strValue = str(_value)
         if not isCSV:
             aspects["value"] = _strValue
         if fact.concept is not None and fact.concept.isNumeric:
             _numValue = fact.xValue
             if isinstance(_numValue, Decimal) and not isinf(_numValue) and not isnan(_numValue):
                 if _numValue == _numValue.to_integral():
                     _numValue = int(_numValue)
                 else:
                     _numValue = float(_numValue)
             aspects["numericValue"] = _numValue
             if not fact.isNil:
                 if isinf(_inferredDecimals):
                     if isJSON: _accuracy = "infinity"
                     elif isCSV: _accuracy = "INF"
                 else:
                     _accuracy = _inferredDecimals
                 aspects["accuracy"] = _inferredDecimals
         elif isinstance(_value, bool):
             aspects["booleanValue"] = _value
         elif isCSV:
             aspects["stringValue"] = _strValue
     aspects[qnOimConceptAspect] = oimValue(fact.qname)
     cntx = fact.context
     if cntx is not None:
         if cntx.entityIdentifierElement is not None:
             aspects[qnOimEntityAspect] = oimValue(qname(*cntx.entityIdentifier))
         if cntx.period is not None:
             if isJSON:
                 aspects[qnOimPeriodAspect] = oimPeriodValue(cntx)
             elif isCSV:
                 _periodValue = oimPeriodValue(cntx).split("/") + ["", ""] # default blank if no value
                 aspects[qnOimPeriodStartAspect] = _periodValue[0]
                 aspects[qnOimPeriodDurationAspect] = _periodValue[1]
         for _qn, dim in sorted(cntx.qnameDims.items(), key=lambda item: item[0]):
             aspects[dim.dimensionQname] = (oimValue(dim.memberQname) if dim.isExplicit
                                            else None if dim.typedMember.get("{http://www.w3.org/2001/XMLSchema-instance}nil") in ("true", "1")
                                            else dim.typedMember.stringValue)
     unit = fact.unit
     if unit is not None:
         _mMul, _mDiv = unit.measures
         if isJSON:
             aspects[qnOimUnitAspect] = OrderedDict( # use tuple instead of list for hashability
                 (("numerators", tuple(oimValue(m) for m in sorted(_mMul, key=lambda m: oimValue(m)))),)
             )
             if _mDiv:
                 aspects[qnOimUnitAspect]["denominators"] = tuple(oimValue(m) for m in sorted(_mDiv, key=lambda m: oimValue(m)))
         else: # CSV
             if _mMul:
                 aspects[qnOimUnitNumeratorsAspect] = " ".join(oimValue(m)
                                                               for m in sorted(_mMul, key=lambda m: str(m)))
             if _mDiv:
                 aspects[qnOimUnitDenominatorsAspect] = " ".join(oimValue(m)
                                                                 for m in sorted(_mDiv, key=lambda m: str(m)))
     if parent.qname != XbrlConst.qnXbrliXbrl:
         aspects[qnOimTupleParentAspect] = parent.id if parent.id else "f{}".format(parent.objectIndex)
         aspects[qnOimTupleOrderAspect] = elementIndex(fact)
         
     if isJSON:
         _footnotes = factFootnotes(fact)
         if _footnotes:
             aspects["footnotes"] = _footnotes
     return aspects