def loadit(self): ''' Load saved objects ''' self.sc.doWeSave() daDate = self.ui.dateEdit.date() daDate = qtime2pd(daDate) self.loadedDate = daDate self.settings.setValue('theDate', daDate) self.initialize() if not self.indir: logging.info('No file to load?') return jf = JournalFiles(indir=self.indir, outdir=self.outdir, theDate=self.theDate, infile=self.infile, inputType=self.inputtype, infile2=self.positions, mydevel=True) lf = LayoutForms(self.sc, jf, None) if not lf.loadTradesFromDB(daDate): msg = f'No user data has been saved for {daDate.strftime("%A %B %d")}. Loading trade data.' logging.info(msg) # msgbx = QMessageBox() # msgbx.setIconPixmap(QPixmap("structjour/images/ZSLogo.png")) # msgbx.setText(msg) # msgbx.exec() self.runnit(True)
def setUp(self): ddiirr = os.path.dirname(__file__) os.chdir(os.path.realpath(ddiirr)) os.chdir(os.path.realpath('../')) self.inputtype = 'IB_CSV' indir = 'data/' # f2 = 'ActivityStatement.20190313_PL.html' jf = JournalFiles(indir=indir, infile=self.f1, theDate=self.theDate, inputType='IB_CSV', mydevel=False) jf.inputType = 'IB_CSV' # statement = Statement_IBActivity(jf) # df = statement.getTrades_IBActivity(jf.inpathfile) ibs = IbStatement(db=self.testdb) ibdb = StatementDB(self.testdb) ibdb.reinitializeTradeTables() ibs.openIBStatementCSV(jf.inpathfile) df2 = ibdb.getStatement(self.theDate) if df2.empty: sdate = self.theDate.strftime('%Y-%m-%d') msg = f'In test_dailycontrol.setup: Error: found no trades in db for {sdate}' self.assertTrue(not df2.empty, msg) tu = DefineTrades(jf.inputType) self.df, ldf = tu.processDBTrades(df2) sc = SumControl() lf = LayoutForms(sc, jf, self.df) lf.runTtoSummaries(ldf) self.ts = lf.ts ibdb.addTradeSummariesSA(self.ts, ldf)
def setUpClass(cls): bu = Backup() bu.backup() if ModelBase.session: ModelBase.session.rollback() ddiirr = os.path.dirname(__file__) os.chdir(os.path.realpath(ddiirr + '/../')) outdir = 'test/out' cls.outdir = os.path.realpath(outdir) cls.db = 'data/testdb.sqlite' cls.db = os.path.realpath(cls.db) if os.path.exists(cls.db): clearTables(cls.db) cls.rtg = RTG(db=cls.db) # cls.dates = ['20200203 09:30', '20200204 07:30', '20200205 09:35', '20200206 11:40', '20200207 10:39'] cls.dates = ['20200207 10:39'] cls.infiles = cls.rtg.saveSomeTestFiles(cls.dates, cls.outdir, strict=True, overwrite=True) settings = QSettings('zero_substance', 'structjour') for i, name in enumerate(cls.infiles): name = os.path.join(cls.outdir, name) x, cls.inputType = getStatementType(name) # print(cls.inputType) if cls.inputType == 'DAS': ds = DasStatement(name, settings, cls.dates[i]) ds.getTrades(testFileLoc=cls.outdir, testdb=cls.db) elif cls.inputType == "IB_CSV": ibs = IbStatement(db=cls.db) ibs.openIBStatement(name) else: continue # self.assertTrue(4 == 5, "Unsupported file type in test_TheTradeObject") statement = StatementDB(db=cls.db) df = statement.getStatement(cls.dates[i]) # self.assertFalse(df.empty, f"Found no trades in db on {daDate}") dtrade = DefineTrades(cls.inputType) dframe, ldf = dtrade.processDBTrades(df) # tto = TheTradeObject(ldf[0], False, SumReqFields()) jf = JournalFiles(indir=cls.outdir, outdir=outdir, theDate=cls.dates[i], infile=name) cls.sc = SumControl() lf = LayoutForms(cls.sc, jf, dframe) lf.runTtoSummaries(ldf) cls.jfs.append(jf) cls.dframes.append(dframe) # cls.ttos.append(tto) cls.ldfs.append(ldf) cls.lfs.append(lf)
def runDBInput(self, daDate, jf): ''' Get the trades from daDate in the DB and process the trades ''' self.statement = StatementDB() daDate = qtime2pd(daDate) df = self.statement.getStatement(daDate) if df.empty: return False tu = DefineTrades(self.inputtype) dframe, ldf = tu.processDBTrades(df) lf = LayoutForms(self.sc, jf, dframe) lf.pickleitnow() lf.runTtoSummaries(ldf) self.statement.addTradeSummariesSA(lf.ts, ldf) return True
def setUpClass(cls): ddiirr = os.path.dirname(__file__) os.chdir(os.path.realpath(ddiirr + '/../')) outdir = 'test/out' cls.outdir = os.path.realpath(outdir) cls.db = 'data/testdb.sqlite' cls.db = os.path.realpath(cls.db) if os.path.exists(cls.db): clearTables(cls.db) cls.rtg = RTG(db=cls.db) # cls.dates = ['20200203 09:30', '20200204 07:30', '20200205 09:35', '20200206 11:40', '20200207 10:39'] cls.theDate = '20200207 10:39' cls.infile = cls.rtg.saveSomeTestFiles([cls.theDate], cls.outdir)[0] settings = QSettings('zero_substance', 'structjour') # for i, name in enumerate(cls.infiles): name = os.path.join(cls.outdir, cls.infile) x, inputType = getStatementType(name) if inputType == 'DAS': ds = DasStatement(name, settings, cls.theDate) ds.getTrades(testFileLoc=cls.outdir, testdb=cls.db) elif inputType == "IB_CSV": ibs = IbStatement(db=cls.db) ibs.openIBStatement(name) else: raise ValueError(f'Unsupported File type: {inputType}') statement = StatementDB(db=cls.db) df = statement.getStatement(cls.theDate) dtrade = DefineTrades(inputType) dframe, cls.ldf = dtrade.processDBTrades(df) cls.jf = JournalFiles(indir=cls.outdir, outdir=outdir, theDate=cls.theDate, infile=name) cls.sc = SumControl() lf = LayoutForms(cls.sc, cls.jf, dframe) lf.runTtoSummaries(cls.ldf) # Setup mistake note fields to test cls.note = 'Ground control to Major Tom' for i, key in enumerate(lf.ts): tto = lf.ts[key] notex = cls.note + str(i + 1) tto['MstkNote'] = notex # Setup a couple images to add imdir = 'images/' img1 = os.path.join(imdir, 'fractal-art-fractals.jpg') img2 = os.path.join(imdir, 'psych.jpg') assert os.path.exists(img1) assert os.path.exists(img2) for key in lf.ts: tto = lf.ts[key]['chart1'] = img1 tto = lf.ts[key]['chart2'] = img2 t = ExportToExcel(lf.ts, cls.jf, df) imageNames = t.getImageNamesFromTS() cls.imageLocation, dframe = t.layoutExcelData(t.df, cls.ldf, imageNames) assert len(cls.ldf) == len(cls.imageLocation) # Create an openpyxl wb from the dataframe ls = LayoutSheet(t.topMargin, len(t.df)) cls.wb, ws, nt = ls.createWorkbook(dframe) # Place both forms 2 cells to the right of the main table mstkAnchor = (len(dframe.columns) + 2, 1) cls.mistake = MistakeSummary(numTrades=len(cls.ldf), anchor=mstkAnchor) cls.t = t cls.a = mstkAnchor