키워드 삽입시 기간 자동분할 기능

크롤링 삽입시 키워드 다중선택 기능 

git-svn-id: svn://192.168.0.12/source@238 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
admin
2016-01-14 07:17:35 +00:00
parent 7994b43baa
commit ef669df7ad
2 changed files with 172 additions and 2 deletions

View File

@@ -13,6 +13,45 @@
#include <QStack>
#include <QFileDialog>
#include "stable.h"
QDate lastDayofMonth(QDate date)
{
QDate last = date.addMonths(1);
last.setDate(last.year(), last.month(), 1);
return last.addDays(-1);
}
QDate firstDayofMonth(QDate date)
{
QDate first = date;
first.setDate(first.year(), first.month(), 1);
return first;
}
QDate lastDayofWeek(QDate date)
{
QDate last = date.addDays(6);
if(last.month() > date.month())
last = lastDayofMonth(date);
return last;
}
QDate divideMonth(QDate date, int n)
{
QDate first = firstDayofMonth(date);
QDate last = lastDayofMonth(date);
int nRemain = first.daysTo(last) + 1;
int nDiv = nRemain / n;
int nMod = nRemain % n;
int nBefore = 1, nAfter = 1;
for(int i = 0; i < n; i++)
{
nAfter = nBefore + nDiv + ((nMod-- > 0)? 1 : 0) - 1;
if(nBefore <= date.day() && date.day() <= nAfter)
break;
nBefore = nAfter + 1;
}
return QDate(date.year(), date.month(), nAfter);
}
Widget::Widget(QWidget *parent)
: QWidget(parent)
@@ -43,6 +82,8 @@ Widget::Widget(QWidget *parent)
"WHEN 8 THEN 'Kakao Story User' "
"WHEN 9 THEN 'Instagram Tag' "
"WHEN 10 THEN 'Instagram User' "
"WHEN 11 THEN 'Facebook Tag' "
"WHEN 12 THEN 'Facebook User' "
"ELSE 'UnKnown'"
"END AS platform FROM keyword where state is null");
m_pmodelGroup->setQuery("SELECT * FROM datagroup");
@@ -97,10 +138,16 @@ QGroupBox *Widget::setKeywordWidgets()
m_pcbPlatform = new QComboBox;
m_pcbPlatform->addItems(QStringList() << "Naver Cafe" << "Naver Blog" << "Daum Cafe" << "Naver News" << "Naver Cafe List" << "Daum Cafe List"
<< "Kakao Story Channel" << "Kakao Story Tag" << "Kakao Story User" << "Instagram Tag" << "Instagram User");
<< "Kakao Story Channel" << "Kakao Story Tag" << "Kakao Story User" << "Instagram Tag" << "Instagram User"
<< "Facebook Tag" << "Facebook User");
m_pleKeyword = new QLineEdit;
m_pleAuthorship = new QLineEdit;
m_pcbSplit = new QComboBox;
m_pcbSplit->addItems(QStringList() << "None" << "Monthly" << "Daily");
m_pleSplit = new QLineEdit;
m_pleSplit->setText("1");
}
{
QHBoxLayout *hlayout = new QHBoxLayout();
@@ -113,6 +160,9 @@ QGroupBox *Widget::setKeywordWidgets()
hlayout->addWidget(m_pdeStart);
hlayout->addWidget(new QLabel("End:"));
hlayout->addWidget(m_pdeEnd);
hlayout->addWidget(new QLabel("Split:"));
hlayout->addWidget(m_pcbSplit);
hlayout->addWidget(m_pleSplit);
hlayout->addWidget(new QLabel("Authorship:"));
hlayout->addWidget(m_pleAuthorship);
vlayout->addLayout(hlayout);
@@ -323,12 +373,101 @@ void Widget::on_keyword_currentRowChanged(QModelIndex _index)
if (str == QString("Kakao Story User")) nSelect = 8;
if (str == QString("Instagram Tag")) nSelect = 9;
if (str == QString("Instagram User")) nSelect = 10;
if (str == QString("Facebook Tag")) nSelect = 11;
if (str == QString("Facebook User")) nSelect = 12;
m_pcbPlatform->setCurrentIndex(nSelect);
}
}
void Widget::on_keyword_button_insert()
{
bool ok;
int nSplit = m_pleSplit->text().toInt(&ok);
if(!ok || nSplit < 1)
return;
QDate dateStart = m_pdeStart->date();
QDate dateEnd = m_pdeEnd->date();
if(m_pcbRealTime->currentIndex() == 1)
nSplit = 1;
qint64 nDays = dateStart.daysTo(dateEnd) + 1;
qint64 nDiv = nDays / nSplit;
qint64 nMod = nDays % nSplit;
if(m_pcbSplit->currentIndex() == 0)
{
QString strQuery = QString("insert into keyword set "
"start = STR_TO_DATE('%1', '%Y-%m-%d'),"
"end = STR_TO_DATE('%2', '%Y-%m-%d'),"
"searches = '%3',"
"realtime = %4,"
"authorship = '%5',"
"platform = %6")
.arg(m_pdeStart->date().toString("yyyy-MM-dd"))
.arg(m_pdeEnd->date().toString("yyyy-MM-dd"))
.arg(m_pleKeyword->text())
.arg(m_pcbRealTime->currentIndex())
.arg(m_pleAuthorship->text())
.arg(m_pcbPlatform->currentIndex());
m_pmodelKeyword->setQuery(QString(strQuery.toUtf8()));
}
else if(m_pcbSplit->currentIndex() == 1)
{
while(true)
{
QDate end = divideMonth(dateStart, nSplit);
if(dateStart > dateEnd)
break;
if(end > dateEnd)
end = dateEnd;
QString strQuery = QString("insert into keyword set "
"start = STR_TO_DATE('%1', '%Y-%m-%d'),"
"end = STR_TO_DATE('%2', '%Y-%m-%d'),"
"searches = '%3',"
"realtime = %4,"
"authorship = '%5',"
"platform = %6")
.arg(dateStart.toString("yyyy-MM-dd"))
.arg(end.toString("yyyy-MM-dd"))
.arg(m_pleKeyword->text())
.arg(m_pcbRealTime->currentIndex())
.arg(m_pleAuthorship->text())
.arg(m_pcbPlatform->currentIndex());
m_pmodelKeyword->setQuery(QString(strQuery.toUtf8()));
dateStart = end.addDays(1);
}
}
else
{
for(int i = 0; i < nSplit; i++)
{
int nAddDay = nDiv + ((nMod > 0)? 1:0) - 1;
qDebug() << nAddDay;
QString strQuery = QString("insert into keyword set "
"start = STR_TO_DATE('%1', '%Y-%m-%d'),"
"end = STR_TO_DATE('%2', '%Y-%m-%d'),"
"searches = '%3',"
"realtime = %4,"
"authorship = '%5',"
"platform = %6")
.arg(dateStart.toString("yyyy-MM-dd"))
.arg(dateStart.addDays(nAddDay).toString("yyyy-MM-dd"))
.arg(m_pleKeyword->text())
.arg(m_pcbRealTime->currentIndex())
.arg(m_pleAuthorship->text())
.arg(m_pcbPlatform->currentIndex());
m_pmodelKeyword->setQuery(QString(strQuery.toUtf8()));
nMod--;
dateStart = dateStart.addDays(nAddDay + 1);
}
}
/*
QString strQuery = QString("insert into keyword set "
"start = STR_TO_DATE('%1', '%Y-%m-%d'),"
"end = STR_TO_DATE('%2', '%Y-%m-%d'),"
@@ -344,6 +483,7 @@ void Widget::on_keyword_button_insert()
.arg(m_pcbPlatform->currentIndex());
m_pmodelKeyword->setQuery(QString(strQuery.toUtf8()));
*/
m_pmodelKeyword->setQuery("SELECT id,realtime,searches,start,end,authorship,CASE platform "
"WHEN 0 THEN 'Naver Cafe' "
"WHEN 1 THEN 'Naver Blog' "
@@ -356,6 +496,8 @@ void Widget::on_keyword_button_insert()
"WHEN 8 THEN 'Kakao Story User' "
"WHEN 9 THEN 'Instagram Tag' "
"WHEN 10 THEN 'Instagram User' "
"WHEN 11 THEN 'Facebook Tag' "
"WHEN 12 THEN 'Facebook User' "
"ELSE 'UnKnown'"
"END AS platform FROM keyword where state is null");
}
@@ -384,6 +526,8 @@ void Widget::on_keyword_button_delete()
"WHEN 8 THEN 'Kakao Story User' "
"WHEN 9 THEN 'Instagram Tag' "
"WHEN 10 THEN 'Instagram User' "
"WHEN 11 THEN 'Facebook Tag' "
"WHEN 12 THEN 'Facebook User' "
"ELSE 'UnKnown'"
"END AS platform FROM keyword where state is null");
}
@@ -422,6 +566,8 @@ void Widget::on_keyword_button_modify()
"WHEN 8 THEN 'Kakao Story User' "
"WHEN 9 THEN 'Instagram Tag' "
"WHEN 10 THEN 'Instagram User' "
"WHEN 11 THEN 'Facebook Tag' "
"WHEN 12 THEN 'Facebook User' "
"ELSE 'UnKnown'"
"END AS platform FROM keyword where state is null");
}
@@ -711,9 +857,29 @@ void Widget::on_crawling_button_insert()
if (strGroupId.isEmpty()) return;
QString strKeywordId;
/*
foreach (QModelIndex index,m_ptableKeyword->selectionModel()->selectedIndexes())
{
strKeywordId = m_pmodelKeyword->record(index.row()).value("id").toString();
qDebug() << strKeywordId;
}
*/
foreach (QModelIndex index, m_ptableKeyword->selectionModel()->selectedRows())
{
strKeywordId = m_pmodelKeyword->record(index.row()).value("id").toString();
if (strKeywordId.isEmpty()) return;
QString strQuery = "insert into crawling set ";
strQuery += "Keyword_id = '" + strKeywordId + "',";
strQuery += "DataGroup_id = '" + strGroupId + "',";
strQuery += "state = 0";
m_pmodelCrawling->setQuery(strQuery.toUtf8());
}
/*
if (strKeywordId.isEmpty()) return;
QString strQuery = "insert into crawling set ";
@@ -722,6 +888,7 @@ void Widget::on_crawling_button_insert()
strQuery += "state = 0";
m_pmodelCrawling->setQuery(strQuery.toUtf8());
*/
UpdateCrawling();
}
@@ -886,6 +1053,8 @@ void Widget::UpdateCrawling()
"WHEN 8 THEN 'Kakao Story User' "
"WHEN 9 THEN 'Instagram Tag' "
"WHEN 10 THEN 'Instagram User' "
"WHEN 11 THEN 'Facebook Tag' "
"WHEN 12 THEN 'Facebook User' "
"ELSE 'UnKnown' END ) AS platform , "
"(CASE _crawling.state WHEN 0 THEN 'Waiting' WHEN 1 THEN 'Running' WHEN 2 THEN 'Terminated' ELSE 'None' END ) AS state "
"FROM crawling _crawling INNER JOIN keyword _keyword ON _crawling.keyword_id = _keyword.id "