#NEWLINE# def on_xbrl_valid( job , instance ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# import tempfile #NEWLINE# tmp = tempfile . gettempdir ( ) #NEWLINE# tmplk = os . path . join ( tmp , 'extract_ratios_lock.tmp' ) #NEWLINE# lock = Lock ( tmplk ) #NEWLINE# lock . acquire ( ) #NEWLINE# if ( not os . path . isfile ( 'ratios.csv' ) ) : #NEWLINE# #INDENT# with open ( 'ratios.csv' , 'a' ) as ratiofile : #NEWLINE# #INDENT# ratiofile . write ( 'DocumentType,EntityName,CIK,PeriodEndDate,CurrentRatio,QuickRatio,CashRatio\n' ) #NEWLINE# ratiofile . close ( ) #NEWLINE# #UNINDENT# #UNINDENT# docEndDate = '2013-12-31' #NEWLINE# documentType = factFinder ( instance , sec_ns , 'DocumentType' ) #NEWLINE# documentFiscalYearFocus = factFinder ( instance , sec_ns , 'DocumentFiscalYearFocus' ) #NEWLINE# documentFiscalPeriodFocus = factFinder ( instance , sec_ns , 'DocumentFiscalPeriodFocus' ) #NEWLINE# documentPeriodEndDate = factFinder ( instance , sec_ns , 'DocumentPeriodEndDate' ) #NEWLINE# if ( len ( documentPeriodEndDate ) > 0 ) : #NEWLINE# #INDENT# docEndDate = documentPeriodEndDate [ 0 ] . normalized_value #NEWLINE# #UNINDENT# entityRegistrantName = factFinder ( instance , sec_ns , 'EntityRegistrantName' ) #NEWLINE# entityCentralIndexKey = factFinder ( instance , sec_ns , 'EntityCentralIndexKey' ) #NEWLINE# entityCommonStockSharesOutstanding = factFinder ( instance , sec_ns , 'EntityCommonStockSharesOutstanding' ) #NEWLINE# print ( 'Document and Entity Information:' ) #NEWLINE# docType = printFacts ( documentType ) #NEWLINE# entityName = printFacts ( entityRegistrantName ) #NEWLINE# entityCIK = printFacts ( entityCentralIndexKey ) #NEWLINE# printFacts ( documentPeriodEndDate ) #NEWLINE# printFacts ( documentFiscalPeriodFocus ) #NEWLINE# printFacts ( documentFiscalYearFocus ) #NEWLINE# if ( ( docType == '10-K' ) or ( docType == '10-Q' ) ) : #NEWLINE# #INDENT# print ( 'Analytical Ratios:' ) #NEWLINE# print ( '\tBalance Sheet:' ) #NEWLINE# currentRatio = 0 #NEWLINE# print ( '\t\tCurrent Ratio = Current Assets / Current Liabilities:' ) #NEWLINE# currentAssetsFacts = factFinder ( instance , fasb_ns , 'AssetsCurrent' ) #NEWLINE# currentLiabilitiesFacts = factFinder ( instance , fasb_ns , 'LiabilitiesCurrent' ) #NEWLINE# currentAssets = printFacts ( currentAssetsFacts , 3 , docEndDate ) #NEWLINE# currentLiabilities = printFacts ( currentLiabilitiesFacts , 3 , docEndDate ) #NEWLINE# if ( not ( currentLiabilities == 0 ) ) : #NEWLINE# #INDENT# currentRatio = ( currentAssets / currentLiabilities ) #NEWLINE# #UNINDENT# print ( ( 3 * '\t' ) , 'Current Ratio = ' . ljust ( ( 100 - ( 3 * 8 ) ) ) , '{0:.2f}' . format ( currentRatio ) ) #NEWLINE# quickRatio = 0 #NEWLINE# print ( '\t\tQuick Ratio = ( Cash + Short-Term Marketable Securities + Accounts Receivable ) / Current Liabilities:' ) #NEWLINE# cashFacts = factFinder ( instance , fasb_ns , 'Cash' ) #NEWLINE# if ( len ( cashFacts ) == 0 ) : #NEWLINE# #INDENT# cashFacts = factFinder ( instance , fasb_ns , 'CashAndCashEquivalentsAtCarryingValue' ) #NEWLINE# #UNINDENT# if ( len ( cashFacts ) == 0 ) : #NEWLINE# #INDENT# cashFacts = factFinder ( instance , fasb_ns , 'CashCashEquivalentsAndShortTermInvestments' ) #NEWLINE# #UNINDENT# marketableSecuritiesFacts = factFinder ( instance , fasb_ns , 'MarketableSecuritiesCurrent' ) #NEWLINE# if ( len ( marketableSecuritiesFacts ) == 0 ) : #NEWLINE# #INDENT# marketableSecuritiesFacts = factFinder ( instance , fasb_ns , 'AvailableForSaleSecuritiesCurrent' ) #NEWLINE# #UNINDENT# if ( len ( marketableSecuritiesFacts ) == 0 ) : #NEWLINE# #INDENT# marketableSecuritiesFacts = factFinder ( instance , fasb_ns , 'ShortTermInvestments' ) #NEWLINE# #UNINDENT# if ( len ( marketableSecuritiesFacts ) == 0 ) : #NEWLINE# #INDENT# marketableSecuritiesFacts = factFinder ( instance , fasb_ns , 'OtherShortTermInvestments' ) #NEWLINE# #UNINDENT# accountsReceivableFacts = factFinder ( instance , fasb_ns , 'AccountsReceivableNetCurrent' ) #NEWLINE# currentLiabilitiesFacts = factFinder ( instance , fasb_ns , 'LiabilitiesCurrent' ) #NEWLINE# cash = printFacts ( cashFacts , 3 , docEndDate ) #NEWLINE# marketableSecurities = printFacts ( marketableSecuritiesFacts , 3 , docEndDate ) #NEWLINE# accountsReceivable = printFacts ( accountsReceivableFacts , 3 , docEndDate ) #NEWLINE# currentLiabilities = printFacts ( currentLiabilitiesFacts , 3 , docEndDate ) #NEWLINE# if ( not ( currentLiabilities == 0 ) ) : #NEWLINE# #INDENT# quickRatio = ( ( ( cash + marketableSecurities ) + accountsReceivable ) / currentLiabilities ) #NEWLINE# #UNINDENT# print ( ( 3 * '\t' ) , 'Quick Ratio = ' . ljust ( ( 100 - ( 3 * 8 ) ) ) , '{0:.2f}' . format ( quickRatio ) ) #NEWLINE# cashRatio = 0 #NEWLINE# print ( '\t\tCash Ratio = ( Cash + Short-Term Marketable Securities ) / Current Liabilities:' ) #NEWLINE# cash = printFacts ( cashFacts , 3 , docEndDate ) #NEWLINE# marketableSecurities = printFacts ( marketableSecuritiesFacts , 3 , docEndDate ) #NEWLINE# currentLiabilities = printFacts ( currentLiabilitiesFacts , 3 , docEndDate ) #NEWLINE# if ( not ( currentLiabilities == 0 ) ) : #NEWLINE# #INDENT# cashRatio = ( ( cash + marketableSecurities ) / currentLiabilities ) #NEWLINE# #UNINDENT# print ( ( 3 * '\t' ) , 'Cash Ratio = ' . ljust ( ( 100 - ( 3 * 8 ) ) ) , '{0:.2f}' . format ( cashRatio ) ) #NEWLINE# with open ( 'ratios.csv' , 'a' ) as ratiofile : #NEWLINE# #INDENT# ratiofile . write ( ( ( ( ( ( ( ( ( ( ( ( ( ( docType + ',"' ) + entityName ) + '",' ) + entityCIK ) + ',' ) + docEndDate ) + ',' ) + '{0:.2f}' . format ( currentRatio ) ) + ',' ) + '{0:.2f}' . format ( quickRatio ) ) + ',' ) + '{0:.2f}' . format ( cashRatio ) ) + '\n' ) ) #NEWLINE# ratiofile . close ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# lock . release ( )