1781 lines
76 KiB
C++
1781 lines
76 KiB
C++
#include <QtAlgorithms>
|
|
#include <QSqlQuery>
|
|
#include <QSqlDatabase>
|
|
#include <QVariant>
|
|
#include <QSqlError>
|
|
#include <QDebug>
|
|
#include <QDate>
|
|
#include <QDateTime>
|
|
#include <QJsonArray>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include <QJsonValue>
|
|
#include <QFile>
|
|
#include "sinfluencerinteractorurlmaker.h"
|
|
#include "sinfluencer.h"
|
|
|
|
const double SInfluencer::SInfluencerWeight::m_multipleValue = 100.0/3;
|
|
|
|
void SInfluencer::setInitiaizer(SInitializer &_initializer)
|
|
{
|
|
m_pSInitializer = &_initializer;
|
|
m_SBodyInfluencerMap.setInitiaizer(_initializer);
|
|
m_SReplyInfluencerMap.setInitiaizer(_initializer);
|
|
//m_SStatsInfBloggerBuzzbyday.setInitiaizer(_initializer);
|
|
//m_SStatsInfBloggerRank.setInitiaizer(_initializer);
|
|
m_STInfluencer.setInitiaizer(_initializer);
|
|
m_SStatsJson.setInitiaizer(_initializer);
|
|
}
|
|
|
|
bool SInfluencer::uploadData(int _companyNum)
|
|
{
|
|
m_pSInitializer->insertLog("Start upload influencer");
|
|
|
|
QSqlDatabase dbWeb = m_pSInitializer->getDatabase(SDBManager::E_DATABASE_WEB);
|
|
m_pSInitializer->updateWebDBInfoState(dbWeb, _companyNum, "Influence (Start)");
|
|
if (!m_SBodyInfluencerMap.uploadData(dbWeb, _companyNum))
|
|
{
|
|
m_pSInitializer->insertLog("Fail to upload influencer body map");
|
|
return false;
|
|
}
|
|
if (!m_SReplyInfluencerMap.uploadData(dbWeb, _companyNum))
|
|
{
|
|
m_pSInitializer->insertLog("Fail to upload influencer reply map");
|
|
return false;
|
|
}
|
|
/*
|
|
if (!m_SStatsInfBloggerBuzzbyday.uploadData(dbWeb, _companyNum))
|
|
{
|
|
m_pSInitializer->insertLog("Fail to upload stats_inf_blogger_buzzbyday");
|
|
return false;
|
|
}
|
|
if (!m_SStatsInfBloggerRank.uploadData(dbWeb, _companyNum))
|
|
{
|
|
m_pSInitializer->insertLog("Fail to upload stats_inf_blogger_rank");
|
|
return false;
|
|
}
|
|
*/
|
|
if (!m_STInfluencer.uploadData(dbWeb, _companyNum))
|
|
{
|
|
m_pSInitializer->insertLog("Fail to upload influencer");
|
|
return false;
|
|
}
|
|
if (!m_SStatsJson.uploadData(dbWeb, _companyNum))
|
|
{
|
|
m_pSInitializer->insertLog("Fail to upload stats_json");
|
|
return false;
|
|
}
|
|
|
|
m_pSInitializer->insertLog("End upload influencer");
|
|
m_pSInitializer->updateWebDBInfoState(dbWeb, _companyNum, "Influence (Finish)");
|
|
|
|
return true;
|
|
}
|
|
|
|
bool SInfluencer::changeTable(int _companyNum)
|
|
{
|
|
m_pSInitializer->insertLog("Start table change influencer");
|
|
QSqlDatabase dbWeb = m_pSInitializer->getDatabase(SDBManager::E_DATABASE_WEB);
|
|
if (!m_SBodyInfluencerMap.changeTable(dbWeb, _companyNum))
|
|
{
|
|
m_pSInitializer->insertLog("Fail to change influencer body map");
|
|
return false;
|
|
}
|
|
if (!m_SReplyInfluencerMap.changeTable(dbWeb, _companyNum))
|
|
{
|
|
m_pSInitializer->insertLog("Fail to change influencer reply map");
|
|
return false;
|
|
}
|
|
if (!m_STInfluencer.changeTable(dbWeb, _companyNum))
|
|
{
|
|
m_pSInitializer->insertLog("Fail to change influencer");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool SInfluencer::makeCategory(SDatagroup &_datagroup, int _nCategory, const QList<SInitializer::stFilter> &_listFilter)
|
|
{
|
|
QVector<QStringList> vecData[SInitializer::E_ARTICLE_MAX];
|
|
bool bFiltered[SInitializer::E_ARTICLE_MAX];
|
|
|
|
for (int i = 0; i < SInitializer::E_ARTICLE_MAX; i++)
|
|
bFiltered[i] = false;
|
|
_datagroup.copyData(vecData);
|
|
m_pSInitializer->insertDebugLog(QString("Influencer Category: ") + m_pSInitializer->getCategoryName(_nCategory));
|
|
foreach (SInitializer::stFilter filter, _listFilter)
|
|
{
|
|
switch(filter.m_nType)
|
|
{
|
|
case E_FILTER_TYPE_DATE://Date
|
|
m_SFilterAlgorithm.FilterDate(vecData, bFiltered, filter.m_vData.toString(),
|
|
m_pSInitializer->getColumnIntArray()[SInitializer::E_DATA_article_date]);
|
|
|
|
break;
|
|
case E_FILTER_TYPE_SEARCH:
|
|
m_SFilterAlgorithm.FilterSearch(vecData, bFiltered, filter.m_vData.toString());
|
|
|
|
break;
|
|
case E_FILTER_TYPE_LENGTH:
|
|
m_SFilterAlgorithm.FilterLength(vecData, bFiltered, filter.m_vData.toString());
|
|
break;
|
|
case E_FILTER_TYPE_REPLACE:
|
|
m_SFilterAlgorithm.FilterReplace(vecData, bFiltered, filter.m_vData.toString());
|
|
break;
|
|
case E_FILTER_TYPE_COUNTER:
|
|
m_SFilterAlgorithm.FilterCounter(vecData, bFiltered, filter.m_vData.toString());
|
|
break;
|
|
}
|
|
m_pSInitializer->insertDebugLog("Body: " + QString::number(vecData[SInitializer::E_ARTICLE_BODY].size()) + ", " +
|
|
"Reply: " + QString::number(vecData[SInitializer::E_ARTICLE_REPLY].size()) + ", " +
|
|
SService::convertJsonToStr(filter.m_nType, filter.m_vData.toString()));
|
|
}
|
|
stReal streal;
|
|
m_pSInitializer->insertLog(QString("Category:") + m_pSInitializer->getCategoryName(_nCategory) + ",(" +
|
|
QString::number(vecData[SInitializer::E_ARTICLE_BODY].size()) + '/' + QString::number(vecData[SInitializer::E_ARTICLE_REPLY].size()) + ")" + "(Body/Reply)" );
|
|
m_pSInitializer->insertDebugLog(QString("Category:") + m_pSInitializer->getCategoryName(_nCategory) + ",(" +
|
|
QString::number(vecData[SInitializer::E_ARTICLE_BODY].size()) + '/' + QString::number(vecData[SInitializer::E_ARTICLE_REPLY].size()) + ")" + "(Body/Reply)" );
|
|
m_pSInitializer->insertDebugLog("");
|
|
const int *anColumn = m_pSInitializer->getColumnIntArray();
|
|
if (bFiltered[SInitializer::E_ARTICLE_BODY])
|
|
{
|
|
foreach (const QStringList& strlist, vecData[SInitializer::E_ARTICLE_BODY])
|
|
{
|
|
streal.m_setRealAllUrl.insert(strlist[anColumn[SInitializer::E_DATA_article_url]].trimmed());
|
|
streal.m_setRealBodyUrl.insert(strlist[anColumn[SInitializer::E_DATA_article_url]].trimmed());
|
|
_datagroup.addRealUrl(strlist[anColumn[SInitializer::E_DATA_article_url]].trimmed());
|
|
}
|
|
}
|
|
|
|
if (bFiltered[SInitializer::E_ARTICLE_REPLY])
|
|
{
|
|
foreach (const QStringList& strlist, vecData[SInitializer::E_ARTICLE_REPLY])
|
|
{
|
|
streal.m_setRealAllUrl.insert(strlist[anColumn[SInitializer::E_DATA_article_url]].trimmed());
|
|
streal.m_mapRealReplyUniqueUrl.insertMulti(strlist[anColumn[SInitializer::E_DATA_article_url]].trimmed(),
|
|
strlist[anColumn[SInitializer::E_DATA_article_order]].trimmed().toInt());
|
|
_datagroup.addRealUrl(strlist[anColumn[SInitializer::E_DATA_article_url]].trimmed());
|
|
}
|
|
}
|
|
|
|
m_mapCategory.insert(_nCategory, streal);
|
|
return true;
|
|
}
|
|
|
|
bool SInfluencer::makeOverallCategory(int _categoryNum)
|
|
{
|
|
if (m_mapCategory.size() < 1)
|
|
return true;
|
|
|
|
stReal streal;
|
|
for (QMap<int, stReal>::iterator iterPos = m_mapCategory.begin(); iterPos != m_mapCategory.end(); iterPos++ )
|
|
{
|
|
stReal& val = iterPos.value();
|
|
foreach (const QString& _strurl, val.m_setRealBodyUrl )
|
|
streal.m_setRealBodyUrl.insert(_strurl);
|
|
foreach (const QString& _strurl, val.m_setRealAllUrl )
|
|
streal.m_setRealAllUrl.insert(_strurl);
|
|
|
|
for (QMap<QString, int>::iterator iterPos1 = val.m_mapRealReplyUniqueUrl.begin(); iterPos1 != val.m_mapRealReplyUniqueUrl.end();
|
|
iterPos1++)
|
|
{
|
|
if (streal.m_mapRealReplyUniqueUrl.contains(iterPos1.key()) && streal.m_mapRealReplyUniqueUrl.values(iterPos1.key()).contains(iterPos1.value()))
|
|
continue;
|
|
else
|
|
streal.m_mapRealReplyUniqueUrl.insertMulti(iterPos1.key(), iterPos1.value());
|
|
}
|
|
}
|
|
|
|
m_mapCategory.insert(_categoryNum, streal);
|
|
return true;
|
|
|
|
}
|
|
|
|
bool SInfluencer::makeTable(SDatagroup &_datagroup)
|
|
{
|
|
//if (m_mapCategory.size() > 1)
|
|
if (m_mapCategory.size() > 0)
|
|
{
|
|
m_pSInitializer->insertLog("Make influencer tables");
|
|
m_pSInitializer->insertLog("Make influencer body tables");
|
|
m_SBodyInfluencerMap.makeTable(_datagroup, m_mapCategory);
|
|
m_pSInitializer->insertLog("Make influencer reply tables");
|
|
m_SReplyInfluencerMap.makeTable(_datagroup, m_mapCategory);
|
|
/*
|
|
m_pSInitializer->insertLog("Make influencer stats_inf_blogger_buzzy tables");
|
|
m_SStatsInfBloggerBuzzbyday.makeTable(_datagroup, m_mapCategory);
|
|
m_pSInitializer->insertLog("Make influencer stats_inf_blogger_rank table");
|
|
m_SStatsInfBloggerRank.makeTable(_datagroup, m_mapCategory);
|
|
*/
|
|
m_pSInitializer->insertLog("Make influencer influencer");
|
|
m_STInfluencer.makeTable(_datagroup, m_mapCategory);
|
|
m_pSInitializer->insertLog("Make influencer stats_json");
|
|
//m_SStatsJson.makeTable(_datagroup, m_mapCategory);
|
|
m_SStatsJson.makeTable(_datagroup, m_STInfluencer);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
QList<SInfluencer::stInfluencer>& SInfluencer::STInfluencer::getInfluencerList()
|
|
{
|
|
return m_listMap;
|
|
}
|
|
|
|
bool SInfluencer::SaveDataFile(int _companyNum)
|
|
{
|
|
if (!m_STInfluencer.SaveDataFile(_companyNum))
|
|
{
|
|
m_pSInitializer->insertLog("influencer file save fail");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool SInfluencer::STInfluencer::SaveDataFile(int _companyNum)
|
|
{
|
|
QString strFileName = QString::number(_companyNum) + "_Influencer_" + QDate::currentDate().toString("yyyyMMdd") + ".csv";
|
|
QFile InfluecnerFile(strFileName);
|
|
if (!InfluecnerFile.open(QFile::WriteOnly | QFile::Truncate))
|
|
{
|
|
//process
|
|
return false;
|
|
}
|
|
|
|
QTextStream stream(&InfluecnerFile);
|
|
stream.setAutoDetectUnicode(true);
|
|
stream << "Category," << "ID," << "Nick," << "Title," << "Url," << "Like," << "Share," << "Body," << "Reply," << "Value" << "\n";
|
|
|
|
QMapIterator<int, QList<stInfluencer>> iter1(m_mapInfluencerOfCategory);
|
|
while (iter1.hasNext())
|
|
{
|
|
iter1.next();
|
|
int nCategoryNum = iter1.key();
|
|
const QList<stInfluencer> listInfluencer = iter1.value();
|
|
foreach (stInfluencer Influecner, listInfluencer)
|
|
{
|
|
stream << Influecner.category_num << "," << Influecner.id_id << "," << Influecner.nickname_nickname << "," << Influecner.community_title << ","
|
|
<< "http://" + Influecner.community_url << "," << Influecner.likecount << "," << Influecner.sharecount << "," << Influecner.bodycount << ","
|
|
<< Influecner.replycount << "," << Influecner.influencervalue << "\n";
|
|
}
|
|
}
|
|
|
|
InfluecnerFile.close();
|
|
|
|
return true;
|
|
}
|
|
|
|
void SInfluencer::STInfluencer::makeTable(SDatagroup &_datagroup, const QMap<int, stReal>& _mapCategory)
|
|
{
|
|
const QMap<QString, QStringList>* mapBody = _datagroup.getmapBody();
|
|
const QMap<QString, QMap<int, QStringList> >* mapReply = _datagroup.getmapReply();
|
|
const QStringList* orderedUrl = _datagroup.getOrderedUrl();
|
|
|
|
const int* anColumn = m_pSInitializer->getColumnIntArray();
|
|
|
|
for (QMap<int, stReal>::const_iterator iterPos = _mapCategory.constBegin(); iterPos != _mapCategory.constEnd(); iterPos++)
|
|
{
|
|
QMap<SDatagroup::stProfileurlKey, stInfluencer> mapRank;
|
|
const stReal& streal = iterPos.value();
|
|
foreach (const QString& _url, *orderedUrl)
|
|
{
|
|
if (streal.m_setRealBodyUrl.contains(_url))
|
|
{
|
|
SDatagroup::stProfileurlKey stprofileurlkey(m_pSInitializer->getPlatformForm((*mapBody)[_url][anColumn[SInitializer::E_DATA_platform_form]].trimmed()),
|
|
(*mapBody)[_url][anColumn[SInitializer::E_DATA_article_id]].trimmed());
|
|
if (!mapRank.contains(stprofileurlkey))
|
|
{
|
|
mapRank.insert(stprofileurlkey, stInfluencer());
|
|
mapRank[stprofileurlkey].id_id = _datagroup.getstBody(_url)->id_id;
|
|
mapRank[stprofileurlkey].id_num = _datagroup.getstBody(_url)->id_num;
|
|
mapRank[stprofileurlkey].nickname_num = _datagroup.getstBody(_url)->nickname_num;
|
|
mapRank[stprofileurlkey].community_num = _datagroup.getstBody(_url)->community_num;
|
|
mapRank[stprofileurlkey].profile = (*(_datagroup.getmapBody(stprofileurlkey)))[anColumn[SInitializer::E_DATA_article_profile]].trimmed();
|
|
mapRank[stprofileurlkey].profileurl = (*(_datagroup.getmapBody(stprofileurlkey)))[anColumn[SInitializer::E_DATA_article_profileurl]].trimmed();
|
|
mapRank[stprofileurlkey].category_num = iterPos.key();
|
|
//mapRank[stprofileurlkey].community_title = _datagroup.getstCommunity(*(_datagroup.getmapBody(stprofileurlkey)))->title;
|
|
//mapRank[stprofileurlkey].community_url = _datagroup.getstCommunity(*(_datagroup.getmapBody(stprofileurlkey)))->url;
|
|
//mapRank[stprofileurlkey].community_id = _datagroup.getstCommunity(*(_datagroup.getmapBody(stprofileurlkey)))->id;
|
|
mapRank[stprofileurlkey].community_title = _datagroup.getstCommunity((*mapBody)[_url])->title;
|
|
mapRank[stprofileurlkey].community_url = _datagroup.getstCommunity((*mapBody)[_url])->url;
|
|
mapRank[stprofileurlkey].community_id = _datagroup.getstCommunity((*mapBody)[_url])->id;
|
|
mapRank[stprofileurlkey].nickname_nickname = _datagroup.getstBody(_url)->nickname_nickname;
|
|
mapRank[stprofileurlkey].nickname_exnickname = _datagroup.getstBody(_url)->nickname_exnickname;
|
|
mapRank[stprofileurlkey].platformname_num = _datagroup.getstBody(_url)->platformname_num;
|
|
mapRank[stprofileurlkey].platformname_name = _datagroup.getstBody(_url)->platformname_name;
|
|
//m_pSInitializer->insertLog(_url);
|
|
//m_pSInitializer->insertLog(stprofileurlkey.m_strId);
|
|
//m_pSInitializer->insertLog(mapRank[stprofileurlkey].community_url);
|
|
}
|
|
mapRank[stprofileurlkey].bodycount++;
|
|
mapRank[stprofileurlkey].sharecount += _datagroup.getstBody(_url)->share;
|
|
mapRank[stprofileurlkey].likecount += _datagroup.getstBody(_url)->like;
|
|
|
|
if ((*mapReply).contains(_url))
|
|
{
|
|
for (QMap<int, QStringList>::const_iterator iterPos1 = (*mapReply)[_url].constBegin(); iterPos1 != (*mapReply)[_url].constEnd(); iterPos1++)
|
|
{
|
|
//if ((iterPos1.value()[anColumn[SInitializer::E_DATA_article_id]].trimmed() != (*mapBody)[_url][anColumn[SInitializer::E_DATA_article_id]].trimmed()))
|
|
mapRank[stprofileurlkey].replycount++;
|
|
}
|
|
}
|
|
|
|
|
|
//insert Reply
|
|
const QMap<int, SDatagroup::stReply>* mapstReply = _datagroup.getstReply(_url);
|
|
if (mapstReply == 0) continue;
|
|
for (QMap<int, SDatagroup::stReply>::const_iterator iterPos1 = mapstReply->constBegin(); iterPos1 != mapstReply->constEnd(); iterPos1++)
|
|
{
|
|
SDatagroup::stReply ReplyInstance = iterPos1.value();
|
|
//if (!ReplyInstance.realbycategorynum.contains(iterPos.key())) continue;
|
|
|
|
QString strId = ReplyInstance.id_id;
|
|
if (mapRank[stprofileurlkey].id_id == strId) continue;
|
|
|
|
mapRank[stprofileurlkey].interactions[strId].append(ReplyInstance);
|
|
mapRank[stprofileurlkey].interactionsTotalReplyCount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
for (QMap<SDatagroup::stProfileurlKey, stInfluencer>::iterator iterPos1 = mapRank.begin(); iterPos1 != mapRank.end(); iterPos1++)
|
|
{
|
|
stInfluencer &val = iterPos1.value();
|
|
SIdrankbyinteraction idrankbyinteractionColumn;
|
|
val.interactionrank = idrankbyinteractionColumn.makeIdrankbyinteractionColumnJson(val);
|
|
}
|
|
|
|
|
|
// for (QMap<SDatagroup::stProfileurlKey, stInfluencer>::iterator iterPos1 = mapRank.begin(); iterPos1 != mapRank.end(); iterPos1++)
|
|
// {
|
|
// stInfluencer &val = iterPos1.value();
|
|
// //val.influencervalue = val.bodycount * m_pSInitializer->getInfluencerParam(0) + val.replycount * m_pSInitializer->getInfluencerParam(1);
|
|
// if (val.bodycount == 0)
|
|
// val.influencervalue = 0;
|
|
// else
|
|
// val.influencervalue = static_cast<double>(val.replycount + val.sharecount + val.likecount) * m_pSInitializer->getInfluencerParam().A /
|
|
// (val.bodycount * m_pSInitializer->getInfluencerParam().B);
|
|
// }
|
|
|
|
SInfluencerWeight influecnerWeight;
|
|
for (QMap<SDatagroup::stProfileurlKey, stInfluencer>::iterator iter = mapRank.begin(); iter != mapRank.end(); iter++)
|
|
{
|
|
stInfluencer &influencer = iter.value();
|
|
influecnerWeight.insert(influencer);
|
|
}
|
|
|
|
influecnerWeight.calculateWeight();
|
|
|
|
for (QMap<SDatagroup::stProfileurlKey, stInfluencer>::iterator iter = mapRank.begin(); iter != mapRank.end(); iter++)
|
|
{
|
|
stInfluencer &influencer = iter.value();
|
|
influencer.influencervalue = influecnerWeight.getInfluenceValue(influencer);
|
|
}
|
|
|
|
|
|
QList<stInfluencer> listmap = mapRank.values();
|
|
qSort(listmap.begin(), listmap.end(), isGreaterInfluencerValue());
|
|
int rank = 1;
|
|
for (QList<stInfluencer>::iterator iterPos1 = listmap.begin(); iterPos1 != listmap.end(); iterPos1++)
|
|
{
|
|
iterPos1->rank = rank++;
|
|
}
|
|
m_listMap.append(listmap);
|
|
}
|
|
|
|
|
|
|
|
//Make Map Influencer Group by Category within limit range, Sort by rank
|
|
int nInfluencerLimitFrom = m_pSInitializer->getInfluencerLimitFrom().toInt();
|
|
int nInfluencerLimitTo = m_pSInitializer->getInfluencerLimitTo().toInt();
|
|
QListIterator<stInfluencer> iter(m_listMap);
|
|
while (iter.hasNext())
|
|
{
|
|
const stInfluencer& influencer = iter.next();
|
|
if (influencer.rank < nInfluencerLimitFrom || nInfluencerLimitTo < influencer.rank)
|
|
continue;
|
|
|
|
m_mapInfluencerOfCategory[influencer.category_num].append(influencer);
|
|
}
|
|
|
|
for (QMap<int, QList<stInfluencer>>::iterator iter = m_mapInfluencerOfCategory.begin(); iter != m_mapInfluencerOfCategory.end(); iter++)
|
|
{
|
|
QList<stInfluencer>& listInfluencer = iter.value();
|
|
qSort(listInfluencer.begin(), listInfluencer.end(), isGreaterInfluencerRank());
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
bool SInfluencer::STInfluencer::uploadData(QSqlDatabase &_db, const int &_nCompany)
|
|
{
|
|
QString strQuery = "delete from influencer where company_num = " + QString::number(_nCompany);
|
|
QSqlQuery query(_db);
|
|
if (query.exec(strQuery.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
strQuery = "insert into influencer (rank,company_num,id_num,nickname_num,community_num,bodycount,replycount,influencervalue,profile,profileurl,id_id)"
|
|
" VALUES (:RANK,:COMPANY_NUM,:ID_NUM,:NICKNAME_NUM,:COMMUNITY_NUM,:BODY_COUNT,:REPLY_COUNT,:INPL,:PROFILE,:PROFILE_URL,:ID_ID)";
|
|
|
|
query.clear();
|
|
query.prepare(strQuery.toUtf8());
|
|
|
|
foreach (const stInfluencer& stinfluencer, m_listMap)
|
|
{
|
|
query.bindValue(":RANK", stinfluencer.rank);
|
|
query.bindValue(":COMPANY_NUM", _nCompany);
|
|
query.bindValue(":ID_NUM", stinfluencer.id_num);
|
|
query.bindValue(":NICKNAME_NUM", stinfluencer.nickname_num);
|
|
query.bindValue(":COMMUNITY_NUM", stinfluencer.community_num);
|
|
query.bindValue(":BODY_COUNT", stinfluencer.bodycount);
|
|
query.bindValue(":REPLY_COUNT", stinfluencer.replycount);
|
|
query.bindValue(":ID_ID", stinfluencer.id_id);
|
|
query.bindValue(":INPL", QString::number(stinfluencer.influencervalue, 'g', 3));
|
|
//query.bindValue(":PROFILE", ((stinfluencer.profile.trimmed().isEmpty())? " " : sqlString(stinfluencer.profile).trimmed().replace(QChar(160), "")));
|
|
//query.bindValue(":PROFILE_URL", ((stinfluencer.profileurl.trimmed().isEmpty())? " ", stinfluencer.profileurl.trimmed()));
|
|
query.bindValue(":PROFILE", sqlString(stinfluencer.profile).trimmed().replace(QChar(160), ""));
|
|
query.bindValue(":PROFILE_URL", stinfluencer.profileurl.trimmed());
|
|
if (query.exec() == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
strQuery = "update dbinfo set influencercount = " + QString::number(m_listMap.size()) + " where company_num = "
|
|
+ QString::number(_nCompany);
|
|
query.exec(strQuery);
|
|
|
|
return true;
|
|
}
|
|
*/
|
|
|
|
//bool SInfluencer::STInfluencer::uploadData(QSqlDatabase &_db, const int &_nCompany)
|
|
//{
|
|
// QString strQuery = "delete from influencer_" + QString::number(_nCompany) + "_update";
|
|
// QSqlQuery query(_db);
|
|
// if (query.exec(strQuery.toUtf8()) == false)
|
|
// {
|
|
// m_pSInitializer->insertLog(query.lastQuery());
|
|
// m_pSInitializer->insertLog(query.lastError().text());
|
|
// return false;
|
|
// }
|
|
// strQuery = "insert into influencer_" + QString::number(_nCompany) +
|
|
// "_update (rank,category_num,id_num,nickname_num,community_num,bodycount,replycount, likecount, sharecount, influencervalue,profile,profileurl,id_id,"
|
|
// "community_title,community_url,community_id,nickname_nickname,nickname_exnickname,platformname_num,idrankbyinteraction,platformname_name) VALUES (";
|
|
|
|
// query.clear();
|
|
|
|
// foreach (const stInfluencer& stinfluencer, m_listMap)
|
|
// {
|
|
// QString str = strQuery;
|
|
// str += QString::number(stinfluencer.rank) + ",";
|
|
// str += QString::number(stinfluencer.category_num) + ",";
|
|
// str += QString::number(stinfluencer.id_num) + ",";
|
|
// str += QString::number(stinfluencer.nickname_num) + ",";
|
|
// str += QString::number(stinfluencer.community_num) + ",";
|
|
// str += QString::number(stinfluencer.bodycount) + ",";
|
|
// str += QString::number(stinfluencer.replycount) + ",";
|
|
// str += QString::number(stinfluencer.likecount) + ",";
|
|
// str += QString::number(stinfluencer.sharecount) + ",";
|
|
// str += QString::number(stinfluencer.influencervalue, 'g', 3) + ",";
|
|
// str += "'" + sqlString(stinfluencer.profile).trimmed().replace(QChar(160), "") + "',";
|
|
// str += "'" + sqlString(stinfluencer.profileurl.trimmed()) + "',";
|
|
// str += "'" + sqlString(stinfluencer.id_id) + "',";
|
|
// str += "'" + sqlString(stinfluencer.community_title) + "',";
|
|
// str += "'" + sqlString(stinfluencer.community_url) + "',";
|
|
// str += "'" + sqlString(stinfluencer.community_id) + "',";
|
|
// str += "'" + sqlString(stinfluencer.nickname_nickname) + "',";
|
|
// str += "'" + sqlString(stinfluencer.nickname_exnickname) + "',";
|
|
// str += QString::number(stinfluencer.platformname_num) + ",";
|
|
//str += "'" + sqlString(stinfluencer.interactionrank) + "',";
|
|
// str += "'" + sqlString(stinfluencer.platformname_name) + "')";
|
|
|
|
// if (query.exec(str.toUtf8()) == false)
|
|
// {
|
|
// m_pSInitializer->insertLog(query.lastQuery());
|
|
// m_pSInitializer->insertLog(query.lastError().text());
|
|
// return false;
|
|
// }
|
|
// }
|
|
|
|
// strQuery = "update dbinfo set influencercount = " + QString::number(m_listMap.size()) + " where company_num = "
|
|
// + QString::number(_nCompany);
|
|
// query.exec(strQuery);
|
|
|
|
// return true;
|
|
//}
|
|
|
|
bool SInfluencer::STInfluencer::uploadData(QSqlDatabase &_db, const int &_nCompany)
|
|
{
|
|
QString strQuery = "delete from influencer_" + QString::number(_nCompany) + "_update";
|
|
QSqlQuery query(_db);
|
|
if (query.exec(strQuery.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
strQuery = "insert into influencer_" + QString::number(_nCompany) +
|
|
"_update (rank,category_num,id_num,nickname_num,community_num,bodycount,replycount, likecount, sharecount, influencervalue,profile,profileurl,id_id,"
|
|
"community_title,community_url,community_id,nickname_nickname,nickname_exnickname,platformname_num,idrankbyinteraction,platformname_name) VALUES (";
|
|
|
|
query.clear();
|
|
|
|
QMapIterator<int, QList<stInfluencer>> iter1(m_mapInfluencerOfCategory);
|
|
while (iter1.hasNext())
|
|
{
|
|
iter1.next();
|
|
const QList<stInfluencer>& listInfluencer = iter1.value();
|
|
foreach (stInfluencer stinfluencer, listInfluencer)
|
|
{
|
|
QString str = strQuery;
|
|
str += QString::number(stinfluencer.rank) + ",";
|
|
str += QString::number(stinfluencer.category_num) + ",";
|
|
str += QString::number(stinfluencer.id_num) + ",";
|
|
str += QString::number(stinfluencer.nickname_num) + ",";
|
|
str += QString::number(stinfluencer.community_num) + ",";
|
|
str += QString::number(stinfluencer.bodycount) + ",";
|
|
str += QString::number(stinfluencer.replycount) + ",";
|
|
str += QString::number(stinfluencer.likecount) + ",";
|
|
str += QString::number(stinfluencer.sharecount) + ",";
|
|
str += QString::number(stinfluencer.influencervalue, 'g', 3) + ",";
|
|
str += "'" + sqlString(stinfluencer.profile).trimmed().replace(QChar(160), "") + "',";
|
|
str += "'" + sqlString(stinfluencer.profileurl.trimmed()) + "',";
|
|
str += "'" + sqlString(stinfluencer.id_id) + "',";
|
|
str += "'" + sqlString(stinfluencer.community_title) + "',";
|
|
str += "'" + sqlString(stinfluencer.community_url) + "',";
|
|
str += "'" + sqlString(stinfluencer.community_id) + "',";
|
|
str += "'" + sqlString(stinfluencer.nickname_nickname) + "',";
|
|
str += "'" + sqlString(stinfluencer.nickname_exnickname) + "',";
|
|
str += QString::number(stinfluencer.platformname_num) + ",";
|
|
str += "'" + sqlString(stinfluencer.interactionrank) + "',";
|
|
str += "'" + sqlString(stinfluencer.platformname_name) + "')";
|
|
|
|
if (query.exec(str.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// foreach (const stInfluencer& stinfluencer, m_listMap)
|
|
// {
|
|
// QString str = strQuery;
|
|
// str += QString::number(stinfluencer.rank) + ",";
|
|
// str += QString::number(stinfluencer.category_num) + ",";
|
|
// str += QString::number(stinfluencer.id_num) + ",";
|
|
// str += QString::number(stinfluencer.nickname_num) + ",";
|
|
// str += QString::number(stinfluencer.community_num) + ",";
|
|
// str += QString::number(stinfluencer.bodycount) + ",";
|
|
// str += QString::number(stinfluencer.replycount) + ",";
|
|
// str += QString::number(stinfluencer.likecount) + ",";
|
|
// str += QString::number(stinfluencer.sharecount) + ",";
|
|
// str += QString::number(stinfluencer.influencervalue, 'g', 3) + ",";
|
|
// str += "'" + sqlString(stinfluencer.profile).trimmed().replace(QChar(160), "") + "',";
|
|
// str += "'" + sqlString(stinfluencer.profileurl.trimmed()) + "',";
|
|
// str += "'" + sqlString(stinfluencer.id_id) + "',";
|
|
// str += "'" + sqlString(stinfluencer.community_title) + "',";
|
|
// str += "'" + sqlString(stinfluencer.community_url) + "',";
|
|
// str += "'" + sqlString(stinfluencer.community_id) + "',";
|
|
// str += "'" + sqlString(stinfluencer.nickname_nickname) + "',";
|
|
// str += "'" + sqlString(stinfluencer.nickname_exnickname) + "',";
|
|
// str += QString::number(stinfluencer.platformname_num) + ",";
|
|
//str += "'" + sqlString(stinfluencer.interactionrank) + "',";
|
|
// str += "'" + sqlString(stinfluencer.platformname_name) + "')";
|
|
|
|
// if (query.exec(str.toUtf8()) == false)
|
|
// {
|
|
// m_pSInitializer->insertLog(query.lastQuery());
|
|
// m_pSInitializer->insertLog(query.lastError().text());
|
|
// return false;
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
|
|
// strQuery = "delete from influencer_" + QString::number(_nCompany) + "_update " +
|
|
// "where rank < " + m_pSInitializer->getInfluencerLimitFrom() + " or rank > " + m_pSInitializer->getInfluencerLimitTo();
|
|
// if (query.exec(strQuery.toUtf8()) == false)
|
|
// {
|
|
// m_pSInitializer->insertLog(query.lastQuery());
|
|
// m_pSInitializer->insertLog(query.lastError().text());
|
|
// return false;
|
|
// }
|
|
|
|
|
|
strQuery = "select count(*) from influencer_" + QString::number(_nCompany) + "_update";
|
|
if (query.exec(strQuery.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
|
|
query.next();
|
|
QString strInfluencerCount = query.value(0).toString();
|
|
query.clear();
|
|
|
|
strQuery = "update dbinfo set influencercount = " + strInfluencerCount + " where company_num = "
|
|
+ QString::number(_nCompany);
|
|
query.exec(strQuery);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool SInfluencer::STInfluencer::changeTable(QSqlDatabase &_db, const int &_nCompany)
|
|
{
|
|
QString strQuery;
|
|
QSqlQuery query(_db);
|
|
strQuery = "RENAME TABLE ";
|
|
strQuery += "influencer_" + QString::number(_nCompany) + " TO " + "influencer_" + QString::number(_nCompany) + "_temp" + ",";
|
|
strQuery += "influencer_" + QString::number(_nCompany) + "_update" + " TO " + "influencer_" + QString::number(_nCompany) + ",";
|
|
strQuery += "influencer_" + QString::number(_nCompany) + "_temp" + " TO " + "influencer_" + QString::number(_nCompany) + "_update";
|
|
m_pSInitializer->insertLog("influencer_" + QString::number(_nCompany) + " rename table start");
|
|
if (!query.exec(strQuery.toUtf8()))
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
m_pSInitializer->insertLog("influencer_" + QString::number(_nCompany) + " rename table end");
|
|
return true;
|
|
}
|
|
|
|
void SInfluencer::SStatsInfBloggerRank::makeTable(SDatagroup &_datagroup, const QMap<int, stReal>& _mapCategory)
|
|
{
|
|
const QMap<QString, QStringList>* mapBody = _datagroup.getmapBody();
|
|
const QMap<QString, QMap<int, QStringList> >* mapReply = _datagroup.getmapReply();
|
|
const int* anColumn = m_pSInitializer->getColumnIntArray();
|
|
const int RANK = 10;
|
|
|
|
|
|
for (QMap<int, stReal>::const_iterator iterPos = _mapCategory.constBegin(); iterPos != _mapCategory.constEnd(); iterPos++)
|
|
{
|
|
const stReal& streal = iterPos.value();
|
|
QMap<SDatagroup::stProfileurlKey, stStatsInfBloggerRank> mapRank;
|
|
|
|
foreach (const QString& _url, streal.m_setRealBodyUrl)
|
|
{
|
|
SDatagroup::stProfileurlKey stprofileurlkey(m_pSInitializer->getPlatformForm((*mapBody)[_url][anColumn[SInitializer::E_DATA_platform_form]].trimmed()),
|
|
(*mapBody)[_url][anColumn[SInitializer::E_DATA_article_id]].trimmed());
|
|
|
|
if (!mapRank.contains(stprofileurlkey))
|
|
{
|
|
mapRank.insert(stprofileurlkey, stStatsInfBloggerRank());
|
|
mapRank[stprofileurlkey].id_id = (*mapBody)[_url][anColumn[SInitializer::E_DATA_article_id]].trimmed();
|
|
mapRank[stprofileurlkey].nickname_nickname = (*mapBody)[_url][anColumn[SInitializer::E_DATA_article_nickname]].trimmed();
|
|
}
|
|
|
|
mapRank[stprofileurlkey].bodycount++;
|
|
|
|
if ((*mapReply).contains(_url))
|
|
{
|
|
for (QMap<int, QStringList>::const_iterator iterPos1 = (*mapReply)[_url].constBegin(); iterPos1 != (*mapReply)[_url].constEnd(); iterPos1++)
|
|
{
|
|
//if ((iterPos1.value()[anColumn[SInitializer::E_DATA_article_id]].trimmed() != (*mapBody)[_url][anColumn[SInitializer::E_DATA_article_id]].trimmed()))
|
|
mapRank[stprofileurlkey].replycount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
for (QMap<SDatagroup::stProfileurlKey, stStatsInfBloggerRank>::iterator iterPos = mapRank.begin(); iterPos != mapRank.end(); iterPos++)
|
|
{
|
|
stStatsInfBloggerRank &val = iterPos.value();
|
|
//val.influencevalue = val.bodycount * m_pSInitializer->getInfluencerParam(0) + val.replycount * m_pSInitializer->getInfluencerParam(1);
|
|
if (val.bodycount == 0)
|
|
val.influencevalue = 0;
|
|
else
|
|
val.influencevalue = val.replycount / val.bodycount;
|
|
//val.influencevalue = val.bodycount * m_pSInitializer->getInfluencerParam(0) + val.replycount * m_pSInitializer->getInfluencerParam(1);
|
|
}
|
|
|
|
QList<stStatsInfBloggerRank> listMap = mapRank.values();
|
|
|
|
qSort(listMap.begin(), listMap.end(), isGreaterInfluencerValue());
|
|
// influencevalue
|
|
for(int i = 0; i < RANK && i < listMap.size(); i++)
|
|
{
|
|
listMap[i].rank = i + 1;
|
|
listMap[i].subject = "influencevalue";
|
|
m_listMap.append(listMap.at(i));
|
|
//qDebug() << listMap[i].id_id;
|
|
}
|
|
|
|
qSort(listMap.begin(), listMap.end(), isGreaterBodyCount());
|
|
// influencevalue
|
|
for(int i = 0; i < RANK && i < listMap.size(); i++)
|
|
{
|
|
listMap[i].rank = i + 1;
|
|
listMap[i].subject = "bodycount";
|
|
m_listMap.append(listMap.at(i));
|
|
//qDebug() << listMap[i].id_id;
|
|
}
|
|
|
|
qSort(listMap.begin(), listMap.end(), isGreaterReplyCount());
|
|
// influencevalue
|
|
for(int i = 0; i < RANK && i < listMap.size(); i++)
|
|
{
|
|
listMap[i].rank = i + 1;
|
|
listMap[i].subject = "replycount";
|
|
m_listMap.append(listMap.at(i));
|
|
//qDebug() << listMap[i].id_id;
|
|
}
|
|
listMap.clear();
|
|
}
|
|
}
|
|
|
|
/*
|
|
bool SInfluencer::SStatsInfBloggerRank::uploadData(QSqlDatabase &_db, const int &_nCompany)
|
|
{
|
|
//_db.transaction();
|
|
QString strQuery = "delete from stats_inf_blogger_rank where company_num = " + QString::number(_nCompany);
|
|
QSqlQuery query(_db);
|
|
if (query.exec(strQuery.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
//_db.commit();
|
|
//_db.transaction();
|
|
strQuery = "insert into stats_inf_blogger_rank(rank,id_id,nickname_nickname,bodycount,replycount,influencevalue,subject,company_num)"
|
|
" VALUES (:rank,:id_id,:nickname_nickname,:bodycount,:replycount,:influencevalue,:subject,:company_num)";
|
|
query.clear();
|
|
query.prepare(strQuery.toUtf8());
|
|
|
|
foreach (const stStatsInfBloggerRank& ststats, m_listMap)
|
|
{
|
|
query.bindValue(":rank", ststats.rank);
|
|
query.bindValue(":id_id", ststats.id_id);
|
|
query.bindValue(":company_num", _nCompany);
|
|
query.bindValue(":nickname_nickname", ststats.nickname_nickname);
|
|
query.bindValue(":bodycount", ststats.bodycount);
|
|
query.bindValue(":replycount", ststats.replycount);
|
|
query.bindValue(":influencevalue", QString::number(ststats.influencevalue, 'g', 3));
|
|
query.bindValue(":subject", ststats.subject);
|
|
if (query.exec() == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
}
|
|
//_db.commit();
|
|
return true;
|
|
}
|
|
*/
|
|
|
|
bool SInfluencer::SStatsInfBloggerRank::uploadData(QSqlDatabase &_db, const int &_nCompany)
|
|
{
|
|
//_db.transaction();
|
|
QString strQuery = "delete from stats_inf_blogger_rank where company_num = " + QString::number(_nCompany);
|
|
QSqlQuery query(_db);
|
|
if (query.exec(strQuery.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
//_db.commit();
|
|
//_db.transaction();
|
|
strQuery = "insert into stats_inf_blogger_rank(rank,id_id,nickname_nickname,bodycount,replycount,influencevalue,subject,company_num)"
|
|
" VALUES (";
|
|
query.clear();
|
|
|
|
foreach (const stStatsInfBloggerRank& ststats, m_listMap)
|
|
{
|
|
QString str = strQuery;
|
|
str += QString::number(ststats.rank) + ",";
|
|
str += "'" + sqlString(ststats.id_id) + "',";
|
|
str += "'" + sqlString(ststats.nickname_nickname) + "',";
|
|
str += QString::number(ststats.bodycount) + ",";
|
|
str += QString::number(ststats.replycount) + ",";
|
|
str += QString::number(ststats.influencevalue, 'g', 3) + ",";
|
|
str += "'" + sqlString(ststats.subject) + "',";
|
|
str += QString::number(_nCompany) + ")";
|
|
if (query.exec(str.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
}
|
|
//_db.commit();
|
|
return true;
|
|
}
|
|
|
|
|
|
void SInfluencer::SStatsInfBloggerBuzzbyday::makeTable(SDatagroup &_datagroup, const QMap<int, stReal> &_mapCategory)
|
|
{
|
|
const QMap<QString, QStringList>* mapBody = _datagroup.getmapBody();
|
|
const QMap<QString, QMap<int, QStringList> >* mapReply = _datagroup.getmapReply();
|
|
const int* anColumn = m_pSInitializer->getColumnIntArray();
|
|
QDate dateStart(2100,1,1),dateEnd(2000,1,1);
|
|
|
|
QMap<QDate, stInfluenceBuzz> map;
|
|
|
|
for (QMap<int, stReal>::const_iterator iterPos = _mapCategory.constBegin(); iterPos != _mapCategory.constEnd(); iterPos++)
|
|
{
|
|
const stReal& streal = iterPos.value();
|
|
foreach (const QString& _url, streal.m_setRealBodyUrl)
|
|
{
|
|
QDate date = QDateTime::fromString((*mapBody)[_url][anColumn[SInitializer::E_DATA_article_date]].trimmed().replace("T", " "), "yyyy-MM-dd HH:mm:ss").date();
|
|
dateStart = (date < dateStart ) ? date : dateStart;
|
|
dateEnd = (date > dateEnd ) ? date : dateEnd;
|
|
if (!map.contains(date))
|
|
map.insert(date, stInfluenceBuzz());
|
|
map[date].bodycount++;
|
|
map[date].idcount.insert((*mapBody)[_url][anColumn[SInitializer::E_DATA_article_id]].trimmed());
|
|
}
|
|
if (streal.m_mapRealReplyUniqueUrl.size() > 0)
|
|
{
|
|
for (QMap<QString, int>::const_iterator iterPos1 = streal.m_mapRealReplyUniqueUrl.constBegin(); iterPos1 != streal.m_mapRealReplyUniqueUrl.constEnd(); iterPos1++)
|
|
{
|
|
QDate date = QDateTime::fromString((*mapReply)[iterPos1.key()][iterPos1.value()][anColumn[SInitializer::E_DATA_article_date]].trimmed().replace("T", " "),
|
|
"yyyy-MM-dd HH:mm:ss").date();
|
|
dateStart = (date < dateStart ) ? date : dateStart;
|
|
dateEnd = (date > dateEnd ) ? date : dateEnd;
|
|
if (!map.contains(date))
|
|
map.insert(date, stInfluenceBuzz());
|
|
map[date].replycount++;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (const QString& _url, streal.m_setRealBodyUrl)
|
|
{
|
|
for (QMap<int, QStringList>::const_iterator iterPos1 = mapReply->value(_url).constBegin(); iterPos1 != mapReply->value(_url).constEnd(); iterPos1++)
|
|
{
|
|
QDate date = QDateTime::fromString((*iterPos1)[anColumn[SInitializer::E_DATA_article_date]].trimmed().replace("T", " "),
|
|
"yyyy-MM-dd HH:mm:ss").date();
|
|
dateStart = (date < dateStart ) ? date : dateStart;
|
|
dateEnd = (date > dateEnd ) ? date : dateEnd;
|
|
if (!map.contains(date))
|
|
map.insert(date, stInfluenceBuzz());
|
|
map[date].replycount++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for (QDate date = dateStart; date <= dateEnd; date = date.addDays(1))
|
|
{
|
|
if (!map.contains(date))
|
|
map.insert(date, stInfluenceBuzz());
|
|
stStatsInfBloggerBuzzbyday ststats;
|
|
|
|
ststats.date = date.toString("yyyy-MM-dd");
|
|
ststats.formateddate = date.toString("yyyyMMdd").toInt();
|
|
ststats.bodycount = map[date].bodycount;
|
|
ststats.idcount = map[date].idcount.size();
|
|
ststats.replycount = map[date].replycount;
|
|
m_listMap.append(ststats);
|
|
}
|
|
}
|
|
/*
|
|
bool SInfluencer::SStatsInfBloggerBuzzbyday::uploadData(QSqlDatabase &_db, const int &_nCompany)
|
|
{
|
|
//_db.transaction();
|
|
QString strQuery = "delete from stats_inf_blogger_buzzbyday where company_num = " + QString::number(_nCompany);
|
|
QSqlQuery query(_db);
|
|
if (query.exec(strQuery.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
//_db.commit();
|
|
//_db.transaction();
|
|
strQuery = "insert into stats_inf_blogger_buzzbyday (company_num,date,formateddate,idcount,bodycount,replycount) "
|
|
"VALUES (:company_num,:date,:formateddate,:idcount,:bodycount,:replycount)";
|
|
query.clear();
|
|
query.prepare(strQuery.toUtf8());
|
|
|
|
foreach (const stStatsInfBloggerBuzzbyday& ststats, m_listMap)
|
|
{
|
|
query.bindValue(":company_num", _nCompany);
|
|
query.bindValue(":date", ststats.date);
|
|
query.bindValue(":formateddate", ststats.formateddate);
|
|
query.bindValue(":idcount", ststats.idcount);
|
|
query.bindValue(":bodycount", ststats.bodycount);
|
|
query.bindValue(":replycount", ststats.replycount);
|
|
|
|
if (query.exec() == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
}
|
|
//_db.commit();
|
|
return true;
|
|
}
|
|
*/
|
|
|
|
|
|
bool SInfluencer::SStatsInfBloggerBuzzbyday::uploadData(QSqlDatabase &_db, const int &_nCompany)
|
|
{
|
|
QString strQuery = "delete from stats_inf_blogger_buzzbyday where company_num = " + QString::number(_nCompany);
|
|
QSqlQuery query(_db);
|
|
if (query.exec(strQuery.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
strQuery = "insert into stats_inf_blogger_buzzbyday (company_num,date,formateddate,idcount,bodycount,replycount) "
|
|
"VALUES (";
|
|
query.clear();
|
|
|
|
foreach (const stStatsInfBloggerBuzzbyday& ststats, m_listMap)
|
|
{
|
|
QString str = strQuery;
|
|
str += QString::number(_nCompany) + ",";
|
|
str += "'" + sqlString(ststats.date) + "',";
|
|
str += QString::number(ststats.formateddate) + ",";
|
|
str += QString::number(ststats.idcount) + ",";
|
|
str += QString::number(ststats.bodycount) + ",";
|
|
str += QString::number(ststats.replycount) + ")";
|
|
if (query.exec(str.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
void SInfluencer::SBodyInfluencerMap::makeTable(SDatagroup &_datagroup, const QMap<int, stReal> &_mapCategory)
|
|
{
|
|
int num = 0;
|
|
const QStringList* orderedUrl = _datagroup.getOrderedUrl();
|
|
for (QMap<int, stReal>::const_iterator iterPos = _mapCategory.constBegin(); iterPos != _mapCategory.constEnd(); iterPos++)
|
|
{
|
|
const stReal& streal = iterPos.value();
|
|
foreach (const QString& strUrl, *orderedUrl)
|
|
{
|
|
if (streal.m_setRealBodyUrl.contains(strUrl))
|
|
{
|
|
stBodyInfluencerMap stbody;
|
|
stbody.num = num++;
|
|
stbody.body_num = _datagroup.getstBodyNum(strUrl);
|
|
stbody.id_num = _datagroup.getstBody(strUrl)->id_num;
|
|
stbody.category_num = iterPos.key();
|
|
stbody.realin |= REAL_BODY;
|
|
stbody.community_num = _datagroup.getstBody(strUrl)->community_num;
|
|
stbody.date = _datagroup.getstBody(strUrl)->date;
|
|
m_listMap.append(stbody);
|
|
_datagroup.addRealBodyCategory(strUrl, iterPos.key());
|
|
if (streal.m_mapRealReplyUniqueUrl.contains(strUrl))
|
|
{
|
|
stbody.realin |= REAL_REPLY;
|
|
foreach (int order, streal.m_mapRealReplyUniqueUrl.values(strUrl))
|
|
{
|
|
_datagroup.addRealReplyCategory(strUrl, order, iterPos.key());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/*
|
|
bool SInfluencer::SBodyInfluencerMap::uploadData(QSqlDatabase &_db, const int &_nCompany)
|
|
{
|
|
QString strQuery = "truncate body_influencer_map_" + QString::number(_nCompany) + "_update";
|
|
|
|
QSqlQuery query(_db);
|
|
if (query.exec(strQuery.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
strQuery = "insert into body_influencer_map_" + QString::number(_nCompany) + "_update (num,category_num,id_num,body_num,realin)"
|
|
" values (:num,:category_num,:id_num,:body_num,:realin)";
|
|
query.clear();
|
|
query.prepare(strQuery.toUtf8());
|
|
|
|
foreach (const stBodyInfluencerMap& stmap, m_listMap)
|
|
{
|
|
query.bindValue(":num", stmap.num);
|
|
query.bindValue(":category_num", stmap.category_num);
|
|
query.bindValue(":id_num", stmap.id_num);
|
|
query.bindValue(":body_num", stmap.body_num);
|
|
query.bindValue(":realin", stmap.realin);
|
|
if (query.exec() == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
*/
|
|
|
|
|
|
bool SInfluencer::SBodyInfluencerMap::uploadData(QSqlDatabase &_db, const int &_nCompany)
|
|
{
|
|
QString strQuery = "truncate body_influencer_map_" + QString::number(_nCompany) + "_update";
|
|
|
|
QSqlQuery query(_db);
|
|
if (query.exec(strQuery.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
strQuery = "insert into body_influencer_map_" + QString::number(_nCompany) + "_update (num,category_num,id_num,body_num,realin,community_num,date)"
|
|
" values (";
|
|
query.clear();
|
|
|
|
|
|
foreach (const stBodyInfluencerMap& stmap, m_listMap)
|
|
{
|
|
QString str = strQuery;
|
|
str += QString::number(stmap.num) + ",";
|
|
str += QString::number(stmap.category_num) + ",";
|
|
str += QString::number(stmap.id_num) + ",";
|
|
str += QString::number(stmap.body_num) + ",";
|
|
str += QString::number(stmap.realin) + ",";
|
|
str += QString::number(stmap.community_num) + ",";
|
|
str += "'" + sqlString(stmap.date) + "')";
|
|
|
|
if (query.exec(str.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
void SInfluencer::SReplyInfluencerMap::makeTable(SDatagroup &_datagroup, const QMap<int, stReal> &_mapCategory)
|
|
{
|
|
int num = 0;
|
|
const QMap<QString, QMap<int, QStringList> >* mapReply = _datagroup.getmapReply();
|
|
|
|
int nAll = 0;
|
|
for (QMap<int, stReal>::const_iterator iterPos = _mapCategory.constBegin(); iterPos != _mapCategory.constEnd(); iterPos++)
|
|
{
|
|
if (iterPos.value().m_mapRealReplyUniqueUrl.size() > 0)
|
|
++nAll;
|
|
}
|
|
|
|
bool bAll = true;
|
|
if (_mapCategory.size() == nAll)
|
|
bAll = false;
|
|
|
|
for (QMap<int, stReal>::const_iterator iterPos = _mapCategory.constBegin(); iterPos != _mapCategory.constEnd(); iterPos++)
|
|
{
|
|
const stReal& streal = iterPos.value();
|
|
|
|
//new part
|
|
if (iterPos.key() == m_pSInitializer->getAllCategoryNum(1))
|
|
{
|
|
if (bAll)
|
|
{
|
|
foreach (const QString& _url, streal.m_setRealBodyUrl)
|
|
{
|
|
for (QMap<int, QStringList>::const_iterator iterPos1 = mapReply->value(_url).constBegin(); iterPos1 != mapReply->value(_url).constEnd(); iterPos1++)
|
|
{
|
|
stReplyInfluencerMap streply;
|
|
streply.num = num++;
|
|
streply.body_num = _datagroup.getstBodyNum(_url);
|
|
streply.category_num = iterPos.key();
|
|
streply.realin |= REAL_REPLY;
|
|
streply.id_num = _datagroup.getstReply(_url, iterPos1.key())->id_num;
|
|
streply.reply_num = _datagroup.getstReply(_url, iterPos1.key())->num;
|
|
streply.community_num = _datagroup.getstReply(_url, iterPos1.key())->community_num;
|
|
streply.body_date = _datagroup.getstBody(_url)->date;
|
|
_datagroup.addRealReplyCategory((iterPos1.value()[SInitializer::E_DATA_article_url]).trimmed(), iterPos1.key(), iterPos.key());
|
|
m_listMap.append(streply);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (QMap<QString, int>::const_iterator iterPos1 = streal.m_mapRealReplyUniqueUrl.constBegin(); iterPos1 != streal.m_mapRealReplyUniqueUrl.end(); iterPos1++)
|
|
{
|
|
stReplyInfluencerMap streply;
|
|
streply.num = num++;
|
|
streply.body_num = _datagroup.getstBodyNum(iterPos1.key());
|
|
streply.category_num = iterPos.key();
|
|
streply.realin |= REAL_REPLY;
|
|
streply.id_num = _datagroup.getstReply(iterPos1.key(), iterPos1.value())->id_num;
|
|
streply.reply_num = _datagroup.getstReply(iterPos1.key(), iterPos1.value())->num;
|
|
streply.community_num = _datagroup.getstReply(iterPos1.key(), iterPos1.value())->community_num;
|
|
streply.body_date = _datagroup.getstBody(iterPos1.key())->date;
|
|
m_listMap.append(streply);
|
|
|
|
_datagroup.addRealReplyCategory(iterPos1.key(), iterPos1.value(), iterPos.key());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (streal.m_mapRealReplyUniqueUrl.size() > 0)
|
|
{
|
|
for (QMap<QString, int>::const_iterator iterPos1 = streal.m_mapRealReplyUniqueUrl.constBegin(); iterPos1 != streal.m_mapRealReplyUniqueUrl.end(); iterPos1++)
|
|
{
|
|
stReplyInfluencerMap streply;
|
|
streply.num = num++;
|
|
streply.body_num = _datagroup.getstBodyNum(iterPos1.key());
|
|
streply.category_num = iterPos.key();
|
|
streply.realin |= REAL_REPLY;
|
|
streply.id_num = _datagroup.getstReply(iterPos1.key(), iterPos1.value())->id_num;
|
|
streply.reply_num = _datagroup.getstReply(iterPos1.key(), iterPos1.value())->num;
|
|
streply.community_num = _datagroup.getstReply(iterPos1.key(), iterPos1.value())->community_num;
|
|
streply.body_date = _datagroup.getstBody(iterPos1.key())->date;
|
|
m_listMap.append(streply);
|
|
|
|
_datagroup.addRealReplyCategory(iterPos1.key(), iterPos1.value(), iterPos.key());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (const QString& _url, streal.m_setRealBodyUrl)
|
|
{
|
|
for (QMap<int, QStringList>::const_iterator iterPos1 = mapReply->value(_url).constBegin(); iterPos1 != mapReply->value(_url).constEnd(); iterPos1++)
|
|
{
|
|
stReplyInfluencerMap streply;
|
|
streply.num = num++;
|
|
streply.body_num = _datagroup.getstBodyNum(_url);
|
|
streply.category_num = iterPos.key();
|
|
streply.realin |= REAL_REPLY;
|
|
streply.id_num = _datagroup.getstReply(_url, iterPos1.key())->id_num;
|
|
streply.reply_num = _datagroup.getstReply(_url, iterPos1.key())->num;
|
|
streply.community_num = _datagroup.getstReply(_url, iterPos1.key())->community_num;
|
|
streply.body_date = _datagroup.getstBody(_url)->date;
|
|
_datagroup.addRealReplyCategory((iterPos1.value()[SInitializer::E_DATA_article_url]).trimmed(), iterPos1.key(), iterPos.key());
|
|
m_listMap.append(streply);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/* for restore filter -_-;
|
|
if (streal.m_mapRealReplyUniqueUrl.size() > 0)
|
|
{
|
|
for (QMap<QString, int>::const_iterator iterPos1 = streal.m_mapRealReplyUniqueUrl.constBegin(); iterPos1 != streal.m_mapRealReplyUniqueUrl.end(); iterPos1++)
|
|
{
|
|
stReplyInfluencerMap streply;
|
|
streply.num = num++;
|
|
streply.body_num = _datagroup.getstBodyNum(iterPos1.key());
|
|
streply.category_num = iterPos.key();
|
|
streply.realin |= REAL_REPLY;
|
|
streply.id_num = _datagroup.getstReply(iterPos1.key(), iterPos1.value())->id_num;
|
|
streply.reply_num = _datagroup.getstReply(iterPos1.key(), iterPos1.value())->num;
|
|
streply.community_num = _datagroup.getstReply(iterPos1.key(), iterPos1.value())->community_num;
|
|
streply.body_date = _datagroup.getstBody(iterPos1.key())->date;
|
|
m_listMap.append(streply);
|
|
|
|
_datagroup.addRealReplyCategory(iterPos1.key(), iterPos1.value(), iterPos.key());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (const QString& _url, streal.m_setRealBodyUrl)
|
|
{
|
|
for (QMap<int, QStringList>::const_iterator iterPos1 = mapReply->value(_url).constBegin(); iterPos1 != mapReply->value(_url).constEnd(); iterPos1++)
|
|
{
|
|
stReplyInfluencerMap streply;
|
|
streply.num = num++;
|
|
streply.body_num = _datagroup.getstBodyNum(_url);
|
|
streply.category_num = iterPos.key();
|
|
streply.realin |= REAL_REPLY;
|
|
streply.id_num = _datagroup.getstReply(_url, iterPos1.key())->id_num;
|
|
streply.reply_num = _datagroup.getstReply(_url, iterPos1.key())->num;
|
|
streply.community_num = _datagroup.getstReply(_url, iterPos1.key())->community_num;
|
|
streply.body_date = _datagroup.getstBody(_url)->date;
|
|
_datagroup.addRealReplyCategory((iterPos1.value()[SInitializer::E_DATA_article_url]).trimmed(), iterPos1.key(), iterPos.key());
|
|
m_listMap.append(streply);
|
|
}
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
bool SInfluencer::SReplyInfluencerMap::uploadData(QSqlDatabase &_db, const int &_nCompany)
|
|
{
|
|
QString strQuery = "truncate reply_influencer_map_" + QString::number(_nCompany) + "_update";
|
|
QSqlQuery query(_db);
|
|
if (query.exec(strQuery.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
strQuery = "insert into reply_influencer_map_" + QString::number(_nCompany) + "_update (num,category_num,id_num,body_num,reply_num,realin)"
|
|
" values (:num,:category_num,:id_num,:body_num,:reply_num,:realin)";
|
|
query.clear();
|
|
query.prepare(strQuery.toUtf8());
|
|
|
|
foreach (const stReplyInfluencerMap& stmap, m_listMap)
|
|
{
|
|
query.bindValue(":num", stmap.num);
|
|
query.bindValue(":category_num", stmap.category_num);
|
|
query.bindValue(":id_num", stmap.id_num);
|
|
query.bindValue(":body_num", stmap.body_num);
|
|
query.bindValue(":realin", stmap.realin);
|
|
query.bindValue(":reply_num", stmap.reply_num);
|
|
if (query.exec() == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
*/
|
|
|
|
bool SInfluencer::SReplyInfluencerMap::uploadData(QSqlDatabase &_db, const int &_nCompany)
|
|
{
|
|
QString strQuery = "truncate reply_influencer_map_" + QString::number(_nCompany) + "_update";
|
|
QSqlQuery query(_db);
|
|
if (query.exec(strQuery.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
strQuery = "insert into reply_influencer_map_" + QString::number(_nCompany) +
|
|
"_update (num,category_num,id_num,body_num,reply_num,realin,community_num,body_date)"
|
|
" values (";
|
|
query.clear();
|
|
|
|
foreach (const stReplyInfluencerMap& stmap, m_listMap)
|
|
{
|
|
QString str = strQuery;
|
|
str += QString::number(stmap.num) + ",";
|
|
str += QString::number(stmap.category_num) + ",";
|
|
str += QString::number(stmap.id_num) + ",";
|
|
str += QString::number(stmap.body_num) + ",";
|
|
str += QString::number(stmap.reply_num) + ",";
|
|
str += QString::number(stmap.realin) + ",";
|
|
str += QString::number(stmap.community_num) + ",";
|
|
str += "'" + sqlString(stmap.body_date) + "')";
|
|
if (query.exec(str.toUtf8()) == false)
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
bool SInfluencer::SBodyInfluencerMap::changeTable(QSqlDatabase &_db, const int &_nCompany)
|
|
{
|
|
QString strQuery;
|
|
QSqlQuery query(_db);
|
|
strQuery = "RENAME TABLE ";
|
|
strQuery += "body_influencer_map_" + QString::number(_nCompany) + " TO " + "body_influencer_map_" + QString::number(_nCompany) + "_temp" + ",";
|
|
strQuery += "body_influencer_map_" + QString::number(_nCompany) + "_update" + " TO " + "body_influencer_map_" + QString::number(_nCompany) + ",";
|
|
strQuery += "body_influencer_map_" + QString::number(_nCompany) + "_temp" + " TO " + "body_influencer_map_" + QString::number(_nCompany) + "_update";
|
|
m_pSInitializer->insertLog("body_influencer_map_" + QString::number(_nCompany) + " rename table start");
|
|
if (!query.exec(strQuery.toUtf8()))
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
m_pSInitializer->insertLog("body_influencer_map_" + QString::number(_nCompany) + " rename table end");
|
|
return true;
|
|
}
|
|
|
|
|
|
bool SInfluencer::SReplyInfluencerMap::changeTable(QSqlDatabase &_db, const int &_nCompany)
|
|
{
|
|
QString strQuery;
|
|
QSqlQuery query(_db);
|
|
strQuery = "RENAME TABLE ";
|
|
strQuery += "reply_influencer_map_" + QString::number(_nCompany) + " TO " + "reply_influencer_map_" + QString::number(_nCompany) + "_temp" + ",";
|
|
strQuery += "reply_influencer_map_" + QString::number(_nCompany) + "_update" + " TO " + "reply_influencer_map_" + QString::number(_nCompany) + ",";
|
|
strQuery += "reply_influencer_map_" + QString::number(_nCompany) + "_temp" + " TO " + "reply_influencer_map_" + QString::number(_nCompany) + "_update";
|
|
m_pSInitializer->insertLog("reply_influencer_map_" + QString::number(_nCompany) + " rename table start");
|
|
if (!query.exec(strQuery.toUtf8()))
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
m_pSInitializer->insertLog("reply_influencer_map_" + QString::number(_nCompany) + " rename table end");
|
|
return true;
|
|
}
|
|
|
|
namespace
|
|
{
|
|
QString strSeparator = "!@#";
|
|
}
|
|
|
|
struct stCount
|
|
{
|
|
unsigned int body;
|
|
unsigned int reply;
|
|
QSet<QString> id;
|
|
stCount():body(0), reply(0){}
|
|
};
|
|
|
|
struct stDate
|
|
{
|
|
QDate dStart;
|
|
QDate dEnd;
|
|
stDate():dStart(2020, 1, 1), dEnd(1990, 1, 1){}
|
|
};
|
|
|
|
|
|
//void SInfluencer::SStatsJson::makeTable(SDatagroup &_datagroup, const QMap<int, stReal> &_mapCategory)
|
|
//{
|
|
// const QMap<QString, QStringList>* mapBody = _datagroup.getmapBody();
|
|
// const QMap<QString, QMap<int, QStringList> >* mapReply = _datagroup.getmapReply();
|
|
// const int* anColumn = m_pSInitializer->getColumnIntArray();
|
|
// const QStringList *slOrderedUrl = _datagroup.getOrderedUrl();
|
|
|
|
// QMap<QString, stCount> mapCount;
|
|
// QMap<QString, stDate> mapBodyDate;
|
|
|
|
// foreach (const QString& strUrl, *slOrderedUrl)
|
|
// {
|
|
// if (mapBody->contains(strUrl))
|
|
// {
|
|
// QString strKey = (*mapBody)[strUrl][anColumn[SInitializer::E_DATA_platform_name]].trimmed() + strSeparator + (*mapBody)[strUrl][anColumn[SInitializer::E_DATA_platform_form]].trimmed();
|
|
// if (!mapCount.contains(strKey))
|
|
// mapCount.insert(strKey, stCount());
|
|
|
|
// mapCount[strKey].body += 1;
|
|
// mapCount[strKey].id.insert((*mapBody)[strUrl][anColumn[SInitializer::E_DATA_article_id]].trimmed());
|
|
|
|
// if (mapReply->contains(strUrl))
|
|
// mapCount[strKey].reply += (*mapReply)[strUrl].size();
|
|
|
|
// if (!mapBodyDate.contains(strKey))
|
|
// mapBodyDate.insert(strKey, stDate());
|
|
// QDate dBodyDate = QDateTime::fromString((*mapBody)[strUrl][anColumn[SInitializer::E_DATA_article_date]].trimmed().replace("T", " "), "yyyy-MM-dd hh:mm:ss").date();
|
|
// mapBodyDate[strKey].dStart = (mapBodyDate.value(strKey).dStart < dBodyDate) ? mapBodyDate.value(strKey).dStart : dBodyDate;
|
|
// mapBodyDate[strKey].dEnd = (mapBodyDate.value(strKey).dEnd > dBodyDate) ? mapBodyDate.value(strKey).dEnd : dBodyDate;
|
|
// }
|
|
// }
|
|
|
|
// QSet<QString> setRealAllUrl;
|
|
|
|
// for (QMap<int, stReal>::const_iterator iterPos = _mapCategory.constBegin(); iterPos != _mapCategory.constEnd(); iterPos++)
|
|
// {
|
|
// stStatsJson ststatsjson;
|
|
// ststatsjson.category_num = iterPos.key();
|
|
// ststatsjson.platformname_num = 1;
|
|
// ststatsjson.servicenum = 1;
|
|
// ststatsjson.title = "info";
|
|
// ststatsjson.subtitle = "";
|
|
|
|
// const stReal& streal = iterPos.value();
|
|
// QSet<QString> setPlatformType;
|
|
|
|
// foreach (const QString& strUrl, streal.m_setRealAllUrl)
|
|
// {
|
|
// if (mapBody->contains(strUrl))
|
|
// setPlatformType.insert((*mapBody)[strUrl][anColumn[SInitializer::E_DATA_platform_name]].trimmed() + strSeparator + (*mapBody)[strUrl][anColumn[SInitializer::E_DATA_platform_form]].trimmed());
|
|
// setRealAllUrl.insert(strUrl);
|
|
// }
|
|
|
|
// unsigned int nBody = 0;
|
|
// unsigned int nUser = 0;
|
|
// QJsonObject jsonObj;
|
|
|
|
// foreach (const QString& strKey, setPlatformType)
|
|
// {
|
|
// if (strKey == "naver!@#blog")
|
|
// {
|
|
// nBody += ((mapBodyDate.value(strKey).dStart.daysTo(mapBodyDate.value(strKey).dEnd) + 1) * 1000);
|
|
// if (setPlatformType.size() == 1)
|
|
// jsonObj["pagenum"] = m_pSInitializer->getBlogPageNum();
|
|
// }
|
|
// else
|
|
// {
|
|
// nBody += mapCount[strKey].body;
|
|
// }
|
|
|
|
// nUser += mapCount[strKey].id.size();
|
|
// }
|
|
|
|
// unsigned int nTotalCount = nBody;
|
|
// jsonObj["totalcount"] = static_cast<int>(nTotalCount);
|
|
// jsonObj["totalusercount"] = static_cast<int>(nUser);
|
|
// if (!jsonObj.contains("pagenum"))
|
|
// jsonObj["pagenum"] = -1;
|
|
// QJsonDocument jsonDoc(jsonObj);
|
|
// ststatsjson.jdata = jsonDoc.toJson();
|
|
// m_listMap.append(ststatsjson);
|
|
// }
|
|
|
|
// {
|
|
// stStatsJson ststatsjson;
|
|
// ststatsjson.category_num = -1;
|
|
// ststatsjson.platformname_num = 1;
|
|
// ststatsjson.servicenum = 1;
|
|
// ststatsjson.title = "info";
|
|
// ststatsjson.subtitle = "";
|
|
|
|
// QSet<QString> setPlatformType;
|
|
|
|
// foreach (const QString& strUrl, setRealAllUrl)
|
|
// {
|
|
// if (mapBody->contains(strUrl))
|
|
// setPlatformType.insert((*mapBody)[strUrl][anColumn[SInitializer::E_DATA_platform_name]].trimmed() + strSeparator + (*mapBody)[strUrl][anColumn[SInitializer::E_DATA_platform_form]].trimmed());
|
|
// }
|
|
|
|
// unsigned int nBody = 0;
|
|
// unsigned int nUser = 0;
|
|
// QJsonObject jsonObj;
|
|
|
|
// foreach (const QString& strKey, setPlatformType)
|
|
// {
|
|
// if (strKey == "naver!@#blog")
|
|
// {
|
|
// nBody += ((mapBodyDate.value(strKey).dStart.daysTo(mapBodyDate.value(strKey).dEnd) + 1) * 1000);
|
|
// if (setPlatformType.size() == 1)
|
|
// jsonObj["pagenum"] = m_pSInitializer->getBlogPageNum();
|
|
// }
|
|
// else
|
|
// {
|
|
// nBody += mapCount[strKey].body;
|
|
// }
|
|
// nUser += mapCount[strKey].id.size();
|
|
// }
|
|
// unsigned int nTotalCount = nBody;
|
|
// jsonObj["totalcount"] = static_cast<int>(nTotalCount);
|
|
// jsonObj["totalusercount"] = static_cast<int>(nUser);
|
|
// if (!jsonObj.contains("pagenum"))
|
|
// jsonObj["pagenum"] = -1;
|
|
// QJsonDocument jsonDoc(jsonObj);
|
|
// ststatsjson.jdata = jsonDoc.toJson();
|
|
// m_listMap.append(ststatsjson);
|
|
// }
|
|
//}
|
|
|
|
void SInfluencer::SStatsJson::makeGroupStatsJson(SGroupStatistics _groupStatistics, SPlatformStatistics _platformStatistics)
|
|
{
|
|
QList<int> listGroup = m_pSInitializer->getInfluencerGroup().keys();
|
|
foreach (int nGroupNum, listGroup)
|
|
{
|
|
QString strPlatformName = _groupStatistics.getPlatform(nGroupNum);
|
|
stStatsJson ststatsjson;
|
|
ststatsjson.influencerGroupNum = nGroupNum;
|
|
ststatsjson.platformname_num = 1;
|
|
ststatsjson.servicenum = 1;
|
|
ststatsjson.title = "info";
|
|
ststatsjson.subtitle = "";
|
|
ststatsjson.category_num = 0;
|
|
ststatsjson.platformname_name = strPlatformName;
|
|
ststatsjson.bodyCountOfPlatform = _platformStatistics.getBodyCount(strPlatformName);
|
|
ststatsjson.userCount = _platformStatistics.getUserCount(strPlatformName);
|
|
ststatsjson.jdata = makeStatsJson(ststatsjson);
|
|
|
|
m_listMap.append(ststatsjson);
|
|
}
|
|
}
|
|
|
|
void SInfluencer::SStatsJson::makeTotalStatsJson(SPlatformStatistics _platformStatistics)
|
|
{
|
|
stStatsJson ststatsjson;
|
|
ststatsjson.influencerGroupNum = -1;
|
|
ststatsjson.platformname_num = 1;
|
|
ststatsjson.servicenum = 1;
|
|
ststatsjson.title = "info";
|
|
ststatsjson.subtitle = "";
|
|
ststatsjson.category_num = 0;
|
|
ststatsjson.platformname_name = "";
|
|
ststatsjson.bodyCountOfPlatform = _platformStatistics.getTotalBodyCount();
|
|
ststatsjson.userCount = _platformStatistics.getTotalUserCount();
|
|
ststatsjson.jdata = makeStatsJson(ststatsjson);
|
|
|
|
m_listMap.append(ststatsjson);
|
|
}
|
|
|
|
QString SInfluencer::SStatsJson::makeStatsJson(stStatsJson _ststatsJson)
|
|
{
|
|
QJsonObject jsonObj;
|
|
|
|
jsonObj["totalcount"] = static_cast<int>(_ststatsJson.bodyCountOfPlatform);
|
|
jsonObj["totalusercount"] = static_cast<int>(_ststatsJson.userCount);
|
|
|
|
if (_ststatsJson.platformname_name == "naver")
|
|
jsonObj["pagenum"] = m_pSInitializer->getBlogPageNum();
|
|
else
|
|
jsonObj["pagenum"] = -1;
|
|
|
|
QJsonDocument jsonDoc(jsonObj);
|
|
|
|
return jsonDoc.toJson();
|
|
}
|
|
|
|
void SInfluencer::SStatsJson::makeTable(SDatagroup &_datagroup, STInfluencer& _influencer)
|
|
{
|
|
QList<stInfluencer>& listInfluencer = _influencer.getInfluencerList();
|
|
|
|
SPlatformStatistics platformStatistics;
|
|
platformStatistics.calculatePlatformsStatistics(_datagroup);
|
|
|
|
SGroupStatistics groupStatistics(m_pSInitializer->getInfluencerGroup(), listInfluencer);
|
|
groupStatistics.calculateGroupStatistics();
|
|
|
|
makeGroupStatsJson(groupStatistics, platformStatistics);
|
|
makeTotalStatsJson(platformStatistics);
|
|
}
|
|
|
|
bool SInfluencer::SStatsJson::uploadData(QSqlDatabase &_db, const int &_nCompany)
|
|
{
|
|
QSqlQuery query(_db);
|
|
{
|
|
QString strQuery = "delete from stats_json where company_num = " + QString::number(_nCompany) + " and servicenum = 1";
|
|
if (!query.exec(strQuery.toUtf8()))
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
foreach (const stStatsJson& ststats, m_listMap)
|
|
{
|
|
QString strQuery = "insert into stats_json (company_num, servicenum, title, subtitle, platformname_num, category_num, categorygroup_num, jdata) values (";
|
|
strQuery += QString::number(_nCompany) + ",";
|
|
strQuery += QString::number(ststats.servicenum) + ",";
|
|
strQuery += "'" + ststats.title + "',";
|
|
strQuery += "'" + ststats.subtitle + "',";
|
|
strQuery += QString::number(ststats.platformname_num) + ",";
|
|
strQuery += QString::number(ststats.category_num) + ",";
|
|
strQuery += QString::number(ststats.influencerGroupNum) + ",";
|
|
strQuery += "'" + ststats.jdata +"')";
|
|
|
|
if (!query.exec(strQuery.toUtf8()))
|
|
{
|
|
m_pSInitializer->insertLog(query.lastQuery());
|
|
m_pSInitializer->insertLog(query.lastError().text());
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void SInfluencer::SIdrankbyinteraction::makeInteractorsJson(const SInfluencer::stInfluencer& _val)
|
|
{
|
|
QMap<QString, QList<SDatagroup::stReply>> mapInteractions = _val.interactions;
|
|
for (QMap<QString, QList<SDatagroup::stReply>>::const_iterator iterPos = mapInteractions.constBegin(); iterPos != mapInteractions.constEnd(); iterPos++)
|
|
{
|
|
QJsonObject interactionJson;
|
|
QList<SDatagroup::stReply> listReplys = iterPos.value();
|
|
QString strId = iterPos.key();
|
|
interactionJson["id"] = strId;
|
|
interactionJson["nickname"] = listReplys.at(0).nickname_nickname;
|
|
interactionJson["count"] = listReplys.count();
|
|
interactionJson["url"] = SInfluencerInteractorUrlMaker::makeInfluencerInteractorUrl(listReplys.at(0));
|
|
m_interactorsJson.append(interactionJson);
|
|
}
|
|
}
|
|
|
|
void SInfluencer::SIdrankbyinteraction::pickInteractorsByHighReplyCount(int _pickLimit)
|
|
{
|
|
for (int i=0; i<_pickLimit; i++)
|
|
{
|
|
int maxReplyCount = 0;
|
|
int maxReplyInteractionIndex;
|
|
QJsonObject maxReplyInteraction;
|
|
for (int j=0; j<m_interactorsJson.count(); j++)
|
|
{
|
|
QJsonObject targetObj = m_interactorsJson.at(j).toObject();
|
|
int replyCount = targetObj["count"].toInt();
|
|
if (replyCount >= maxReplyCount)
|
|
{
|
|
maxReplyCount = replyCount;
|
|
maxReplyInteractionIndex = j;
|
|
maxReplyInteraction = targetObj;
|
|
}
|
|
}
|
|
|
|
if (m_interactorsJson.isEmpty())
|
|
break;
|
|
|
|
m_pickedInteractorsJson.append(maxReplyInteraction);
|
|
m_interactorsJson.removeAt(maxReplyInteractionIndex);
|
|
}
|
|
}
|
|
|
|
QString SInfluencer::SIdrankbyinteraction::makeIdrankbyinteractionColumnJson(const SInfluencer::stInfluencer& _val)
|
|
{
|
|
makeInteractorsJson(_val);
|
|
pickInteractorsByHighReplyCount(10);
|
|
|
|
QJsonObject IdrankbyinteractionColumnJson;
|
|
IdrankbyinteractionColumnJson["totalreplycount"] = _val.interactionsTotalReplyCount;
|
|
IdrankbyinteractionColumnJson["totalcommentercount"] = _val.interactions.count();
|
|
IdrankbyinteractionColumnJson["value"] = m_pickedInteractorsJson;
|
|
|
|
QJsonDocument finalResultJson(IdrankbyinteractionColumnJson);
|
|
return finalResultJson.toJson();
|
|
}
|
|
|
|
|
|
void SInfluencer::SInfluencerWeight::calculateSectionWeight(QMap<int, double>& _mapSection)
|
|
{
|
|
int nTotalCount = _mapSection.count();
|
|
double weightValue = 0.0;
|
|
double accValue = 1.0/nTotalCount;
|
|
|
|
for (QMap<int, double>::iterator iter = _mapSection.begin(); iter != _mapSection.end(); iter++)
|
|
{
|
|
int nKey = iter.key();
|
|
|
|
_mapSection[nKey] = weightValue;
|
|
weightValue += accValue;
|
|
}
|
|
}
|
|
|
|
void SInfluencer::SInfluencerWeight::calculateWeight()
|
|
{
|
|
calculateSectionWeight(m_mapBodyWeight);
|
|
calculateSectionWeight(m_mapReplyWeight);
|
|
calculateSectionWeight(m_mapLikeWeight);
|
|
}
|
|
|
|
void SInfluencer::SInfluencerWeight::insert(stInfluencer &_val)
|
|
{
|
|
m_mapBodyWeight[_val.bodycount] = 0;
|
|
m_mapReplyWeight[_val.replycount] = 0;
|
|
m_mapLikeWeight[_val.likecount] = 0;
|
|
}
|
|
|
|
double SInfluencer::SInfluencerWeight::getInfluenceValue(stInfluencer &_val)
|
|
{
|
|
double fBodyScore = m_mapBodyWeight[_val.bodycount];
|
|
double fReplyScore = m_mapReplyWeight[_val.replycount];
|
|
double fLikeScore = m_mapLikeWeight[_val.likecount];
|
|
|
|
return (fBodyScore + fReplyScore + fLikeScore) * m_multipleValue;
|
|
}
|
|
|
|
void SInfluencer::SPlatformStatistics::calculatePlatformsStatistics(SDatagroup &_datagroup)
|
|
{
|
|
m_mapBodyCountOfPlatform = _datagroup.getMapBodyCountOfPlatform();
|
|
m_mapUserCountOfPlatform = _datagroup.getMapUserCountOfPlatform();
|
|
|
|
m_nTotalBodyCount = _datagroup.getBodyCount();
|
|
m_nTotalUserCount = _datagroup.getUserCount();
|
|
}
|
|
|
|
|
|
int SInfluencer::SPlatformStatistics::getBodyCount(QString _platformname)
|
|
{
|
|
if (m_mapBodyCountOfPlatform.contains(_platformname))
|
|
return m_mapBodyCountOfPlatform[_platformname];
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
int SInfluencer::SPlatformStatistics::getUserCount(QString _platformname)
|
|
{
|
|
if (m_mapUserCountOfPlatform.contains(_platformname))
|
|
return m_mapUserCountOfPlatform[_platformname];
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
int SInfluencer::SPlatformStatistics::getTotalBodyCount()
|
|
{
|
|
return m_nTotalBodyCount;
|
|
}
|
|
|
|
int SInfluencer::SPlatformStatistics::getTotalUserCount()
|
|
{
|
|
return m_nTotalUserCount;
|
|
}
|
|
|
|
void SInfluencer::SGroupStatistics::calculateUserCount()
|
|
{
|
|
for (QMap<int, QList<int>>::const_iterator iter = m_mapCategorysOfGroup.constBegin(); iter != m_mapCategorysOfGroup.constEnd(); iter++)
|
|
{
|
|
QList<int> listCategory = iter.value();
|
|
|
|
QSet<int> setInfluecnerIds;
|
|
foreach (const stInfluencer& stinfluencer, m_listInfluencer)
|
|
{
|
|
if (!listCategory.contains(stinfluencer.category_num)) continue;
|
|
|
|
setInfluecnerIds.insert(stinfluencer.id_num);
|
|
}
|
|
m_mapUserCountOfGroup[iter.key()] = setInfluecnerIds.count();
|
|
}
|
|
}
|
|
|
|
void SInfluencer::SGroupStatistics::calculatePlatform()
|
|
{
|
|
for (QMap<int, QList<int>>::const_iterator iter = m_mapCategorysOfGroup.constBegin(); iter != m_mapCategorysOfGroup.constEnd(); iter++)
|
|
{
|
|
QList<int> listCategory = iter.value();
|
|
|
|
QMap<QString, int> mapBodyCountOfPlatform;
|
|
foreach (const stInfluencer& stinfluencer, m_listInfluencer)
|
|
{
|
|
if (!listCategory.contains(stinfluencer.category_num)) continue;
|
|
|
|
mapBodyCountOfPlatform[stinfluencer.platformname_name]++;
|
|
}
|
|
|
|
m_mapPlatformOfGroup[iter.key()] = getMaxBodyCountPlatform(mapBodyCountOfPlatform);
|
|
}
|
|
}
|
|
|
|
QString SInfluencer::SGroupStatistics::getMaxBodyCountPlatform(QMap<QString, int> _mapBodyCountOfPlatform)
|
|
{
|
|
int nMaxValue = 0;
|
|
QString maxBodyCountPlatform;
|
|
for (QMap<QString, int>::const_iterator iter = _mapBodyCountOfPlatform.constBegin(); iter != _mapBodyCountOfPlatform.constEnd(); iter++)
|
|
{
|
|
int nBodyCountOfPlatform = iter.value();
|
|
if (nBodyCountOfPlatform >= nMaxValue)
|
|
{
|
|
nMaxValue = nBodyCountOfPlatform;
|
|
maxBodyCountPlatform = iter.key();
|
|
}
|
|
}
|
|
|
|
return maxBodyCountPlatform;
|
|
}
|
|
|
|
void SInfluencer::SGroupStatistics::calculateGroupStatistics()
|
|
{
|
|
calculatePlatform();
|
|
}
|
|
|
|
QString SInfluencer::SGroupStatistics::getPlatform(int _nGroupNum)
|
|
{
|
|
if (m_mapPlatformOfGroup.contains(_nGroupNum))
|
|
return m_mapPlatformOfGroup[_nGroupNum];
|
|
else
|
|
return "";
|
|
}
|