def doImport2(self): self.processCache = self.initProcessCache(self.filename, self.session) reportDict = self.getReportDict(self.processCache, ["Cover", "Statements"], self.session) factVOList = self.getFactByReport(reportDict, self.processCache, self.session) factVOList = self.setFactValues(factVOList, self.processCache) FactDao().addFact(factVOList, self.fileData, reportDict, self.session) return factVOList
def getTraceData(self, reportShortName, conceptName, CIK, periodType): rs = FactDao.getFactValues2(reportShortName=reportShortName, conceptName=conceptName, CIK=CIK, periodType=periodType) rows = rs.fetchall() if (len(rows) != 0): df = DataFrame(rows) df.columns = rs.keys() trace = go.Scatter(x=df["date_"], y=df["value"], name=conceptName) return trace else: raise Exception("No data found " + conceptName)
def getFactValues(CIK, ticker, customOrFact): rs = FactDao.getFactValues2(CIK=CIK, customOrFact=customOrFact) rows = rs.fetchall() tableDict = {} rowDict = {} columnNameForDate = [] oldRowID = None for row in rows: reportName = row.reportShortName[0:70] conceptName = row.conceptName value = getNumberValueAsString(row.value) valueDate = row.date_ periodType = row.periodType order = row.order_ newRowID = reportName +"-"+ conceptName +"-"+ periodType # print('newRowID', newRowID) if(oldRowID is None or newRowID != oldRowID): #Changing row # print('oldRowID', oldRowID) if(rowDict.get('conceptName', None) is not None): tableDict[oldRowID] = rowDict oldRowID = newRowID rowDict = {} rowDict['reportName'] = reportName rowDict['conceptName'] = conceptName rowDict['periodType'] = periodType rowDict['order'] = order rowDict[valueDate.strftime('%d-%m-%Y')] = value if valueDate not in columnNameForDate: columnNameForDate.append(valueDate) tableDict[newRowID] = rowDict columnKeys = ['reportName', 'conceptName', 'periodType', 'order'] columnNameForDate.sort() columnNameForDate = (x.strftime('%d-%m-%Y') for x in columnNameForDate) columnKeys.extend(columnNameForDate) columnKeys.append('CURRENT') setCurrentFactValues(tableDict=tableDict, CIK=CIK, ticker=ticker) df = DataFrame(list(tableDict.values()), columns=columnKeys) df = df.sort_values(["reportName", "order"], ascending=[True, True]) # print(df.to_string()) app.CIK = CIK app.ticker = ticker return df
def copyToCustomFactQTDINST2(self, fileData, customConceptList, newCFVDict, session): factValueRS = FactDao().getFactValue3(periodTypeList=['QTD', 'INST'], fileDataOID=fileData.OID, session=session) rsDict = {} for row in factValueRS: rsDict.setdefault(str(row.conceptOID) + "-" + row.type, []).append(row) for customConcept in customConceptList: for relationConcept in customConcept.relationConceptList: for row in rsDict.get( str(relationConcept.conceptOID) + "-" + customConcept.periodType, []): if (customConcept.conceptName not in newCFVDict.keys()): cfvVO = CustomFactValueVO( value=row.value, origin='COPY', fileDataOID=fileData.OID, customConcept=customConcept, periodOID=row.periodOID, order_=relationConcept.order_) newCFVDict[customConcept.conceptName] = cfvVO
def copyToCustomFactYTD2(self, fileData, customConceptList, newCFVDict, session): # Solo toma el Q1 en YTD y lo completa en QTD de los custom facts if (fileData.documentFiscalPeriodFocus == 'Q1'): factValueRS = FactDao().getFactValue3(periodTypeList=['YTD'], fileDataOID=fileData.OID, session=session) rsDict = {} for row in factValueRS: rsDict.setdefault(row.conceptOID, []).append(row) for customConcept in customConceptList: for relationConcept in customConcept.relationConceptList: for row in rsDict.get(relationConcept.conceptOID, []): if (customConcept.conceptName not in newCFVDict.keys()): cfvVO = CustomFactValueVO( value=row.value, origin='COPY', fileDataOID=fileData.OID, customConcept=customConcept, endDate=row.endDate, order_=relationConcept.order_) newCFVDict[customConcept.conceptName] = cfvVO
def calculateMissingQTDValues2(self, fileData, customConceptList, session): cfvVOList = [] mainYTDDict = {} mainQTDDict = {} mainCustomQTDDict = {} if (fileData.documentFiscalYearFocus is None): raise Exception("fileData documentFiscalYearFocus is None") currentPeriodFocus = fileData.documentFiscalPeriodFocus listYTD = FactDao().getFactValue4( companyOID=fileData.companyOID, periodType='YTD', documentFiscalYearFocus=fileData.documentFiscalYearFocus, session=session) for currentYTD in listYTD: itemYTDDict = mainYTDDict.get(currentYTD.conceptOID, {}) itemYTDDict[currentYTD.documentFiscalPeriodFocus] = currentYTD mainYTDDict[currentYTD.conceptOID] = itemYTDDict listQTD = FactDao().getFactValue4( companyOID=fileData.companyOID, periodType='QTD', documentFiscalYearFocus=fileData.documentFiscalYearFocus, session=session) for itemQTD in listQTD: itemQTDDict = mainQTDDict.get(itemQTD.conceptOID, {}) itemQTDDict[itemQTD.documentFiscalPeriodFocus] = itemQTD mainQTDDict[itemQTD.conceptOID] = itemQTDDict listCustomQTD = CustomFactDao().getCustomFactValue4( companyOID=fileData.companyOID, periodType='QTD', documentFiscalYearFocus=fileData.documentFiscalYearFocus, session=session) for itemCustomQTD in listCustomQTD: itemQTDDict = mainCustomQTDDict.get(itemCustomQTD.customConceptOID, {}) itemQTDDict[ itemCustomQTD.documentFiscalPeriodFocus] = itemCustomQTD mainCustomQTDDict[itemCustomQTD.customConceptOID] = itemQTDDict for customConcept in customConceptList: currentYTD = None customFactValueVO = None itemCustomQTDDict = mainCustomQTDDict.get(customConcept.OID, None) q1QTD = None q2QTD = None q3QTD = None q4QTD = None prevYTD = None itemYTDDict = None itemQTDDict = None q1QTD = self.getQTDItem(q1QTD, itemCustomQTDDict, 'Q1') q2QTD = self.getQTDItem(q2QTD, itemCustomQTDDict, 'Q2') q3QTD = self.getQTDItem(q3QTD, itemCustomQTDDict, 'Q3') q4QTD = self.getQTDItem(q4QTD, itemCustomQTDDict, 'Q4') if q4QTD is None: q4QTD = self.getQTDItem(q4QTD, itemCustomQTDDict, 'FY') for relationConcept in customConcept.relationConceptList: itemYTDDict = mainYTDDict.get(relationConcept.concept.OID, None) if (itemYTDDict is not None): # FILL DATA -> currentYTD if (currentYTD is None): currentYTD = itemYTDDict.get(currentPeriodFocus, None) # FILL DATA -> prevYTD if (prevYTD is None): prevYTD = itemYTDDict.get( self.getPrevPeriodFocus(currentPeriodFocus), None) # FILL DATA -> q1QTD, q2QTD, q3QTD, q4QTD TODO set duplicated exception itemQTDDict = mainQTDDict.get(relationConcept.concept.OID, None) if (itemQTDDict is not None): q1QTD = self.getQTDItem(q1QTD, itemQTDDict, 'Q1') q2QTD = self.getQTDItem(q2QTD, itemQTDDict, 'Q2') q3QTD = self.getQTDItem(q3QTD, itemQTDDict, 'Q3') q4QTD = self.getQTDItem(q4QTD, itemQTDDict, 'Q4') if q4QTD is None: q4QTD = self.getQTDItem(q4QTD, itemQTDDict, 'FY') # YTD STRATEGY Q1 if (currentPeriodFocus == 'Q1'): if (itemYTDDict is not None): itemYTDq1 = itemYTDDict.get('Q1', None) if (itemYTDq1 is not None): print("NEW FACT VALUE 1 " + customConcept.conceptName + " " + str(itemYTDq1.value) + " " + relationConcept.concept.conceptName) customFactValueVO = self.fillCustomFactValueVO( value=itemYTDq1.value, fileData=fileData, customConcept=customConcept, endDate=itemYTDq1.endDate) break # deja de recorrer los conceptos if customFactValueVO is None: # YTD STRATEGY YTD-YTD if (currentYTD is not None and prevYTD is not None): print("NEW FACT VALUE 2 " + customConcept.conceptName + " " + str(currentYTD.value - prevYTD.value) + " " + relationConcept.concept.conceptName) customFactValueVO = self.fillCustomFactValueVO( value=(currentYTD.value - prevYTD.value), fileData=fileData, customConcept=customConcept, endDate=currentYTD.endDate) # YTD STRATEGY YTD-QTD if (currentYTD is not None and customFactValueVO is None): if (q1QTD is not None and currentPeriodFocus == 'Q2'): print("NEW FACT VALUE 3 " + customConcept.conceptName + " " + str(currentYTD.value - q1QTD.value) + " " + relationConcept.concept.conceptName) customFactValueVO = self.fillCustomFactValueVO( value=(currentYTD.value - q1QTD.value), fileData=fileData, customConcept=customConcept, endDate=currentYTD.endDate) elif (q1QTD is not None and q2QTD is not None and currentPeriodFocus == 'Q3'): print("NEW FACT VALUE 4 " + customConcept.conceptName + " " + str(currentYTD.value - q1QTD.value - q2QTD.value) + " " + relationConcept.concept.conceptName) customFactValueVO = self.fillCustomFactValueVO( value=(currentYTD.value - q1QTD.value - q2QTD.value), fileData=fileData, customConcept=customConcept, endDate=currentYTD.endDate) elif (q1QTD is not None and q2QTD is not None and q3QTD is not None and (currentPeriodFocus == 'Q4' or currentPeriodFocus == 'FY')): print("NEW FACT VALUE 5 " + customConcept.conceptName + " " + str(currentYTD.value - q1QTD.value - q2QTD.value - q3QTD.value) + " " + relationConcept.concept.conceptName) customFactValueVO = self.fillCustomFactValueVO( value=(currentYTD.value - q1QTD.value - q2QTD.value - q3QTD.value), fileData=fileData, customConcept=customConcept, endDate=currentYTD.endDate) if (customFactValueVO is not None): cfvVOList.append(customFactValueVO) return cfvVOList
def deleteImportedObject(self): FactDao().deleteFactByFD(self.fileData.OID, self.session)