void avlog_do_search(boost::asio::io_service & io_service, std::string c, std::string q, std::string date, boost::function<void (boost::system::error_code, pt::ptree)> handler, soci::session & db) { pt::ptree outjson; std::string q_escaped; // 根据 channel_name , query string , date 像数据库查找 AVLOG_DBG << " c = " << c << " q = " << q << " date= " << date ; std::vector<std::string> r_date(1000); std::vector<std::string> r_channel(1000); std::vector<std::string> r_nick(1000); std::vector<std::string> r_message(1000); std::vector<std::string> r_rowid(1000); avhttp::detail::unescape_path(q, q_escaped); boost::timer::cpu_timer cputimer; cputimer.start(); db << "select date,channel,nick,message,rowid from avlog where channel=:c " "and message like \"%" << q_escaped << "%\" order by strftime(`date`) DESC" , soci::into(r_date) , soci::into(r_channel) , soci::into(r_nick) , soci::into(r_message) , soci::into(r_rowid) , soci::use(c); pt::ptree results; // print out the result for (int i = 0; i < r_date.size() ; i ++) { pt::ptree onemsg; onemsg.put("date", r_date[i]); onemsg.put("channel", r_channel[i]); onemsg.put("nick", r_nick[i]); onemsg.put("channel", r_channel[i]); onemsg.put("message", r_message[i]); onemsg.put("id", r_rowid[i]); results.push_back(std::make_pair("", onemsg)); } outjson.put("params.num_results", r_date.size()); outjson.put_child("data", results); outjson.put("params.time_used", boost::timer::format(cputimer.elapsed(), 6, "%w")); io_service.post( boost::asio::detail::bind_handler(handler, boost::system::error_code(), outjson ) ); };
// check whether X chr can be handled const bool RISELF16::check_handle_x_chr(const bool any_x_chr) { if(any_x_chr) { r_message("X chr ignored for RIL by selfing."); return false; } return true; // most crosses can handle the X chr }
// check that founder genotype data has correct no. founders and markers const bool RISELF16::check_founder_geno_size(const IntegerMatrix& founder_geno, const int n_markers) { bool result=true; const int fg_mar = founder_geno.cols(); const int fg_f = founder_geno.rows(); if(fg_mar != n_markers) { result = false; r_message("founder_geno has incorrect number of markers"); } if(fg_f != 16) { result = false; r_message("founder_geno should have 16 founders"); } return result; }
// check that cross_info conforms to expectation const bool RISELF16::check_crossinfo(const IntegerMatrix& cross_info, const bool any_x_chr) { bool result = true; const int n_row = cross_info.rows(); const int n_col = cross_info.cols(); // 16 columns with order of cross if(n_col != 16) { result = false; r_message("cross_info should have 16 columns, indicating the order of the cross"); return result; } int n_missing=0; int n_invalid=0; for(int i=0; i<n_row; i++) { for(int j=0; j<n_col; j++) { if(cross_info(i,j) == NA_INTEGER) ++n_missing; else if(cross_info(i,j) < 1 || cross_info(i,j)>n_col) ++n_invalid; } // count values 1..ncol IntegerVector counts(n_col); for(int j=0; j<n_col; j++) counts[j] = 0; // zero counts for(int j=0; j<n_col; j++) ++counts[cross_info(i,j)-1]; // count values for(int j=0; j<n_col; j++) { if(counts[j] != 1) n_invalid += abs(counts[j] - 1); } } if(n_missing > 0) { result = false; r_message("cross_info has missing values (it shouldn't)"); } if(n_invalid > 0) { result = false; r_message("cross_info has invalid values; each row should be permutation of {1, 2, ..., 16}"); } return result; }
// check that founder genotype data has correct values const bool RISELF16::check_founder_geno_values(const IntegerMatrix& founder_geno) { const int fg_mar = founder_geno.cols(); const int fg_f = founder_geno.rows(); for(int f=0; f<fg_f; f++) { for(int mar=0; mar<fg_mar; mar++) { int fg = founder_geno(f,mar); if(fg != 0 && fg != 1 && fg != 3) { // at least one invalid value r_message("founder_geno contains invalid values; should be in {0, 1, 3}"); return false; } } } return true; }