소트 와 1변수 카운트 추가
git-svn-id: svn://192.168.0.12/source@194 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
@@ -27,8 +27,6 @@ void SCountDlg::setWidgets()
|
||||
QVBoxLayout *vlayout = new QVBoxLayout;
|
||||
{
|
||||
QHBoxLayout *hlayout = new QHBoxLayout;
|
||||
|
||||
|
||||
m_pCombo = new QComboBox[C_COMBO_MAX];
|
||||
for (int i = 0; i < C_COMBO_MAX ; i++)
|
||||
hlayout->addWidget(&m_pCombo[i]);
|
||||
@@ -58,55 +56,192 @@ void SCountDlg::setWidgets()
|
||||
m_pCombo[i].addItem(strList.at(SColumn::E_NAME));
|
||||
}
|
||||
|
||||
m_strGraph = "<html>"
|
||||
"\r\n<meta charset=\"utf8\">"
|
||||
"\r\n<style>"
|
||||
"\r\nbody {"
|
||||
"\r\n font: 10px sans-serif;"
|
||||
"\r\n}"
|
||||
"\r\n"
|
||||
"\r\n.axis path,"
|
||||
"\r\n.axis line {"
|
||||
"\r\n fill: none;"
|
||||
"\r\n stroke: #000;"
|
||||
"\r\n shape-rendering: crispEdges;"
|
||||
"\r\n}"
|
||||
"\r\n"
|
||||
"\r\n.x.axis path {"
|
||||
"\r\n display: none;"
|
||||
"\r\n}"
|
||||
"\r\n"
|
||||
"\r\n.line {"
|
||||
"\r\n fill: none;"
|
||||
"\r\n stroke: steelblue;"
|
||||
"\r\n stroke-width: 1.5px;"
|
||||
"\r\n}"
|
||||
"\r\n"
|
||||
"\r\n</style>"
|
||||
"\r\n<body>"
|
||||
"\r\n<script src=\"http://d3js.org/d3.v3.min.js\"></script>"
|
||||
"\r\n<script>"
|
||||
"\r\n"
|
||||
"\r\nvar margin = {top: 20, right: 80, bottom: 30, left: 50},"
|
||||
"\r\n width = 960 - margin.left - margin.right,"
|
||||
"\r\n height = 500 - margin.top - margin.bottom;"
|
||||
"\r\n"
|
||||
"\r\nvar parseDate = d3.time.format(\"%Y-%m-%d\").parse;"
|
||||
"\r\n"
|
||||
"\r\nvar x = d3.time.scale()"
|
||||
"\r\n .range([0, width]);"
|
||||
"\r\n"
|
||||
"\r\nvar y = d3.scale.linear()"
|
||||
"\r\n .range([height, 0]);"
|
||||
"\r\n"
|
||||
"\r\nvar color = d3.scale.category10();"
|
||||
"\r\n"
|
||||
"\r\nvar xAxis = d3.svg.axis()"
|
||||
"\r\n .scale(x)"
|
||||
"\r\n .orient(\"bottom\");"
|
||||
"\r\n"
|
||||
"\r\nvar yAxis = d3.svg.axis()"
|
||||
"\r\n .scale(y)"
|
||||
for (int i = 0; i < C_COMBO_MAX ; i++)
|
||||
{
|
||||
m_pCombo[i].addItem("[--------]");
|
||||
m_pCombo[i].setCurrentIndex(GetColumn().data().size());
|
||||
}
|
||||
}
|
||||
|
||||
void SCountDlg::choose_1()
|
||||
{
|
||||
int nCatalog = D_NOT_SELECT;
|
||||
for (int i = 0; i < C_COMBO_MAX ; i++)
|
||||
{
|
||||
if (m_pCombo[i].currentIndex() != GetColumn().data().size())
|
||||
{
|
||||
nCatalog = m_pCombo[i].currentIndex();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (nCatalog == D_NOT_SELECT) return;
|
||||
m_pTable->SetHeaderList(QStringList() << GetColumn().data().at(nCatalog).at(SColumn::E_NAME) << "Count");
|
||||
QTableWidget *pCurrent = (QTableWidget *)GetMainWindow()->m_pDataDlg->GetCurrentWidget();
|
||||
GetMainWindow()->m_progress.setRange(0,pCurrent->rowCount());
|
||||
if (GetColumn().isDateColumn(nCatalog))
|
||||
{
|
||||
QMap <QDate,int> mapCount;
|
||||
QDate dateStart(2055,12,31),dateEnd(1900,1,1);
|
||||
for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ )
|
||||
{
|
||||
//if(pCurrent->item(nCount,nCatalog)->text().trimmed().isEmpty()) continue;
|
||||
QDateTime date;
|
||||
QDate day = date.fromString(pCurrent->item(nCount,nCatalog)->text().trimmed(),"yyyy-MM-dd hh:mm:ss").date();
|
||||
if (day.year() < 1901) continue;
|
||||
if (day < dateStart) dateStart=day;
|
||||
if (day > dateEnd) dateEnd=day;
|
||||
if (mapCount.contains(day))
|
||||
mapCount[day]++;
|
||||
else
|
||||
mapCount.insert(day,1);
|
||||
GetMainWindow()->m_progress.setValue(nCount);
|
||||
GetMainWindow()->m_progress.repaint();
|
||||
}
|
||||
int nCount = 0;
|
||||
m_pTable->setRowCount(dateStart.daysTo(dateEnd));
|
||||
for (QDate now = dateStart; now < dateEnd ; now=now.addDays(1) )
|
||||
{
|
||||
int nCol = 0;
|
||||
QString str = now.toString("yyyy-MM-dd").trimmed();
|
||||
m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(str));
|
||||
if (mapCount.contains(now))
|
||||
m_pTable->setItem(nCount,nCol,new STableNumberItem(QString::number(mapCount[now])));
|
||||
else
|
||||
m_pTable->setItem(nCount,nCol,new STableNumberItem(QString::number(0)));
|
||||
nCount++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QMap <QString,int> mapCount;
|
||||
for (int nCount = 0 ; nCount < pCurrent->rowCount() ; nCount++ )
|
||||
{
|
||||
QString str = pCurrent->item(nCount,nCatalog)->text().trimmed();
|
||||
if(str.isEmpty()) continue;
|
||||
if (mapCount.contains(str))
|
||||
mapCount[str]++;
|
||||
else
|
||||
mapCount.insert(str,1);
|
||||
GetMainWindow()->m_progress.setValue(nCount);
|
||||
GetMainWindow()->m_progress.repaint();
|
||||
}
|
||||
m_pTable->setRowCount(mapCount.size());
|
||||
int nCount = 0;
|
||||
for (QMap<QString,int> ::iterator i = mapCount.begin(); i != mapCount.end(); ++i)
|
||||
{
|
||||
int nCol = 0;
|
||||
m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(i.key()));
|
||||
m_pTable->setItem(nCount,nCol++,new STableNumberItem(QString::number(i.value())));
|
||||
nCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SCountDlg::choose_2()
|
||||
{
|
||||
QTableWidget *pCurrent = (QTableWidget *)GetMainWindow()->m_pDataDlg->GetCurrentWidget();
|
||||
int anCatalog[C_COMBO_MAX];
|
||||
|
||||
for (int i = 0; i < C_COMBO_MAX ; i++)
|
||||
anCatalog[i] = m_pCombo[i].currentIndex();
|
||||
|
||||
QMap <QString,QMap<QString,int> > mapCount;
|
||||
QSet <QString> setList;
|
||||
QDate dateStart(2055,12,31),dateEnd(1900,1,1);
|
||||
GetMainWindow()->m_progress.setRange(0,pCurrent->rowCount());
|
||||
for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ )
|
||||
{
|
||||
QString astr[C_COMBO_MAX];
|
||||
bool bFlag=true;
|
||||
for (int i = 0; i < C_COMBO_MAX ; i++)
|
||||
{
|
||||
if (GetColumn().isDateColumn(anCatalog[i]))
|
||||
{
|
||||
QDateTime date;
|
||||
QDate day = date.fromString(pCurrent->item(nCount,anCatalog[i])->text().trimmed(),"yyyy-MM-dd hh:mm:ss").date();
|
||||
astr[i] = day.toString("yyyy-MM-dd").trimmed();
|
||||
if(astr[i].isEmpty()) continue;
|
||||
if (day.year() == 0) continue;
|
||||
if (day < dateStart) dateStart=day;
|
||||
if (day > dateEnd) dateEnd=day;
|
||||
}
|
||||
else
|
||||
astr[i] = pCurrent->item(nCount,anCatalog[i])->text().trimmed();
|
||||
if (astr[i].isEmpty()) bFlag = false;
|
||||
}
|
||||
if (bFlag == false) continue;
|
||||
if (mapCount.contains(astr[0]) == false)
|
||||
{
|
||||
QMap <QString,int> mapSec;
|
||||
mapCount.insert(astr[0],mapSec);
|
||||
}
|
||||
if (mapCount[astr[0]].contains(astr[1]) == false)
|
||||
mapCount[astr[0]].insert(astr[1],0);
|
||||
if (setList.contains(astr[1]) == false)
|
||||
setList.insert(astr[1]);
|
||||
mapCount[astr[0]][astr[1]]++;
|
||||
GetMainWindow()->m_progress.setValue(nCount);
|
||||
GetMainWindow()->m_progress.repaint();
|
||||
}
|
||||
m_pTable->clear();
|
||||
QStringList strList;
|
||||
strList.push_back(m_pCombo[0].currentText());
|
||||
for (QSet<QString>::iterator i = setList.begin(); i != setList.end(); ++i)
|
||||
strList.push_back(*i);
|
||||
m_pTable->SetHeaderList(strList);
|
||||
int nCount = 0;
|
||||
m_dTotal = 0.0;
|
||||
if (GetColumn().isDateColumn(anCatalog[0]))
|
||||
{
|
||||
//qDebug() << dateStart.daysTo(dateEnd);
|
||||
m_pTable->setRowCount(dateStart.daysTo(dateEnd));
|
||||
for (QDate now = dateStart; now < dateEnd ; now=now.addDays(1) )
|
||||
{
|
||||
int nCol = 0;
|
||||
QString str = now.toString("yyyy-MM-dd").trimmed();
|
||||
m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(str));
|
||||
if (mapCount.contains(str))
|
||||
{
|
||||
for (QSet<QString>::iterator j = setList.begin(); j != setList.end(); ++j)
|
||||
{
|
||||
if (mapCount[str].contains(*j))
|
||||
m_pTable->setItem(nCount,nCol++,new STableNumberItem(QString::number(mapCount[str].value(*j))));
|
||||
else
|
||||
m_pTable->setItem(nCount,nCol++,new STableNumberItem(QString::number(0)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (;nCol < strList.size();nCol++)
|
||||
m_pTable->setItem(nCount,nCol,new STableNumberItem(QString::number(0)));
|
||||
}
|
||||
nCount++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pTable->setRowCount(mapCount.size());
|
||||
for (QMap<QString,QMap<QString,int> >::iterator i = mapCount.begin(); i != mapCount.end(); ++i)
|
||||
{
|
||||
int nCol = 0;
|
||||
m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(i.key()));
|
||||
for (QSet<QString>::iterator j = setList.begin(); j != setList.end(); ++j)
|
||||
{
|
||||
if (i->contains(*j))
|
||||
m_pTable->setItem(nCount,nCol++,new STableNumberItem(QString::number(i->value(*j))));
|
||||
else
|
||||
m_pTable->setItem(nCount,nCol++,new STableNumberItem(QString::number(0)));
|
||||
}
|
||||
nCount++;
|
||||
}
|
||||
}
|
||||
|
||||
m_strGraph = "<html>\r\n<meta charset=\"utf8\">\r\n<style>\r\nbody {\r\n font: 10px sans-serif;\r\n}\r\n\r\n.axis path,\r\n.axis line {\r\n fill: none;"
|
||||
"\r\n stroke: #000;\r\n shape-rendering: crispEdges;\r\n}\r\n\r\n.x.axis path {\r\n display: none;\r\n}\r\n\r\n.line {\r\n fill: none;\r\n stroke: steelblue;"
|
||||
"\r\n stroke-width: 1.5px;\r\n}\r\n\r\n</style>\r\n<body>\r\n<script src=\"http://d3js.org/d3.v3.min.js\"></script>\r\n<script>\r\n"
|
||||
"\r\nvar margin = {top: 20, right: 80, bottom: 30, left: 50},\r\n width = 960 - margin.left - margin.right,\r\n height = 500 - margin.top - margin.bottom;"
|
||||
"\r\n\r\nvar parseDate = d3.time.format(\"%Y-%m-%d\").parse;\r\n\r\nvar x = d3.time.scale()\r\n .range([0, width]);\r\n\r\nvar y = d3.scale.linear()\r\n .range([height, 0]);"
|
||||
"\r\n\r\nvar color = d3.scale.category10();\r\n\r\nvar xAxis = d3.svg.axis()\r\n .scale(x)\r\n .orient(\"bottom\");\r\n\r\nvar yAxis = d3.svg.axis()\r\n .scale(y)"
|
||||
"\r\n .orient(\"left\");"
|
||||
"\r\n"
|
||||
"\r\nvar line = d3.svg.line()"
|
||||
@@ -187,158 +322,19 @@ void SCountDlg::setWidgets()
|
||||
|
||||
void SCountDlg::run()
|
||||
{
|
||||
QTableWidget *pCurrent = (QTableWidget *)GetMainWindow()->m_pDataDlg->GetCurrentWidget();
|
||||
int anCatalog[C_COMBO_MAX];
|
||||
|
||||
for (int i = 0; i < C_COMBO_MAX ; i++)
|
||||
anCatalog[i] = m_pCombo[i].currentIndex();
|
||||
|
||||
QMap <QString,QMap<QString,int> > mapCount;
|
||||
QSet <QString> setList;
|
||||
QDate dateStart(2055,12,31),dateEnd(1900,1,1);
|
||||
GetMainWindow()->m_progress.setRange(0,pCurrent->rowCount());
|
||||
for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ )
|
||||
{
|
||||
QString astr[C_COMBO_MAX];
|
||||
bool bFlag=true;
|
||||
int nNone=0;
|
||||
for (int i = 0; i < C_COMBO_MAX ; i++)
|
||||
{
|
||||
if (GetColumn().isDateColumn(anCatalog[i]))
|
||||
if (m_pCombo[i].currentIndex() == GetColumn().data().size())
|
||||
nNone++;
|
||||
}
|
||||
switch(nNone)
|
||||
{
|
||||
QDateTime date;
|
||||
QDate day = date.fromString(pCurrent->item(nCount,anCatalog[i])->text().trimmed(),"yyyy-MM-dd hh:mm:ss").date();
|
||||
astr[i] = day.toString("yyyy-MM-dd").trimmed();
|
||||
if(astr[i].isEmpty()) continue;
|
||||
if (day.year() == 0) continue;
|
||||
if (day < dateStart) dateStart=day;
|
||||
if (day > dateEnd) dateEnd=day;
|
||||
}
|
||||
else
|
||||
astr[i] = pCurrent->item(nCount,anCatalog[i])->text().trimmed();
|
||||
if (astr[i].isEmpty()) bFlag = false;
|
||||
}
|
||||
if (bFlag == false) continue;
|
||||
if (mapCount.contains(astr[0]) == false)
|
||||
{
|
||||
QMap <QString,int> mapSec;
|
||||
mapCount.insert(astr[0],mapSec);
|
||||
}
|
||||
if (mapCount[astr[0]].contains(astr[1]) == false)
|
||||
mapCount[astr[0]].insert(astr[1],0);
|
||||
if (setList.contains(astr[1]) == false)
|
||||
setList.insert(astr[1]);
|
||||
mapCount[astr[0]][astr[1]]++;
|
||||
GetMainWindow()->m_progress.setValue(nCount);
|
||||
GetMainWindow()->m_progress.repaint();
|
||||
}
|
||||
m_pTable->clear();
|
||||
QStringList strList;
|
||||
strList.push_back(m_pCombo[0].currentText());
|
||||
for (QSet<QString>::iterator i = setList.begin(); i != setList.end(); ++i)
|
||||
strList.push_back(*i);
|
||||
m_pTable->SetHeaderList(strList);
|
||||
int nCount = 0;
|
||||
m_dTotal = 0.0;
|
||||
if (GetColumn().isDateColumn(anCatalog[0]))
|
||||
{
|
||||
qDebug() << dateStart.daysTo(dateEnd);
|
||||
m_pTable->setRowCount(dateStart.daysTo(dateEnd));
|
||||
for (QDate now = dateStart; now < dateEnd ; now=now.addDays(1) )
|
||||
{
|
||||
int nCol = 0;
|
||||
QString str = now.toString("yyyy-MM-dd").trimmed();
|
||||
m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(str));
|
||||
if (mapCount.contains(str))
|
||||
{
|
||||
for (QSet<QString>::iterator j = setList.begin(); j != setList.end(); ++j)
|
||||
{
|
||||
if (mapCount[str].contains(*j))
|
||||
m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(QString::number(mapCount[str].value(*j))));
|
||||
else
|
||||
m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(QString::number(0)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (;nCol < strList.size();nCol++)
|
||||
m_pTable->setItem(nCount,nCol,new QTableWidgetItem(QString::number(0)));
|
||||
}
|
||||
nCount++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pTable->setRowCount(mapCount.size());
|
||||
for (QMap<QString,QMap<QString,int> >::iterator i = mapCount.begin(); i != mapCount.end(); ++i)
|
||||
{
|
||||
int nCol = 0;
|
||||
m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(i.key()));
|
||||
for (QSet<QString>::iterator j = setList.begin(); j != setList.end(); ++j)
|
||||
{
|
||||
if (i->contains(*j))
|
||||
m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(QString::number(i->value(*j))));
|
||||
else
|
||||
m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(QString::number(0)));
|
||||
}
|
||||
nCount++;
|
||||
}
|
||||
case 0:choose_2();break;
|
||||
case 1:choose_1();break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void SCountDlg::run()
|
||||
{
|
||||
QTableWidget *pCurrent = (QTableWidget *)GetMainWindow()->m_pDataDlg->GetCurrentWidget();
|
||||
if (pCurrent == NULL) return;
|
||||
QMap <QString,QMap<QString,int> > mapCount;
|
||||
QSet <QString> setList;
|
||||
GetMainWindow()->m_progress.setRange(0,pCurrent->rowCount());
|
||||
for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ )
|
||||
{
|
||||
QString astr[2];
|
||||
astr[0] = QDateTime::fromString(pCurrent->item(nCount,GetColumn().getDateColumn())->text().trimmed(),"yyyy-MM-dd hh:mm:ss").date().toString("yyyy-MM-dd").trimmed();
|
||||
astr[1] = pCurrent->item(nCount,GetColumn().getColumnIndex("platform_name"))->text().trimmed() + "-";
|
||||
astr[1] += pCurrent->item(nCount,GetColumn().getColumnIndex("platform_form"))->text().trimmed() + "-";
|
||||
astr[1] += pCurrent->item(nCount,GetColumn().getColumnIndex("article_form"))->text().trimmed();
|
||||
if (mapCount.contains(astr[0]) == false)
|
||||
{
|
||||
QMap <QString,int> mapSec;
|
||||
mapCount.insert(astr[0],mapSec);
|
||||
}
|
||||
if (mapCount[astr[0]].contains(astr[1]) == false)
|
||||
mapCount[astr[0]].insert(astr[1],0);
|
||||
if (setList.contains(astr[1]) == false)
|
||||
setList.insert(astr[1]);
|
||||
mapCount[astr[0]][astr[1]]++;
|
||||
GetMainWindow()->m_progress.setValue(nCount);
|
||||
GetMainWindow()->m_progress.repaint();
|
||||
}
|
||||
m_pTable->clear();
|
||||
QStringList strList;
|
||||
strList.push_back("date");
|
||||
//strList.push_back(m_pCombo[0].currentText());
|
||||
for (QSet<QString>::iterator i = setList.begin(); i != setList.end(); ++i)
|
||||
strList.push_back(*i);
|
||||
m_pTable->SetHeaderList(strList);
|
||||
m_pTable->setRowCount(mapCount.size());
|
||||
int nCount = 0;
|
||||
m_dTotal = 0.0;
|
||||
for (QMap<QString,QMap<QString,int> >::iterator i = mapCount.begin(); i != mapCount.end(); ++i)
|
||||
{
|
||||
int nCol = 0;
|
||||
m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(i.key()));
|
||||
for (QSet<QString>::iterator j = setList.begin(); j != setList.end(); ++j)
|
||||
{
|
||||
if (i->contains(*j))
|
||||
m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(QString::number(i->value(*j))));
|
||||
else
|
||||
m_pTable->setItem(nCount,nCol++,new QTableWidgetItem(QString::number(0)));
|
||||
}
|
||||
nCount++;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void SCountDlg::graph()
|
||||
{
|
||||
QFile file(QApplication::applicationDirPath()+"/graph.tsv");
|
||||
|
||||
@@ -22,6 +22,8 @@ private:
|
||||
QString m_strGraph;
|
||||
double m_dTotal;
|
||||
void setWidgets();
|
||||
void choose_1();
|
||||
void choose_2();
|
||||
};
|
||||
|
||||
#endif // SCOUNTDLG_H
|
||||
|
||||
Reference in New Issue
Block a user