void downloader_instance_simple::handle_open(const boost::system::error_code& ec) { if (!ec) { ofstream_.open(file_, (std::ios_base::out | std::ios_base::binary | std::ios_base::trunc) ); if (!ofstream_) { if (owner()->state_notify_) owner()->state_notify_(http_downloader::stateError); return; } read_stream_.async_read_some( boost::asio::buffer(buffer_), boost::bind(&downloader_instance_simple::handle_read, shared_from_this(), _1, _2)); owner()->state_ = http_downloader_simple::stateDownload; if (owner()->state_notify_) owner()->state_notify_(http_downloader::stateStart); } else { if (owner()->state_notify_) owner()->state_notify_(http_downloader::stateError); } }
inline void DEBUG_TURNS_STOP() { if (dg_output_turn_debug) { dg_debug_turns_file << std::endl << "]}" << std::endl; dg_debug_turns_file.close(); } }
inline void DEBUG_GEOMETRY_STOP() { if (dg_output_debug_geometry) { debug_geometry_file << std::endl << "]}" << std::endl; debug_geometry_file.close(); } }
inline void DEBUG_TURNS_START(const std::string & debug_turns_path) { dg_output_turn_debug = debug_turns_path != ""; if (dg_output_turn_debug) { dg_debug_turns_file.open(debug_turns_path); dg_debug_turns_file << "{\"type\":\"FeatureCollection\", \"features\":[" << std::endl; } }
inline void DEBUG_GEOMETRY_START(const ContractorConfig &config) { time_t raw_time; struct tm *timeinfo; time(&raw_time); timeinfo = localtime(&raw_time); strftime(dg_time_buffer, 80, "%Y-%m-%d %H:%M %Z", timeinfo); dg_output_debug_geometry = config.debug_geometry_path != ""; if (dg_output_debug_geometry) { debug_geometry_file.open(config.debug_geometry_path, std::ios::binary); debug_geometry_file << "{\"type\":\"FeatureCollection\", \"features\":[" << std::endl; } }
void downloader_instance_simple::handle_read(const boost::system::error_code& ec, std::size_t length) { if (!ec) { ofstream_.write(buffer_, length); readed_bytes_ += length; if (owner()->progress_notify_) owner()->progress_notify_(readed_bytes_); { boost::mutex::scoped_lock lock(owner()->stateGuard_); while (owner()->command_ != http_downloader_simple::commandNull) { switch (owner()->command_) { case http_downloader_simple::commandPause: { owner()->state_ = http_downloader_simple::statePaused; owner()->command_ = http_downloader_simple::commandNull; if (owner()->state_notify_) owner()->state_notify_(http_downloader::statePause); while ( owner()->command_ != http_downloader_simple::commandCancel && owner()->command_ != http_downloader_simple::commandResume ) { lock.unlock(); boost::this_thread::sleep( boost::posix_time::milliseconds(100) ); lock.lock(); } if (owner()->command_ == http_downloader_simple::commandResume) { owner()->state_ = http_downloader_simple::stateDownload; owner()->command_ = http_downloader_simple::commandNull; if (owner()->state_notify_) owner()->state_notify_(http_downloader::stateResume); } } break; case http_downloader_simple::commandCancel: { owner()->command_ = http_downloader_simple::commandNull; ofstream_.close(); if (owner()->state_notify_) owner()->state_notify_(http_downloader::stateCancel); return; } break; case http_downloader_simple::commandResume: break; } } } read_stream_.async_read_some( boost::asio::buffer(buffer_), boost::bind(&downloader_instance_simple::handle_read, shared_from_this(), _1, _2)); } else { ofstream_.close(); if ( boost::asio::error::misc_category == ec.category() ) { if (boost::asio::error::eof == ec.value()) { if (owner()->state_notify_) owner()->state_notify_(http_downloader::stateFinish); } } else { if (owner()->state_notify_) owner()->state_notify_(http_downloader::stateError); } } }
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; }