1912 lines
75 KiB
C++
1912 lines
75 KiB
C++
// chart.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
|
||
//
|
||
|
||
#include "chart.h"
|
||
#include <windows.h>
|
||
#include <stdio.h>
|
||
|
||
using namespace std;
|
||
//全局、Cal_start(int flag)、type_table()函数中有路径 修改路径就修改这三个地方
|
||
|
||
QString this_day;
|
||
QString Month_Data_csv = "C:\\Users\\28221\\Desktop\\"; //离线路径
|
||
//QString Month_Data_csv = "C:\\Users\\Administrator\\Desktop\\"; //现场路径
|
||
//QString Month_Data_csv = "./csv/"; //现场路径
|
||
|
||
chart::chart()
|
||
{
|
||
this->MainWidget = new QWidget();
|
||
this->MainWidgetLayout = new QGridLayout();
|
||
this->MainWidget->setLayout(this->MainWidgetLayout);
|
||
|
||
Creat_label();
|
||
}
|
||
|
||
chart::~chart()
|
||
{
|
||
}
|
||
|
||
template<class T>
|
||
void chart::Data_Exchange(T& a, T& b)
|
||
{
|
||
T c = a;
|
||
a = b;
|
||
b = c;
|
||
}
|
||
|
||
void chart::clear_all()
|
||
{
|
||
this->all = 0;
|
||
this->max_time = 0;
|
||
this->r_flag = 5;
|
||
this->g_flag = 5;
|
||
this->b_flag = 5;
|
||
this->month_day_NG = 0;
|
||
this->month_night_NG = 0;
|
||
this->All_SN = 0;
|
||
this->OK_SN = 0;
|
||
this->NG_SN = 0;
|
||
|
||
this->Cal_NG_Num.SN_NG_Num.clear();
|
||
this->Cal_NG_Num.SN_NG_Rang.clear();
|
||
|
||
this->Cal_NG_Hour.SN_NG_Hour.clear();
|
||
this->Cal_NG_Hour.SN_NG_Num.clear();
|
||
this->Cal_NG_Hour.NG_Color.clear();
|
||
this->Cal_NG_Hour.NG_Color_Flag.clear();
|
||
|
||
this->NG_Same_Flag.clear();
|
||
this->read_All.clear();
|
||
|
||
this->name_first_null = "";
|
||
this->name_second_null = "";
|
||
this->name_third_null = "";
|
||
}
|
||
|
||
//读取路径
|
||
void chart::Cal_start(int flag,QString Str_Time)
|
||
{
|
||
if (flag == 0)
|
||
{
|
||
QDateTime dateTime = QDateTime::currentDateTime();//获取系统当前的时间
|
||
this->file_path = dateTime.toString("yyyy-MM-dd");//格式化时间
|
||
}
|
||
|
||
//this->file_path = "2023-09-09"; //打开该日期的CSV表格,注释掉为打开当天的CSV表格
|
||
this_day = this->file_path;
|
||
this->file_name = "Data_" + Str_Time + ".csv";
|
||
{
|
||
this->file_path = "D:\\CCD\\result\\"+Str_Time+"\\" + this->file_name; //现场csv路径
|
||
}
|
||
//this->file_path = "C:\\Users\\28221\\Desktop\\cpp_file\\UI\\" + this->file_name; //注释掉为现场csv路径,打开为离线路径
|
||
//this->file_path = "./csv/" + this->file_name; //注释掉为现场csv路径,打开为离线路径
|
||
|
||
qDebug() << "path :" << this->file_path << endl;
|
||
this->plot(Str_Time);
|
||
//Creat_label();
|
||
}
|
||
|
||
//当月表格
|
||
void chart::type_table(QString Str_Time)
|
||
{
|
||
QHBoxLayout* mainWidgetLayout = new QHBoxLayout();
|
||
QWidget* mainWidget = new QWidget;
|
||
mainWidget->setMouseTracking(true);
|
||
mainWidgetLayout->addWidget(mainWidget);
|
||
mainWidgetLayout->setMargin(0);
|
||
|
||
//mainWidget->setMaximumWidth(300);
|
||
//mainWidget->setMaximumHeight(300);
|
||
|
||
this->maintable = new QTableView();
|
||
this->table_model = new QStandardItemModel();
|
||
this->maintable->setModel(table_model);
|
||
this->maintable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||
this->maintable->verticalHeader()->hide();
|
||
this->maintable->horizontalHeader()->hide();
|
||
|
||
int day_num;
|
||
//qDebug() << this_day;
|
||
//QStringList month = this_day.split("-");
|
||
QStringList month = Str_Time.split("-");
|
||
if (month[1] == "01" || month[1] == "03" || month[1] == "05" || month[1] == "07" || month[1] == "08" || month[1] == "10" || month[1] == "12")
|
||
{
|
||
day_num = 31;
|
||
}
|
||
if (month[1] == "04" || month[1] == "06" || month[1] == "09" || month[1] == "11")
|
||
{
|
||
day_num = 30;
|
||
}
|
||
if (month[0].toInt() % 4 == 0)
|
||
{
|
||
if (month[1] == "02")
|
||
day_num = 29;
|
||
}
|
||
else
|
||
{
|
||
if (month[1] == "02")
|
||
day_num = 28;
|
||
}
|
||
|
||
if (month[1].toInt() < 10)
|
||
month[1].replace("0", "");
|
||
|
||
QStandardItem* head_tabel = new QStandardItem(gb2312ToGB18030("不良项"));
|
||
head_tabel->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
head_tabel->setBackground(QBrush(QColor("#FFD966")));
|
||
this->table_model->setItem(0, 0, head_tabel);
|
||
|
||
QStandardItem* head_tabe2 = new QStandardItem(gb2312ToGB18030("合计"));
|
||
head_tabe2->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
head_tabe2->setBackground(QBrush(QColor("#FFD966")));
|
||
this->table_model->setItem(0, 1, head_tabe2);
|
||
|
||
QStandardItem* head_tabe3 = new QStandardItem(gb2312ToGB18030("班次"));
|
||
head_tabe3->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
head_tabe3->setBackground(QBrush(QColor("#FFD966")));
|
||
this->table_model->setItem(1, 0, head_tabe3);
|
||
|
||
QStandardItem* head_tabe4 = new QStandardItem(gb2312ToGB18030("当班设备总投入数"));
|
||
head_tabe4->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
head_tabe4->setBackground(QBrush(QColor("#FFD966")));
|
||
this->table_model->setItem(2, 0, head_tabe4);
|
||
|
||
QStandardItem* head_tabe5 = new QStandardItem(gb2312ToGB18030("当班不良总数"));
|
||
head_tabe5->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
head_tabe5->setBackground(QBrush(QColor("#FFD966")));
|
||
this->table_model->setItem(3, 0, head_tabe5);
|
||
|
||
QStandardItem* head_tabe6 = new QStandardItem(gb2312ToGB18030("不良率"));
|
||
head_tabe6->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
head_tabe6->setBackground(QBrush(QColor("#FFD966")));
|
||
this->table_model->setItem(4, 0, head_tabe6);
|
||
|
||
for (int i = 0; i < day_num; i++)
|
||
{
|
||
QStandardItem* head_tabel = new QStandardItem(month[1] + gb2312ToGB18030("月") + QString::number(i + 1) + gb2312ToGB18030("日"));
|
||
head_tabel->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
this->table_model->setItem(0, 2 + 2 * i, head_tabel);
|
||
QStandardItem* head_tabe2 = new QStandardItem(gb2312ToGB18030("白"));
|
||
head_tabe2->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
this->table_model->setItem(1, 2 + 2 * i, head_tabe2);
|
||
QStandardItem* head_tabe3 = new QStandardItem(gb2312ToGB18030("夜"));
|
||
head_tabe3->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
this->table_model->setItem(1, 3 + 2 * i, head_tabe3);
|
||
}
|
||
|
||
for (int m = 2; m < 2 + 2 * day_num; m += 2)
|
||
{
|
||
this->maintable->setSpan(0, m, 1, 2);
|
||
}
|
||
this->maintable->setSpan(0, 1, 2, 1);
|
||
|
||
QFile Parameter("./000_Dllparam.txt");
|
||
|
||
Parameter.open(QIODevice::ReadOnly);
|
||
int col = 0;
|
||
while (!Parameter.atEnd())
|
||
{
|
||
QString line = Parameter.readLine();
|
||
//qDebug() << line;
|
||
if (-1 != line.indexOf(","))
|
||
{
|
||
QStringList str = line.split("=");
|
||
QStandardItem* head_tabel = new QStandardItem(str[0]);
|
||
head_tabel->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
if (5 + col >= 31)
|
||
head_tabel->setBackground(QBrush(QColor("#F4B084")));
|
||
this->table_model->setItem(5 + col, 0, head_tabel);
|
||
col++;
|
||
}
|
||
}
|
||
Parameter.close();
|
||
|
||
QList<QString> day_NG_sn;
|
||
QMap<QString, int> day_NG_num;
|
||
QMap<QString, int> night_NG_num;
|
||
QMap<QString, QMap<QString, QMap<QString, QMap<QString, QList<QString>>>>> today_NG;
|
||
QMap<QString, QMap<QString, QMap<QString, QMap<QString, QList<QString>>>>> tomorrow_NG;
|
||
int table_row = this->maintable->model()->rowCount();
|
||
int table_col = this->maintable->model()->columnCount();
|
||
|
||
//QStringList month_1 = this_day.split("-");
|
||
QStringList month_1 = Str_Time.split("-");
|
||
int Mouth_NG_Num = 0;
|
||
int Mouth_All_Num = 0;
|
||
for (int day_1 = 1; day_1 <= day_num; day_1++)
|
||
{
|
||
day_NG_num.clear();
|
||
//night_NG_num.clear();
|
||
QString str_day;
|
||
if (day_1 < 10)
|
||
str_day = "0" + QString::number(day_1);
|
||
else
|
||
str_day = QString::number(day_1);
|
||
QString dir_filename = month_1[0] + "-" + month_1[1] + "-" + str_day;
|
||
QString path_filename = "Data_" + dir_filename + ".csv";
|
||
//qDebug() << path_filename;
|
||
QString open_csv;
|
||
if (dir_filename == this_day)
|
||
{
|
||
open_csv = "C:\\111\\" + path_filename; //现场路径
|
||
open_csv = "C:\\Users\\28221\\Desktop\\cpp_file\\UI\\" + path_filename; //离线路径
|
||
//open_csv = "./csv/" + path_filename; //离线路径
|
||
}
|
||
else
|
||
{
|
||
open_csv = "D:\\111\\" + dir_filename + "\\" + path_filename; //现场路径
|
||
open_csv = "C:\\Users\\28221\\Desktop\\cpp_file\\UI\\" + path_filename; //离线路径
|
||
//open_csv = "./csv/" + path_filename; //离线路径
|
||
}
|
||
QFile today_csv(open_csv);
|
||
if (!today_csv.open(QIODevice::ReadOnly))
|
||
continue;
|
||
//qDebug() << open_csv << "----------------------------------------------------------------------------------------------------------";
|
||
int cal_read_time = 0;
|
||
while (!today_csv.atEnd())
|
||
{
|
||
QString line_csv = today_csv.readLine();
|
||
if (cal_read_time == 0)
|
||
{
|
||
cal_read_time++;
|
||
continue;
|
||
}
|
||
line_csv = line_csv.trimmed();
|
||
if (line_csv.isEmpty()) {
|
||
qDebug() << "CSV FILE HAS READ DONE!" << '\n';
|
||
continue;
|
||
}
|
||
|
||
QStringList Str_NG = line_csv.split(",");
|
||
QStringList split_Hour_NG = Str_NG[0].split("-");
|
||
QString time_decide = split_Hour_NG[3] + split_Hour_NG[4];
|
||
//qDebug() << "time_decide : " << time_decide;
|
||
if (time_decide.toInt() >= 830 && time_decide.toInt() < 2030)
|
||
{
|
||
//qDebug() << dir_filename << "time : " << Str_NG[0] << "----- SN : " << Str_NG[1] << "----- path : " << Str_NG[2] << "----- result : " << Str_NG[3] << "----- NG : " << Str_NG[4] << endl;
|
||
if (!night_NG_num.isEmpty())
|
||
{
|
||
//if (day_1 != 1)
|
||
{
|
||
for (int i = 0; i < table_col; i++)
|
||
{
|
||
for (int j = 0; j < table_row; j++)
|
||
{
|
||
if (j == 2)
|
||
{
|
||
//qDebug() << Mouth_All_Num;
|
||
QStandardItem* head_tabel_add = new QStandardItem(QString::number(Mouth_All_Num));
|
||
head_tabel_add->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
this->table_model->setItem(j, 2 * str_day.toInt() - 1, head_tabel_add);
|
||
}
|
||
if (j == 3)
|
||
{
|
||
//qDebug() << Mouth_NG_Num;
|
||
QStandardItem* head_tabel_add = new QStandardItem(QString::number(Mouth_NG_Num));
|
||
head_tabel_add->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
this->table_model->setItem(j, 2 * str_day.toInt() - 1, head_tabel_add);
|
||
}
|
||
if (j == 4)
|
||
{
|
||
float NG_All_present = ((Mouth_NG_Num * 1.00) / Mouth_All_Num) * 100;
|
||
//qDebug() << NG_All_present << "%" << " " << j << " " << 2 * str_day.toInt();
|
||
QStandardItem* head_tabel_add = new QStandardItem(QString::number(NG_All_present, 'f', 2) + "%");
|
||
head_tabel_add->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
this->table_model->setItem(j, 2 * str_day.toInt() - 1, head_tabel_add);
|
||
}
|
||
if (j >= 5)
|
||
{
|
||
QMap<QString, int>::iterator iter;
|
||
for (iter = night_NG_num.begin(); iter != night_NG_num.end(); ++iter)
|
||
{
|
||
QModelIndex index3 = this->table_model->index(j, 0); //获取单元格的内容
|
||
QString index_unit = this->table_model->data(index3).toString();
|
||
if (index_unit == iter.key())
|
||
{
|
||
//qDebug() << i <<" " << j << " " << "! - " << index_unit << " x : " << j << " y : " << 2 * month_1[2].toInt() + 1 << " - " << iter.key() << " : " << iter.value();
|
||
QStandardItem* head_tabel_add = new QStandardItem(QString::number(iter.value()));
|
||
head_tabel_add->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
this->table_model->setItem(j, 2 * str_day.toInt() - 1, head_tabel_add);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//qDebug() << Mouth_All_Num << " " << Mouth_NG_Num << " " << (float)Mouth_NG_Num / Mouth_All_Num;
|
||
qApp->processEvents();
|
||
Mouth_All_Num = 0;
|
||
Mouth_NG_Num = 0;
|
||
night_NG_num.clear();
|
||
tomorrow_NG.clear();
|
||
}
|
||
Mouth_All_Num++;
|
||
if (Str_NG[3] == gb2312ToGB18030("缺图") || Str_NG[3] == "NG")
|
||
{
|
||
Mouth_NG_Num++;
|
||
}
|
||
//qDebug() << Str_NG;
|
||
QStringList split_Str_NG = Str_NG[4].split("&");
|
||
int calu_split_Str_NG = split_Str_NG.size();
|
||
for (int i = 1; i < calu_split_Str_NG; i++)
|
||
{
|
||
if (Str_NG[3] == "OK")
|
||
{
|
||
continue;
|
||
}
|
||
if (-1 != split_Str_NG[i].indexOf("OK")) //去除记为OK的缺陷
|
||
{
|
||
continue;
|
||
}
|
||
|
||
int start_split = split_Str_NG[i].indexOf("-");
|
||
if (-1 == start_split)
|
||
break;
|
||
int stop_split = split_Str_NG[i].indexOf("_");
|
||
if (-1 == stop_split)
|
||
break;
|
||
|
||
QString NG_rang = split_Str_NG[i].mid(start_split + 1, stop_split - start_split - 1);
|
||
day_NG_sn << NG_rang;
|
||
//qDebug() << split_Str_NG[i] << " ? " << Str_NG[0] << " - " << NG_rang << " : " << day_NG_sn;
|
||
}
|
||
day_NG_sn = day_NG_sn.toSet().toList();
|
||
|
||
QList<QString>::iterator it1 = day_NG_sn.begin();
|
||
|
||
for (; it1 != day_NG_sn.end(); ++it1)
|
||
{
|
||
int _NG_num_ = 0;
|
||
_NG_num_ = day_NG_num[*it1];
|
||
_NG_num_++;
|
||
day_NG_num[*it1] = _NG_num_;
|
||
}
|
||
|
||
today_NG[Str_NG[0]][Str_NG[1]][Str_NG[2]][Str_NG[3]] = day_NG_sn;
|
||
day_NG_sn.clear();
|
||
|
||
//qDebug() << day_NG_sn;
|
||
|
||
}
|
||
if (time_decide.toInt() >= 2030 || time_decide.toInt() < 830)
|
||
{
|
||
if (!day_NG_num.isEmpty())
|
||
{
|
||
//qDebug() << open_csv << " night";
|
||
for (int i = 0; i < table_col; i++)
|
||
{
|
||
for (int j = 0; j < table_row; j++)
|
||
{
|
||
if (j == 2)
|
||
{
|
||
QStandardItem* head_tabel_add = new QStandardItem(QString::number(Mouth_All_Num));
|
||
head_tabel_add->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
this->table_model->setItem(j, 2 * str_day.toInt(), head_tabel_add);
|
||
}
|
||
if (j == 3)
|
||
{
|
||
QStandardItem* head_tabel_add = new QStandardItem(QString::number(Mouth_NG_Num));
|
||
head_tabel_add->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
this->table_model->setItem(j, 2 * str_day.toInt(), head_tabel_add);
|
||
}
|
||
if (j == 4)
|
||
{
|
||
float NG_All_present = ((Mouth_NG_Num * 1.00) / Mouth_All_Num) * 100;
|
||
QStandardItem* head_tabel_add = new QStandardItem(QString::number(NG_All_present,'f',2)+"%");
|
||
head_tabel_add->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
this->table_model->setItem(j, 2 * str_day.toInt(), head_tabel_add);
|
||
}
|
||
if (j >= 5)
|
||
{
|
||
QMap<QString, int>::iterator iter;
|
||
for (iter = day_NG_num.begin(); iter != day_NG_num.end(); ++iter)
|
||
{
|
||
QModelIndex index3 = this->table_model->index(j, 0); //获取单元格的内容
|
||
QString index_unit = this->table_model->data(index3).toString();
|
||
if (index_unit == iter.key())
|
||
{
|
||
//qDebug() << i <<" " << j << " " << "! - " << index_unit << " x : " << j << " y : " << 2 * month_1[2].toInt() + 1 << " - " << iter.key() << " : " << iter.value();
|
||
QStandardItem* head_tabel_add = new QStandardItem(QString::number(iter.value()));
|
||
head_tabel_add->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
this->table_model->setItem(j, 2 * str_day.toInt(), head_tabel_add);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
qApp->processEvents();
|
||
Mouth_All_Num = 0;
|
||
Mouth_NG_Num = 0;
|
||
day_NG_num.clear();
|
||
today_NG.clear();
|
||
}
|
||
|
||
Mouth_All_Num++;
|
||
if (Str_NG[3] == gb2312ToGB18030("缺图") || Str_NG[3] == "NG")
|
||
{
|
||
Mouth_NG_Num++;
|
||
}
|
||
|
||
//qDebug() << dir_filename << "time : " << Str_NG[0] << "----- SN : " << Str_NG[1] << "----- path : " << Str_NG[2] << "----- result : " << Str_NG[3] << "----- NG : " << Str_NG[4] << endl;
|
||
QStringList split_Str_NG = Str_NG[4].split("&");
|
||
int calu_split_Str_NG = split_Str_NG.size();
|
||
for (int i = 1; i < calu_split_Str_NG; i++)
|
||
{
|
||
if (Str_NG[3] == gb2312ToGB18030("缺图"))
|
||
{
|
||
continue;
|
||
}
|
||
if (Str_NG[3] == "OK")
|
||
{
|
||
continue;
|
||
}
|
||
if (-1 != split_Str_NG[i].indexOf("OK")) //去除记为OK的缺陷
|
||
{
|
||
continue;
|
||
}
|
||
|
||
int start_split = split_Str_NG[i].indexOf("-");
|
||
if (-1 == start_split)
|
||
break;
|
||
int stop_split = split_Str_NG[i].indexOf("_");
|
||
if (-1 == stop_split)
|
||
break;
|
||
|
||
QString NG_rang = split_Str_NG[i].mid(start_split + 1, stop_split - start_split - 1);
|
||
day_NG_sn << NG_rang;
|
||
//qDebug() << split_Str_NG[i] << " ? " << Str_NG[0] << " - " << NG_rang << " : " << day_NG_sn;
|
||
}
|
||
day_NG_sn = day_NG_sn.toSet().toList();
|
||
//qDebug() << time_decide << "--------" << day_NG_sn;
|
||
QList<QString>::iterator it1 = day_NG_sn.begin();
|
||
|
||
for (; it1 != day_NG_sn.end(); ++it1)
|
||
{
|
||
int _NG_num_ = night_NG_num[*it1];
|
||
//qDebug() << "num : " << night_NG_num[*it1];
|
||
_NG_num_++;
|
||
night_NG_num[*it1] = _NG_num_;
|
||
}
|
||
tomorrow_NG[Str_NG[0]][Str_NG[1]][Str_NG[2]][Str_NG[3]] = day_NG_sn;
|
||
//qDebug() << day_NG_sn;
|
||
day_NG_sn.clear();
|
||
}
|
||
}
|
||
today_csv.close();
|
||
|
||
}
|
||
|
||
int Month_rows = this->maintable->model()->rowCount();//获取行数
|
||
int Month_cols = this->maintable->model()->columnCount();//获取列数
|
||
for (int m = 2; m < Month_rows; m++)
|
||
{
|
||
this->table_model->insertRow(Month_rows);
|
||
this->table_model->setItem(m, 1, new QStandardItem());
|
||
this->table_model->item(m, 1)->setBackground(QBrush(QColor("#FFD966")));
|
||
}
|
||
|
||
QFile Mouth_csv(Month_Data_csv + "Mouth_" + month_1[1] + ".csv");
|
||
Mouth_csv.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||
QTextStream csv_Mouth(&Mouth_csv);
|
||
|
||
QString write_Qstring = "";
|
||
for (int i = 0; i < Month_rows; i++)
|
||
{
|
||
for (int j = 0; j < Month_cols; j++)
|
||
{
|
||
QModelIndex index = this->table_model->index(i, j);
|
||
QString get_str = this->table_model->data(index).toString();
|
||
if (j == Month_rows - 1)
|
||
{
|
||
write_Qstring = get_str;
|
||
}
|
||
else
|
||
write_Qstring = get_str + ",";
|
||
|
||
csv_Mouth << write_Qstring;
|
||
}
|
||
csv_Mouth << endl;
|
||
}
|
||
Mouth_csv.close();
|
||
|
||
QGridLayout* pLayout = new QGridLayout();
|
||
pLayout->addWidget(maintable);
|
||
mainWidget->setWindowTitle(gb2312ToGB18030("本月不良缺陷分布表"));
|
||
mainWidget->setLayout(pLayout);
|
||
mainWidget->show();
|
||
mainWidget->resize(800, 600);
|
||
mainWidget->move(100, 700);
|
||
|
||
//this->MainWidgetLayout->addWidget(mainWidget, 2, 0, 1, 1);
|
||
}
|
||
|
||
bool chart::same_NG(QString& NG)
|
||
{
|
||
if (NG_Same_Flag[NG] == 0)
|
||
{
|
||
NG_Same_Flag[NG] = 1;
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
bool chart::copyFile(QString srcPath, QString dstPath, bool coverFileIfExist)
|
||
{
|
||
srcPath.replace("\\", "/");
|
||
dstPath.replace("\\", "/");
|
||
if (srcPath == dstPath) {
|
||
return true;
|
||
}
|
||
|
||
if (!QFile::exists(srcPath)) { //源文件不存在
|
||
return false;
|
||
}
|
||
|
||
if (QFile::exists(dstPath)) {
|
||
if (coverFileIfExist) {
|
||
QFile::remove(dstPath);
|
||
}
|
||
}
|
||
|
||
if (!QFile::copy(srcPath, dstPath)) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
QString chart::gb2312ToGB18030(const char* strUtf8)
|
||
{
|
||
QTextCodec* codec = QTextCodec::codecForName("GB18030");
|
||
return codec->toUnicode(strUtf8);
|
||
}
|
||
|
||
QString chart::gb2312ToUtf8(const QString strUtf8)
|
||
{
|
||
QTextCodec* utf8Codec = QTextCodec::codecForName("utf-8");
|
||
QTextCodec* gb2312Codec = QTextCodec::codecForName("gb2312");
|
||
|
||
QString strUnicode = gb2312Codec->toUnicode(strUtf8.toLocal8Bit().data());
|
||
QByteArray ByteUtf8 = utf8Codec->fromUnicode(strUnicode);
|
||
return ByteUtf8;
|
||
}
|
||
|
||
void chart::show_NG_Num(int& all, QString Str_Time)
|
||
{
|
||
QHBoxLayout* mainWidgetLayout = new QHBoxLayout();
|
||
QWidget* mainWidget = new QWidget;
|
||
QPushButton* button = new QPushButton;
|
||
button->resize(100, 50);
|
||
button->setText(gb2312ToGB18030("截取界面"));
|
||
//QMainWindow* mainWidget = new QMainWindow;
|
||
mainWidget->setMouseTracking(true);
|
||
//mainWidgetLayout->addWidget(button);
|
||
mainWidgetLayout->addWidget(mainWidget);
|
||
mainWidgetLayout->setMargin(0);
|
||
|
||
//mainWidget->setMaximumWidth(300);
|
||
//mainWidget->setMaximumHeight(300);
|
||
|
||
QCustomPlot* customPlot = new QCustomPlot();
|
||
QCPBars* fossil = new QCPBars(customPlot->xAxis, customPlot->yAxis);
|
||
|
||
customPlot->addPlottable(fossil);
|
||
// set names and colors:
|
||
QPen pen;
|
||
pen.setWidthF(1.2);
|
||
|
||
fossil->setName(gb2312ToGB18030("缺陷数量"));
|
||
pen.setColor(QColor(255, 131, 0));
|
||
fossil->setPen(pen);
|
||
fossil->setBrush(QColor(255, 131, 0, 50));
|
||
|
||
//prepare x axis with country labels:
|
||
QVector<double> ticks;
|
||
QVector<QString> labels;
|
||
QVector<int> labels_num;
|
||
|
||
int num = 0;
|
||
|
||
QVector<double> fossilData;
|
||
QMap<QString, int>::const_iterator iter;
|
||
QMap<int, QMap<int, QString>> NG_Sort;
|
||
|
||
QList<int> NUM_NG;
|
||
QList<QString> NAME_NG;
|
||
|
||
int rank = 0;
|
||
for (iter = Cal_NG_Num.SN_NG_Num.begin(); iter != Cal_NG_Num.SN_NG_Num.end(); ++iter)
|
||
{
|
||
NAME_NG << iter.key();
|
||
NUM_NG << iter.value();
|
||
//NG_Sort[rank++][iter.value()] = iter.key();
|
||
}
|
||
for (int max = 0; max < NUM_NG.size() - 1; max++)
|
||
{
|
||
for (int min = max + 1; min < NUM_NG.size(); min++)
|
||
{
|
||
if (NUM_NG[max] < NUM_NG[min])
|
||
{
|
||
Data_Exchange(NUM_NG[max], NUM_NG[min]);
|
||
Data_Exchange(NAME_NG[max], NAME_NG[min]);
|
||
}
|
||
}
|
||
}
|
||
for (int k = 0; k < NUM_NG.size(); k++)
|
||
{
|
||
NG_Sort[rank++][NUM_NG[k]] = NAME_NG[k];
|
||
}
|
||
QMap<int, QMap<int, QString>>::iterator iter_1;
|
||
double NG_present = 0;
|
||
|
||
int cal_num = 0;
|
||
for (iter_1 = NG_Sort.begin(); iter_1 != NG_Sort.end(); ++iter_1)
|
||
{
|
||
QMap<int, QString>::iterator iter_2;
|
||
for (iter_2 = iter_1.value().begin(); iter_2 != iter_1.value().end(); iter_2++)
|
||
{
|
||
//qDebug() << iter_1.key() << " NG_Name : " << iter_2.value() << " NG_Num : " << iter_2.key() << endl;
|
||
NG_present += (double)iter_2.key() / this->NG_SN;
|
||
ticks << ++num;
|
||
labels << iter_2.value();
|
||
|
||
QString val = QString::number(((double)iter_2.key() / this->NG_SN) * 100, 'g', 3);
|
||
fossilData << val.toFloat()/100;
|
||
|
||
if (cal_num == 0)
|
||
this->name_first_null = iter_2.value();
|
||
if (cal_num == 1)
|
||
this->name_second_null = iter_2.value();
|
||
if (cal_num == 2)
|
||
this->name_third_null = iter_2.value();
|
||
cal_num++;
|
||
|
||
QCPItemText* iTemQ_add = new QCPItemText(customPlot);
|
||
iTemQ_add->setColor(Qt::black);
|
||
iTemQ_add->setPositionAlignment(Qt::AlignTop);
|
||
iTemQ_add->position->setCoords((double)ticks[num - 1], (double)fossilData[num - 1]);
|
||
iTemQ_add->setText(QString::number(iter_2.key()) + " : " + QString::number(((double)iter_2.key() / this->All_SN) * 100, 'g', 3) + "%");
|
||
iTemQ_add->setTextAlignment(Qt::AlignTop);
|
||
iTemQ_add->setFont(QFont(font().family(), 10));
|
||
iTemQ_add->setPadding(QMargins(8, 0, 0, 0));
|
||
}
|
||
}
|
||
|
||
//for (iter = Cal_NG_Num.SN_NG_Num.cbegin(); iter != Cal_NG_Num.SN_NG_Num.cend(); ++iter)
|
||
//{
|
||
// NG_Sort[iter.value()] = iter.key();
|
||
//}
|
||
//QMap<int, QString>::const_iterator iter_1 = NG_Sort.cbegin();
|
||
//for (iter_1 = NG_Sort.cbegin(); iter_1 != NG_Sort.cend(); ++iter_1)
|
||
//{
|
||
// qDebug() << "NG_Num : " << iter_1.key();
|
||
// qDebug() << "NG_Name : " << iter_1.value() << endl;
|
||
// ticks << ++num;
|
||
// labels << iter_1.value();
|
||
// fossilData << ((double)iter_1.key() / all) * iter_1.key();
|
||
// //labels_num << iter.value();
|
||
//}
|
||
|
||
//double i = 0;
|
||
//int cal_num = 0;
|
||
//for (iter_1 = --NG_Sort.end(); iter_1 != NG_Sort.begin(); iter_1--)
|
||
//{
|
||
// qDebug() << "NG_Num : " << iter_1.key();
|
||
// qDebug() << "NG_Name : " << iter_1.value() << endl;
|
||
// i += (double)iter_1.key() / all;
|
||
// ticks << ++num;
|
||
// labels << iter_1.value();
|
||
// //fossilData << ((double)iter_1.key() / all) * iter_1.key();
|
||
// fossilData << (double)iter_1.key();
|
||
// //labels_num << iter.value();
|
||
// if (cal_num == 0)
|
||
// this->name_first_null = iter_1.value();
|
||
// if (cal_num == 1)
|
||
// this->name_second_null = iter_1.value();
|
||
// if (cal_num == 2)
|
||
// this->name_third_null = iter_1.value();
|
||
|
||
// cal_num++;
|
||
|
||
// QCPItemText* iTemQ_add = new QCPItemText(customPlot);
|
||
// iTemQ_add->setColor(Qt::black);
|
||
// iTemQ_add->setPositionAlignment(Qt::AlignTop);
|
||
// iTemQ_add->position->setCoords((double)ticks[num - 1], (double)fossilData[num - 1]);
|
||
// iTemQ_add->setText(QString::number(iter_1.key()) + " : " + QString::number(((double)iter_1.key() / all) * 100, 'g', 3) + "%");
|
||
// iTemQ_add->setTextAlignment(Qt::AlignTop);
|
||
// iTemQ_add->setFont(QFont(font().family(), 10));
|
||
// iTemQ_add->setPadding(QMargins(8, 0, 0, 0));
|
||
//}
|
||
//qDebug() << "% : " << i;
|
||
fossil->setData(ticks, fossilData);
|
||
|
||
//customPlot->graph(0)->setData(x, y);
|
||
customPlot->xAxis->setAutoTicks(false);
|
||
customPlot->xAxis->setAutoTickLabels(false);
|
||
customPlot->xAxis->setTickVector(ticks);
|
||
|
||
customPlot->xAxis->setTickVectorLabels(labels);
|
||
|
||
customPlot->xAxis->setTickLabelRotation(60);
|
||
customPlot->xAxis->setSubTickCount(0);
|
||
customPlot->xAxis->setTickLength(0, 4);
|
||
customPlot->xAxis->setGrid(false);
|
||
customPlot->xAxis->setRange(0, 8);
|
||
|
||
// prepare y axis:
|
||
customPlot->yAxis->setRange(0, 12.1);
|
||
customPlot->yAxis->setPadding(5); // a bit more space to the left border
|
||
customPlot->yAxis->setLabel(gb2312ToGB18030("缺陷项与占比关系"));
|
||
customPlot->yAxis->setSubGrid(true);
|
||
QPen gridPen;
|
||
gridPen.setStyle(Qt::SolidLine);
|
||
gridPen.setColor(QColor(0, 0, 0, 25));
|
||
customPlot->yAxis->setGridPen(gridPen);
|
||
gridPen.setStyle(Qt::DotLine);
|
||
customPlot->yAxis->setSubGridPen(gridPen);
|
||
|
||
// Add data:
|
||
|
||
// setup legend:
|
||
customPlot->legend->setVisible(true);
|
||
customPlot->legend->setPositionStyle(QCPLegend::psTop);
|
||
customPlot->legend->setBrush(QColor(255, 255, 255, 200));
|
||
QPen legendPen;
|
||
legendPen.setColor(QColor(130, 130, 130, 200));
|
||
customPlot->legend->setBorderPen(legendPen);
|
||
QFont legendFont = mainWidget->font();
|
||
legendFont.setPointSize(10);
|
||
customPlot->legend->setFont(legendFont);
|
||
|
||
customPlot->setRangeDrag(Qt::Horizontal | Qt::Vertical);
|
||
customPlot->setRangeZoom(Qt::Horizontal | Qt::Vertical);
|
||
|
||
QGridLayout* pLayout = new QGridLayout();
|
||
pLayout->addWidget(button);
|
||
pLayout->addWidget(customPlot);
|
||
mainWidget->setWindowTitle(gb2312ToGB18030("缺陷排序图"));
|
||
mainWidget->setLayout(pLayout);
|
||
mainWidget->show();
|
||
mainWidget->resize(800, 600);
|
||
mainWidget->move(100, 100);
|
||
|
||
QObject::connect(button, &QPushButton::clicked, [=]() {
|
||
QPixmap pixmap = QPixmap::grabWidget(customPlot);
|
||
QString tmp = Month_Data_csv + Str_Time + "_All.jpg";
|
||
pixmap.save(tmp, "JPG");
|
||
});
|
||
//this->MainWidgetLayout->addWidget(mainWidget,1,0,1,1);
|
||
|
||
// //创建菜单项
|
||
//m_pContextMenu = new QMenu(this);
|
||
//m_pActionCopy = new QAction(this);
|
||
//m_pActionCopy->setText(QString::fromUtf8("截取界面"));
|
||
//m_pContextMenu->addAction(m_pActionCopy);
|
||
//connect(m_pContextMenu, &QMenu::triggered, [this](QAction* act) {
|
||
// if (act == m_pActionCopy)
|
||
// {
|
||
// qDebug() << "!!!";
|
||
// }
|
||
// });
|
||
}
|
||
|
||
void chart::show_NG_Top_Three(int& all, QString Str_Time)
|
||
{
|
||
QList<QCPBars*> list_first;
|
||
QList<QCPBars*> list_second;
|
||
QList<QCPBars*> list_third;
|
||
|
||
QList<QString> name_first;
|
||
QList<QString> name_second;
|
||
QList<QString> name_third;
|
||
|
||
int hour_all = 0;
|
||
QHBoxLayout* mainWidgetLayout = new QHBoxLayout();
|
||
QWidget* mainWidget = new QWidget;
|
||
QPushButton* button = new QPushButton;
|
||
button->resize(100, 50);
|
||
button->setText(gb2312ToGB18030("截取界面"));
|
||
mainWidget->setMouseTracking(true);
|
||
mainWidget->setMouseTracking(true);
|
||
|
||
//mainWidget->setMinimumWidth(900);
|
||
//mainWidget->setMinimumHeight(900);
|
||
|
||
mainWidgetLayout->addWidget(mainWidget);
|
||
mainWidgetLayout->setMargin(0);
|
||
|
||
QCustomPlot* customPlot = new QCustomPlot();
|
||
|
||
QVector<double> ticks;
|
||
QVector<QString> labels;
|
||
|
||
int front_time = 0;
|
||
int the_time = 0;
|
||
|
||
int index_stop = 0;
|
||
int index_start = 0;
|
||
|
||
QStringList NG_cls;
|
||
QString NG_find;
|
||
QString NG_rang;
|
||
QString NG_rang_s;
|
||
QMap<QString, int> sn_num;
|
||
//QVector<double> rank_data_num;
|
||
|
||
QMap<QString, QMap<QString, int>> rank_sn;
|
||
QMap<QString, QMap<QString, QVector<double>>> rank_data_1;//时间 缺陷 数量
|
||
//QMap<QString, QVector<double>> rank_data;
|
||
QVector<double> fossilData, nuclearData, regenData;
|
||
|
||
QMap<QString, QVector<QString>>::iterator iter;
|
||
|
||
//qDebug() << "max_time : " << this->max_time;
|
||
|
||
for (int i = 0; i < 24; i++)
|
||
{
|
||
QString time_in = "";
|
||
QMap<QString, int>::iterator iter_ng;
|
||
for (iter_ng = Cal_NG_Hour.SN_NG_Num.begin(); iter_ng != Cal_NG_Hour.SN_NG_Num.end(); iter_ng++)
|
||
{
|
||
QVector<double> rank_data_num;
|
||
for (int j = 0; j < 24; j++)
|
||
{
|
||
rank_data_num << 0;
|
||
}
|
||
if (i < 10)
|
||
time_in = "0" + QString::number(i);
|
||
else
|
||
time_in = QString::number(i);
|
||
|
||
//qDebug() << "add : " << iter_ng.key() << endl;
|
||
rank_data_1[time_in][iter_ng.key()] = rank_data_num;
|
||
}
|
||
//qDebug() << "time_hour : " << i;
|
||
}
|
||
|
||
//QMap<QString, QMap<QString, QVector<double>>>::iterator iter_test;
|
||
//for (iter_test = rank_data_1.begin(); iter_test != rank_data_1.end(); iter_test++)
|
||
//{
|
||
// qDebug() << endl << "iter_test.key() : " << iter_test.key();
|
||
// QMap<QString, QVector<double>>::iterator iter_two;
|
||
// for (iter_two = rank_data_1[iter_test.key()].begin(); iter_two != rank_data_1[iter_test.key()].end(); iter_two++)
|
||
// {
|
||
// qDebug() << "iter_two.key() : " << iter_two.key();
|
||
// qDebug() << "iter_two.value() : " << iter_two.value();
|
||
// }
|
||
//}
|
||
|
||
QString cop_str_first = "";
|
||
QString cop_str_second = "";
|
||
QString cop_str_third = "";
|
||
QString cop_str_fourth = "";
|
||
for (iter = Cal_NG_Hour.SN_NG_Hour.begin(); iter != Cal_NG_Hour.SN_NG_Hour.end(); iter++)
|
||
{
|
||
hour_all = 0;
|
||
qDebug() << "Time : " << iter.key() << "--------------------------------------------------------------------------------------------------------";
|
||
|
||
|
||
int cop_num_first = 0;
|
||
int cop_num_second = 0;
|
||
int cop_num_third = 0;
|
||
int cop_num_fourth = 0;
|
||
|
||
//qDebug() << "iter.value() : " << iter.value() << "\0";
|
||
//qDebug() << "iter.key() : " << iter.key() << "\0";
|
||
ticks << iter.key().toInt();
|
||
the_time = iter.key().toInt();
|
||
//labels << QString(iter.key()) + "H";
|
||
QVector<QString>::iterator iter_1;
|
||
for (iter_1 = Cal_NG_Hour.SN_NG_Hour[iter.key()].begin(); iter_1 != Cal_NG_Hour.SN_NG_Hour[iter.key()].end(); iter_1++)
|
||
{
|
||
NG_find = *iter_1;
|
||
//qDebug() << "NG_find : " << NG_find << "\0";
|
||
if (NG_find.isEmpty())continue;
|
||
|
||
|
||
QStringList NG_unique;
|
||
QStringList NG_ = NG_find.split("&");
|
||
for (int i = 0; i < NG_.length(); i++) {
|
||
if (!NG_unique.contains(NG_[i])) {
|
||
NG_unique.append(NG_[i]);
|
||
}
|
||
}
|
||
|
||
//while (1)
|
||
for (int t = 1; t < NG_unique.size(); t++)
|
||
{
|
||
//index_start = NG_unique[t].indexOf("-");
|
||
//if (-1 == index_start)break;
|
||
//index_stop = NG_unique[t].indexOf("_");
|
||
//if (-1 == index_stop)
|
||
//{
|
||
// int find_str = NG_unique[t].indexOf("&");
|
||
// if (-1 == find_str)break;
|
||
// NG_unique[t].remove(0, find_str + 1);
|
||
//}
|
||
////qDebug() << "item[4] : " << item[1] <<"__ : __ " << item[4];
|
||
|
||
//QString NG_rang = NG_unique[t].mid(index_start + 1, index_stop - index_start - 1);
|
||
|
||
//while (1) {
|
||
//index_start = NG_find.indexOf("-");
|
||
//if (-1 == index_start)break;
|
||
//index_stop = NG_find.indexOf("_");
|
||
//if (-1 == index_stop)
|
||
//{
|
||
// int find_str = NG_find.indexOf("&");
|
||
// if (-1 == find_str)break;
|
||
// NG_find.remove(0, find_str + 1);
|
||
//}
|
||
|
||
//NG_rang = NG_find.mid(index_start + 1, index_stop - index_start - 1);
|
||
//NG_rang_s = NG_rang;
|
||
//NG_find.remove(0, index_stop + 1);
|
||
|
||
index_start = NG_unique[t].indexOf("-");
|
||
if (-1 == index_start)break;
|
||
index_stop = NG_unique[t].indexOf("_");
|
||
if (-1 == index_stop)
|
||
{
|
||
int find_str = NG_unique[t].indexOf("&");
|
||
if (-1 == find_str)break;
|
||
NG_unique[t].remove(0, find_str + 1);
|
||
}
|
||
|
||
NG_rang = NG_unique[t].mid(index_start + 1, index_stop - index_start - 1);
|
||
NG_rang_s = NG_rang;
|
||
NG_unique[t].remove(0, index_stop + 1);
|
||
|
||
|
||
|
||
//qDebug() << "NG_rang : " << NG_rang << endl;
|
||
|
||
int num = sn_num[NG_rang_s];
|
||
sn_num[NG_rang_s] = ++num;
|
||
hour_all++;
|
||
//qDebug() << "num_1" << num << endl;
|
||
//qDebug() << "num_2" << num << endl;
|
||
|
||
//qDebug() << "NG_rang_s : " << NG_rang_s << "----num : " << num;
|
||
//qDebug() << "cop_str_first : " << cop_str_first << "----cop_num_first :" << cop_num_first;
|
||
//qDebug() << "cop_str_second : " << cop_str_second << "----cop_num_second :" << cop_num_second;
|
||
//qDebug() << "cop_str_third : " << cop_str_third << "----cop_num_third :" << cop_num_third << endl;
|
||
|
||
if (cop_str_first.compare(NG_rang_s) == 0) {
|
||
cop_num_first = num;
|
||
}
|
||
else if (cop_str_second.compare(NG_rang_s) == 0) {
|
||
cop_num_second = num;
|
||
}
|
||
else if (cop_str_third.compare(NG_rang_s) == 0) {
|
||
cop_num_third = num;
|
||
}
|
||
else if (num >= cop_num_first) {
|
||
cop_str_third = cop_str_second;
|
||
cop_num_third = cop_num_second;
|
||
cop_str_second = cop_str_first;
|
||
cop_num_second = cop_num_first;
|
||
cop_str_first = NG_rang_s;
|
||
cop_num_first = num;
|
||
}
|
||
else if (num >= cop_num_second && num < cop_num_first) {
|
||
cop_str_third = cop_str_second;
|
||
cop_num_third = cop_num_second;
|
||
cop_str_second = NG_rang_s;
|
||
cop_num_second = num;
|
||
}
|
||
else if (num >= cop_num_third && num < cop_num_second) {
|
||
cop_str_second = NG_rang_s;
|
||
cop_num_second = num;
|
||
}
|
||
|
||
if (cop_num_third > cop_num_first) {
|
||
QString buf_str = cop_str_first;
|
||
cop_str_first = cop_str_third;
|
||
cop_str_third = buf_str;
|
||
int buf_num = cop_num_first;
|
||
cop_num_first = cop_num_third;
|
||
cop_num_third = buf_num;
|
||
}
|
||
if (cop_num_third > cop_num_second)
|
||
{
|
||
QString buf_str = cop_str_second;
|
||
cop_str_second = cop_str_third;
|
||
cop_str_third = buf_str;
|
||
int buf_num = cop_num_second;
|
||
cop_num_second = cop_num_third;
|
||
cop_num_third = buf_num;
|
||
}
|
||
if (cop_num_second > cop_num_first) {
|
||
QString buf_str = cop_str_first;
|
||
cop_str_first = cop_str_second;
|
||
cop_str_second = buf_str;
|
||
int buf_num = cop_num_first;
|
||
cop_num_first = cop_num_second;
|
||
cop_num_second = buf_num;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
labels << QString(iter.key()) + "H";
|
||
|
||
|
||
rank_sn[iter.key()] = sn_num;
|
||
sn_num.clear();
|
||
|
||
if (cop_str_first == "")
|
||
cop_str_first = this->name_first_null;
|
||
if (cop_str_second == "")
|
||
cop_str_second = this->name_second_null;
|
||
if (cop_str_third == "")
|
||
cop_str_third = this->name_third_null;
|
||
if (cop_str_first == "" || cop_str_second == "" || cop_str_third == "")
|
||
return;
|
||
qDebug() << "1." << cop_num_first;
|
||
qDebug() << "1_NG : " << cop_str_first;
|
||
qDebug() << "2." << cop_num_second;
|
||
qDebug() << "2_NG : " << cop_str_second;
|
||
qDebug() << "3." << cop_num_third;
|
||
qDebug() << "3_NG : " << cop_str_third << endl;
|
||
|
||
name_first.push_back(cop_str_first);
|
||
name_second.push_back(cop_str_second);
|
||
name_third.push_back(cop_str_third);
|
||
|
||
QCPBars* regen_1 = new QCPBars(customPlot->xAxis, customPlot->yAxis);
|
||
QCPBars* nuclear_1 = new QCPBars(customPlot->xAxis, customPlot->yAxis);
|
||
QCPBars* fossil_1 = new QCPBars(customPlot->xAxis, customPlot->yAxis);
|
||
|
||
QPen* pen_1 = new QPen;
|
||
QPen* pen_2 = new QPen;
|
||
QPen* pen_3 = new QPen;
|
||
pen_1->setWidthF(1.2);
|
||
//qDebug() << "iter.key()_first : " <<iter.key().toInt();
|
||
//qDebug() << "name_first : " << name_first[iter.key().toInt()];
|
||
if (same_NG(name_first[iter.key().toInt()]) == true)
|
||
{
|
||
customPlot->addPlottable(fossil_1);
|
||
fossil_1->setName(name_first[iter.key().toInt()]);
|
||
pen_1->setColor(Cal_NG_Hour.NG_Color[name_first[iter.key().toInt()]]);
|
||
fossil_1->setPen(*pen_1);
|
||
}
|
||
else
|
||
delete(pen_1);
|
||
if (same_NG(name_second[iter.key().toInt()]) == true)
|
||
{
|
||
customPlot->addPlottable(nuclear_1);
|
||
nuclear_1->setName(name_second[iter.key().toInt()]);
|
||
pen_2->setColor(Cal_NG_Hour.NG_Color[name_second[iter.key().toInt()]]);
|
||
nuclear_1->setPen(*pen_2);
|
||
}
|
||
else
|
||
delete(pen_2);
|
||
if (same_NG(name_third[iter.key().toInt()]) == true)
|
||
{
|
||
customPlot->addPlottable(regen_1);
|
||
regen_1->setName(name_third[iter.key().toInt()]);
|
||
pen_3->setColor(Cal_NG_Hour.NG_Color[name_third[iter.key().toInt()]]);
|
||
regen_1->setPen(*pen_3);
|
||
}
|
||
else
|
||
delete(pen_3);
|
||
|
||
list_first.push_back(fossil_1);
|
||
list_second.push_back(nuclear_1);
|
||
list_third.push_back(regen_1);
|
||
|
||
list_first[iter.key().toInt()]->setBrush(Cal_NG_Hour.NG_Color[name_first[iter.key().toInt()]]);
|
||
list_second[iter.key().toInt()]->setBrush(Cal_NG_Hour.NG_Color[name_second[iter.key().toInt()]]);
|
||
list_third[iter.key().toInt()]->setBrush(Cal_NG_Hour.NG_Color[name_third[iter.key().toInt()]]);
|
||
|
||
if (hour_all == 0)
|
||
{
|
||
rank_data_1[iter.key()][name_first[iter.key().toInt()]].replace(iter.key().toInt(), 0);
|
||
rank_data_1[iter.key()][name_second[iter.key().toInt()]].replace(iter.key().toInt(), 0);
|
||
rank_data_1[iter.key()][name_third[iter.key().toInt()]].replace(iter.key().toInt(), 0);
|
||
}
|
||
else
|
||
{
|
||
rank_data_1[iter.key()][name_first[iter.key().toInt()]].replace(iter.key().toInt(), ((double)cop_num_first / hour_all) * cop_num_first);
|
||
rank_data_1[iter.key()][name_second[iter.key().toInt()]].replace(iter.key().toInt(), ((double)cop_num_second / hour_all) * cop_num_second);
|
||
rank_data_1[iter.key()][name_third[iter.key().toInt()]].replace(iter.key().toInt(), ((double)cop_num_third / hour_all) * cop_num_third);
|
||
//rank_data_1[iter.key()][name_first[iter.key().toInt()]].replace(iter.key().toInt(), (double)cop_num_first);
|
||
//rank_data_1[iter.key()][name_second[iter.key().toInt()]].replace(iter.key().toInt(), (double)cop_num_second);
|
||
//rank_data_1[iter.key()][name_third[iter.key().toInt()]].replace(iter.key().toInt(), (double) cop_num_third);
|
||
}
|
||
|
||
list_second[iter.key().toInt()]->moveAbove(list_first[iter.key().toInt()]);
|
||
list_third[iter.key().toInt()]->moveAbove(list_second[iter.key().toInt()]);
|
||
|
||
//qDebug() << "iter.key().toInt() : " << iter.key().toInt() << endl;
|
||
//qDebug() << "ticks[iter.key().toInt()] :" << ticks[iter.key().toInt()] << endl;
|
||
//qDebug() << "fossilData[iter.key().toInt()] : " << fossilData[iter.key().toInt()] << endl;
|
||
|
||
QCPItemText* iTemQ_add1 = new QCPItemText(customPlot);
|
||
iTemQ_add1->setColor(Qt::black);
|
||
iTemQ_add1->setPositionAlignment(Qt::AlignRight);
|
||
iTemQ_add1->position->setCoords(ticks[iter.key().toInt()], ((double)cop_num_first / hour_all) * cop_num_first);
|
||
iTemQ_add1->setText(cop_str_first + " : " + QString::number(cop_num_first) + "(" + QString::number(((double)cop_num_first / hour_all) * 100, 'g', 3) + "%)");
|
||
iTemQ_add1->setTextAlignment(Qt::AlignRight);
|
||
iTemQ_add1->setFont(QFont(font().family(), 10));
|
||
iTemQ_add1->setPadding(QMargins(8, 0, 0, 0));
|
||
|
||
QCPItemText* iTemQ_add2 = new QCPItemText(customPlot);
|
||
iTemQ_add2->setColor(Qt::black);
|
||
iTemQ_add2->setPositionAlignment(Qt::AlignRight);
|
||
iTemQ_add2->position->setCoords(ticks[iter.key().toInt()], ((double)cop_num_second / hour_all) * cop_num_second + ((double)cop_num_first / hour_all) * cop_num_first);
|
||
iTemQ_add2->setText(cop_str_second + " : " + QString::number(cop_num_second) + "(" + QString::number(((double)cop_num_second / hour_all) * 100, 'g', 3) + "%)");
|
||
iTemQ_add2->setTextAlignment(Qt::AlignRight);
|
||
iTemQ_add2->setFont(QFont(font().family(), 10));
|
||
iTemQ_add2->setPadding(QMargins(8, 0, 0, 0));
|
||
|
||
QCPItemText* iTemQ_add3 = new QCPItemText(customPlot);
|
||
iTemQ_add3->setColor(Qt::black);
|
||
iTemQ_add3->setPositionAlignment(Qt::AlignRight);
|
||
iTemQ_add3->position->setCoords(ticks[iter.key().toInt()], ((double)cop_num_third / hour_all) * cop_num_third + ((double)cop_num_second / hour_all) * cop_num_second + ((double)cop_num_first / hour_all) * cop_num_first);
|
||
iTemQ_add3->setText(cop_str_third + " : " + QString::number(cop_num_third) + "(" + QString::number(((double)cop_num_third / hour_all) * 100, 'g', 3) + "%)");
|
||
iTemQ_add3->setTextAlignment(Qt::AlignRight);
|
||
iTemQ_add3->setFont(QFont(font().family(), 10));
|
||
iTemQ_add3->setPadding(QMargins(8, 0, 0, 0));
|
||
|
||
list_first[iter.key().toInt()]->setData(ticks, rank_data_1[iter.key()][name_first[iter.key().toInt()]]);
|
||
list_second[iter.key().toInt()]->setData(ticks, rank_data_1[iter.key()][name_second[iter.key().toInt()]]);
|
||
list_third[iter.key().toInt()]->setData(ticks, rank_data_1[iter.key()][name_third[iter.key().toInt()]]);
|
||
|
||
cop_num_first = 0;
|
||
cop_num_second = 0;
|
||
cop_num_third = 0;
|
||
|
||
front_time = the_time;
|
||
}
|
||
//nuclear->moveAbove(fossil);
|
||
//regen->moveAbove(nuclear);
|
||
|
||
customPlot->xAxis->setAutoTicks(false);
|
||
customPlot->xAxis->setAutoTickLabels(false);
|
||
customPlot->xAxis->setTickVector(ticks);
|
||
customPlot->xAxis->setTickVectorLabels(labels);
|
||
customPlot->xAxis->setTickLabelRotation(60);
|
||
customPlot->xAxis->setSubTickCount(0);
|
||
customPlot->xAxis->setTickLength(0, 4);
|
||
customPlot->xAxis->setGrid(false);
|
||
customPlot->xAxis->setRange(0, 8);
|
||
|
||
// prepare y axis:
|
||
customPlot->yAxis->setRange(0, 12.1);
|
||
customPlot->yAxis->setPadding(5); // a bit more space to the left border
|
||
customPlot->yAxis->setLabel(gb2312ToGB18030("缺陷数量与时间关系"));
|
||
customPlot->yAxis->setSubGrid(true);
|
||
QPen gridPen;
|
||
gridPen.setStyle(Qt::SolidLine);
|
||
gridPen.setColor(QColor(0, 0, 0, 25));
|
||
customPlot->yAxis->setGridPen(gridPen);
|
||
gridPen.setStyle(Qt::DotLine);
|
||
customPlot->yAxis->setSubGridPen(gridPen);
|
||
|
||
// setup legend:
|
||
customPlot->legend->setVisible(true);
|
||
customPlot->legend->setPositionStyle(QCPLegend::psTopRight);
|
||
customPlot->legend->setBrush(QColor(255, 255, 255, 200));
|
||
QPen legendPen;
|
||
legendPen.setColor(QColor(130, 130, 130, 200));
|
||
customPlot->legend->setBorderPen(legendPen);
|
||
QFont legendFont = mainWidget->font();
|
||
legendFont.setPointSize(10);
|
||
customPlot->legend->setFont(legendFont);
|
||
|
||
customPlot->setRangeDrag(Qt::Horizontal | Qt::Vertical);
|
||
customPlot->setRangeZoom(Qt::Horizontal | Qt::Vertical);
|
||
|
||
QGridLayout* pLayout = new QGridLayout();
|
||
pLayout->addWidget(button);
|
||
pLayout->addWidget(customPlot);
|
||
//this->pLayout->addWidget(mainWidget);
|
||
|
||
mainWidget->setWindowTitle(gb2312ToGB18030("小时缺陷排序图"));
|
||
mainWidget->setLayout(pLayout);
|
||
mainWidget->show();
|
||
mainWidget->resize(1200, 900);
|
||
mainWidget->move(900, 100);
|
||
|
||
QObject::connect(button, &QPushButton::clicked, [=]() {
|
||
QPixmap pixmap = QPixmap::grabWidget(customPlot);
|
||
QString tmp = Month_Data_csv + Str_Time + "_EveryHour.jpg";
|
||
pixmap.save(tmp, "JPG");
|
||
});
|
||
|
||
//this->MainWidgetLayout->addWidget(mainWidget,0,1,3,3);
|
||
}
|
||
/*
|
||
void chart::show_NG_Top_Ten(int& all)
|
||
{
|
||
QList<QCPBars*> list_first;
|
||
QList<QCPBars*> list_second;
|
||
QList<QCPBars*> list_third;
|
||
|
||
QList<QString> name_first;
|
||
QList<QString> name_second;
|
||
QList<QString> name_third;
|
||
|
||
int hour_all = 0;
|
||
QHBoxLayout* mainWidgetLayout = new QHBoxLayout();
|
||
QWidget* mainWidget = new QWidget;
|
||
mainWidget->setMouseTracking(true);
|
||
mainWidget->setMouseTracking(true);
|
||
|
||
//mainWidget->setMinimumWidth(900);
|
||
//mainWidget->setMinimumHeight(900);
|
||
|
||
mainWidgetLayout->addWidget(mainWidget);
|
||
mainWidgetLayout->setMargin(0);
|
||
|
||
QCustomPlot* customPlot = new QCustomPlot();
|
||
|
||
QVector<double> ticks;
|
||
QVector<QString> labels;
|
||
|
||
int front_time = 0;
|
||
int the_time = 0;
|
||
|
||
int index_stop = 0;
|
||
int index_start = 0;
|
||
|
||
QStringList NG_cls;
|
||
QString NG_find;
|
||
QString NG_rang;
|
||
QString NG_rang_s;
|
||
QMap<QString, int> sn_num;
|
||
//QVector<double> rank_data_num;
|
||
|
||
QMap<QString, QMap<QString, int>> rank_sn;
|
||
QMap<QString, QMap<QString, QVector<double>>> rank_data_1;//时间 缺陷 数量
|
||
//QMap<QString, QVector<double>> rank_data;
|
||
QVector<double> fossilData, nuclearData, regenData;
|
||
|
||
QMap<QString, QVector<QString>>::iterator iter;
|
||
|
||
//qDebug() << "max_time : " << this->max_time;
|
||
|
||
for (int i = 0; i < 24; i++)
|
||
{
|
||
QString time_in = "";
|
||
QMap<QString, int>::iterator iter_ng;
|
||
for (iter_ng = Cal_NG_Hour.SN_NG_Num.begin(); iter_ng != Cal_NG_Hour.SN_NG_Num.end(); iter_ng++)
|
||
{
|
||
QVector<double> rank_data_num;
|
||
for (int j = 0; j < 24; j++)
|
||
{
|
||
rank_data_num << 0;
|
||
}
|
||
if (i < 10)
|
||
time_in = "0" + QString::number(i);
|
||
else
|
||
time_in = QString::number(i);
|
||
|
||
//qDebug() << "add : " << iter_ng.key() << endl;
|
||
rank_data_1[time_in][iter_ng.key()] = rank_data_num;
|
||
}
|
||
//qDebug() << "time_hour : " << i;
|
||
}
|
||
|
||
//QMap<QString, QMap<QString, QVector<double>>>::iterator iter_test;
|
||
//for (iter_test = rank_data_1.begin(); iter_test != rank_data_1.end(); iter_test++)
|
||
//{
|
||
// qDebug() << endl << "iter_test.key() : " << iter_test.key();
|
||
// QMap<QString, QVector<double>>::iterator iter_two;
|
||
// for (iter_two = rank_data_1[iter_test.key()].begin(); iter_two != rank_data_1[iter_test.key()].end(); iter_two++)
|
||
// {
|
||
// qDebug() << "iter_two.key() : " << iter_two.key();
|
||
// qDebug() << "iter_two.value() : " << iter_two.value();
|
||
// }
|
||
//}
|
||
|
||
QString cop_str_first = "";
|
||
QString cop_str_second = "";
|
||
QString cop_str_third = "";
|
||
QString cop_str_fourth = "";
|
||
for (iter = Cal_NG_Hour.SN_NG_Hour.begin(); iter != Cal_NG_Hour.SN_NG_Hour.end(); iter++)
|
||
{
|
||
hour_all = 0;
|
||
qDebug() << "Time : " << iter.key() << "--------------------------------------------------------------------------------------------------------";
|
||
|
||
|
||
int cop_num_first = 0;
|
||
int cop_num_second = 0;
|
||
int cop_num_third = 0;
|
||
int cop_num_fourth = 0;
|
||
|
||
//qDebug() << "iter.value() : " << iter.value() << "\0";
|
||
//qDebug() << "iter.key() : " << iter.key() << "\0";
|
||
ticks << iter.key().toInt();
|
||
the_time = iter.key().toInt();
|
||
//labels << QString(iter.key()) + "H";
|
||
QVector<QString>::iterator iter_1;
|
||
for (iter_1 = Cal_NG_Hour.SN_NG_Hour[iter.key()].begin(); iter_1 != Cal_NG_Hour.SN_NG_Hour[iter.key()].end(); iter_1++)
|
||
{
|
||
NG_find = *iter_1;
|
||
//qDebug() << "NG_find : " << NG_find << "\0";
|
||
if (NG_find.isEmpty())continue;
|
||
|
||
while (1) {
|
||
index_start = NG_find.indexOf("-");
|
||
if (-1 == index_start)break;
|
||
index_stop = NG_find.indexOf("_");
|
||
if (-1 == index_stop)
|
||
{
|
||
int find_str = NG_find.indexOf("&");
|
||
if (-1 == find_str)break;
|
||
NG_find.remove(0, find_str + 1);
|
||
}
|
||
|
||
NG_rang = NG_find.mid(index_start + 1, index_stop - index_start - 1);
|
||
NG_rang_s = NG_rang;
|
||
NG_find.remove(0, index_stop + 1);
|
||
|
||
//qDebug() << "NG_rang : " << NG_rang << endl;
|
||
|
||
int num = sn_num[NG_rang_s];
|
||
sn_num[NG_rang_s] = ++num;
|
||
hour_all++;
|
||
//qDebug() << "num_1" << num << endl;
|
||
//qDebug() << "num_2" << num << endl;
|
||
|
||
//qDebug() << "NG_rang_s : " << NG_rang_s << "----num : " << num;
|
||
//qDebug() << "cop_str_first : " << cop_str_first << "----cop_num_first :" << cop_num_first;
|
||
//qDebug() << "cop_str_second : " << cop_str_second << "----cop_num_second :" << cop_num_second;
|
||
//qDebug() << "cop_str_third : " << cop_str_third << "----cop_num_third :" << cop_num_third << endl;
|
||
|
||
if (cop_str_first.compare(NG_rang_s) == 0) {
|
||
cop_num_first = num;
|
||
}
|
||
else if (cop_str_second.compare(NG_rang_s) == 0) {
|
||
cop_num_second = num;
|
||
}
|
||
else if (cop_str_third.compare(NG_rang_s) == 0) {
|
||
cop_num_third = num;
|
||
}
|
||
else if (num >= cop_num_first) {
|
||
cop_str_third = cop_str_second;
|
||
cop_num_third = cop_num_second;
|
||
cop_str_second = cop_str_first;
|
||
cop_num_second = cop_num_first;
|
||
cop_str_first = NG_rang_s;
|
||
cop_num_first = num;
|
||
}
|
||
else if (num >= cop_num_second && num < cop_num_first) {
|
||
cop_str_third = cop_str_second;
|
||
cop_num_third = cop_num_second;
|
||
cop_str_second = NG_rang_s;
|
||
cop_num_second = num;
|
||
}
|
||
else if (num >= cop_num_third && num < cop_num_second) {
|
||
cop_str_second = NG_rang_s;
|
||
cop_num_second = num;
|
||
}
|
||
|
||
if (cop_num_third > cop_num_first) {
|
||
QString buf_str = cop_str_first;
|
||
cop_str_first = cop_str_third;
|
||
cop_str_third = buf_str;
|
||
int buf_num = cop_num_first;
|
||
cop_num_first = cop_num_third;
|
||
cop_num_third = buf_num;
|
||
}
|
||
if (cop_num_third > cop_num_second)
|
||
{
|
||
QString buf_str = cop_str_second;
|
||
cop_str_second = cop_str_third;
|
||
cop_str_third = buf_str;
|
||
int buf_num = cop_num_second;
|
||
cop_num_second = cop_num_third;
|
||
cop_num_third = buf_num;
|
||
}
|
||
if (cop_num_second > cop_num_first) {
|
||
QString buf_str = cop_str_first;
|
||
cop_str_first = cop_str_second;
|
||
cop_str_second = buf_str;
|
||
int buf_num = cop_num_first;
|
||
cop_num_first = cop_num_second;
|
||
cop_num_second = buf_num;
|
||
}
|
||
}
|
||
}
|
||
|
||
labels << QString(iter.key()) + "H";
|
||
|
||
|
||
rank_sn[iter.key()] = sn_num;
|
||
sn_num.clear();
|
||
|
||
if (cop_str_first == "")
|
||
cop_str_first = this->name_first_null;
|
||
if (cop_str_second == "")
|
||
cop_str_second = this->name_second_null;
|
||
if (cop_str_third == "")
|
||
cop_str_third = this->name_third_null;
|
||
|
||
qDebug() << "1." << cop_num_first;
|
||
qDebug() << "1_NG : " << cop_str_first;
|
||
qDebug() << "2." << cop_num_second;
|
||
qDebug() << "2_NG : " << cop_str_second;
|
||
qDebug() << "3." << cop_num_third;
|
||
qDebug() << "3_NG : " << cop_str_third << endl;
|
||
|
||
name_first.push_back(cop_str_first);
|
||
name_second.push_back(cop_str_second);
|
||
name_third.push_back(cop_str_third);
|
||
|
||
QCPBars* regen_1 = new QCPBars(customPlot->xAxis, customPlot->yAxis);
|
||
QCPBars* nuclear_1 = new QCPBars(customPlot->xAxis, customPlot->yAxis);
|
||
QCPBars* fossil_1 = new QCPBars(customPlot->xAxis, customPlot->yAxis);
|
||
|
||
QPen* pen_1 = new QPen;
|
||
QPen* pen_2 = new QPen;
|
||
QPen* pen_3 = new QPen;
|
||
pen_1->setWidthF(1.2);
|
||
//qDebug() << "iter.key()_first : " <<iter.key().toInt();
|
||
//qDebug() << "name_first : " << name_first[iter.key().toInt()];
|
||
if (same_NG(name_first[iter.key().toInt()]) == true)
|
||
{
|
||
customPlot->addPlottable(fossil_1);
|
||
fossil_1->setName(name_first[iter.key().toInt()]);
|
||
pen_1->setColor(Cal_NG_Hour.NG_Color[name_first[iter.key().toInt()]]);
|
||
fossil_1->setPen(*pen_1);
|
||
}
|
||
else
|
||
delete(pen_1);
|
||
if (same_NG(name_second[iter.key().toInt()]) == true)
|
||
{
|
||
customPlot->addPlottable(nuclear_1);
|
||
nuclear_1->setName(name_second[iter.key().toInt()]);
|
||
pen_2->setColor(Cal_NG_Hour.NG_Color[name_second[iter.key().toInt()]]);
|
||
nuclear_1->setPen(*pen_2);
|
||
}
|
||
else
|
||
delete(pen_2);
|
||
if (same_NG(name_third[iter.key().toInt()]) == true)
|
||
{
|
||
customPlot->addPlottable(regen_1);
|
||
regen_1->setName(name_third[iter.key().toInt()]);
|
||
pen_3->setColor(Cal_NG_Hour.NG_Color[name_third[iter.key().toInt()]]);
|
||
regen_1->setPen(*pen_3);
|
||
}
|
||
else
|
||
delete(pen_3);
|
||
|
||
list_first.push_back(fossil_1);
|
||
list_second.push_back(nuclear_1);
|
||
list_third.push_back(regen_1);
|
||
|
||
list_first[iter.key().toInt()]->setBrush(Cal_NG_Hour.NG_Color[name_first[iter.key().toInt()]]);
|
||
list_second[iter.key().toInt()]->setBrush(Cal_NG_Hour.NG_Color[name_second[iter.key().toInt()]]);
|
||
list_third[iter.key().toInt()]->setBrush(Cal_NG_Hour.NG_Color[name_third[iter.key().toInt()]]);
|
||
|
||
if (hour_all == 0)
|
||
{
|
||
rank_data_1[iter.key()][name_first[iter.key().toInt()]].replace(iter.key().toInt(), 0);
|
||
rank_data_1[iter.key()][name_second[iter.key().toInt()]].replace(iter.key().toInt(), 0);
|
||
rank_data_1[iter.key()][name_third[iter.key().toInt()]].replace(iter.key().toInt(), 0);
|
||
}
|
||
else
|
||
{
|
||
rank_data_1[iter.key()][name_first[iter.key().toInt()]].replace(iter.key().toInt(), ((double)cop_num_first / hour_all) * cop_num_first);
|
||
rank_data_1[iter.key()][name_second[iter.key().toInt()]].replace(iter.key().toInt(), ((double)cop_num_second / hour_all) * cop_num_second);
|
||
rank_data_1[iter.key()][name_third[iter.key().toInt()]].replace(iter.key().toInt(), ((double)cop_num_third / hour_all) * cop_num_third);
|
||
//rank_data_1[iter.key()][name_first[iter.key().toInt()]].replace(iter.key().toInt(), (double)cop_num_first);
|
||
//rank_data_1[iter.key()][name_second[iter.key().toInt()]].replace(iter.key().toInt(), (double)cop_num_second);
|
||
//rank_data_1[iter.key()][name_third[iter.key().toInt()]].replace(iter.key().toInt(), (double) cop_num_third);
|
||
}
|
||
|
||
list_second[iter.key().toInt()]->moveAbove(list_first[iter.key().toInt()]);
|
||
list_third[iter.key().toInt()]->moveAbove(list_second[iter.key().toInt()]);
|
||
|
||
//qDebug() << "iter.key().toInt() : " << iter.key().toInt() << endl;
|
||
//qDebug() << "ticks[iter.key().toInt()] :" << ticks[iter.key().toInt()] << endl;
|
||
//qDebug() << "fossilData[iter.key().toInt()] : " << fossilData[iter.key().toInt()] << endl;
|
||
|
||
QCPItemText* iTemQ_add1 = new QCPItemText(customPlot);
|
||
iTemQ_add1->setColor(Qt::black);
|
||
iTemQ_add1->setPositionAlignment(Qt::AlignRight);
|
||
iTemQ_add1->position->setCoords(ticks[iter.key().toInt()], ((double)cop_num_first / hour_all) * cop_num_first);
|
||
iTemQ_add1->setText(cop_str_first + " : " + QString::number(cop_num_first) + "(" + QString::number(((double)cop_num_first / hour_all) * 100, 'g', 3) + "%)");
|
||
iTemQ_add1->setTextAlignment(Qt::AlignRight);
|
||
iTemQ_add1->setFont(QFont(font().family(), 10));
|
||
iTemQ_add1->setPadding(QMargins(8, 0, 0, 0));
|
||
|
||
QCPItemText* iTemQ_add2 = new QCPItemText(customPlot);
|
||
iTemQ_add2->setColor(Qt::black);
|
||
iTemQ_add2->setPositionAlignment(Qt::AlignRight);
|
||
iTemQ_add2->position->setCoords(ticks[iter.key().toInt()], ((double)cop_num_second / hour_all) * cop_num_second + ((double)cop_num_first / hour_all) * cop_num_first);
|
||
iTemQ_add2->setText(cop_str_second + " : " + QString::number(cop_num_second) + "(" + QString::number(((double)cop_num_second / hour_all) * 100, 'g', 3) + "%)");
|
||
iTemQ_add2->setTextAlignment(Qt::AlignRight);
|
||
iTemQ_add2->setFont(QFont(font().family(), 10));
|
||
iTemQ_add2->setPadding(QMargins(8, 0, 0, 0));
|
||
|
||
QCPItemText* iTemQ_add3 = new QCPItemText(customPlot);
|
||
iTemQ_add3->setColor(Qt::black);
|
||
iTemQ_add3->setPositionAlignment(Qt::AlignRight);
|
||
iTemQ_add3->position->setCoords(ticks[iter.key().toInt()], ((double)cop_num_third / hour_all) * cop_num_third + ((double)cop_num_second / hour_all) * cop_num_second + ((double)cop_num_first / hour_all) * cop_num_first);
|
||
iTemQ_add3->setText(cop_str_third + " : " + QString::number(cop_num_third) + "(" + QString::number(((double)cop_num_third / hour_all) * 100, 'g', 3) + "%)");
|
||
iTemQ_add3->setTextAlignment(Qt::AlignRight);
|
||
iTemQ_add3->setFont(QFont(font().family(), 10));
|
||
iTemQ_add3->setPadding(QMargins(8, 0, 0, 0));
|
||
|
||
list_first[iter.key().toInt()]->setData(ticks, rank_data_1[iter.key()][name_first[iter.key().toInt()]]);
|
||
list_second[iter.key().toInt()]->setData(ticks, rank_data_1[iter.key()][name_second[iter.key().toInt()]]);
|
||
list_third[iter.key().toInt()]->setData(ticks, rank_data_1[iter.key()][name_third[iter.key().toInt()]]);
|
||
|
||
cop_num_first = 0;
|
||
cop_num_second = 0;
|
||
cop_num_third = 0;
|
||
|
||
front_time = the_time;
|
||
}
|
||
//nuclear->moveAbove(fossil);
|
||
//regen->moveAbove(nuclear);
|
||
|
||
customPlot->xAxis->setAutoTicks(false);
|
||
customPlot->xAxis->setAutoTickLabels(false);
|
||
customPlot->xAxis->setTickVector(ticks);
|
||
customPlot->xAxis->setTickVectorLabels(labels);
|
||
customPlot->xAxis->setTickLabelRotation(60);
|
||
customPlot->xAxis->setSubTickCount(0);
|
||
customPlot->xAxis->setTickLength(0, 4);
|
||
customPlot->xAxis->setGrid(false);
|
||
customPlot->xAxis->setRange(0, 8);
|
||
|
||
// prepare y axis:
|
||
customPlot->yAxis->setRange(0, 12.1);
|
||
customPlot->yAxis->setPadding(5); // a bit more space to the left border
|
||
customPlot->yAxis->setLabel(gb2312ToGB18030("缺陷数量与时间关系"));
|
||
customPlot->yAxis->setSubGrid(true);
|
||
QPen gridPen;
|
||
gridPen.setStyle(Qt::SolidLine);
|
||
gridPen.setColor(QColor(0, 0, 0, 25));
|
||
customPlot->yAxis->setGridPen(gridPen);
|
||
gridPen.setStyle(Qt::DotLine);
|
||
customPlot->yAxis->setSubGridPen(gridPen);
|
||
|
||
// setup legend:
|
||
customPlot->legend->setVisible(true);
|
||
customPlot->legend->setPositionStyle(QCPLegend::psTopRight);
|
||
customPlot->legend->setBrush(QColor(255, 255, 255, 200));
|
||
QPen legendPen;
|
||
legendPen.setColor(QColor(130, 130, 130, 200));
|
||
customPlot->legend->setBorderPen(legendPen);
|
||
QFont legendFont = mainWidget->font();
|
||
legendFont.setPointSize(10);
|
||
customPlot->legend->setFont(legendFont);
|
||
|
||
customPlot->setRangeDrag(Qt::Horizontal | Qt::Vertical);
|
||
customPlot->setRangeZoom(Qt::Horizontal | Qt::Vertical);
|
||
|
||
QGridLayout* pLayout = new QGridLayout();
|
||
pLayout->addWidget(customPlot);
|
||
//this->pLayout->addWidget(mainWidget);
|
||
|
||
mainWidget->setWindowTitle(gb2312ToGB18030("小时缺陷排序图"));
|
||
mainWidget->setLayout(pLayout);
|
||
mainWidget->show();
|
||
mainWidget->resize(1200, 900);
|
||
mainWidget->move(900, 100);
|
||
|
||
//this->MainWidgetLayout->addWidget(mainWidget,0,1,3,3);
|
||
}
|
||
*/
|
||
void chart::Creat_label()
|
||
{
|
||
QHBoxLayout* mainWidgetLayout = new QHBoxLayout();
|
||
QWidget* mainWidget = new QWidget;
|
||
mainWidget->setMouseTracking(true);
|
||
mainWidgetLayout->addWidget(mainWidget);
|
||
mainWidgetLayout->setMargin(0);
|
||
//mainWidget->setMaximumWidth(300);
|
||
//mainWidget->setMaximumHeight(300);
|
||
|
||
QCalendarWidget* today = new QCalendarWidget(this);
|
||
today->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
|
||
QGridLayout* pLayout = new QGridLayout();
|
||
pLayout->addWidget(today);
|
||
|
||
mainWidget->setWindowTitle(gb2312ToGB18030("日历"));
|
||
mainWidget->setLayout(pLayout);
|
||
mainWidget->show();
|
||
mainWidget->resize(600, 400);
|
||
//mainWidget->move(100, 100);
|
||
|
||
QObject::connect(today, &QCalendarWidget::clicked, [=]() {
|
||
QDate get_time = today->selectedDate();
|
||
QString Str_Time = get_time.toString("yyyy-MM-dd");
|
||
qDebug() << get_time<<" "<< Str_Time;
|
||
Cal_start(0, Str_Time);
|
||
//Read(get_time);
|
||
});
|
||
|
||
//this->MainWidgetLayout->addWidget(mainWidget, 0, 0, 1, 1);
|
||
}
|
||
|
||
void chart::show_NG_csv()
|
||
{
|
||
//Creat_label();
|
||
|
||
}
|
||
|
||
void chart::cartogram()
|
||
{
|
||
QString compare = "00";
|
||
copyFile(this->file_path, this->file_name, 1);
|
||
QDir dir = QDir::current();
|
||
QFile file(dir.filePath(this->file_path));
|
||
QVector<QString> SN_Hour;
|
||
QVector<QString> SN_Hour_Error;
|
||
int error_vec_flag = 0;
|
||
QString Hour3 ;
|
||
QStringList item, item_hour;
|
||
|
||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||
qDebug() << "open file failed!" << '\n';
|
||
return;
|
||
}
|
||
QTextStream stream(&file);
|
||
|
||
//stream.setCodec("UTF-8");
|
||
int i = 1;
|
||
while (!stream.atEnd())
|
||
{
|
||
QString line = stream.readLine();
|
||
if (i)
|
||
{
|
||
line = stream.readLine();
|
||
i--;
|
||
}
|
||
|
||
line = line.trimmed();
|
||
if (line.isEmpty()) {
|
||
qDebug() << "CSV FILE HAS READ DONE!" << '\n';
|
||
continue;
|
||
} //将读取的每一行用,分割
|
||
|
||
read_All.push_back(line);
|
||
item = line.split(',');
|
||
|
||
//qDebug() << "item[1] : " << item[1] << endl;
|
||
//qDebug() << "item[4]_All : " << item[4] << endl;
|
||
if (item[3] == "OK")
|
||
{
|
||
this->OK_SN++;
|
||
this->All_SN++;
|
||
}
|
||
if (item[3] == "NG")
|
||
{
|
||
this->NG_SN++;
|
||
this->All_SN++;
|
||
}
|
||
if (item[3] == "缺图")
|
||
{
|
||
this->All_SN++;
|
||
|
||
}
|
||
|
||
int index_stop = 0;
|
||
int index_start = 0;
|
||
|
||
item_hour = item[0].split('-');
|
||
Hour3 = item[0].replace("H","");
|
||
//qDebug() << "item[0] : " << item[0] << endl;
|
||
//qDebug() << "item[1] : " << item[1] << endl;
|
||
//qDebug() << "item[4] : " << item[4] << endl;
|
||
|
||
Cal_NG_Num.SN_NG_Rang[item[1]] = item[4];
|
||
SN_Hour.push_back(item[4]);
|
||
|
||
//qDebug() << "Hour3_1 : " << Hour3 << endl;
|
||
if (QString::localeAwareCompare(compare, Hour3) != 0)
|
||
{
|
||
int cal_1 = compare.toInt();
|
||
int cal_2 = Hour3.toInt();
|
||
//qDebug() << "cal_1 : " << cal_1;
|
||
//qDebug() << "cal_2 : " << cal_2;
|
||
//qDebug() << "cal_2 - cal_1 = : " << cal_2 - cal_1<< endl;
|
||
if (cal_2 - cal_1 == 1)
|
||
{
|
||
if (cal_2 > this->max_time)
|
||
this->max_time++;
|
||
Cal_NG_Hour.SN_NG_Hour[compare] = SN_Hour;
|
||
compare = Hour3;
|
||
SN_Hour.clear();
|
||
//qDebug() << "Hour3_2 : " << Hour3;
|
||
//qDebug() << "compare_2 : " << compare << endl;
|
||
}
|
||
if (cal_2 - cal_1 > 1)
|
||
{
|
||
Cal_NG_Hour.SN_NG_Hour[compare] = SN_Hour;
|
||
SN_Hour.clear();
|
||
int buf = cal_1;
|
||
if (cal_2 > this->max_time)
|
||
this->max_time++;
|
||
if (buf == 0)
|
||
{
|
||
QString c_str = QString::number(compare.toInt());
|
||
if (c_str.toInt() < 10)
|
||
compare = "0" + c_str;
|
||
else
|
||
compare = c_str;
|
||
Cal_NG_Hour.SN_NG_Hour[compare] = SN_Hour;
|
||
SN_Hour.clear();
|
||
buf++;
|
||
//qDebug() << "this->max_time : " << this->max_time;
|
||
//qDebug() << "Hour3_3 : " << Hour3;
|
||
//qDebug() << "compare_3 : " << compare << endl;
|
||
}
|
||
for (int cal_add = 0; cal_add < cal_2 - cal_1; cal_add++)
|
||
{
|
||
QString c_str = QString::number(compare.toInt() + 1);
|
||
if (c_str.toInt() < 10)
|
||
compare = "0" + c_str;
|
||
else
|
||
compare = c_str;
|
||
Cal_NG_Hour.SN_NG_Hour[compare] = SN_Hour;
|
||
SN_Hour.clear();
|
||
//qDebug() << "this->max_time : " << this->max_time;
|
||
//qDebug() << "Hour3_4 : " << Hour3;
|
||
//qDebug() << "compare_4 : " << compare << endl;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
SN_Hour_Error = SN_Hour;
|
||
Cal_NG_Hour.SN_NG_Hour[compare] = SN_Hour_Error;
|
||
error_vec_flag = cal_1;
|
||
compare = Hour3;
|
||
}
|
||
|
||
if (error_vec_flag == compare.toInt())
|
||
{
|
||
QVector<QString>::iterator iter;
|
||
for (iter = SN_Hour.begin(); iter != SN_Hour.end(); iter++)
|
||
{
|
||
SN_Hour_Error.push_back(*iter);
|
||
}
|
||
SN_Hour_Error.clear();
|
||
}
|
||
}
|
||
|
||
QStringList NG_unique;
|
||
QStringList NG_str = item[4].split("&");
|
||
|
||
for (int i = 0; i < NG_str.length(); i++) {
|
||
if (!NG_unique.contains(NG_str[i])) {
|
||
NG_unique.append(NG_str[i]);
|
||
}
|
||
}
|
||
|
||
QStringList NG_New = NG_unique;
|
||
for (int i = 0; i < NG_New.length(); i++)
|
||
{
|
||
int Find_str_start = NG_New[i].indexOf("-");
|
||
int Find_str_end = NG_New[i].indexOf("_");
|
||
QString NG_rang = NG_New[i].mid(Find_str_start + 1, Find_str_end - Find_str_start - 1);
|
||
NG_New[i] = NG_rang;
|
||
}
|
||
//qDebug() << NG_unique << endl;
|
||
int del_num = 0;
|
||
for (int m = 1; m < NG_New.length()-1; m++)
|
||
{
|
||
for (int n = m + 1; n < NG_New.length(); n++)
|
||
{
|
||
if (NG_New[m] == NG_New[n])
|
||
{
|
||
NG_unique.removeAt(n - del_num);
|
||
del_num ++ ;
|
||
}
|
||
}
|
||
}
|
||
|
||
//qDebug() << NG_unique<<endl;
|
||
//while (1)
|
||
for(int t = 1;t< NG_unique.size();t++)
|
||
{
|
||
index_start = NG_unique[t].indexOf("-");
|
||
if (-1 == index_start)break;
|
||
index_stop = NG_unique[t].indexOf("_");
|
||
if (-1 == index_stop)
|
||
{
|
||
int find_str = NG_unique[t].indexOf("&");
|
||
if (-1 == find_str)break;
|
||
NG_unique[t].remove(0, find_str + 1);
|
||
}
|
||
//qDebug() << "item[4] : " << item[1] <<"__ : __ " << item[4];
|
||
|
||
QString NG_rang = NG_unique[t].mid(index_start + 1, index_stop - index_start - 1);
|
||
|
||
|
||
//index_start = item[4].indexOf("-");
|
||
//if (-1 == index_start)break;
|
||
//index_stop = item[4].indexOf("_");
|
||
//if (-1 == index_stop)
|
||
//{
|
||
// int find_str = item[4].indexOf("&");
|
||
// if (-1 == find_str)break;
|
||
// item[4].remove(0, find_str + 1);
|
||
//}
|
||
////qDebug() << "item[4] : " << item[1] <<"__ : __ " << item[4];
|
||
|
||
//QString NG_rang = item[4].mid(index_start + 1, index_stop - index_start - 1);
|
||
//item[4].remove(0, index_stop + 1);
|
||
|
||
//qDebug() << "NG_rang : " << NG_rang << endl;
|
||
//qDebug() << "item[0] : " << item[0] << endl;
|
||
//qDebug() << "item[4] : " << item[4] << endl;
|
||
QString NG_rang_s = NG_rang;
|
||
|
||
int num = this->Cal_NG_Num.SN_NG_Num.value(NG_rang_s);
|
||
this->Cal_NG_Num.SN_NG_Num[NG_rang_s] = ++num;
|
||
this->Cal_NG_Hour.SN_NG_Num[NG_rang_s] = num;
|
||
all++;
|
||
|
||
int color_NG = 66;
|
||
int all_color = 255 - color_NG;
|
||
|
||
if (this->Cal_NG_Hour.NG_Color_Flag[NG_rang_s] == 0)
|
||
{
|
||
this->Cal_NG_Hour.NG_Color_Flag[NG_rang_s] = 1;
|
||
if (this->r_flag < all_color)
|
||
{
|
||
this->r_flag += color_NG;
|
||
if (this->r_flag > all_color)
|
||
this->g_flag = 255 - this->g_flag;
|
||
}
|
||
else if (this->g_flag < all_color)
|
||
{
|
||
this->g_flag += color_NG;
|
||
if (this->g_flag > all_color)
|
||
this->b_flag = 255 - this->b_flag;
|
||
}
|
||
else if (this->b_flag < all_color)
|
||
{
|
||
this->b_flag += color_NG;
|
||
if (this->b_flag > all_color)
|
||
this->r_flag = 255 - this->r_flag;
|
||
}
|
||
this->Cal_NG_Hour.NG_Color[NG_rang_s] = QColor(this->r_flag, this->g_flag, this->b_flag);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
Cal_NG_Hour.SN_NG_Hour[compare] = SN_Hour;
|
||
compare = Hour3;
|
||
SN_Hour.clear();
|
||
}
|
||
|
||
void chart::plot(QString Str_Time)
|
||
{
|
||
//Creat_label();
|
||
|
||
clear_all();
|
||
cartogram();
|
||
type_table(Str_Time);
|
||
show_NG_Num(all, Str_Time);
|
||
show_NG_Top_Three(all, Str_Time);
|
||
//show_NG_Top_Ten(all);
|
||
|
||
//this->MainWidget->setLayout(this->MainWidgetLayout);
|
||
//this->MainWidget->show();
|
||
////this->MainWidget->resize(1200, 800);
|
||
//this->MainWidget->move(150, 150);
|
||
//this->MainWidget->setWindowTitle(QString::fromLocal8Bit("缺陷排布统计图"));
|
||
|
||
return;
|
||
}
|
||
|
||
// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
|
||
// 调试程序: F5 或调试 >“开始调试”菜单
|
||
|
||
// 入门使用技巧:
|
||
// 1. 使用解决方案资源管理器窗口添加/管理文件
|
||
// 2. 使用团队资源管理器窗口连接到源代码管理
|
||
// 3. 使用输出窗口查看生成输出和其他消息
|
||
// 4. 使用错误列表窗口查看错误
|
||
// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
|
||
// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
|