inline void _Log::write (const string& msg) { assert (this->pOS); boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time(); (*pOS) << to_iso_extended_string(now) << " | " << msg << endl; cout << to_iso_extended_string(now) << " | " << msg << endl; }
void CalendarTemplateElement::toParametersMap( util::ParametersMap& map, bool withAdditionalParameters, boost::logic::tribool withFiles /*= boost::logic::indeterminate*/, std::string prefix /*= std::string() */ ) const { map.insert(TABLE_COL_ID, getKey()); map.insert( CalendarTemplateElementTableSync::COL_CALENDAR_ID, getCalendar() ? getCalendar()->getKey() : RegistryKeyType(0) ); map.insert( CalendarTemplateElementTableSync::COL_RANK, getRank() ); map.insert( CalendarTemplateElementTableSync::COL_MIN_DATE, getMinDate().is_special() ? string() : to_iso_extended_string(getMinDate()) ); map.insert( CalendarTemplateElementTableSync::COL_MAX_DATE, getMaxDate().is_special() ? string() : to_iso_extended_string(getMaxDate()) ); map.insert( CalendarTemplateElementTableSync::COL_INTERVAL, boost::lexical_cast<std::string>(static_cast<int>(getStep().days())) ); map.insert( CalendarTemplateElementTableSync::COL_POSITIVE, static_cast<int>(getOperation()) ); map.insert( CalendarTemplateElementTableSync::COL_INCLUDE_ID, getInclude() ? getInclude()->getKey() : RegistryKeyType(0) ); }
DriverAllocationTemplateTableSync::SearchResult DriverAllocationTemplateTableSync::Search( util::Env& env, boost::gregorian::date date /*= boost::gregorian::date(not_a_date_time)*/, size_t first /*= 0*/, boost::optional<std::size_t> number /*= boost::optional<std::size_t>()*/, bool orderByDate /*= true*/, bool raisingOrder /*= true*/, util::LinkLevel linkLevel /*= util::UP_LINKS_LOAD_LEVEL */ ) { SelectQuery<DriverAllocationTemplateTableSync> query; if (!date.is_not_a_date()) { query.addWhereField(SimpleObjectFieldDefinition<Date>::FIELD.name, to_iso_extended_string(date)); } if (orderByDate) { query.addOrderField(SimpleObjectFieldDefinition<Date>::FIELD.name, raisingOrder); } if (number) { query.setNumber(*number + 1); } if (first > 0) { query.setFirst(first); } return LoadFromQuery(query, env, linkLevel); }
bool CameraVideo::grabImage(Frame &img){ Mat frame; if(mCap.read(frame)) { //BGR (3 channels) to G (1 channel) cvtColor(frame, frame, CV_BGR2GRAY); boost::posix_time::ptime time = boost::posix_time::microsec_clock::universal_time(); Frame f = Frame(frame, 0, 0, to_iso_extended_string(time)); img = f; img.mFrameNumber = mCap.get(CV_CAP_PROP_POS_FRAMES); img.mFrameRemaining = mCap.get(CV_CAP_PROP_FRAME_COUNT) - mCap .get(CV_CAP_PROP_POS_FRAMES); return true; } if(mCap.get(CV_CAP_PROP_FRAME_COUNT) - mCap .get(CV_CAP_PROP_POS_FRAMES) <=0) { mVideoID++; mReadDataStatus = true; } return false; }
void connection::handle_read(const boost::system::error_code& e, std::size_t bytes_transferred) { if (!e) { boost::tribool result; boost::posix_time::ptime t(boost::posix_time::microsec_clock::local_time()); std::string nowTime = to_iso_extended_string(t); std::ostringstream in; int pos = nowTime.find('T'); nowTime.replace(pos,1,std::string(" ")); startTime = t; in << nowTime << " Client [" << socket_.remote_endpoint().address() << ":" << socket_.remote_endpoint().port() << "] request file "; boost::tie(result, boost::tuples::ignore) = request_parser_.parse( request_, buffer_.data(), buffer_.data() + bytes_transferred); in<<request_.uri; log::log_write(in.str()); if (result) { request_status = request_handler_.handle_request(request_, reply_); boost::asio::async_write(socket_, reply_.to_buffers(), strand_.wrap( boost::bind(&connection::handle_write, shared_from_this(), boost::asio::placeholders::error))); } else if (!result) { reply_ = reply::stock_reply(reply::bad_request); request_status = "Bad Request"; boost::asio::async_write(socket_, reply_.to_buffers(), strand_.wrap( boost::bind(&connection::handle_write, shared_from_this(), boost::asio::placeholders::error))); } else { socket_.async_read_some(boost::asio::buffer(buffer_), strand_.wrap( boost::bind(&connection::handle_read, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred))); } } // If an error occurs then no new asynchronous operations are started. This // means that all shared_ptr references to the connection object will // disappear and the object will be destroyed automatically after this // handler returns. The connection class's destructor closes the socket. }
Datum convert_element<std::string>(PG_FUNCTION_ARGS, const mongo::BSONElement e) { std::stringstream ss; switch(e.type()) { case mongo::String: case mongo::DBRef: case mongo::Symbol: return return_string(std::string(e.valuestr(), e.valuestrsize()-1)); case mongo::NumberDouble: ss << e._numberDouble(); break; case mongo::jstOID: ss << e.__oid().str(); break; case mongo::Bool: ss << std::boolalpha << e.boolean(); break; case mongo::Date: return return_string( to_iso_extended_string( boost::posix_time::ptime( boost::gregorian::date(1970, 1, 1), boost::posix_time::milliseconds(e.date().millis) ) ) ); case mongo::RegEx: ss << e.regex(); break; case mongo::NumberInt: ss << e._numberInt(); break; case mongo::NumberLong: ss << e._numberLong(); break; default: throw convertion_error("text"); } return return_string(ss.str()); }
void WebPage::procPostList(const QString &jsonStr) { recs_t recs = BatDownUtils::jsonStringToRecordList(jsonStr); for(int i=0, len=recs.size(); i<len; ++i){ record_t rec = recs.at(i); ptime t(second_clock::local_time()); rec.insert( "last_index_dt", QString::fromStdString(to_iso_extended_string(t)) ); QString url = rec.value("url"); QString sql = QString("SELECT COUNT(*) FROM btdl_post WHERE url='%1'").arg( url ); QStringList count = m_pApp->getDbMgr().query( sql.toLocal8Bit().data() ).at(0); int c = QString( count.at(0) ).toInt(); if(c == 0){ static_cast<PostModel*>( m_pApp->getPostView()->model() )->insertRecord(rec, 0); } else if(c == 1){ m_pApp->getDbMgr().updateRecord(rec, QString("url='%1'").arg(url).toLatin1().data() ,"btdl_post"); } else { yERROR(QString::fromLocal8Bit("Duplicate record! key:%1, table:btdl_post") .arg(url).toLocal8Bit().data()); } } }
void connection::handle_write(const boost::system::error_code& e) { boost::posix_time::ptime t(boost::posix_time::microsec_clock::local_time()); std::string nowTime = to_iso_extended_string(t); std::ostringstream in; int pos = nowTime.find('T'); nowTime.replace(pos,1,std::string(" ")); endTime = t; if (!e) { // Initiate graceful connection closure. boost::system::error_code ignored_ec; if(request_status == "ok") { in << nowTime << " Successful send file " << request_.uri << " with " << reply_.content.size(); in << " bytes to client [" << socket_.remote_endpoint().address() << ":" << socket_.remote_endpoint().port(); in << "] after " << (endTime-startTime).total_milliseconds() << " ms from receiving its request."; //in << "] after " << (endTime-startTime).total_microseconds() << " ms from receiving its request."; } else { in << nowTime << " Fail to send file " << request_.uri; in << " to client [" << socket_.remote_endpoint().address() << ":" << socket_.remote_endpoint().port(); in << "] due to error " << request_status << "."; } log::log_write(in.str()); socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec); } else { in << nowTime << " Fail to send file " << request_.uri; in << " to client [" << socket_.remote_endpoint().address() << ":" << socket_.remote_endpoint().port(); in << "] due to error " << e.message() << "."; log::log_write(in.str()); } // No new asynchronous operations are started. This means that all shared_ptr // references to the connection object will disappear and the object will be // destroyed automatically after this handler returns. The connection class's // destructor closes the socket. }
void BaseCalendarUpdateAction::_doCalendarUpdate( Calendar& object, server::Request& request ) const { // Link to remove if(_linkToRemove) { DeleteQuery<CalendarLinkTableSync> deleteQuery; deleteQuery.addWhereField(TABLE_COL_ID, *_linkToRemove); deleteQuery.execute(); } // Add date if(!object.isLinked() && !_addLink) { // Preparation of the mask Calendar mask; if( !_startDate.is_not_a_date() && !_endDate.is_not_a_date()) { for (date d = _startDate; d <= _endDate; d += _period) { mask.setActive(d); } } if(_calendarTemplate.get()) { if(!mask.empty()) { mask = _calendarTemplate->getResult(mask); } else if(_calendarTemplate->isLimited()) { mask = _calendarTemplate->getResult(); } else if(_calendarTemplate2.get() && _calendarTemplate2->isLimited()) { mask = _calendarTemplate->getResult(_calendarTemplate2->getResult()); } } if(_calendarTemplate2.get()) { if(!mask.empty()) { mask = _calendarTemplate2->getResult(mask); } else if(_calendarTemplate2->isLimited()) { mask = _calendarTemplate2->getResult(); } } // Applying the mask if( !mask.empty()) { if(_add) { object |= mask; } else { object -= mask; } } } else if(_calendarUpdateToDo()) // Add link { CalendarLink link; link.setCalendar(&object); link.setStartDate(_startDate); link.setEndDate(_endDate); link.setCalendarTemplate(_calendarTemplate.get()); link.setCalendarTemplate2(_calendarTemplate2.get()); CalendarLinkTableSync::Save(&link); } // Storage of parameters in session variable if( !_startDate.is_not_a_date() && !_endDate.is_not_a_date() && _startDate != _endDate ){ if(!_startDate.is_not_a_date() && !_startDate.is_special()) { request.getSession()->setSessionVariable( SESSION_VARIABLE_SERVICE_ADMIN_START_DATE, to_iso_extended_string(_startDate) ); } if(!_endDate.is_not_a_date() && !_endDate.is_special()) { request.getSession()->setSessionVariable( SESSION_VARIABLE_SERVICE_ADMIN_END_DATE, to_iso_extended_string(_endDate) ); } } if(_calendarTemplate.get()) { request.getSession()->setSessionVariable( SESSION_VARIABLE_SERVICE_ADMIN_CALENDAR_TEMPLATE_ID, lexical_cast<string>(_calendarTemplate->getKey()) ); } if(_calendarTemplate2.get()) { request.getSession()->setSessionVariable( SESSION_VARIABLE_SERVICE_ADMIN_CALENDAR_TEMPLATE_ID2, lexical_cast<string>(_calendarTemplate2->getKey()) ); } // Dates to force to add if(!_dateToForceToAdd.is_not_a_date()) { Calendar::DatesSet dates(object.getDatesToForce()); dates.insert(_dateToForceToAdd); object.setDatesToForce(dates); object.setActive(_dateToForceToAdd); // Add date if non linked calendar (linked calendar behavior emulation) object.setActive(_dateToForceToAdd); } // Dates to force to remove if(!_dateToForceToRemove.is_not_a_date()) { Calendar::DatesSet dates(object.getDatesToForce()); dates.erase(_dateToForceToRemove); object.setDatesToForce(dates); object.setInactive(_dateToForceToRemove); } // Dates to bypass to add if(!_dateToBypassToAdd.is_not_a_date()) { // Add date to bypass Calendar::DatesSet dates(object.getDatesToBypass()); dates.insert(_dateToBypassToAdd); object.setDatesToBypass(dates); // Remove date if non linked calendar (linked calendar behavior emulation) object.setInactive(_dateToBypassToAdd); } // Dates to bypass to remove if(!_dateToBypassToRemove.is_not_a_date()) { Calendar::DatesSet dates(object.getDatesToBypass()); dates.erase(_dateToBypassToRemove); object.setDatesToBypass(dates); object.setActive(_dateToBypassToRemove); } }
bool Fits2D::writeFits(Mat img, ImgBitDepth imgType, string fileName, string compression) { int status = 0; long firstPixel, nbelements; // 2-dimensional image. long naxis = 2; // Image size. long naxes[2] = { img.cols, img.rows }; // First pixel to write. firstPixel = 1; // Number of pixels to write. nbelements = naxes[0] * naxes[1]; // Fits creation date : 'YYYY-MM-JJTHH:MM:SS.SS' boost::posix_time::ptime time = boost::posix_time::microsec_clock::universal_time(); kDATE = to_iso_extended_string(time); // Date in the fits filename. string dateFileName = TimeDate::getYYYYMMDDThhmmss(to_iso_string(time)); // Define CRPIX1 and CRPIX2 kCRPIX1 = (int)naxes[0] / 2; kCRPIX2 = (int)naxes[1] / 2; fitsfile *fptr; const char * filename; const char * filename2; // Creation of the fits filename. string pathAndname = ""; if(fileName != ""){ pathAndname = mFitsPath + fileName + ".fit"; kFILENAME = fileName + ".fit"; }else{ pathAndname = mFitsPath + kTELESCOP + "_" + dateFileName + "_UT.fit"; kFILENAME = kTELESCOP + "_" + dateFileName + "_UT.fit"; } filename = pathAndname.c_str(); pathAndname += compression; filename2 = pathAndname.c_str(); switch(imgType){ // UC8 case 0: { //https://www-n.oca.eu/pichon/Tableau_2D.pdf unsigned char ** tab = (unsigned char * *)malloc( img.rows * sizeof(unsigned char *)) ; if(tab == NULL){ BOOST_LOG_SEV(logger, fail) << "Fail to allocate unsigned char** array (NULL)."; return false; } tab[0] = (unsigned char *) malloc( naxes[0] * naxes[1] * sizeof(unsigned char) ) ; if(tab[0] == NULL){ BOOST_LOG_SEV(logger, fail) << "Fail to allocate unsigned char* array (NULL)."; return false; } for( int a = 1; a<naxes[1]; a++ ){ tab[a] = tab[a-1] + naxes[0]; } // Delete old file if it already exists. remove(filename); // Create new FITS file. if(fits_create_file(&fptr, filename2, &status)){ printerror(status); free(tab[0]); return false; } if (fits_create_img(fptr, BYTE_IMG, naxis, naxes, &status)){ printerror(status); free(tab[0]); return false; } // Initialize the values in the fits image with the mat's values. for ( int j = 0; j < naxes[1]; j++){ unsigned char * matPtr = img.ptr<unsigned char>(j); for ( int i = 0; i < naxes[0]; i++){ // Affect a value and inverse the image. tab[img.rows-1-j][i] = (unsigned char)matPtr[i]; } } // Write the array of unsigned short to the FITS file. if(fits_write_img(fptr, TBYTE, firstPixel, nbelements, tab[0], &status)){ printerror(status); free(tab[0]); return false; } // Free previously allocated memory. free(tab[0]); break; } case 1: { //https://www-n.oca.eu/pichon/Tableau_2D.pdf char ** tab = (char * *) malloc( img.rows * sizeof( char * ) ) ; if(tab == NULL){ BOOST_LOG_SEV(logger, fail) << "Fail to allocate char** array (NULL)."; return false; } tab[0] = (char *) malloc( naxes[0] * naxes[1] * sizeof(char) ) ; if(tab[0] == NULL){ BOOST_LOG_SEV(logger, fail) << "Fail to allocate char* array (NULL)."; return false; } for( int a = 1; a<naxes[1]; a++ ){ tab[a] = tab[a-1] + naxes[0]; } // Delete old file if it already exists. remove(filename); // Create new FITS file. if(fits_create_file(&fptr, filename2, &status)){ printerror(status); free(tab[0]); return false; } if(fits_create_img(fptr, SBYTE_IMG, naxis, naxes, &status)){ printerror(status); free(tab[0]); return false; } // Initialize the values in the fits image with the mat's values. for( int j = 0; j < naxes[1]; j++){ char * matPtr = img.ptr<char>(j); for(int i = 0; i < naxes[0]; i++){ // Affect a value and inverse the image. tab[img.rows-1-j][i] = (char)matPtr[i]; } } // Write the array of unsigned short to the FITS file. if(fits_write_img(fptr, TSBYTE, firstPixel, nbelements, tab[0], &status)){ printerror(status); free(tab[0]); return false; } // Free previously allocated memory. free(tab[0]); break; } case 2 : { //https://www-n.oca.eu/pichon/Tableau_2D.pdf unsigned short ** tab = (unsigned short * *) malloc( img.rows * sizeof( unsigned short * ) ) ; if(tab == NULL){ BOOST_LOG_SEV(logger, fail) << "Fail to allocate unsigned short** array (NULL)."; return false; } tab[0] = (unsigned short *) malloc( naxes[0] * naxes[1] * sizeof(unsigned short) ) ; if(tab[0] == NULL){ BOOST_LOG_SEV(logger, fail) << "Fail to allocate unsigned short* array (NULL)."; return false; } for( int a = 1; a<naxes[1]; a++ ){ tab[a] = tab[a-1] + naxes[0]; } // Delete old file if it already exists. remove(filename); // Create new FITS file. if (fits_create_file(&fptr, filename2, &status)){ printerror(status); free( *tab); free( tab ); return false; } if ( fits_create_img(fptr, USHORT_IMG, naxis, naxes, &status)){ printerror(status); free( *tab); free( tab ); return false; } // Initialize the values in the fits image with the mat's values. for ( int j = 0; j < naxes[1]; j++){ unsigned short * matPtr = img.ptr<unsigned short>(j); for ( int i = 0; i < naxes[0]; i++){ // Affect a value and inverse the image. tab[img.rows-1-j][i] = (unsigned short)matPtr[i]; } } // write the array of unsigned short to the FITS file if ( fits_write_img(fptr, TUSHORT, firstPixel, nbelements, tab[0], &status)){ printerror(status); free( *tab); free( tab ); return false; } // Free previously allocated memory. free( *tab); free( tab ); break; } case 3 : { Mat newMat; if(img.type() == CV_16UC1) { // Convert unsigned short type image in short type image. newMat = Mat(img.rows, img.cols, CV_16SC1, Scalar(0)); // Set bzero and bscale for print unsigned short value in soft visualization. kBZERO = 32768; kBSCALE = 1; unsigned short * ptr; short * ptr2; for(int i = 0; i < img.rows; i++){ ptr = img.ptr<unsigned short>(i); ptr2 = newMat.ptr<short>(i); for(int j = 0; j < img.cols; j++){ if(ptr[j] - 32768 > 32767){ ptr2[j] = 32767; }else{ ptr2[j] = ptr[j] - 32768; } } } }else{ img.copyTo(newMat); } //https://www-n.oca.eu/pichon/Tableau_2D.pdf short ** tab = (short * *) malloc( img.rows * sizeof( short * ) ) ; if(tab == NULL){ BOOST_LOG_SEV(logger, fail) << "Fail to allocate short** array (NULL)."; return false; } tab[0] = (short *) malloc( naxes[0] * naxes[1] * sizeof(short) ) ; if(tab[0] == NULL){ BOOST_LOG_SEV(logger, fail) << "Fail to allocate short* array (NULL)."; return false; } for( int a = 1; a<naxes[1]; a++ ){ tab[a] = tab[a-1] + naxes[0]; } // Delete old file if it already exists. remove(filename); // Create new FITS file. if (fits_create_file(&fptr, filename2, &status)){ printerror(status); free( *tab); free( tab ); return false; } if ( fits_create_img(fptr, SHORT_IMG, naxis, naxes, &status)){ printerror(status); free( *tab); free( tab ); return false; } // Initialize the values in the fits image with the mat's values. for ( int j = 0; j < naxes[1]; j++){ short * matPtr = newMat.ptr<short>(j); for ( int i = 0; i < naxes[0]; i++){ // Affect a value and inverse the image. tab[newMat.rows-1-j][i] = (short)matPtr[i]; } } // write the array of signed short to the FITS file if ( fits_write_img(fptr, TSHORT, firstPixel, nbelements, tab[0], &status)){ printerror(status); free( *tab); free( tab ); return false; } // Free previously allocated memory. free( *tab); free( tab ); break; } case 4 : { //https://www-n.oca.eu/pichon/Tableau_2D.pdf float ** tab = (float * *) malloc( img.rows * sizeof( float * ) ) ; if(tab == NULL){ BOOST_LOG_SEV(logger, fail) << "Fail to allocate float** array (NULL)."; return false; } tab[0] = (float *) malloc( naxes[0] * naxes[1] * sizeof(float) ) ; if(tab[0] == NULL){ BOOST_LOG_SEV(logger, fail) << "Fail to allocate float* array (NULL)."; return false; } for( int a = 1; a<naxes[1]; a++ ){ tab[a] = tab[a-1] + naxes[0]; } // Delete old file if it already exists. remove(filename); // Create new FITS file if(fits_create_file(&fptr, filename, &status)){ printerror(status); free( *tab); free( tab ); return false; } if( fits_create_img(fptr, FLOAT_IMG, naxis, naxes, &status)){ printerror(status); free( *tab); free( tab ); return false; } // Initialize the values in the fits image with the mat's values. for( int j = 0; j < naxes[1]; j++){ float * matPtr = img.ptr<float>(j); for ( int i = 0; i < naxes[0]; i++){ // Affect a value and inversed the image. tab[img.rows-1-j][i] = (float)matPtr[i]; } } // Write the array of unsigned short to the FITS file. if( fits_write_img(fptr, TFLOAT, firstPixel, nbelements, tab[0], &status)){ printerror(status); free( *tab); free( tab ); return false; } // Free previously allocated memory. free(*tab); free(tab); break; } } if(!writeKeywords(fptr)){ if(fits_close_file(fptr, &status)){ printerror(status); } return false; } if(fits_close_file(fptr, &status)){ printerror(status); return false; } return true; }
bool CameraGigeAravis::grabImage(Frame &newFrame){ ArvBuffer *arv_buffer; //exp = arv_camera_get_exposure_time(camera); arv_buffer = arv_stream_timeout_pop_buffer(stream,2000000); //us char *buffer_data; size_t buffer_size; if(arv_buffer == NULL){ throw runtime_error("arv_buffer is NULL"); return false; }else{ try{ if(arv_buffer_get_status(arv_buffer) == ARV_BUFFER_STATUS_SUCCESS){ //BOOST_LOG_SEV(logger, normal) << "Success to grab a frame."; buffer_data = (char *) arv_buffer_get_data (arv_buffer, &buffer_size); //Timestamping. //string acquisitionDate = TimeDate::localDateTime(microsec_clock::universal_time(),"%Y:%m:%d:%H:%M:%S"); //BOOST_LOG_SEV(logger, normal) << "Date : " << acquisitionDate; boost::posix_time::ptime time = boost::posix_time::microsec_clock::universal_time(); string acquisitionDate = to_iso_extended_string(time); //BOOST_LOG_SEV(logger, normal) << "Date : " << acqDateInMicrosec; Mat image; CamPixFmt imgDepth = MONO8; int saturateVal = 0; if(pixFormat == ARV_PIXEL_FORMAT_MONO_8){ //BOOST_LOG_SEV(logger, normal) << "Creating Mat 8 bits ..."; image = Mat(mHeight, mWidth, CV_8UC1, buffer_data); imgDepth = MONO8; saturateVal = 255; }else if(pixFormat == ARV_PIXEL_FORMAT_MONO_12){ //BOOST_LOG_SEV(logger, normal) << "Creating Mat 16 bits ..."; image = Mat(mHeight, mWidth, CV_16UC1, buffer_data); imgDepth = MONO12; saturateVal = 4095; //double t3 = (double)getTickCount(); if(shiftBitsImage){ //BOOST_LOG_SEV(logger, normal) << "Shifting bits ..."; unsigned short * p; for(int i = 0; i < image.rows; i++){ p = image.ptr<unsigned short>(i); for(int j = 0; j < image.cols; j++) p[j] = p[j] >> 4; } //BOOST_LOG_SEV(logger, normal) << "Bits shifted."; } //t3 = (((double)getTickCount() - t3)/getTickFrequency())*1000; //cout << "> Time shift : " << t3 << endl; } //BOOST_LOG_SEV(logger, normal) << "Creating frame object ..."; newFrame = Frame(image, gain, exp, acquisitionDate); //BOOST_LOG_SEV(logger, normal) << "Setting date of frame ..."; //newFrame.setAcqDateMicro(acqDateInMicrosec); //BOOST_LOG_SEV(logger, normal) << "Setting fps of frame ..."; newFrame.mFps = fps; newFrame.mFormat = imgDepth; //BOOST_LOG_SEV(logger, normal) << "Setting saturated value of frame ..."; newFrame.mSaturatedValue = saturateVal; newFrame.mFrameNumber = frameCounter; frameCounter++; //BOOST_LOG_SEV(logger, normal) << "Re-pushing arv buffer in stream ..."; arv_stream_push_buffer(stream, arv_buffer); return true; }else{ switch(arv_buffer_get_status(arv_buffer)){
void solve_const_value_in_wherecondition(Node *&cur) { if(cur==NULL)return; switch(cur->type) { case t_name: { Columns *col=(Columns *)cur; }break; case t_name_name: { Columns *col=(Columns *)cur; }break; case t_query_stmt: { }break; case t_expr_cal: { Expr_cal *node=(Expr_cal*)cur; solve_const_value_in_wherecondition(node->lnext); solve_const_value_in_wherecondition(node->rnext); }break; case t_expr_func: { Expr_func* node=(Expr_func *)cur; string datestr; date constdate(from_string("1990-10-01")); if(strcmp(node->funname,"FDATE_ADD")==0) { if(node->args->type==t_stringval) { datestr=string(((Expr *)node->args)->data); Expr_func *datefunc=(Expr_func *)node->parameter1; assert(((Expr *)datefunc->args)->type==t_intnum); if(strcmp(datefunc->funname,"INTERVAL_DAY")==0) { date_duration dd(atof(((Expr *)datefunc->args)->data)); constdate=date(from_string(datestr))+dd; // date_duration *dd=new date_duration(atof(((Expr *)datefunc->args)->data)); // constdate=from_string(datestr)+(*(date_duration *)dd); } else if(strcmp(datefunc->funname,"INTERVAL_WEEK")==0) { weeks dd(atof(((Expr *)datefunc->args)->data)); constdate=date(from_string(datestr))+dd; } else if(strcmp(datefunc->funname,"INTERVAL_MONTH")==0) { months dd(atof(((Expr *)datefunc->args)->data)); constdate=date(from_string(datestr))+dd; } else if(strcmp(datefunc->funname,"INTERVAL_YEAR")==0) { years dd(atof(((Expr *)datefunc->args)->data)); constdate=date(from_string(datestr))+dd; } else if(strcmp(datefunc->funname,"INTERVAL_QUARTER")==0) { months dd(atof(((Expr *)datefunc->args)->data)*3); constdate=date(from_string(datestr))+dd; } datestr=to_iso_extended_string(constdate); char *datechar=(char *)malloc(datestr.length()+2); strcpy(datechar,datestr.c_str()); // SQLParse_log("the date result after date_add, string= %s ------------------\n",datechar); //free(cur); cur=(Node *)newExpr(t_stringval,datechar); } } else if(strcmp(node->funname,"FDATE_SUB")==0) { if(node->args->type==t_stringval) { datestr=string(((Expr *)node->args)->data); Expr_func *datefunc=(Expr_func *)node->parameter1; assert(((Expr *)datefunc->args)->type==t_intnum); if(strcmp(datefunc->funname,"INTERVAL_DAY")==0) { date_duration dd(atof(((Expr *)datefunc->args)->data)); constdate=date(from_string(datestr))-dd; } else if(strcmp(datefunc->funname,"INTERVAL_WEEK")==0) { weeks dd(atof(((Expr *)datefunc->args)->data)); constdate=date(from_string(datestr))-dd; } else if(strcmp(datefunc->funname,"INTERVAL_MONTH")==0) { months dd(atof(((Expr *)datefunc->args)->data)); constdate=date(from_string(datestr))-dd; } else if(strcmp(datefunc->funname,"INTERVAL_YEAR")==0) { years dd(atof(((Expr *)datefunc->args)->data)); constdate=date(from_string(datestr))-dd; } else if(strcmp(datefunc->funname,"INTERVAL_QUARTER")==0) { months dd(atof(((Expr *)datefunc->args)->data)*3); constdate=date(from_string(datestr))-dd; } datestr=to_simple_string(constdate); char *datechar=(char *)malloc(datestr.length()+2); strcpy(datechar,datestr.c_str()); // SQLParse_log("the date result after date_sub, string= %s ------------------\n",datechar); //free(cur); cur=(Node *)newExpr(t_stringval,datechar); } } else { } }break; case t_expr_list: { Expr_list * node=(Expr_list *)cur; }break; default: { SQLParse_log("solve_const_value_in_wherecondition can't know the type=%d\n",cur->type); } } }
string Test::runSingleQarterTest(TestResults& tResults) { LOG_INFO << "\n --- Running runSingleQarterTest() ---\n"; string testName("Test-Single Quarter 10Q retrieval: "); //LOG_INFO << "single quarter test under restructuring\n"; //return ""; T_Stock ts; T_Ep te; O_Stock stock = ts.select( ts._ticker() == string("CVX")).front(); tResults.setStockTickerName( stock._ticker() ); string filing = getMockFromDisk("CVX_2014_1stQ.txt"); if ( filing == "") { tResults.addFailure(testName + "Could not load mock 10q for testing"); return tResults.getResultsSummary(); } //cout << "Got filing " << filing.substr(0,300) << endl; EdgarData edgar; Acn acn( string("0000093410-14-000024"), date(2014,May,2), 1 ); acn._year = 2014; //string cover_rep_mok = ""; //string page = filing; Parser parser(stock); string cover_rep = parser.get_report_from_complete_filing(filing,ReportType::COVER); //check_report_year_and_date(cover_rep, *it); string income_rep = parser.get_report_from_complete_filing(filing,ReportType::INCOME); edgar.addIncomeStatmentToDB( income_rep, stock, acn._year, acn._quarter, cover_rep, to_iso_extended_string( acn._report_date) ); //Test results writen to DB if (te.select( te._stock_id() == stock._id() && te._year() == 2014 && te._quarter() == 1).empty()) { tResults.addFailure(testName + "No record was added to DB"); return tResults.getResultsSummary(); } O_Ep cvx2013Q1 = te.select( te._stock_id() == stock._id() && te._year() == 2014 && te._quarter() == 1).front() ; if (cvx2013Q1._year() != 2014) tResults.addFailure(testName + "Year should be: 2014, but is: " + to_string(cvx2013Q1._year()) ); if (cvx2013Q1._quarter() != 1) tResults.addFailure(testName + "Quarter should be: 1, but is: " + to_string(cvx2013Q1._quarter()) ); if (cvx2013Q1._revenue() != "53265000000") tResults.addFailure(testName + "Revenue should be: 53265000000, but is: " + cvx2013Q1._revenue() ); if (cvx2013Q1._net_income() != "4512000000") tResults.addFailure(testName + "Net Income should be: 4512000000, but is: " + cvx2013Q1._net_income() ); if (cvx2013Q1._eps() != 2.36) tResults.addFailure(testName + "(diluted) Eps should be: 2.36, but is: " + to_string(cvx2013Q1._eps()) ); if (cvx2013Q1._shares() != "1909424000") tResults.addFailure(testName + "Number of (diluted) shares should be: 1909424000, but is: " + cvx2013Q1._shares() ); // erase record from DB te.erase( te._id() == cvx2013Q1._id()); return tResults.getResultsSummary(); }
void assign(basic_json<char,Storage>& self, boost::gregorian::date val) { std::string s(to_iso_extended_string(val)); self = s; }
bool CameraGigeSdkIc::grabSingleImage(Frame &frame, int camID){ // Retrieve a list with the video capture devices connected to the computer. DShowLib::Grabber::tVidCapDevListPtr pVidCapDevList = m_pGrabber->getAvailableVideoCaptureDevices(); if(pVidCapDevList == 0 || pVidCapDevList->empty()){ cout << "No device available." << endl; return false; }else{ // Print available devices. int numCam = -1; for(int i = 0; i < pVidCapDevList->size(); i++){ cout << "(" << i << ") " << pVidCapDevList->at(i).c_str() << endl; if(camID == i){ numCam = i; break; } } if(numCam == -1){ return false; }else{ // Open the selected video capture device. m_pGrabber->openDev(pVidCapDevList->at(numCam)); /*cout << "Available video formats : " << endl; DShowLib::Grabber::tVidFmtDescListPtr DecriptionList; DecriptionList = m_pGrabber->getAvailableVideoFormatDescs(); for( DShowLib::Grabber::tVidFmtDescList::iterator pDescription = DecriptionList->begin(); pDescription != DecriptionList->end(); pDescription++ ) { printf("%s\n", (*pDescription)->toString().c_str()); }*/ DShowLib::tFrameHandlerSinkPtr pSink; cout << "Current bits per pixel : " << m_pGrabber->getVideoFormat().getBitsPerPixel() << endl; switch(frame.getBitDepth()){ case MONO_8 : m_pGrabber->setVideoFormat("Y8 (1280x960-1280x960)"); // Set the image buffer format to eY800. eY800 means monochrome, 8 bits (1 byte) per pixel. // Let the sink create a matching MemBufferCollection with 1 buffer. pSink = DShowLib::FrameHandlerSink::create( DShowLib::eY800, 1 ); break; case MONO_12 : m_pGrabber->setVideoFormat("Y16 (1280x960-1280x960)"); // Disable overlay. // http://www.theimagingsourceforums.com/archive/index.php/t-319880.html m_pGrabber->setOverlayBitmapPathPosition(DShowLib::ePP_NONE); // Set the image buffer format to eY16. eY16 means monochrome, 16 bits (2 byte) per pixel. // Let the sink create a matching MemBufferCollection with 1 buffer. pSink = DShowLib::FrameHandlerSink::create( DShowLib::eY16, 1 ); break; default: return false; break; } cout << "New video format : " << m_pGrabber->getVideoFormat().getBitsPerPixel() << endl; // Get properties. _DSHOWLIB_NAMESPACE::tIVCDPropertyItemsPtr pItems = m_pGrabber->getAvailableVCDProperties(); // Set Exposure time. int exposure = frame.getExposure(); long eMin = getPropertyRangeMin(DShowLib::VCDID_Exposure, pItems); long eMax = getPropertyRangeMax(DShowLib::VCDID_Exposure, pItems); long e = getPropertyValue(DShowLib::VCDID_Exposure, pItems); cout << "Previous exposure time value : " << e << endl; if(exposure <= eMax && exposure >= eMin){ setPropertyValue(DShowLib::VCDID_Exposure, (long)exposure, pItems); cout << "New exposure time value : " << getPropertyValue(DShowLib::VCDID_Exposure, pItems) << endl; }else{ cout << "Fail to set exposure. Available range value is " << eMin << " to " << eMax << endl; return false; } // Set Gain (db) int gain = frame.getGain(); long gMin = getPropertyRangeMin(DShowLib::VCDID_Gain, pItems); long gMax = getPropertyRangeMax(DShowLib::VCDID_Gain, pItems); long g = getPropertyValue(DShowLib::VCDID_Gain, pItems); cout << "Previous gain value : " << g << endl; if(gain <= gMax && gain >= gMin){ setPropertyValue(DShowLib::VCDID_Gain, (long)gain, pItems); cout << "New gain value : " << getPropertyValue(DShowLib::VCDID_Gain, pItems) << endl; }else{ cout << "Fail to set gain. Available range value is " << gMin << " to " << gMax << endl; return false; } // Set the sink. m_pGrabber->setSinkType(pSink); // We use snap mode. pSink->setSnapMode(true); // Prepare the live mode, to get the output size if the sink. if(!m_pGrabber->prepareLive(false)){ std::cerr << "Could not render the VideoFormat into a eY800 sink."; return false; } // Retrieve the output type and dimension of the handler sink. // The dimension of the sink could be different from the VideoFormat, when // you use filters. DShowLib::FrameTypeInfo info; pSink->getOutputFrameType(info); cout << info.getBitsPerPixel() << endl; Mat newImg; DShowLib::Grabber::tMemBufferCollectionPtr pCollection; switch(info.getBitsPerPixel()){ case 8 : { newImg = Mat(info.dim.cy, info.dim.cx, CV_8UC1, Scalar(0)); BYTE* pBuf[1]; // Allocate image buffers of the above calculate buffer size. pBuf[0] = new BYTE[info.buffersize]; // Create a new MemBuffer collection that uses our own image buffers. pCollection = DShowLib::MemBufferCollection::create( info, 1, pBuf ); if( pCollection == 0 || !pSink->setMemBufferCollection(pCollection)){ std::cerr << "Could not set the new MemBufferCollection, because types do not match."; return false; } m_pGrabber->startLive(false); pSink->snapImages(1); memcpy(newImg.ptr(), pBuf[0], info.buffersize); } break; case 16 : { newImg = Mat(info.dim.cy, info.dim.cx, CV_16UC1, Scalar(0)); BYTE * pBuf[1]; // Allocate image buffers of the above calculate buffer size. pBuf[0] = new BYTE[info.buffersize]; // Create a new MemBuffer collection that uses our own image buffers. pCollection = DShowLib::MemBufferCollection::create(info, 1, pBuf); if(pCollection == 0 || !pSink->setMemBufferCollection(pCollection)){ std::cerr << "Could not set the new MemBufferCollection, because types do not match."; return false; } m_pGrabber->startLive(false); pSink->snapImages(1); memcpy(newImg.ptr(), pBuf[0], info.buffersize); } break; default: return false; break; } m_pGrabber->stopLive(); m_pGrabber->closeDev(); //Timestamping. string acquisitionDate = TimeDate::localDateTime(microsec_clock::universal_time(),"%Y:%m:%d:%H:%M:%S"); boost::posix_time::ptime time = boost::posix_time::microsec_clock::universal_time(); string acqDateInMicrosec = to_iso_extended_string(time); frame = Frame(newImg, 0, 0, acquisitionDate); frame.setAcqDateMicro(acqDateInMicrosec); frame.setFPS(0); //cout << "save " << endl; //pCollection->save( "yio*.bmp" ); double minVal, maxVal; minMaxLoc(newImg, &minVal, &maxVal); cout << "minVal :" << minVal << endl; cout << "maxVal :" << maxVal << endl; unsigned short * ptr; double t = (double)getTickCount(); for(int i = 0; i < newImg.rows; i++){ ptr = newImg.ptr<unsigned short>(i); for(int j = 0; j < newImg.cols; j++){ ptr[j] = ptr[j] >> 4; } } t = (((double)getTickCount() - t )/getTickFrequency())*1000; cout << "time decalage : " << t << endl; minMaxLoc(newImg, &minVal, &maxVal); cout << "minVal :" << minVal << endl; cout << "maxVal :" << maxVal << endl; } } return true; }