#NEWLINE# def evaluateTableIndex( modelXbrl ) : #NEWLINE# #INDENT# disclosureSystem = modelXbrl . modelManager . disclosureSystem #NEWLINE# if ( disclosureSystem . validationType == 'EFM' ) : #NEWLINE# #INDENT# COVER = '1Cover' #NEWLINE# STMTS = '2Financial Statements' #NEWLINE# NOTES = '3Notes to Financial Statements' #NEWLINE# POLICIES = '4Accounting Policies' #NEWLINE# TABLES = '5Notes Tables' #NEWLINE# DETAILS = '6Notes Details' #NEWLINE# UNCATEG = '7Uncategorized' #NEWLINE# roleDefinitionPattern = re . compile ( '([0-9]+) - (Statement|Disclosure|Schedule|Document) - (.+)' ) #NEWLINE# definitionElrs = dict ( ( ( roleType . definition , roleType ) for roleURI in modelXbrl . relationshipSet ( XbrlConst . parentChild ) . linkRoleUris for roleType in modelXbrl . roleTypes . get ( roleURI , ( ) ) ) ) #NEWLINE# isRR = any ( ( ns . startswith ( 'http://xbrl.sec.gov/rr/' ) for ns in modelXbrl . namespaceDocs . keys ( ) if ns ) ) #NEWLINE# tableGroup = None #NEWLINE# firstTableLinkroleURI = None #NEWLINE# firstDocumentLinkroleURI = None #NEWLINE# sortedRoleTypes = sorted ( definitionElrs . items ( ) , key = ( lambda item : item [ 0 ] ) ) #NEWLINE# for ( roleDefinition , roleType ) in sortedRoleTypes : #NEWLINE# #INDENT# roleType . _tableChildren = [ ] #NEWLINE# match = ( roleDefinitionPattern . match ( roleDefinition ) if roleDefinition else None ) #NEWLINE# if ( not match ) : #NEWLINE# #INDENT# roleType . _tableIndex = ( UNCATEG , '' , roleType . roleURI ) #NEWLINE# continue #NEWLINE# #UNINDENT# ( seq , tblType , tblName ) = match . groups ( ) #NEWLINE# if isRR : #NEWLINE# #INDENT# tableGroup = COVER #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not tableGroup ) : #NEWLINE# #INDENT# tableGroup = ( ( ( 'Paren' in tblName ) and COVER ) or ( ( tblType == 'Statement' ) and STMTS ) or ( ( '(Polic' in tblName ) and NOTES ) or ( ( '(Table' in tblName ) and TABLES ) or ( ( '(Detail' in tblName ) and DETAILS ) or COVER ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( tableGroup == COVER ) : #NEWLINE# #INDENT# tableGroup = ( ( ( tblType == 'Statement' ) and STMTS ) or ( ( 'Paren' in tblName ) and COVER ) or ( ( '(Polic' in tblName ) and NOTES ) or ( ( '(Table' in tblName ) and TABLES ) or ( ( '(Detail' in tblName ) and DETAILS ) or NOTES ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( tableGroup == STMTS ) : #NEWLINE# #INDENT# tableGroup = ( ( ( ( tblType == 'Statement' ) or ( 'Paren' in tblName ) ) and STMTS ) or ( ( '(Polic' in tblName ) and NOTES ) or ( ( '(Table' in tblName ) and TABLES ) or ( ( '(Detail' in tblName ) and DETAILS ) or NOTES ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( tableGroup == NOTES ) : #NEWLINE# #INDENT# tableGroup = ( ( ( '(Polic' in tblName ) and POLICIES ) or ( ( '(Table' in tblName ) and TABLES ) or ( ( '(Detail' in tblName ) and DETAILS ) or ( ( tblType == 'Disclosure' ) and NOTES ) or UNCATEG ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( tableGroup == POLICIES ) : #NEWLINE# #INDENT# tableGroup = ( ( ( '(Table' in tblName ) and TABLES ) or ( ( '(Detail' in tblName ) and DETAILS ) or ( ( ( 'Paren' in tblName ) or ( '(Polic' in tblName ) ) and POLICIES ) or UNCATEG ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( tableGroup == TABLES ) : #NEWLINE# #INDENT# tableGroup = ( ( ( '(Detail' in tblName ) and DETAILS ) or ( ( ( 'Paren' in tblName ) or ( '(Table' in tblName ) ) and TABLES ) or UNCATEG ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( tableGroup == DETAILS ) : #NEWLINE# #INDENT# tableGroup = ( ( ( ( 'Paren' in tblName ) or ( '(Detail' in tblName ) ) and DETAILS ) or UNCATEG ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# tableGroup = UNCATEG #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( ( firstTableLinkroleURI is None ) and ( tableGroup == COVER ) ) : #NEWLINE# #INDENT# firstTableLinkroleURI = roleType . roleURI #NEWLINE# #UNINDENT# if ( ( tblType == 'Document' ) and ( not firstDocumentLinkroleURI ) ) : #NEWLINE# #INDENT# firstDocumentLinkroleURI = roleType . roleURI #NEWLINE# #UNINDENT# roleType . _tableIndex = ( tableGroup , seq , tblName ) #NEWLINE# #UNINDENT# if ( not modelXbrl . qnameDimensionDefaults ) : #NEWLINE# #INDENT# from arelle import ValidateXbrlDimensions #NEWLINE# ValidateXbrlDimensions . loadDimensionDefaults ( modelXbrl ) #NEWLINE# #UNINDENT# reportedFacts = set ( ) #NEWLINE# factsByQname = modelXbrl . factsByQname #NEWLINE# reportingPeriods = set ( ) #NEWLINE# nextEnd = None #NEWLINE# deiFact = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for conceptName in ( 'DocumentPeriodEndDate' , 'DocumentType' , 'CurrentFiscalPeriodEndDate' ) : #NEWLINE# #INDENT# for concept in modelXbrl . nameConcepts [ conceptName ] : #NEWLINE# #INDENT# for fact in factsByQname [ concept . qname ] : #NEWLINE# #INDENT# deiFact [ conceptName ] = fact #NEWLINE# if ( fact . context is not None ) : #NEWLINE# #INDENT# reportingPeriods . add ( ( None , fact . context . endDatetime ) ) #NEWLINE# reportingPeriods . add ( ( fact . context . startDatetime , fact . context . endDatetime ) ) #NEWLINE# nextEnd = fact . context . startDatetime #NEWLINE# duration = ( ( fact . context . endDatetime - fact . context . startDatetime ) . days + 1 ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( 'DocumentType' in deiFact ) : #NEWLINE# #INDENT# fact = deiFact [ 'DocumentType' ] #NEWLINE# if ( '-Q' in fact . xValue ) : #NEWLINE# #INDENT# endDatetime = fact . context . endDatetime #NEWLINE# endDatetimeMonth = endDatetime . month #NEWLINE# if ( ( endDatetime + timedelta ( 2 ) ) . month != endDatetimeMonth ) : #NEWLINE# #INDENT# endOfMonth = True #NEWLINE# while ( endDatetime . month == endDatetimeMonth ) : #NEWLINE# #INDENT# endDatetime += timedelta ( 1 ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# endOfMonth = False #NEWLINE# #UNINDENT# startYr = endDatetime . year #NEWLINE# startMo = ( endDatetime . month - 3 ) #NEWLINE# if ( startMo <= 0 ) : #NEWLINE# #INDENT# startMo += 12 #NEWLINE# startYr -= 1 #NEWLINE# #UNINDENT# startDatetime = datetime ( startYr , startMo , endDatetime . day , endDatetime . hour , endDatetime . minute , endDatetime . second ) #NEWLINE# if endOfMonth : #NEWLINE# #INDENT# startDatetime -= timedelta ( 1 ) #NEWLINE# endDatetime -= timedelta ( 1 ) #NEWLINE# #UNINDENT# reportingPeriods . add ( ( startDatetime , endDatetime ) ) #NEWLINE# duration = 91 #NEWLINE# #UNINDENT# #UNINDENT# while ( nextEnd is not None ) : #NEWLINE# #INDENT# thisEnd = nextEnd #NEWLINE# prevMaxStart = ( thisEnd - timedelta ( ( duration * 0.9 ) ) ) #NEWLINE# prevMinStart = ( thisEnd - timedelta ( ( duration * 1.1 ) ) ) #NEWLINE# nextEnd = None #NEWLINE# for cntx in modelXbrl . contexts . values ( ) : #NEWLINE# #INDENT# if ( cntx . isStartEndPeriod and ( not cntx . qnameDims ) and ( thisEnd == cntx . endDatetime ) and ( prevMinStart <= cntx . startDatetime <= prevMaxStart ) ) : #NEWLINE# #INDENT# reportingPeriods . add ( ( None , cntx . endDatetime ) ) #NEWLINE# reportingPeriods . add ( ( cntx . startDatetime , cntx . endDatetime ) ) #NEWLINE# nextEnd = cntx . startDatetime #NEWLINE# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cntx . isInstantPeriod and ( not cntx . qnameDims ) and ( thisEnd == cntx . endDatetime ) ) : #NEWLINE# #INDENT# reportingPeriods . add ( ( None , cntx . endDatetime ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# stmtReportingPeriods = set ( reportingPeriods ) #NEWLINE# sortedRoleTypes . reverse ( ) #NEWLINE# for ( i , roleTypes ) in enumerate ( sortedRoleTypes ) : #NEWLINE# #INDENT# ( roleDefinition , roleType ) = roleTypes #NEWLINE# tableFacts = set ( ) #NEWLINE# ( tableGroup , tableSeq , tableName ) = roleType . _tableIndex #NEWLINE# ( roleURIdims , priItemQNames ) = EFMlinkRoleURIstructure ( modelXbrl , roleType . roleURI ) #NEWLINE# for priItemQName in priItemQNames : #NEWLINE# #INDENT# for fact in factsByQname [ priItemQName ] : #NEWLINE# #INDENT# cntx = fact . context #NEWLINE# if ( ( cntx is not None ) and all ( ( ( dimQn in modelXbrl . qnameDimensionDefaults ) for dimQn in ( roleURIdims . keys ( ) - cntx . qnameDims . keys ( ) ) ) ) and all ( ( ( mdlDim . memberQname in roleURIdims [ dimQn ] ) for ( dimQn , mdlDim ) in cntx . qnameDims . items ( ) if ( dimQn in roleURIdims ) ) ) ) : #NEWLINE# #INDENT# cntxStartDatetime = cntx . startDatetime #NEWLINE# cntxEndDatetime = cntx . endDatetime #NEWLINE# if ( ( tableGroup != STMTS ) or ( ( ( cntxStartDatetime , cntxEndDatetime ) in stmtReportingPeriods ) and ( ( fact not in reportedFacts ) or all ( ( ( dimQn not in cntx . qnameDims ) for dimQn in ( cntx . qnameDims . keys ( ) - roleURIdims . keys ( ) ) ) ) ) ) ) : #NEWLINE# #INDENT# tableFacts . add ( fact ) #NEWLINE# reportedFacts . add ( fact ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# roleType . _tableFacts = tableFacts #NEWLINE# closestParentType = None #NEWLINE# closestParentMatchLength = 0 #NEWLINE# for ( _parentRoleDefinition , parentRoleType ) in sortedRoleTypes [ ( i + 1 ) : ] : #NEWLINE# #INDENT# matchLen = parentNameMatchLen ( tableName , parentRoleType ) #NEWLINE# if ( matchLen > closestParentMatchLength ) : #NEWLINE# #INDENT# closestParentMatchLength = matchLen #NEWLINE# closestParentType = parentRoleType #NEWLINE# #UNINDENT# #UNINDENT# if ( closestParentType is not None ) : #NEWLINE# #INDENT# closestParentType . _tableChildren . insert ( 0 , roleType ) #NEWLINE# #UNINDENT# unmatchedChildRoles = set ( ) #NEWLINE# longestChildMatchLen = 0 #NEWLINE# numChildren = 0 #NEWLINE# for childRoleType in roleType . _tableChildren : #NEWLINE# #INDENT# matchLen = parentNameMatchLen ( tableName , childRoleType ) #NEWLINE# if ( matchLen < closestParentMatchLength ) : #NEWLINE# #INDENT# unmatchedChildRoles . add ( childRoleType ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( matchLen > longestChildMatchLen ) : #NEWLINE# #INDENT# longestChildMatchLen = matchLen #NEWLINE# numChildren += 1 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( numChildren > 1 ) : #NEWLINE# #INDENT# for childRoleType in roleType . _tableChildren : #NEWLINE# #INDENT# if ( ( childRoleType not in unmatchedChildRoles ) and ( parentNameMatchLen ( tableName , childRoleType ) < longestChildMatchLen ) ) : #NEWLINE# #INDENT# unmatchedChildRoles . add ( childRoleType ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for unmatchedChildRole in unmatchedChildRoles : #NEWLINE# #INDENT# roleType . _tableChildren . remove ( unmatchedChildRole ) #NEWLINE# #UNINDENT# for childRoleType in roleType . _tableChildren : #NEWLINE# #INDENT# childRoleType . _tableParent = roleType #NEWLINE# #UNINDENT# unmatchedChildRoles = None #NEWLINE# #UNINDENT# global UGT_TOPICS #NEWLINE# if ( UGT_TOPICS is None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# from arelle import FileSource #NEWLINE# fh = FileSource . openFileStream ( modelXbrl . modelManager . cntlr , os . path . join ( modelXbrl . modelManager . cntlr . configDir , 'ugt-topics.zip/ugt-topics.json' ) , 'r' , 'utf-8' ) #NEWLINE# UGT_TOPICS = json . load ( fh ) #NEWLINE# fh . close ( ) #NEWLINE# for topic in UGT_TOPICS : #NEWLINE# #INDENT# topic [ 6 ] = set ( topic [ 6 ] ) #NEWLINE# topic [ 7 ] = set ( topic [ 7 ] ) #NEWLINE# topic [ 8 ] = set ( topic [ 8 ] ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception as ex : #NEWLINE# #INDENT# UGT_TOPICS = None #NEWLINE# #UNINDENT# #UNINDENT# if ( UGT_TOPICS is not None ) : #NEWLINE# #INDENT# def roleUgtConcepts( roleType ) : #NEWLINE# #INDENT# roleConcepts = set ( ) #NEWLINE# for rel in modelXbrl . relationshipSet ( XbrlConst . parentChild , roleType . roleURI ) . modelRelationships : #NEWLINE# #INDENT# if ( rel . toModelObject is not None ) : #NEWLINE# #INDENT# roleConcepts . add ( rel . toModelObject . name ) #NEWLINE# #UNINDENT# if ( rel . fromModelObject is not None ) : #NEWLINE# #INDENT# roleConcepts . add ( rel . fromModelObject . name ) #NEWLINE# #UNINDENT# #UNINDENT# if hasattr ( roleType , '_tableChildren' ) : #NEWLINE# #INDENT# for _tableChild in roleType . _tableChildren : #NEWLINE# #INDENT# roleConcepts |= roleUgtConcepts ( _tableChild ) #NEWLINE# #UNINDENT# #UNINDENT# return roleConcepts #NEWLINE# #UNINDENT# topicMatches = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( roleDefinition , roleType ) in sortedRoleTypes : #NEWLINE# #INDENT# roleTopicType = ( 'S' if roleDefinition . startswith ( 'S' ) else 'D' ) #NEWLINE# if ( getattr ( roleType , '_tableParent' , None ) is None ) : #NEWLINE# #INDENT# concepts = roleUgtConcepts ( roleType ) #NEWLINE# for ( i , ugtTopic ) in enumerate ( UGT_TOPICS ) : #NEWLINE# #INDENT# if ( ugtTopic [ 0 ] == roleTopicType ) : #NEWLINE# #INDENT# countAbstracts = len ( ( concepts & ugtTopic [ 6 ] ) ) #NEWLINE# countTextBlocks = len ( ( concepts & ugtTopic [ 7 ] ) ) #NEWLINE# countLineItems = len ( ( concepts & ugtTopic [ 8 ] ) ) #NEWLINE# if ( countAbstracts or countTextBlocks or countLineItems ) : #NEWLINE# #INDENT# _score = ( ( ( 10 * countAbstracts ) + ( 1000 * countTextBlocks ) ) + ( countLineItems / len ( concepts ) ) ) #NEWLINE# if ( ( i not in topicMatches ) or ( _score > topicMatches [ i ] [ 0 ] ) ) : #NEWLINE# #INDENT# topicMatches [ i ] = ( _score , roleType ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# for ( topicNum , scoredRoleType ) in topicMatches . items ( ) : #NEWLINE# #INDENT# ( _score , roleType ) = scoredRoleType #NEWLINE# if ( _score > getattr ( roleType , '_tableTopicScore' , 0 ) ) : #NEWLINE# #INDENT# ugtTopic = UGT_TOPICS [ topicNum ] #NEWLINE# roleType . _tableTopicScore = _score #NEWLINE# roleType . _tableTopicType = ugtTopic [ 0 ] #NEWLINE# roleType . _tableTopicName = ugtTopic [ 3 ] #NEWLINE# roleType . _tableTopicCode = ugtTopic [ 4 ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ( ( firstTableLinkroleURI or firstDocumentLinkroleURI ) , None ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'jp-fsa' in modelXbrl . modelManager . disclosureSystem . names ) : #NEWLINE# #INDENT# roleElrs = dict ( ( ( roleURI , roleType ) for roleURI in modelXbrl . relationshipSet ( XbrlConst . parentChild ) . linkRoleUris for roleType in modelXbrl . roleTypes . get ( roleURI , ( ) ) ) ) #NEWLINE# roleIdentifierItems = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( roleURI , roleType ) in roleElrs . items ( ) : #NEWLINE# #INDENT# roleType . _tableChildren = [ ] #NEWLINE# relSet = modelXbrl . relationshipSet ( XbrlConst . parentChild , roleURI ) #NEWLINE# for rootConcept in relSet . rootConcepts : #NEWLINE# #INDENT# if ( rootConcept . substitutionGroupQname and ( rootConcept . substitutionGroupQname . localName == 'identifierItem' ) ) : #NEWLINE# #INDENT# roleIdentifierItems [ rootConcept ] = roleType #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# linkroleUri = None #NEWLINE# for ( roleURI , roleType ) in roleElrs . items ( ) : #NEWLINE# #INDENT# relSet = modelXbrl . relationshipSet ( XbrlConst . parentChild , roleURI ) #NEWLINE# def addRoleIdentifiers( fromConcept , parentRoleType , visited ) : #NEWLINE# #INDENT# for rel in relSet . fromModelObject ( fromConcept ) : #NEWLINE# #INDENT# _fromConcept = rel . fromModelObject #NEWLINE# _toConcept = rel . toModelObject #NEWLINE# if ( isinstance ( _fromConcept , ModelConcept ) and isinstance ( _toConcept , ModelConcept ) ) : #NEWLINE# #INDENT# _fromSubQn = _fromConcept . substitutionGroupQname #NEWLINE# _toSubQn = _toConcept . substitutionGroupQname #NEWLINE# if ( ( ( parentRoleType is not None ) or ( _fromSubQn and ( _fromSubQn . localName == 'identifierItem' ) and ( _fromConcept in roleIdentifierItems ) ) ) and _toSubQn and ( _toSubQn . localName == 'identifierItem' ) and ( _toConcept in roleIdentifierItems ) ) : #NEWLINE# #INDENT# if ( parentRoleType is None ) : #NEWLINE# #INDENT# parentRoleType = roleIdentifierItems [ _fromConcept ] #NEWLINE# #UNINDENT# _toRoleType = roleIdentifierItems [ _toConcept ] #NEWLINE# if ( _toConcept not in parentRoleType . _tableChildren ) : #NEWLINE# #INDENT# parentRoleType . _tableChildren . append ( _toRoleType ) #NEWLINE# #UNINDENT# if ( _toConcept not in visited ) : #NEWLINE# #INDENT# visited . add ( _toConcept ) #NEWLINE# addRoleIdentifiers ( _toConcept , _toRoleType , visited ) #NEWLINE# visited . discard ( _toConcept ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( _toConcept not in visited ) : #NEWLINE# #INDENT# visited . add ( _toConcept ) #NEWLINE# addRoleIdentifiers ( _toConcept , parentRoleType , visited ) #NEWLINE# visited . discard ( _toConcept ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# for rootConcept in relSet . rootConcepts : #NEWLINE# #INDENT# addRoleIdentifiers ( rootConcept , None , set ( ) ) #NEWLINE# if ( ( not linkroleUri ) and ( len ( roleType . _tableChildren ) > 0 ) ) : #NEWLINE# #INDENT# linkroleUri = roleURI #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ( linkroleUri , linkroleUri ) #NEWLINE# #UNINDENT# #UNINDENT# return ( None , None )