| | |
| | | |
| | | } |
| | | |
| | | void SeparateAnalysis::calcWindowRank() |
| | | { |
| | | // 滑动窗口排名,6个要2+的前100 |
| | | QVector<int> ranks; |
| | | for(int i=0;i<m_model->rowCount();++i){ |
| | | ranks.append(m_model->item(i,9)->text().toInt()); |
| | | if(i >= 6){ |
| | | // 先统计排名计数 |
| | | int cntBig=0, cntSmall=0; |
| | | for(int j=0;j<ranks.size();++j){ |
| | | if(ranks.at(j) > 100){ |
| | | cntBig++; |
| | | }else{ |
| | | cntSmall++; |
| | | } |
| | | } |
| | | // 统计对比 |
| | | if(cntSmall == 2 && ranks.back() <= 100){ |
| | | // 将当前6个元素定为符合的窗口,背景色设置为紫色 |
| | | for(int k=0;k<6;++k){ |
| | | m_model->item(i-k,9)->setData(QColor("red"),Qt::BackgroundColorRole); |
| | | } |
| | | } |
| | | |
| | | // 清除窗口第一个元素 |
| | | ranks.pop_front(); |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | void SeparateAnalysis::initMySQL() |
| | | { |
| | | //添加一个数据库 |
| | |
| | | m_model->setRowCount(0); // 重置模型行数 |
| | | //int rows = 0; |
| | | int rank_val = 0; |
| | | double amount_old = 0; |
| | | |
| | | while (que.next()) { |
| | | QString name = que.value(0).toString(); |
| | | QString code = que.value(1).toString(); |
| | |
| | | items.append(percentItem); |
| | | |
| | | items.append(new QStandardItem(close)); |
| | | items.append(new QStandardItem(amount)); |
| | | |
| | | double amount_val = amount.toDouble(); // 交易额 |
| | | QStandardItem *amountItem = new QStandardItem(amount); |
| | | if(amount_old > 0){ |
| | | if(amount_val / amount_old >= 3){ |
| | | amountItem->setData(QColor("red"),Qt::BackgroundColorRole); |
| | | amountItem->setData(QString::number(amount_val / amount_old),Qt::ToolTipRole); |
| | | } |
| | | } |
| | | items.append(amountItem); |
| | | amount_old = amount_val; |
| | | |
| | | // items.append(new QStandardItem(amount)); |
| | | items.append(new QStandardItem(volume)); |
| | | items.append(new QStandardItem(turnover_rate)); |
| | | items.append(new QStandardItem(pe_ttm)); |
| | |
| | | if(rank_val != 0){ |
| | | double rank_rate = 1 - (amount_rank.toDouble()/rank_val); |
| | | //items.append(new QStandardItem(QString::number(rank_rate))); |
| | | rank_val = amount_rank.toInt(); |
| | | |
| | | QStandardItem * amount_rank_item = new QStandardItem(QString::number(rank_rate)); |
| | | if(rank_rate > 0.9){ |
| | | amount_rank_item->setData(QColor("red"),Qt::BackgroundColorRole); |
| | | } |
| | | |
| | | if(rank_rate > 0.7 && rank_val >= 1000 && amount_rank.toInt() < 1000){ |
| | | if(rank_rate > 0.9){ |
| | | // 紫色 |
| | | amount_rank_item->setData(QColor(170, 85, 255),Qt::BackgroundColorRole); |
| | | }else{ |
| | | // 粉色 |
| | | amount_rank_item->setData(QColor("pink"),Qt::BackgroundColorRole); |
| | | } |
| | | |
| | | } |
| | | |
| | | items.append(amount_rank_item); |
| | | rank_val = amount_rank.toInt(); // 刷新排名 |
| | | |
| | | } |
| | | if(rank_val == 0 && amount_rank.toInt() != 0){ |
| | |
| | | qint64 need = QDateTime::currentMSecsSinceEpoch()-tt; |
| | | ui->label_status->setText(QString("耗时:%1 毫秒,查询完成.条数: %2").arg(QString::number(need)).arg(QString::number(rows))); |
| | | ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
| | | // 滑动窗口统计 |
| | | calcWindowRank(); |
| | | |
| | | } |
| | | |