void Test::runGetQartersTM(O_Stock& stock){ LOG_INFO << "\n --- Testing retreval of latest quarters in test mode for " << stock._ticker() << " ---\n"; // Ensure we switched to test DB bool rok(false); rok = db_setup(); if(!rok) { LOG_ERROR << "Something wrong with TEST(probably with TEST DB setup)." << "EXITING"; cout << "An error uccored. exiting"; exit(-1); } //bool repFail(true); TestResults testRes; string testName(stock._ticker() + ": "); testRes.setTestName(testName); EdgarData edgar; edgar.updateFinancials(stock); // delete added quarters from test DB T_Ep te; vector<DMMM::O_Ep> eps_copy = stock._eps(); for(auto it = eps_copy.begin(); it != eps_copy.end();++it) if (it->_quarter() < 5) te.erase( te._id() == it->_id() ); }
bool Test::updateTest(O_Stock& stock) { LOG_INFO << "\n --- Testing retreval of data for " << stock._ticker() << " ---\n"; // Ensure we switched to test DB bool rok(false); rok = db_setup(); if(!rok) { LOG_ERROR << "Something wrong with TEST(probably with TEST DB setup)." << "EXITING"; cout << "An error uccored. exiting"; exit(-1); } bool repFail(true); TestResults testRes; string testName(stock._ticker() + ": "); testRes.setTestName(testName); EdgarData edgar; edgar.updateFinancials( stock ); // test covreage (if data missing) // income // balance_ return repFail; }
bool Test::setTestDB() { cout << "\n Switching back to TEST DB--------------------" << endl; string testDB("graham_test"); if (DBFace::instance()->switchDB( testDB ) ) cout << "Switch to TEST db succeccful" << endl; return db_setup(); }
void Test::seedStocks(vector<O_Stock>& stocks) { string testDB("graham_test"); cout << "\n Switching to TEST DB--------------------" << endl; if (DBFace::instance()->switchDB( testDB ) ) cout << "Switch to TEST db succeccful" << endl; // Ensure we switched to test DB bool rok(false); rok = db_setup(); if(!rok) { LOG_ERROR << "Something wrong with TEST(probably with TEST DB setup)." << "EXITING"; cout << "An error uccored. exiting"; exit(-1); } T_Stock ts; for(auto it = stocks.begin(); it != stocks.end();++it) { if ( ts.select( ts._ticker() == it->_ticker()).empty() ) { O_Stock stock; stock._ticker() = it->_ticker(); stock._cik() = it->_cik(); stock._fiscal_year_end() = it->_fiscal_year_end(); stock._country() = it->_country(); stock._listed() = it->_listed(); stock._company_type() = it->_company_type(); stock._name() = it->_name(); stock.insert(); LOG_INFO << "Seeded " <<stock._ticker() << " to TEST DB\n"; cout << "Seeded " <<stock._ticker() << " to TEST DB\n"; }else{ LOG_INFO <<it->_ticker() << "Already in TEST DB\n"; O_Stock stock = ts.select( ts._ticker() == it->_ticker()).front(); stock._country() = it->_country(); stock._listed() = it->_listed(); stock._company_type() = it->_company_type(); stock.update(); cout <<it->_ticker() << "Already in TEST DB - UPDATED"<<endl; } } }
bool copy_stocks() { LOG_INFO << "\n --- Coping stocks table from dev environmnet ---\n"; cout << "\n Switching to REAL DB--------------------" << endl; string realDB("graham_dev"); string testDB("graham_test"); if ( DBFace::instance()->switchDB( realDB ) ) cout << "Switch to real db succeccful" << endl; T_Stock rts; auto stocks = rts.select(); cout << "\n Switching back to TEST DB--------------------" << endl; if (DBFace::instance()->switchDB( testDB ) ) cout << "Switch to TEST db succeccful" << endl; // Ensure we switched to test DB bool rok(false); rok = db_setup(); if(!rok) { LOG_ERROR << "Something wrong with TEST(probably with TEST DB setup)." << "EXITING"; cout << "An error uccored. exiting"; exit(-1); } // drop stocks table //copy in as is stocks - in block transaction? return true; }
void Test::run_all() { bool rok(false); rok = db_setup(); if(!rok) { LOG_ERROR << "Something wrong with TEST(probably with TEST DB setup)." << "EXITING"; cout << "An error uccored. exiting"; exit(-1); } string resultSummary; TestResults testRes; // test single year runSingleYearTest(testRes); runSingleQarterTest(testRes); // runFourthQarterTest(testRes); resultSummary = testRes.getResultsSummary(); cout << "\n --- TEST Results ---" <<resultSummary << endl; }
sg_db_t *sg_init_db(char *home) { sg_db_t *sg_db; if(SGDB_T_POOL < 0 ) SGDB_T_POOL = ci_object_pool_register("sg_db_t", sizeof(sg_db_t)); if(SGDB_T_POOL < 0 ) return NULL; sg_db = ci_object_pool_alloc(SGDB_T_POOL); if(!sg_db) return NULL; sg_db->env_db=NULL; sg_db->domains_db=NULL; sg_db->urls_db=NULL; sg_db->env_db = db_setup(home); if(sg_db->env_db==NULL){ ci_object_pool_free(sg_db); return NULL; } sg_db->domains_db = sg_open_db(sg_db->env_db, "domains.db", domainCompare); sg_db->urls_db = sg_open_db(sg_db->env_db, "urls.db", compare_str); if(sg_db->domains_db == NULL && sg_db->urls_db== NULL) { sg_close_db(sg_db); ci_object_pool_free(sg_db); return NULL; } ci_debug_printf(5,"DBs opened\n"); ci_debug_printf(5,"Finished initialisation\n"); return sg_db; }
int main ( int argc, char **argv ) { pthread_mutex_t spinLockMutex; pid_t childPid; struct sigaction sa; sigset_t sigmsk; size_t len; ThreadCallback_t callbacks; GlobalAbort = false; /* Parse the command line options */ MainParseArgs( argc, argv ); #ifndef __CYGWIN__ len = confstr( _CS_GNU_LIBPTHREAD_VERSION, NULL, 0 ); if( len ) { pthreadsVersion = (char *)malloc(len); confstr( _CS_GNU_LIBPTHREAD_VERSION, pthreadsVersion, len ); } if( !pthreadsVersion || strstr( pthreadsVersion, "linuxthreads" ) ) { fprintf( stderr, "beirdobot requires NPTL to operate correctly.\n\n" "The signal handling in linuxthreads is just too " "broken to use.\n\n" ); exit( 1 ); } #else len = 0; #endif /* Do we need to detach? */ if( Daemon ) { childPid = fork(); if( childPid < 0 ) { perror( "Couldn't detach in daemon mode" ); _exit( 1 ); } if( childPid != 0 ) { /* This is still the parent, report the child's pid and exit */ printf( "[Detached as PID %d]\n", childPid ); /* And exit the parent */ _exit( 0 ); } /* After this is in the detached child */ /* Close stdin, stdout, stderr to release the tty */ close(0); close(1); close(2); } mainThreadId = pthread_self(); /* * Setup the sigmasks for this thread (which is the parent to all others). * This will propogate to all children. */ sigfillset( &sigmsk ); sigdelset( &sigmsk, SIGUSR1 ); sigdelset( &sigmsk, SIGUSR2 ); sigdelset( &sigmsk, SIGHUP ); sigdelset( &sigmsk, SIGWINCH ); sigdelset( &sigmsk, SIGINT ); sigdelset( &sigmsk, SIGSEGV ); sigdelset( &sigmsk, SIGILL ); sigdelset( &sigmsk, SIGFPE ); pthread_sigmask( SIG_SETMASK, &sigmsk, NULL ); /* Initialize the non-threadsafe CURL library functionality */ curl_global_init( CURL_GLOBAL_ALL ); /* Start up the Logging thread */ logging_initialize(TRUE); memset( &callbacks, 0, sizeof(ThreadCallback_t) ); callbacks.sighupFunc = mainSighup; thread_register( &mainThreadId, "thread_main", &callbacks ); /* Setup signal handler for SIGUSR1 (toggles Debug) */ sa.sa_sigaction = (sigAction_t)logging_toggle_debug; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART; sigaction( SIGUSR1, &sa, NULL ); /* Setup the exit handler */ atexit( MainDelayExit ); /* Setup signal handler for SIGINT (shut down cleanly) */ sa.sa_sigaction = signal_interrupt; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART; sigaction( SIGINT, &sa, NULL ); /* Setup signal handlers that are to be propogated to all threads */ sa.sa_sigaction = signal_everyone; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART | SA_SIGINFO; sigaction( SIGUSR2, &sa, NULL ); sigaction( SIGHUP, &sa, NULL ); sigaction( SIGWINCH, &sa, NULL ); /* Setup signal handlers for SEGV, ILL, FPE */ sa.sa_sigaction = signal_death; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART | SA_SIGINFO; sigaction( SIGSEGV, &sa, NULL ); sigaction( SIGILL, &sa, NULL ); sigaction( SIGFPE, &sa, NULL ); versionTree = BalancedBTreeCreate( BTREE_KEY_STRING ); #ifndef __CYGWIN__ versionAdd( "pthreads", pthreadsVersion ); #endif curses_start(); cursesMenuItemAdd( 2, MENU_SYSTEM, "About", mainAbout, NULL ); cursesMenuItemAdd( 2, MENU_SYSTEM, "Licensing", mainLicensing, NULL ); cursesMenuItemAdd( 2, MENU_SYSTEM, "Versions", mainVersions, NULL ); cursesMenuItemAdd( 2, MENU_SYSTEM, "Reload All", mainReloadAll, NULL ); /* Add the terminal setting as a version */ versionAdd( "TERM", getenv("TERM") ); /* Print the startup log messages */ LogBanner(); LogPrint( LOG_INFO, "CFLAGS: %s", CFLAGS ); LogPrint( LOG_INFO, "LDFLAGS: %s", LDFLAGS ); /* Setup the CLucene indexer */ clucene_init(0); /* Setup the MySQL connection */ db_setup(); db_check_schema_main(); /* Setup the bot commands */ botCmd_initialize(); /* Setup the regexp support */ regexp_initialize(); /* Setup the plugins */ plugins_initialize(); /* Start the notifier thread */ notify_start(); /* Start the authenticate thread */ authenticate_start(); /* Start the bot */ bot_start(); /* Sit on this and rotate - this causes an intentional deadlock, this * thread should stop dead in its tracks */ pthread_mutex_init( &spinLockMutex, NULL ); pthread_mutex_lock( &spinLockMutex ); pthread_mutex_lock( &spinLockMutex ); return(0); }
/* * file_init -- * Start editing a file, based on the FREF structure. If successsful, * let go of any previous file. Don't release the previous file until * absolutely sure we have the new one. * * PUBLIC: int file_init __P((SCR *, FREF *, char *, int)); */ int file_init(SCR *sp, FREF *frp, char *rcv_name, int flags) { EXF *ep; struct stat sb; size_t psize; int fd, exists, open_err, readonly, stolen; char *oname, tname[MAXPATHLEN]; stolen = open_err = readonly = 0; /* * If the file is a recovery file, let the recovery code handle it. * Clear the FR_RECOVER flag first -- the recovery code does set up, * and then calls us! If the recovery call fails, it's probably * because the named file doesn't exist. So, move boldly forward, * presuming that there's an error message the user will get to see. */ if (F_ISSET(frp, FR_RECOVER)) { F_CLR(frp, FR_RECOVER); return (rcv_read(sp, frp)); } /* * Required FRP initialization; the only flag we keep is the * cursor information. */ F_CLR(frp, ~FR_CURSORSET); /* * Scan the user's path to find the file that we're going to * try and open. */ if (file_spath(sp, frp, &sb, &exists)) return (1); /* * Check whether we already have this file opened in some * other screen. */ if (exists) { EXF *exfp; for (exfp = sp->gp->exfq.cqh_first; exfp != (EXF *)&sp->gp->exfq; exfp = exfp->q.cqe_next) { if (exfp->mdev == sb.st_dev && exfp->minode == sb.st_ino && (exfp != sp->ep || exfp->refcnt > 1)) { ep = exfp; goto postinit; } } } /* * Required EXF initialization: * Flush the line caches. * Default recover mail file fd to -1. * Set initial EXF flag bits. */ CALLOC_RET(sp, ep, EXF *, 1, sizeof(EXF)); CIRCLEQ_INIT(&ep->scrq); sp->c_lno = ep->c_nlines = OOBLNO; ep->rcv_fd = ep->fcntl_fd = -1; F_SET(ep, F_FIRSTMODIFY); /* * If no name or backing file, for whatever reason, create a backing * temporary file, saving the temp file name so we can later unlink * it. If the user never named this file, copy the temporary file name * to the real name (we display that until the user renames it). */ oname = frp->name; if (LF_ISSET(FS_OPENERR) || oname == NULL || !exists) { if (opts_empty(sp, O_TMP_DIRECTORY, 0)) goto err; (void)snprintf(tname, sizeof(tname), "%s/vi.XXXXXX", O_STR(sp, O_TMP_DIRECTORY)); if ((fd = mkstemp(tname)) == -1) { msgq(sp, M_SYSERR, "237|Unable to create temporary file"); goto err; } (void)close(fd); if (frp->name == NULL) F_SET(frp, FR_TMPFILE); if ((frp->tname = strdup(tname)) == NULL || (frp->name == NULL && (frp->name = strdup(tname)) == NULL)) { if (frp->tname != NULL) { free(frp->tname); } msgq(sp, M_SYSERR, NULL); (void)unlink(tname); goto err; } oname = frp->tname; psize = 1024; if (!LF_ISSET(FS_OPENERR)) F_SET(frp, FR_NEWFILE); time(&ep->mtime); } else { /* * XXX * A seat of the pants calculation: try to keep the file in * 15 pages or less. Don't use a page size larger than 10K * (vi should have good locality) or smaller than 1K. */ psize = ((sb.st_size / 15) + 1023) / 1024; if (psize > 10) psize = 10; if (psize == 0) psize = 1; psize *= 1024; F_SET(ep, F_DEVSET); ep->mdev = sb.st_dev; ep->minode = sb.st_ino; ep->mtime = sb.st_mtime; if (!S_ISREG(sb.st_mode)) msgq_str(sp, M_ERR, oname, "238|Warning: %s is not a regular file"); } /* Set up recovery. */ if (rcv_name == NULL) { /* ep->rcv_path NULL if rcv_tmp fails */ rcv_tmp(sp, ep, frp->name); } else { if ((ep->rcv_path = strdup(rcv_name)) == NULL) { msgq(sp, M_SYSERR, NULL); goto err; } F_SET(ep, F_MODIFIED); } if (db_setup(sp, ep)) goto err; /* Open a db structure. */ if ((sp->db_error = db_create(&ep->db, 0, 0)) != 0) { msgq(sp, M_DBERR, "db_create"); goto err; } ep->db->set_re_delim(ep->db, '\n'); /* Always set. */ ep->db->set_pagesize(ep->db, psize); ep->db->set_flags(ep->db, DB_RENUMBER | DB_SNAPSHOT); if (rcv_name == NULL) ep->db->set_re_source(ep->db, oname); /* * Don't let db use mmap when using fcntl for locking */ #ifdef HAVE_LOCK_FCNTL #define NOMMAPIFFCNTL DB_NOMMAP #else #define NOMMAPIFFCNTL 0 #endif #define _DB_OPEN_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH if ((sp->db_error = db_open(ep->db, ep->rcv_path, DB_RECNO, ((rcv_name == 0) ? DB_TRUNCATE : 0) | VI_DB_THREAD | NOMMAPIFFCNTL, _DB_OPEN_MODE)) != 0) { msgq_str(sp, M_DBERR, rcv_name == NULL ? oname : rcv_name, "%s"); /* * !!! * Historically, vi permitted users to edit files that couldn't * be read. This isn't useful for single files from a command * line, but it's quite useful for "vi *.c", since you can skip * past files that you can't read. */ ep->db = NULL; /* Don't close it; it wasn't opened */ if (LF_ISSET(FS_OPENERR)) goto err; open_err = 1; goto oerr; } /* re_source is loaded into the database. * Close it and reopen it in the environment. */ if ((sp->db_error = ep->db->close(ep->db, 0))) { msgq(sp, M_DBERR, "close"); goto err; } if ((sp->db_error = db_create(&ep->db, ep->env, 0)) != 0) { msgq(sp, M_DBERR, "db_create 2"); goto err; } if ((sp->db_error = db_open(ep->db, ep->rcv_path, DB_RECNO, VI_DB_THREAD | NOMMAPIFFCNTL, _DB_OPEN_MODE)) != 0) { msgq_str(sp, M_DBERR, ep->rcv_path, "%s"); goto err; } /* * Do the remaining things that can cause failure of the new file, * mark and logging initialization. */ if (mark_init(sp, ep) || log_init(sp, ep)) goto err; postinit: /* * Set the alternate file name to be the file we're discarding. * * !!! * Temporary files can't become alternate files, so there's no file * name. This matches historical practice, although it could only * happen in historical vi as the result of the initial command, i.e. * if vi was executed without a file name. */ if (LF_ISSET(FS_SETALT)) set_alt_name(sp, sp->frp == NULL || F_ISSET(sp->frp, FR_TMPFILE) ? NULL : sp->frp->name); /* * Close the previous file; if that fails, close the new one and run * for the border. * * !!! * There's a nasty special case. If the user edits a temporary file, * and then does an ":e! %", we need to re-initialize the backing * file, but we can't change the name. (It's worse -- we're dealing * with *names* here, we can't even detect that it happened.) Set a * flag so that the file_end routine ignores the backing information * of the old file if it happens to be the same as the new one. * * !!! * Side-effect: after the call to file_end(), sp->frp may be NULL. */ if (sp->ep != NULL) { F_SET(frp, FR_DONTDELETE); if (file_end(sp, NULL, LF_ISSET(FS_FORCE))) { (void)file_end(sp, ep, 1); goto err; } sp->ep = NULL; F_CLR(frp, FR_DONTDELETE); } /* * Lock the file; if it's a recovery file, it should already be * locked. Note, we acquire the lock after the previous file * has been ended, so that we don't get an "already locked" error * for ":edit!". * * XXX * While the user can't interrupt us between the open and here, * there's a race between the dbopen() and the lock. Not much * we can do about it. * * XXX * We don't make a big deal of not being able to lock the file. As * locking rarely works over NFS, and often fails if the file was * mmap(2)'d, it's far too common to do anything like print an error * message, let alone make the file readonly. At some future time, * when locking is a little more reliable, this should change to be * an error. */ if (rcv_name == NULL && ep->refcnt == 0) { if ((ep->fd = open(oname, O_RDWR)) == -1) goto no_lock; switch (file_lock(sp, oname, &ep->fcntl_fd, ep->fd, 1)) { case LOCK_FAILED: no_lock: F_SET(frp, FR_UNLOCKED); break; case LOCK_UNAVAIL: readonly = 1; msgq_str(sp, M_INFO, oname, "239|%s already locked, session is read-only"); break; case LOCK_SUCCESS: break; } } /* * Historically, the readonly edit option was set per edit buffer in * vi, unless the -R command-line option was specified or the program * was executed as "view". (Well, to be truthful, if the letter 'w' * occurred anywhere in the program name, but let's not get into that.) * So, the persistant readonly state has to be stored in the screen * structure, and the edit option value toggles with the contents of * the edit buffer. If the persistant readonly flag is set, set the * readonly edit option. * * Otherwise, try and figure out if a file is readonly. This is a * dangerous thing to do. The kernel is the only arbiter of whether * or not a file is writeable, and the best that a user program can * do is guess. Obvious loopholes are files that are on a file system * mounted readonly (access catches this one on a few systems), or * alternate protection mechanisms, ACL's for example, that we can't * portably check. Lots of fun, and only here because users whined. * * !!! * Historic vi displayed the readonly message if none of the file * write bits were set, or if an an access(2) call on the path * failed. This seems reasonable. If the file is mode 444, root * users may want to know that the owner of the file did not expect * it to be written. * * Historic vi set the readonly bit if no write bits were set for * a file, even if the access call would have succeeded. This makes * the superuser force the write even when vi expects that it will * succeed. I'm less supportive of this semantic, but it's historic * practice and the conservative approach to vi'ing files as root. * * It would be nice if there was some way to update this when the user * does a "^Z; chmod ...". The problem is that we'd first have to * distinguish between readonly bits set because of file permissions * and those set for other reasons. That's not too hard, but deciding * when to reevaluate the permissions is trickier. An alternative * might be to turn off the readonly bit if the user forces a write * and it succeeds. * * XXX * Access(2) doesn't consider the effective uid/gid values. This * probably isn't a problem for vi when it's running standalone. */ if (readonly || F_ISSET(sp, SC_READONLY) || (!F_ISSET(frp, FR_NEWFILE) && (!(sb.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) || access(frp->name, W_OK)))) O_SET(sp, O_READONLY); else O_CLR(sp, O_READONLY); /* Switch... */ ++ep->refcnt; CIRCLEQ_INSERT_HEAD(&ep->scrq, sp, eq); sp->ep = ep; sp->frp = frp; /* Set the initial cursor position, queue initial command. */ file_cinit(sp); /* Report conversion errors again. */ F_CLR(sp, SC_CONV_ERROR); /* Redraw the screen from scratch, schedule a welcome message. */ F_SET(sp, SC_SCR_REFORMAT | SC_STATUS); if (frp->lno == OOBLNO) F_SET(sp, SC_SCR_TOP); /* Append into the chain of file structures. */ if (ep->refcnt == 1) CIRCLEQ_INSERT_TAIL(&sp->gp->exfq, ep, q); return (0); err: if (frp->name != NULL) { free(frp->name); frp->name = NULL; } if (frp->tname != NULL) { (void)unlink(frp->tname); free(frp->tname); frp->tname = NULL; } oerr: if (F_ISSET(ep, F_RCV_ON)) (void)unlink(ep->rcv_path); if (ep->rcv_path != NULL) { free(ep->rcv_path); ep->rcv_path = NULL; } if (ep->db != NULL) { (void)ep->db->close(ep->db, DB_NOSYNC); ep->db = NULL; } free(ep); return (open_err && !LF_ISSET(FS_OPENERR) ? file_init(sp, frp, rcv_name, flags | FS_OPENERR) : 1); }
bool Test::getReportsTest(O_Stock& stock, boost::filesystem::ofstream& outFile) { LOG_INFO << "\n --- Testing retreval of reports for " << stock._ticker() << " ---\n"; // Ensure we switched to test DB bool rok(false); rok = db_setup(); if(!rok) { LOG_ERROR << "Something wrong with TEST(probably with TEST DB setup)." << "EXITING"; cout << "An error uccored. exiting"; exit(-1); } bool repFail(true); TestResults testRes; string testName(stock._ticker() + ": "); testRes.setTestName(testName); EdgarData edgar; /* Acn* acn = edgar.getLastYear10KAcn(stock); if (acn == NULL) { LOG_INFO << "Did not get acn for "<<stock._ticker() ; return false; } string filing = edgar.getEdgarFiling(stock,*acn); if (filing == "") { LOG_ERROR << "Failed to retrive filing for acn "<<acn->_acn<<"\n"; return false; } */ edgar.getSingleYear(stock,2013); auto reports = &edgar._reports; bool foreign = false; LOG_INFO << "Got "<<reports->size()<<" reports\n"; ReportType reportType = ReportType::COVER; auto coverReportIt = reports->find(reportType); if( coverReportIt == reports->end()) { testRes.addFailure("NO COVER REPORT"); repFail =false; } reportType = ReportType::INCOME; auto incomeReportIt = reports->find(reportType); if( incomeReportIt == reports->end()) { testRes.addFailure("NO INCOME REPORT"); if ( (stock._country() != "") && (stock._country() != "USA") ) foreign = true; repFail =false; } else { T_Ep te; O_Ep earnings_data; bool inDB(true); if (te.select( te._stock_id() == stock._id() && te._year() == 2013).empty() ) { inDB = false; testRes.addFailure("No earnings record for 2013 retrieved from DB"); earnings_data = edgar._ep; } else earnings_data = te.select( te._stock_id() == stock._id() && te._year() == 2013).front(); LOG_INFO << "\n Testing values extracted for eps record with id: " << to_string(earnings_data._id())<<", stock_id is: "<< to_string(earnings_data._stock_id())<<" year "<< to_string(earnings_data._year()) <<", revenue: " <<earnings_data._revenue() << ", income: " <<earnings_data._net_income()<<", and eps: "<< to_string(earnings_data._eps())<<"\n"; if (earnings_data._revenue() == "") testRes.addFailure("No Revenue exracted from Income Statement"); if (earnings_data._net_income() == "") testRes.addFailure("No Income exracted from Income Statement"); if (withinPercent(earnings_data._eps(),0.01,0.0)) testRes.addFailure("No Eps exracted from Income Statement"); if (earnings_data._shares() == "") testRes.addFailure("No Share data exracted from Income Statement"); if (inDB) te.erase( te._id() == earnings_data._id()); } // balancereporttest: reportType = ReportType::BALANCE; auto balanceReportIt = reports->find(reportType); if( balanceReportIt == reports->end()) { testRes.addFailure("NO BALANCE REPORT"); repFail =false; } string resultSummary = testRes.getResultsSummary(); if (testRes._numFails > 0) { if (foreign) outFile << stock._ticker() << " is foreign - " << stock._country(); outFile << resultSummary; outFile.flush(); } LOG_INFO << resultSummary; cout << "\n --- TEST Results for "<<stock._ticker()<<" ---" <<resultSummary << endl; return repFail; }
void Test::runCompanyTest(string& ticker) { // get record from REAL DB for 2013 LOG_INFO << "\n --- Running Test for retreval of " << ticker << " ---\n"; cout << "\n Switching to REAL DB--------------------" << endl; string realDB("graham_dev"); string testDB("graham_test"); if ( DBFace::instance()->switchDB( realDB ) ) cout << "Switch to real db succeccful" << endl; size_t year = 2013; T_Stock rts; T_Ep rte; const O_Stock rstock = rts.select( rts._ticker() == ticker).front(); const O_Ep real2013 = rte.select( rte._stock_id() == rstock._id() && rte._quarter() == 0 && rte._year() == year).front(); cout << "\n Switching back to TEST DB--------------------" << endl; if (DBFace::instance()->switchDB( testDB ) ) cout << "Switch to TEST db succeccful" << endl; // Switch back to TEST DB // Ensure we switched to test DB bool rok(false); rok = db_setup(); if(!rok) { LOG_ERROR << "Something wrong with TEST(probably with TEST DB setup)." << "EXITING"; cout << "An error uccored. exiting"; exit(-1); } TestResults testRes; T_Stock ts; T_Ep te; O_Stock stock; // CREATE Dummy stock in test DB! if ( ts.select( ts._ticker() == ticker).empty() ) { stock._ticker() = ticker; stock._cik() = rstock._cik(); stock.insert(); }else{ stock = ts.select( ts._ticker() == ticker).front(); } string testName("Test-Company " + stock._ticker() + ": "); testRes.setTestName(testName); EdgarData edgar; if ( edgar.getSingleYear( stock, year) ) { compareTest( rstock , real2013, testRes); }else{ testRes.addFailure("Could Not get annual data for " + stock._ticker()); } string resultSummary = testRes.getResultsSummary(); cout << "\n --- TEST Results ---" <<resultSummary << endl; }
int main ( int argc, char **argv ) { extern QueueObject_t *IndexQ; struct sigaction sa; sigset_t sigmsk; uint32 count; GlobalAbort = false; /* Parse the command line options */ MainParseArgs( argc, argv ); mainThreadId = pthread_self(); /* * Setup the sigmasks for this thread (which is the parent to all others). * This will propogate to all children. */ sigfillset( &sigmsk ); sigdelset( &sigmsk, SIGUSR1 ); sigdelset( &sigmsk, SIGUSR2 ); sigdelset( &sigmsk, SIGINT ); sigdelset( &sigmsk, SIGSEGV ); sigdelset( &sigmsk, SIGILL ); sigdelset( &sigmsk, SIGFPE ); pthread_sigmask( SIG_SETMASK, &sigmsk, NULL ); /* Start up the Logging thread */ logging_initialize(FALSE); thread_register( &mainThreadId, "thread_main", NULL ); /* Setup signal handler for SIGUSR1 (toggles Debug) */ sa.sa_sigaction = (sigAction_t)logging_toggle_debug; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART; sigaction( SIGUSR1, &sa, NULL ); /* Setup the exit handler */ atexit( MainDelayExit ); /* Setup signal handler for SIGINT (shut down cleanly) */ sa.sa_sigaction = signal_interrupt; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART; sigaction( SIGINT, &sa, NULL ); /* Setup signal handlers that are to be propogated to all threads */ sa.sa_sigaction = signal_everyone; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART | SA_SIGINFO; sigaction( SIGUSR2, &sa, NULL ); /* Setup signal handlers for SEGV, ILL, FPE */ sa.sa_sigaction = signal_death; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART | SA_SIGINFO; sigaction( SIGSEGV, &sa, NULL ); sigaction( SIGILL, &sa, NULL ); sigaction( SIGFPE, &sa, NULL ); /* Print the startup log messages */ LogBanner(); /* Setup the CLucene indexer */ clucene_init(1); /* Setup the MySQL connection */ db_setup(); db_check_schema_main(); db_rebuild_clucene(); /* Wait for the clucene thread to finish emptying its queue */ while( (count = QueueUsed( IndexQ )) > 0 ) { LogPrint( LOG_INFO, "%d left", count ); sleep( 1 ); } GlobalAbort = TRUE; return(0); }