void AccountDeposit::OnKillfocusEditDepositCard() { UpdateData(TRUE); CDatabase db; db.Open("bankmanagement"); CString sqlstrconfirm,foundflag; sqlstrconfirm.Format(_T("select count(user_name) from user where user_id=(select user_id from card where card_number='%s')"), m_DepositCardnumber); CRecordset rs(&db); rs.Open(CRecordset::forwardOnly, (_T("%s"), sqlstrconfirm)); rs.GetFieldValue(_T("count(user_name)"), foundflag); if (foundflag == '0'){ MessageBox("这张卡不存在"); GetDlgItem(IDC_ACCOUNT_DEPOSIT_COMFIRM)->EnableWindow(false); } else { GetDlgItem(IDC_ACCOUNT_DEPOSIT_COMFIRM)->EnableWindow(true); CString sqlstr; sqlstr.Format(_T("select user_name from user where user_id=(select user_id from card where card_number='%s')"), m_DepositCardnumber); CRecordset rss(&db); rss.Open(CRecordset::forwardOnly, (_T("%s"), sqlstr)); rss.GetFieldValue(_T("user_name"), m_DepositUsername); //MessageBox(m_DepositUsername); UpdateData(FALSE); rss.Close(); } rs.Close(); db.Close(); // TODO: 在此添加控件通知处理程序代码 }
void coordinateDescentLasso( const Eigen::MatrixXf &data, const Eigen::VectorXf &output, Eigen::VectorXf &weights, const float lambda, const int nIters, const bool verbose) { const int nExamples = data.rows(); const int nFeatures = data.cols(); for(int iter = 0; iter < nIters; ++iter){ const int featureInd = iter % nFeatures; float rho = 0; for(int i = 0; i < nExamples; ++i) rho += residualWithoutKWeight( weights, data.row(i).transpose(), output[i], featureInd) * data(i, featureInd); auto column = data.col(featureInd); float sumOfColumn = (column.transpose() * column).sum(); weights[featureInd] = coordinateDescentStepLasso(weights[featureInd], sumOfColumn, rho, lambda); if(verbose){ const float err = rss(weights, data, output); std::cout << "iter " << iter << " err " << err << std::endl; std::cout << weights << std::endl; } } }
void logger::async_log(std::string const &name) { std::string data; ref_str_stream rss(data); rss << "---- [" << timestamp() << "] " << name << "\n" << std::flush; assert(data.size()); impl_->io_service().post( boost::bind(&logger_impl::async_log, impl_, data)); }
void RssData::finished(int id, bool error) { if (error) { qDebug() << "RSS: Received error during HTTP fetch." << endl; } else if (id == mConnectionId) { qDebug() << "RSS: HTTP fetch Success." << endl; QVariant rss(mRssEntries); emit data(rss); } }
void BlockForSeize::createRes(RDOResType rtp, const std::string& res_name) { // Получили список всех ресурсов RDOResourceList rssList(parser::RDOParser::s_parser()); // Создадим ресурс RDOResource rss(rtp, res_name); // Добавим его в систему rssList.append<parser::RDORSSResource>(rss); }
void parseTest::testParseJunk() { QFile rss(":/res/junk.rss"); rss.open(QIODevice::ReadOnly); JenkinsStatus status = parseJenkinsRss(rss); QCOMPARE(status.isValid(), false); QCOMPARE(status.jobs().empty(), true); QCOMPARE(status.errorMessage(), QStringLiteral("Not a jenkins reply")); }
void parseTest::testParseEmptyProjectList() { QFile rss(":/res/empty.rss"); rss.open(QIODevice::ReadOnly); JenkinsStatus status = parseJenkinsRss(rss); QCOMPARE(status.isValid(), true); QCOMPARE(status.jobs().empty(), true); QCOMPARE(status.errorMessage(), QStringLiteral("")); }
void ManagerProperty::OnClickedInterestFee() { CDatabase db; db.Open("bankmanagement"); CString sqlstr,sqlstrcardnumber,sqlstrafteramount,sqlstrupdate,updatenumber; int cardnumber; sqlstr.Format(_T("update card set money_balance=money_balance-2 where card_status='正常'"));//////扣费 db.ExecuteSQL(sqlstr); sqlstr.Format(_T("select count(*) from card where card_status='正常'"));/////查出卡片数 CRecordset rss(&db); rss.Open(CRecordset::forwardOnly, (_T("%f"), sqlstr)); rss.GetFieldValue(_T("count(*)"), sqlstrcardnumber); cardnumber = _ttoi(sqlstrcardnumber); UpdateData(FALSE); rss.Close(); sqlstr.Format(_T("select card_number from card where card_status='正常'"));/////记录收费数据 CRecordset r(&db); r.Open(CRecordset::forwardOnly, (_T("%f"), sqlstr)); CString timestr;///////////get system time CTime tm; while (!r.IsEOF()) { tm = CTime::GetCurrentTime(); timestr = tm.Format("%Y年%m月%d日 %X"); r.GetFieldValue(_T("card_number"), updatenumber); sqlstrupdate.Format(_T("insert into operate_bank(card_number,money_amount,operate_type,operate_time) values('%s',2,'卡管理费','%s')"), updatenumber,timestr); db.ExecuteSQL(sqlstrupdate); r.MoveNext(); } r.Close(); float fee = cardnumber*2.0;//////转入银行账户 sqlstr.Format(_T("update bank_account set money_amount=money_amount+'%f'"), fee); db.ExecuteSQL(sqlstr); sqlstr.Format(_T("select money_amount from bank_account"));////更新现实银行账户余额 CRecordset rs(&db); rs.Open(CRecordset::forwardOnly, (_T("%f"), sqlstr)); CString stramount; rs.GetFieldValue(_T("money_amount"), stramount); m_ManagerPropertyamount = _tstof(stramount); UpdateData(FALSE); rs.Close(); db.Close(); MessageBox("手续费处理成功!"); // TODO: 在此添加控件通知处理程序代码 }
static int db_ss(struct db_variable *vp, db_expr_t *valuep, int op) { if (kdb_frame == NULL) return (0); if (op == DB_VAR_GET) *valuep = (ISPL(kdb_frame->tf_cs)) ? kdb_frame->tf_ss : rss(); else if (ISPL(kdb_frame->tf_cs)) kdb_frame->tf_ss = *valuep; return (1); }
OPEN_COMPILER_MBUILDER_NAMESPACE // -------------------------------------------------------------------------------- // -------------------- BlockForQueue // -------------------------------------------------------------------------------- void BlockForQueue::createRes(RDOResType rtp, const std::string& res_name) { // Получили список всех ресурсов RDOResourceList rssList(parser::RDOParser::s_parser()); // Создадим ресурс RDOResource rss(rtp, res_name); // Добавим его в систему rssList.append<parser::RDORSSResource>(rss); }
static int db_ss(struct db_variable *vp, db_expr_t *valuep, int op) { if (kdb_frame == NULL) return (0); if (op == DB_VAR_GET) *valuep = TF_HAS_STACKREGS(kdb_frame) ? kdb_frame->tf_ss : rss(); else if (TF_HAS_STACKREGS(kdb_frame)) kdb_frame->tf_ss = *valuep; return (1); }
void parseTest::parseMultipleExecutions() { QFile rss(":/res/oneproject_multiplebuilds.rss"); rss.open(QIODevice::ReadOnly); JenkinsStatus status = parseJenkinsRss(rss); QCOMPARE(status.isValid(), true); QCOMPARE(status.jobs().size(), 1); const JenkinsJob &job = status.jobs().at(0); QCOMPARE(job.buildNumber(), 7); QCOMPARE(job.name(), QStringLiteral("proj 1")); QCOMPARE(job.status(), JobStatus::INSTABLE); QCOMPARE(job.url(), QStringLiteral("http://localhost/jenkins/job/proj%201/7/")); }
void preSTRUCT(string &line, RawSource *rs) { int offset=0,align=1; bool gl=false; if (sbcneed(line,'@')) gl=true; string n=getid(line); if (n.empty()) error1("Illegal structure name"); if (comma(line)) { switch(comma(line)) { case 0: if (!ParseExpression(line,offset)) error1("Offset expected"); if (labelnotfound) error1("Forward reference"); if (!comma(line)) break; default: if (!ParseExpression(line,align)) error1("Alignment expected"); if (labelnotfound) error1("Forward reference"); if (align<1) { align=1; error1("Negative or zero alignment not allowed"); } } } checkjunk(line); int scurlin=curlin, slistcurlin=listcurlin; StringList sl=rs->ReadUntil(structurenl,structureel,"structure"); if (structtab.exists(n)) { error("Structure already exists",n); return; } Structure s(n,offset); RSStructure rss(offset,align,gl,s,sl); int ocurlin=curlin, olistcurlin=listcurlin; curlin=scurlin, listcurlin=slistcurlin; rss.Process(); curlin=ocurlin, listcurlin=olistcurlin; if (gl || modlabp.empty()) n.clear(); else n=modlabp+'.'; n+=s.getname(); int i=labtab.insert(n,false); if (i) labtab.setvalue(i,s.getlength(),0); else error("Label already exists",n); structtab.add(s); }
/* * kdb_trap - field a TRACE or BPT trap */ int kdb_trap(int type, int code, struct i386_saved_state *regs) { volatile int ddb_mode = !(boothowto & RB_GDB); /* * XXX try to do nothing if the console is in graphics mode. * Handle trace traps (and hardware breakpoints...) by ignoring * them except for forgetting about them. Return 0 for other * traps to say that we haven't done anything. The trap handler * will usually panic. We should handle breakpoint traps for * our breakpoints by disarming our breakpoints and fixing up * %eip. */ if (cons_unavail && ddb_mode) { if (type == T_TRCTRAP) { regs->tf_eflags &= ~PSL_T; return (1); } return (0); } switch (type) { case T_BPTFLT: /* breakpoint */ case T_TRCTRAP: /* debug exception */ break; default: /* * XXX this is almost useless now. In most cases, * trap_fatal() has already printed a much more verbose * message. However, it is dangerous to print things in * trap_fatal() - kprintf() might be reentered and trap. * The debugger should be given control first. */ if (ddb_mode) db_printf("kernel: type %d trap, code=%x\n", type, code); if (db_nofault) { jmp_buf *no_fault = db_nofault; db_nofault = NULL; longjmp(*no_fault, 1); } } /* * This handles unexpected traps in ddb commands, including calls to * non-ddb functions. db_nofault only applies to memory accesses by * internal ddb commands. */ if (db_global_jmpbuf_valid) longjmp(db_global_jmpbuf, 1); /* * XXX We really should switch to a local stack here. */ ddb_regs = *regs; /* * If in kernel mode, esp and ss are not saved, so dummy them up. */ if (ISPL(regs->tf_cs) == 0) { ddb_regs.tf_esp = (int)®s->tf_esp; ddb_regs.tf_ss = rss(); } crit_enter(); #ifdef SMP db_printf("\nCPU%d stopping CPUs: 0x%08x\n", mycpu->gd_cpuid, mycpu->gd_other_cpus); /* We stop all CPUs except ourselves (obviously) */ stop_cpus(mycpu->gd_other_cpus); db_printf(" stopped\n"); #endif /* SMP */ setjmp(db_global_jmpbuf); db_global_jmpbuf_valid = TRUE; db_active++; if (ddb_mode) { cndbctl(TRUE); db_trap(type, code); cndbctl(FALSE); } else gdb_handle_exception(&ddb_regs, type, code); db_active--; db_global_jmpbuf_valid = FALSE; #ifdef SMP db_printf("\nCPU%d restarting CPUs: 0x%08x\n", mycpu->gd_cpuid, stopped_cpus); /* Restart all the CPUs we previously stopped */ if (stopped_cpus != mycpu->gd_other_cpus) { db_printf("whoa, other_cpus: 0x%08x, stopped_cpus: 0x%08x\n", mycpu->gd_other_cpus, stopped_cpus); panic("stop_cpus() failed"); } restart_cpus(stopped_cpus); db_printf(" restarted\n"); #endif /* SMP */ crit_exit(); regs->tf_eip = ddb_regs.tf_eip; regs->tf_eflags = ddb_regs.tf_eflags; regs->tf_eax = ddb_regs.tf_eax; regs->tf_ecx = ddb_regs.tf_ecx; regs->tf_edx = ddb_regs.tf_edx; regs->tf_ebx = ddb_regs.tf_ebx; /* * If in user mode, the saved ESP and SS were valid, restore them. */ if (ISPL(regs->tf_cs)) { regs->tf_esp = ddb_regs.tf_esp; regs->tf_ss = ddb_regs.tf_ss & 0xffff; } regs->tf_ebp = ddb_regs.tf_ebp; regs->tf_esi = ddb_regs.tf_esi; regs->tf_edi = ddb_regs.tf_edi; regs->tf_es = ddb_regs.tf_es & 0xffff; regs->tf_fs = ddb_regs.tf_fs & 0xffff; regs->tf_gs = ddb_regs.tf_gs & 0xffff; regs->tf_cs = ddb_regs.tf_cs & 0xffff; regs->tf_ds = ddb_regs.tf_ds & 0xffff; return (1); }
BOOL ManagerProperty::OnInitDialog() { CDialogEx::OnInitDialog(); //this->GetParent()->SendMessage(WM_CLOSE);//关闭父对话框 CDatabase db; db.Open("bankmanagement"); CString sqlstr,sqlstramount; sqlstr.Format(_T("select manager_name from manager where manager_login_name='%s'"), CurrentUser); CRecordset rs(&db); rs.Open(CRecordset::forwardOnly, (_T("%s"), sqlstr)); CString name; rs.GetFieldValue(_T("manager_name"), name); GetDlgItem(IDC_MANAGER_NAME)->SetWindowTextA((CString)name); rs.Close(); ////////////////////////////上姓名下金额 sqlstramount.Format(_T("select money_amount from bank_account")); CRecordset rss(&db); rss.Open(CRecordset::forwardOnly, (_T("%f"), sqlstramount)); CString stramount; rss.GetFieldValue(_T("money_amount"), stramount); m_ManagerPropertyamount = _tstof(stramount); UpdateData(FALSE); rss.Close(); db.Close(); ///////////////////////////////产生图表 CSeries0 lineSeries = (CSeries0)m_chartfinal.Series(0); lineSeries.Clear(); sqlstr.Format(_T("CREATE OR REPLACE VIEW `view_day_property`AS SELECT * FROM day_property ORDER BY day_property.dayproperty_id DESC LIMIT 10;")); db.Open("bankmanagement"); db.ExecuteSQL(sqlstr); sqlstr.Format(_T("select day_time,bank_balance from view_day_property ORDER BY dayproperty_id ASC;")); CRecordset rssss(&db); rssss.Open(CRecordset::forwardOnly, (_T("%s"), sqlstr)); CString strx, strbalance; double daybalance; for (int i = 0; i<10; i++) { CString varDayTime; rssss.GetFieldValue(_T("day_time"), varDayTime); strx.Format(_T("%s"), varDayTime); CString varBankBalance; rssss.GetFieldValue(_T("bank_balance"), varBankBalance); strbalance.Format(_T("%s"), varBankBalance); daybalance = _ttof(strbalance); lineSeries.AddXY((double)i, daybalance, strx, 0); rssss.MoveNext(); } rssss.Close(); db.Close(); return true; }
BOOL AccountDetail::OnInitDialog() { CDialogEx::OnInitDialog(); ModifyStyleEx(0, WS_EX_APPWINDOW); HICON m_hIcon; m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 AccountOperate.InsertColumn(1, _T("操作类型"), LVCFMT_LEFT, 200); AccountOperate.InsertColumn(2, _T("金额"), LVCFMT_LEFT, 80); AccountOperate.InsertColumn(3, _T("时间"), LVCFMT_LEFT, 80); CString sqlstr; sqlstr.Format(_T("select money_value,operate_time from operate_deposit where card_number ='%s'"), CardDetail); AccountOperate.DeleteAllItems(); CDatabase db; db.Open("bankmanagement"); CRecordset rs(&db); rs.Open(CRecordset::forwardOnly, (_T("%s"), sqlstr)); while (!rs.IsEOF()) { CString varOperateType; varOperateType = "存款"; AccountOperate.InsertItem(0, varOperateType); CString varOperateAmount; rs.GetFieldValue(_T("money_value"), varOperateAmount); AccountOperate.SetItemText(0, 1, varOperateAmount); CString varOperateTime; rs.GetFieldValue(_T("operate_time"), varOperateTime); AccountOperate.SetItemText(0, 2, varOperateTime); rs.MoveNext(); } rs.Close(); AccountOperate.SetExtendedStyle(LVS_EX_FLATSB | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); //////////////////////////////////////////////////上面是list control内容,下面是编辑框内容 CString sqlstrinfo; m_DetailCard = CardDetail; sqlstrinfo.Format(_T("select register_time,money_balance,card_type from card where card_number='%s'"),m_DetailCard); CRecordset rss(&db); rss.Open(CRecordset::forwardOnly, (_T("%s"), sqlstrinfo)); while (!rss.IsEOF()) { rss.GetFieldValue(_T("register_time"), m_DetailTime); rss.GetFieldValue(_T("money_balance"), m_DetailBalance); rss.GetFieldValue(_T("card_type"), m_DetailType); rss.MoveNext(); } UpdateData(false); rss.Close(); db.Close(); return true; }
/*void CFMUnlockPatientList::OnClerkAddNew(){ CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd(); } */ void CFMUnlockPatientList::OnPrintPreviewSelect() { CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd(); UpdateData(true); CReport rpt; CRecord rs(&pMF->m_db); CRecord rss(&pMF->m_db); CString szSQL, tmpStr, szSysDate; CString szTemp, szClass; int nIdx = 0; double nAmount = 0; long double nTotal = 0; long double nGroupTotal = 0; m_nTotal = 0; szSQL = GetQueryString(); rs.ExecSQL(szSQL); szSQL = GetDepositString(); rss.ExecSQL(szSQL); if (rs.GetRecordCount() + rss.GetRecordCount() <= 0) { ShowMessageBox(_T("No Data"), MB_OK | MB_ICONERROR); return; } if (!rpt.Init(_T("Reports/HMS/HF_DANHSACHBNCHUAKHOASO.RPT"))) return; rpt.GetReportHeader()->SetValue(_T("HealthService"), pMF->m_CompanyInfo.sc_pname); rpt.GetReportHeader()->SetValue(_T("HospitalName"), pMF->m_CompanyInfo.sc_name); tmpStr.Format(rpt.GetReportHeader()->GetValue(_T("ReportDate")), CDateTime::Convert(m_szFromDate, yyyymmdd | hhmm, ddmmyyyy | hhmm), CDateTime::Convert(m_szToDate, yyyymmdd | hhmm, ddmmyyyy | hhmm)); rpt.GetReportHeader()->SetValue(_T("ReportDate"), tmpStr); CReportSection *rptDetail; CString szGroup[] = {_T("I"), _T("II"), _T("III"), _T("IV")}; int nIndex = 0; while (!rs.IsEOF()) { if (szClass != rs.GetValue(_T("fclass"))) { if (nGroupTotal > 0) { rptDetail = rpt.AddDetail(rpt.GetGroupHeader(1)); TranslateString(_T("Total Amt"), tmpStr); tmpStr.AppendFormat(_T(" %s"), szGroup[nIndex++]); rptDetail->SetValue(_T("GroupName"), tmpStr); //tmpStr.Format(_T("%.2lf"), nGroupTotal); FormatCurrency(nGroupTotal, tmpStr); rptDetail->SetValue(_T("SumGroupName"), tmpStr); nTotal += nGroupTotal; nGroupTotal = 0; } nIdx = 1; rs.GetValue(_T("fclass"), szClass); if (szClass == _T("NO")) { rptDetail = rpt.AddDetail(rpt.GetGroupHeader(1)); rptDetail->SetValue(_T("GroupName"), _T("\x43\xE1\x63 kho\x61 n\x1ED9i tr\xFA")); } } rptDetail = rpt.AddDetail(); tmpStr.Format(_T("%d"), nIdx++); rptDetail->SetValue(_T("1"), tmpStr); rs.GetValue(_T("pname"), tmpStr); rptDetail->SetValue(_T("2"), tmpStr); rs.GetValue(_T("docno"), tmpStr); rptDetail->SetValue(_T("3"), tmpStr); rs.GetValue(_T("deptid"), tmpStr); rptDetail->SetValue(_T("4"), tmpStr); rs.GetValue(_T("staff"), tmpStr); rptDetail->SetValue(_T("6"), tmpStr); rs.GetValue(_T("amount"), nAmount); nGroupTotal += nAmount; FormatCurrency(nAmount, tmpStr); rptDetail->SetValue(_T("5"), tmpStr); rs.MoveNext(); } if (nGroupTotal > 0) { rptDetail = rpt.AddDetail(rpt.GetGroupHeader(1)); TranslateString(_T("Total Amt"), tmpStr); tmpStr.AppendFormat(_T(" %s"), szGroup[nIndex++]); rptDetail->SetValue(_T("GroupName"), tmpStr); //tmpStr.Format(_T("%.2lf"), nGroupTotal); FormatCurrency(nGroupTotal, tmpStr); rptDetail->SetValue(_T("SumGroupName"), tmpStr); nTotal += nGroupTotal; nGroupTotal = 0; } //szSQL = GetDepositString(); //rs.ExecSQL(szSQL); if (!rss.IsEOF()) { rptDetail = rpt.AddDetail(rpt.GetGroupHeader(1)); rptDetail->SetValue(_T("GroupName"), _T("Thu t\x1EA1m g\x1EEDi")); nIdx = 1; while (!rss.IsEOF()) { rptDetail = rpt.AddDetail(); tmpStr.Format(_T("%d"), nIdx++); rptDetail->SetValue(_T("1"), tmpStr); rss.GetValue(_T("pname"), tmpStr); rptDetail->SetValue(_T("2"), tmpStr); rss.GetValue(_T("docno"), tmpStr); rptDetail->SetValue(_T("3"), tmpStr); rss.GetValue(_T("deptid"), tmpStr); rptDetail->SetValue(_T("4"), tmpStr); rss.GetValue(_T("staff"), tmpStr); rptDetail->SetValue(_T("6"), tmpStr); rss.GetValue(_T("amount"), nAmount); nGroupTotal += nAmount; FormatCurrency(nAmount, tmpStr); rptDetail->SetValue(_T("5"), tmpStr); rss.MoveNext(); } } if (nGroupTotal > 0) { rptDetail = rpt.AddDetail(rpt.GetGroupHeader(1)); TranslateString(_T("Total Amt"), tmpStr); tmpStr.AppendFormat(_T(" %s"), szGroup[nIndex++]); rptDetail->SetValue(_T("GroupName"), tmpStr); //tmpStr.Format(_T("%.2lf"), nGroupTotal); FormatCurrency(nGroupTotal, tmpStr); rptDetail->SetValue(_T("SumGroupName"), tmpStr); nTotal += nGroupTotal; nGroupTotal = 0; } //rptDetail = rpt.AddDetail(rpt.GetReportFooter()); tmpStr.Format(_T("%s"), _T("T\x1ED5ng \x63\x1ED9ng")); rpt.GetReportFooter()->SetValue(_T("TotalAmount"), tmpStr); nTotal += 0.5; long double nTemp = floor(nTotal); m_nTotal = nTemp; FormatCurrency(nTemp, tmpStr); rpt.GetReportFooter()->SetValue(_T("SumTotalAmount"), tmpStr); tmpStr.Format(_T("%.0lf"), nTemp); CString szMoney = tmpStr; MoneyToString(szMoney, tmpStr); rpt.GetReportFooter()->SetValue(_T("SumInWord"), tmpStr); szSysDate = pMF->GetSysDate(); tmpStr.Format(rpt.GetReportFooter()->GetValue(_T("PrintDate")), szSysDate.Right(2), szSysDate.Mid(5, 2), szSysDate.Left(4)); rpt.GetReportFooter()->SetValue(_T("PrintDate"), tmpStr); rpt.PrintPreview(); }
void rlrt1( double *Ytilde2, const double *D, const double *S0, const double *S1, double *tau0, double *tau1, double *rlrt_obs, double *rlrt_sim, double *gft_obs, double *gft_sim, int *_n, int *_p, int *_m0, int *_m1, int *_nsim, double *_tol, double *_b) { const int n = *_n, p = *_p; const int n_minus_p = n - p; const int m0 = *_m0, m1 = *_m1; const int k0 = m0 + 1, k1 = m1 + 1; const int nsim = *_nsim; const double tol = *_tol; const double br1 = _b[0], br2 = _b[1], bg1 = _b[2], bg2 = _b[3]; /* work space */ int lwork = k1 * 2 + m1 * 3 + n_minus_p * 4; double *const work0 = (double *)malloc(lwork * sizeof(double)); if (work0 == 0) { *rlrt_obs = *gft_obs = 0.0; return; } double *work = work0; rl_extra extra; extra.n_minus_p = n_minus_p; extra.D = D; extra.w2 = Ytilde2; double *const restrict Q = work; work += k1; double *const restrict guess = work; work += k1; double *const restrict init = work; work += m1; double *const restrict lower = work; work += m1; double *const restrict upper = work; work += m1; double *const restrict Dtau0 = work; work += n_minus_p; extra.Dtau = work; work += n_minus_p; extra.w2_Dtau = work; work += n_minus_p; extra.w2_Dtau2 = work; work += n_minus_p; for (int h = 0; h < m1; ++h) { init[h] = 0.0; lower[h] = 0.0; upper[h] = INFINITY; } /* observed test statistics */ double sr, r0, r1, sg, g0, g1; /* under H0 */ projected_bfgs(init, tau0, m0, &extra, nrl_f, nrl_g, 100, tol, lower, upper, &r0); g0 = rss(init, m0, &extra); for (int h = 0; h < m0; ++h) tau0[h] = init[h]; /* under H1 */ projected_bfgs(init, tau1, m1, &extra, nrl_f, nrl_g, 100, tol, lower, upper, &r1); g1 = rss(init, m1, &extra); for (int h = 0; h < m1; ++h) tau1[h] = init[h]; /* difference */ sr = r0 - r1; *rlrt_obs = sr; sg = (g0 - g1) / (g1 / n); *gft_obs = sg; if (((sr <= br1) || (sr >= br2)) && ((sg <= bg1) || (sg >= bg2))) { /* p-value is 1 if sr <= br1, or sg <= bg1 */ /* p-value is 0 if sr >= br2, or sg >= bg2 */ free(work0); return; } static const char no_trans = 'N', trans = 'T', upper_part = 'U'; static const int inc_one = 1; static const double zero = 0.0, one = 1.0; /* Dtau0 <- 1 + c(D[, 1 : m0] %*% tau0) */ F77_CALL(dgemv)(&no_trans, &n_minus_p, &m0, &one, D, &n_minus_p, tau0, &inc_one, &zero, Dtau0, &inc_one); for (int j = 0; j < n_minus_p; ++j) Dtau0[j] += 1.0; /* simulated test statistics */ GetRNGstate(); double *restrict w2 = Ytilde2; double sum_w2, z; for (int i = 0; i < nsim; ++i) { /* w2 <- Dtau0 * rnorm(n_minus_p) ^ 2; sum_w2 <- sum(w2) */ sum_w2 = 0.0; for (int j = 0; j < n_minus_p; ++j) { z = norm_rand(); w2[j] = Dtau0[j] * z * z; sum_w2 += w2[j]; } /* Q <- c(t(D) %*% w2, sum_w2) */ F77_CALL(dgemv)(&trans, &n_minus_p, &m1, &one, D, &n_minus_p, w2, &inc_one, &zero, Q, &inc_one); Q[m1] = sum_w2; for (int h = 0; h < m1; ++h) init[h] = 0.0; /* under H0 */ z = Q[m0]; Q[m0] = sum_w2; F77_CALL(dsymv)(&upper_part, &k0, &one, S0, &k0, Q, &inc_one, &zero, guess, &inc_one); Q[m0] = z; z = guess[m0]; if (z < 1e-6) z = 1e-6; for (int h = 0; h < m0; ++h) { if (guess[h] > 0.0) guess[h] /= z; else guess[h] = 0.0; } projected_bfgs(init, guess, m0, &extra, nrl_f, nrl_g, 100, tol, lower, upper, &r0); g0 = rss(init, m0, &extra); /* under H1 */ F77_CALL(dsymv)(&upper_part, &k1, &one, S1, &k1, Q, &inc_one, &zero, guess, &inc_one); z = guess[m1]; if (z < 1e-6) z = 1e-6; for (int h = 0; h < m1; ++h) { if (guess[h] > 0.0) guess[h] /= z; else guess[h] = 0.0; } projected_bfgs(init, guess, m1, &extra, nrl_f, nrl_g, 100, tol, lower, upper, &r1); g1 = rss(init, m1, &extra); /* simulated test statistics */ sr = r0 - r1; rlrt_sim[i] = sr; sg = (g0 - g1) / (g1 / n); if (sg < 0.0) sg = 0.0; gft_sim[i] = sg; } PutRNGstate(); free(work0); }
void CFMUnlockPatientList::OnExportSelect() { CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd(); UpdateData(true); CExcel xls; CRecord rs(&pMF->m_db); CRecord rss(&pMF->m_db); CString szSQL, tmpStr, szTemp; CString szClass; int nCol = 0, nRow = 0, nIdx = 0; double nAmount = 0; long double nTotal = 0; long double nGroupTotal = 0; m_nTotal = 0; szSQL = GetQueryString(); rs.ExecSQL(szSQL); szSQL = GetDepositString(); rss.ExecSQL(szSQL); if (rs.GetRecordCount() + rss.GetRecordCount() <= 0) { ShowMessageBox(_T("No Data"), MB_OK | MB_ICONERROR); return; } xls.CreateSheet(1); xls.SetWorksheet(0); xls.SetColumnWidth(0, 4); xls.SetColumnWidth(1, 25); xls.SetColumnWidth(2, 9); xls.SetColumnWidth(3, 8); xls.SetColumnWidth(4, 18); xls.SetColumnWidth(5, 15); xls.SetRowHeight(4, 40); //Header xls.SetCellMergedColumns(nCol, nRow, 3); xls.SetCellMergedColumns(nCol, nRow + 1, 3); xls.SetCellMergedColumns(nCol + 3, nRow, 4); xls.SetCellMergedColumns(nCol + 3, nRow + 1, 4); xls.SetCellMergedColumns(nCol, nRow + 2, 6); xls.SetCellMergedColumns(nCol, nRow + 3, 6); xls.SetCellText(nCol, nRow, pMF->m_CompanyInfo.sc_pname, FMT_TEXT | FMT_CENTER, true, 11); xls.SetCellText(nCol, nRow + 1, pMF->m_CompanyInfo.sc_name, FMT_TEXT | FMT_CENTER, true, 11); xls.SetCellText(nCol + 3, nRow, _T("\x43\x1ED8NG H\xD2\x41 \x58\xC3 H\x1ED8I \x43H\x1EE6 NGH\x128\x41 VI\x1EC6T N\x41M"), FMT_TEXT | FMT_CENTER, true); xls.SetCellText(nCol + 3, nRow + 1, _T("\x110\x1ED8\x43 L\x1EACP - T\x1EF0 \x44O - H\x1EA0NH PH\xDA\x43"), FMT_TEXT | FMT_CENTER, true); xls.SetCellText(nCol, nRow + 2, _T("\x42\x1EA2NG TH\x1ED0NG K\xCA \x44\x41NH S\xC1\x43H \x42\x1EC6NH NH\xC2N \x43H\x1AF\x41 KH\xD3\x41 S\x1ED4"), FMT_TEXT | FMT_CENTER, true, 11); tmpStr.Format(_T("T\x1EEB ng\xE0y %s \x111\x1EBFn ng\xE0y %s"), CDateTime::Convert(m_szFromDate, yyyymmdd | hhmm, ddmmyyyy | hhmm), CDateTime::Convert(m_szToDate, yyyymmdd | hhmm, ddmmyyyy | hhmm)); xls.SetCellText(nCol, nRow + 3, tmpStr, FMT_TEXT | FMT_CENTER, false, 11); //Column Header CStringArray arrCol; arrCol.Add(_T("STT")); arrCol.Add(_T("T\xEAn \x62\x1EC7nh nh\xE2n")); arrCol.Add(_T("S\x1ED1 h\x1ED3 s\x1A1")); arrCol.Add(_T("Kho\x61 / Ph\xF2ng kh\xE1m")); arrCol.Add(_T("Ng\x1B0\x1EDDi thu")); arrCol.Add(_T("S\x1ED1 ti\x1EC1n")); CString szGroup[] = {_T("I"), _T("II"), _T("III"), _T("IV")}; int nIndex = 0; nRow = 4; for (int i = 0; i < arrCol.GetCount(); i++) { xls.SetCellText(nCol + i, nRow, arrCol.GetAt(i), FMT_TEXT | FMT_CENTER | FMT_VCENTER | FMT_WRAPING, true, 10); } while (!rs.IsEOF()) { if (szClass != rs.GetValue(_T("fclass"))) { if (nGroupTotal > 0) { nRow++; TranslateString(_T("Total Amt"), tmpStr); tmpStr.AppendFormat(_T(" %s"), szGroup[nIndex++]); xls.SetCellMergedColumns(nCol, nRow, 5); xls.SetCellText(nCol, nRow, tmpStr, FMT_TEXT | FMT_CENTER, true, 11); tmpStr.Format(_T("%.2Lf"), nGroupTotal); xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING, true, 11); nTotal += nGroupTotal; nGroupTotal = 0; } nIdx = 1; rs.GetValue(_T("fclass"), szClass); if (szClass == _T("NO")) { nRow++; xls.SetCellMergedColumns(nCol, nRow, 6); xls.SetCellText(nCol, nRow, _T("\x43\xE1\x63 kho\x61 n\x1ED9i tr\xFA"), FMT_TEXT | FMT_CENTER, true, 11); } } nIdx++; nRow++; tmpStr.Format(_T("%d"), nIdx); xls.SetCellText(nCol, nRow, tmpStr, FMT_INTEGER | FMT_WRAPING); rs.GetValue(_T("pname"), tmpStr); xls.SetCellText(nCol + 1, nRow, tmpStr, FMT_TEXT | FMT_WRAPING); rs.GetValue(_T("docno"), tmpStr); xls.SetCellText(nCol + 2, nRow, tmpStr, FMT_INTEGER | FMT_WRAPING); rs.GetValue(_T("deptid"), tmpStr); xls.SetCellText(nCol + 3, nRow, tmpStr, FMT_TEXT | FMT_WRAPING); rs.GetValue(_T("staff"), tmpStr); xls.SetCellText(nCol + 4, nRow, tmpStr, FMT_TEXT | FMT_WRAPING); rs.GetValue(_T("amount"), nAmount); tmpStr.Format(_T("%.2f"), nAmount); nGroupTotal += nAmount; xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING); rs.MoveNext(); } if (nGroupTotal > 0) { nRow++; TranslateString(_T("Total Amt"), tmpStr); tmpStr.AppendFormat(_T(" %s"), szGroup[nIndex++]); xls.SetCellMergedColumns(nCol, nRow, 5); xls.SetCellText(nCol, nRow, tmpStr, FMT_TEXT | FMT_CENTER, true, 11); tmpStr.Format(_T("%.2Lf"), nGroupTotal); xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING, true, 11); nTotal += nGroupTotal; nGroupTotal = 0; } if (!rss.IsEOF()) { nRow++; xls.SetCellMergedColumns(nCol, nRow, 6); xls.SetCellText(nCol, nRow, _T("Thu t\x1EA1m g\x1EEDi"), FMT_TEXT | FMT_CENTER, true, 11); nIdx = 1; while (!rss.IsEOF()) { nRow++; tmpStr.Format(_T("%d"), nIdx++); xls.SetCellText(nCol, nRow, tmpStr, FMT_INTEGER | FMT_WRAPING); rss.GetValue(_T("pname"), tmpStr); xls.SetCellText(nCol + 1, nRow, tmpStr, FMT_TEXT | FMT_WRAPING); rss.GetValue(_T("docno"), tmpStr); xls.SetCellText(nCol + 2, nRow, tmpStr, FMT_INTEGER | FMT_WRAPING); rss.GetValue(_T("deptid"), tmpStr); xls.SetCellText(nCol + 3, nRow, tmpStr, FMT_TEXT | FMT_WRAPING); rss.GetValue(_T("staff"), tmpStr); xls.SetCellText(nCol + 4, nRow, tmpStr, FMT_TEXT | FMT_WRAPING); rss.GetValue(_T("amount"), nAmount); nGroupTotal += nAmount; tmpStr.Format(_T("%.2f"), nAmount); xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING); rss.MoveNext(); } } if (nGroupTotal > 0) { nRow++; TranslateString(_T("Total Amt"), tmpStr); tmpStr.AppendFormat(_T(" %s"), szGroup[nIndex++]); xls.SetCellMergedColumns(nCol, nRow, 5); xls.SetCellText(nCol, nRow, tmpStr, FMT_TEXT | FMT_CENTER, true, 11); tmpStr.Format(_T("%.2Lf"), nGroupTotal); xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING, true, 11); nTotal += nGroupTotal; nGroupTotal = 0; } if (nTotal > 0) { nRow++; xls.SetCellMergedColumns(nCol, nRow, 5); xls.SetCellText(nCol, nRow, _T("T\x1ED5ng ti\x1EC1n"), FMT_TEXT | FMT_CENTER, true, 11); tmpStr.Format(_T("%.2Lf"), nTotal); xls.SetCellText(nCol + 5, nRow, tmpStr, FMT_NUMBER1 | FMT_WRAPING, true, 11); } xls.Save(_T("Exports\\DanhSachBNChuaKhoaSo.xls")); }
void NETWORK::get_coordinates( double _z, double _dx, double _dy, std::vector<double>& _lrc, std::vector<double>& _x, std::vector<double>& _y ) const { /// create reachable set sizes std::vector<double> rss( Order, 0.0 ); for(int i=0; i<Order; i++) rss[i] = (double)Order * _lrc[i]; /// make levels // sort local reaching centralities std::vector<int> ids( Order, 0 ); for(int i=0; i<Order; i++) ids[i] = i; int len = Order; double rss_elem; int id; bool swapped = false; do { swapped = false; for(int i=1; i<len; i++) { if( rss[i-1] > rss[i] ) { rss_elem = rss[i-1]; rss[i-1] = rss[i]; rss[i] = rss_elem; id = ids[i-1]; ids[i-1] = ids[i]; ids[i] = id; swapped = true; } } len--; } while( swapped ); // network reaching centrality mean and variance double global_av = 0.0; double global_sd = 0.0; double threshold = 0.0; for(int i=0; i<Order; i++) { global_av += rss[i]; global_sd += rss[i]*rss[i]; } global_av /= (double)Order; global_sd = sqrt( fabs(global_sd/(double)Order - global_av*global_av) ); threshold = _z * global_sd + 0.00001; // in case of GRC = 0 // sort nodes in levels int number_of_levels = 0; int level_first_node = 0; int current_node = 1; std::vector<int> levels( Order, -1 ); levels[0] = 0; // start putting nodes in level until we reach last node while( current_node < Order ) { // pick the next node and calculate level average and standard deviation double level_av = 0.0; double level_sd = 0.0; for(int i=level_first_node; i<=current_node; i++) { level_av += rss[i]; level_sd += rss[i]*rss[i]; } level_av /= 1 + current_node - level_first_node; level_sd = sqrt( fabs(level_sd/double(1+current_node-level_first_node) - level_av*level_av) ); // if level deviation is lower than the threshold, keep node, otherwise start new level and put node there if( level_sd < threshold ) { levels[current_node] = number_of_levels; current_node++; } else { levels[current_node] = number_of_levels + 1; number_of_levels++; level_first_node = current_node; current_node++; } } number_of_levels++; /// set y coordinates std::vector<int> nodes_per_level( number_of_levels, 0 ); // calculate level averages std::vector<double> averages( number_of_levels, 0.0 ); for(int i=0; i<Order; i++) { averages[levels[i]] += rss[i]; nodes_per_level[levels[i]]++; } for(int i=0; i<number_of_levels; i++) averages[i] /= nodes_per_level[i]; std::vector<double> y_differences( number_of_levels, 0.0 ); std::vector<double> y_coordinates( number_of_levels, 0.0 ); y_differences[0] = 0.0; y_coordinates[0] = 0.0; double minimum_difference = _dy * (double)Order; for(int i=1; i<number_of_levels; i++) { y_differences[i] = log( averages[i]-averages[i-1] + 1.0 ); if( y_differences[i] < minimum_difference ) minimum_difference = y_differences[i]; } for(int i=1; i<number_of_levels; i++) y_coordinates[i] = y_coordinates[i-1] + _dy*y_differences[i]/minimum_difference; _y.assign( Order, 0.0 ); for(int i=0; i<Order; i++) _y[ids[i]] = y_coordinates[levels[i]]; /// set x coordinates std::vector<double> x_coordinate_starts( number_of_levels, 0.0 ); for(int i=0; i<number_of_levels; i++) { x_coordinate_starts[i] = -0.5 * _dx * (nodes_per_level[i] - 1); nodes_per_level[i] = 0; } _x.assign( Order, 0.0 ); for(int i=0; i<Order; i++) { _x[ids[i]] = x_coordinate_starts[levels[i]] + _dx * nodes_per_level[levels[i]]; nodes_per_level[levels[i]]++; } }