From 99b38ba1c1a960d678775a32de3bbf236d8e78b7 Mon Sep 17 00:00:00 2001
From: wumu <mayi@mayi.com>
Date: 星期四, 21 八月 2025 23:53:04 +0800
Subject: [PATCH] 250821 缓存分析优化显示
---
analysisbyrediscache.h | 1 +
analysisbyrediscache.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 54 insertions(+), 1 deletions(-)
diff --git a/analysisbyrediscache.cpp b/analysisbyrediscache.cpp
index 7d41b52..f9fff34 100644
--- a/analysisbyrediscache.cpp
+++ b/analysisbyrediscache.cpp
@@ -26,6 +26,10 @@
m_model = new QStandardItemModel(this);
ui->tableView->setModel(m_model);
+
+ QStringList labels;
+ labels<<"鑲$エ鍚嶅瓧"<<"甯傚��"<<"鏀剁洏浠�"<<"娑ㄨ穼骞�"<<"鎺掑悕"<<"浜ゆ槗鏃堕棿"<<"鎺掑悕鍙樺寲";
+ m_model->setHorizontalHeaderLabels(labels);
}
AnalysisByRedisCache::~AnalysisByRedisCache()
@@ -54,6 +58,39 @@
m_result = result;
}
+// 婊戝姩绐楀彛璁$畻鎺掑悕鍙樺寲
+void AnalysisByRedisCache::calcWindowRank(int start)
+{
+
+ // 婊戝姩绐楀彛鎺掑悕锛�6涓2+鐨勫墠100
+ QVector<int> ranks;
+ for(int i=start;i<m_model->rowCount();++i){
+ ranks.append(m_model->item(i,4)->text().toInt());
+ if(i >= 6+start){
+ // 鍏堢粺璁℃帓鍚嶈鏁�
+ 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,4)->setData(QColor("red"),Qt::BackgroundColorRole);
+ }
+ }
+
+ // 娓呴櫎绐楀彛绗竴涓厓绱�
+ ranks.pop_front();
+ }
+
+ }
+
+}
void AnalysisByRedisCache::searchAndAnalysisData(QString name)
{
QElapsedTimer timer;
@@ -71,7 +108,20 @@
double market_capital = it["market_capital"].toDouble() / 100000000;
items.append(new QStandardItem(QString::number(market_capital)));
items.append(new QStandardItem(it["close"].toString()));
- items.append(new QStandardItem(it["percent"].toString()));
+
+ QStandardItem *percentItem = new QStandardItem(it["percent"].toString());
+ if(percentItem->text().toDouble() > 0){
+ percentItem->setData(QColor("red"),Qt::DecorationRole); // 娣诲姞瑁呴グ棰滆壊涓虹孩鑹�
+ percentItem->setData(QColor("red"),Qt::TextColorRole); // 娣诲姞鏂囨湰棰滆壊涓虹孩鑹�
+ items.at(0)->setData(QColor("red"),Qt::TextColorRole); // 璁剧疆鑲$エ鍚嶅瓧涓虹孩鑹�
+
+ }else if(percentItem->text().toDouble() < 0){
+ percentItem->setData(QColor("green"),Qt::DecorationRole); // 娣诲姞瑁呴グ棰滆壊涓虹孩鑹�
+ percentItem->setData(QColor("green"),Qt::TextColorRole); // 璁剧疆鑳屾櫙棰滆壊涓虹豢鑹�
+ items.at(0)->setData(QColor("green"),Qt::TextColorRole); // 璁剧疆鑲$エ鍚嶅瓧涓虹豢鑹�
+ }
+ items.append(percentItem);
+ //items.append(new QStandardItem(it["percent"].toString()));
items.append(new QStandardItem(it["amount_rank"].toString()));
items.append(new QStandardItem(it["time_trade"].toString()));
QString amount_rank = it["amount_rank"].toString();
@@ -96,6 +146,8 @@
}
qDebug()<<"cnt="<<cnt;
qDebug() << "Query executed in" << timer.elapsed() << "ms";
+ qDebug()<<"婊戝姩绐楀彛鎺掑悕-cnt:"<<m_model->rowCount()<<cnt<<"start:"<<m_model->rowCount() - cnt + 1;
+ calcWindowRank(m_model->rowCount() - cnt + 1);
}
void AnalysisByRedisCache::on_pushButton_analysisByRedis_clicked()
{
diff --git a/analysisbyrediscache.h b/analysisbyrediscache.h
index 6ff71ce..da502c6 100644
--- a/analysisbyrediscache.h
+++ b/analysisbyrediscache.h
@@ -19,6 +19,7 @@
+ void calcWindowRank(int start); // 婊戝姩绐楀彛璁$畻鍙樺寲鎯呭喌
signals:
void getStockNamesSignal(int); // 鑾峰彇鑲$エ鍓峃鍚嶇殑淇″彿
--
Gitblit v1.8.0