2015-01-15 20:05:44 +08:00
|
|
|
#include "loadmapping.h"
|
|
|
|
|
|
2015-01-15 21:56:30 +08:00
|
|
|
#include <iostream>
|
2015-01-16 21:21:29 +08:00
|
|
|
QHash<QString,QVector<QSharedPointer<LoadInfo> > > *LoadMapping::loads=NULL;
|
|
|
|
|
QHash<QString,QSharedPointer<LoadInfo> > *LoadMapping::loadsToLoadInfo=NULL;
|
2015-01-15 20:05:44 +08:00
|
|
|
LoadMapping::LoadMapping()
|
|
|
|
|
{
|
2015-01-16 21:21:29 +08:00
|
|
|
// if(!LoadMapping::ht)
|
|
|
|
|
// {
|
|
|
|
|
// LoadMapping::ht=new QHash<QString,QVector<double> >;
|
|
|
|
|
// }
|
|
|
|
|
if(!LoadMapping::loads)
|
2015-01-15 20:05:44 +08:00
|
|
|
{
|
2015-01-16 21:21:29 +08:00
|
|
|
LoadMapping::loads=new QHash<QString,QVector<QSharedPointer<LoadInfo> > >;
|
2015-01-15 20:05:44 +08:00
|
|
|
}
|
2015-01-16 21:21:29 +08:00
|
|
|
if(!LoadMapping::loadsToLoadInfo)
|
|
|
|
|
{
|
|
|
|
|
LoadMapping::loadsToLoadInfo=new QHash<QString,QSharedPointer<LoadInfo> >;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-15 20:05:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LoadMapping::~LoadMapping()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-16 21:21:29 +08:00
|
|
|
bool LoadMapping::broadcastUpdateByTime(const QTime& time)
|
|
|
|
|
{
|
2015-01-16 21:27:23 +08:00
|
|
|
QList<QString> keys;
|
|
|
|
|
keys=LoadMapping::loadsToLoadInfo->keys();
|
|
|
|
|
for(QList<QString>::iterator ite=keys.begin();
|
|
|
|
|
ite!=keys.end();
|
|
|
|
|
ite++
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
QSharedPointer<LoadInfo> t=(*LoadMapping::loadsToLoadInfo)[*ite];
|
|
|
|
|
t->updateByTime(time);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2015-01-16 21:21:29 +08:00
|
|
|
}
|
|
|
|
|
|
2015-01-15 22:06:19 +08:00
|
|
|
bool LoadMapping::load(const QString &loadDir,const QString &matchdDir,const QString &exceptionFile)
|
2015-01-15 20:05:44 +08:00
|
|
|
{
|
2015-01-16 16:27:05 +08:00
|
|
|
|
2015-01-16 21:21:29 +08:00
|
|
|
if(LoadMapping::loadsToLoadInfo->keys().length()>0)
|
2015-01-15 20:05:44 +08:00
|
|
|
{
|
|
|
|
|
return true;//只执行一次
|
|
|
|
|
}
|
2015-01-16 16:27:05 +08:00
|
|
|
if(!QFileInfo::exists(loadDir))
|
|
|
|
|
{
|
|
|
|
|
std::cout<<"load file not exists."<<std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if(!QFileInfo::exists(matchdDir))
|
|
|
|
|
{
|
|
|
|
|
std::cout<<"match file not exists."<<std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if(!QFileInfo::exists(exceptionFile))
|
2015-01-15 21:56:30 +08:00
|
|
|
{
|
2015-01-16 16:27:05 +08:00
|
|
|
std::cout<<"match file not exists."<<std::endl;
|
2015-01-15 21:56:30 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
2015-01-16 16:27:05 +08:00
|
|
|
|
2015-01-15 21:56:30 +08:00
|
|
|
if(!this->readMatch(matchdDir))
|
|
|
|
|
{
|
2015-01-16 16:27:05 +08:00
|
|
|
std::cout<<"read match failed"<<std::endl;
|
2015-01-15 21:56:30 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
2015-01-16 16:27:05 +08:00
|
|
|
this->loadMatchException.init(exceptionFile);
|
|
|
|
|
|
2015-01-15 21:56:30 +08:00
|
|
|
if(!this->readLoads(loadDir))
|
2015-01-15 20:05:44 +08:00
|
|
|
{
|
2015-01-16 16:27:05 +08:00
|
|
|
std::cout<<"read load failed"<<std::endl;
|
2015-01-15 20:05:44 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
2015-01-16 16:27:05 +08:00
|
|
|
|
2015-01-15 21:56:30 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LoadMapping::readLoads(const QString &dir)
|
|
|
|
|
{
|
|
|
|
|
RecurseDir recurseDir;
|
|
|
|
|
recurseDir.setDir((dir));
|
|
|
|
|
QStringList filePathList=recurseDir.getFiles();
|
|
|
|
|
foreach(QString filePath,filePathList)
|
|
|
|
|
{
|
|
|
|
|
QFileInfo fileInfo(filePath);
|
|
|
|
|
if(!fileInfo.exists())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QString suffix;
|
|
|
|
|
suffix=fileInfo.suffix();
|
|
|
|
|
if(suffix.toLower()!="csv")
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
QString fileName=fileInfo.baseName();
|
2015-01-16 16:27:05 +08:00
|
|
|
|
|
|
|
|
if(this->loadMatchException.contains(fileName))
|
|
|
|
|
{
|
|
|
|
|
std::cout<<"ignore "<<fileName.toLocal8Bit().data()<<std::endl;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-01-16 21:21:29 +08:00
|
|
|
if(!this->loadsToLoadInfo->contains(fileName))
|
2015-01-15 21:56:30 +08:00
|
|
|
{
|
|
|
|
|
std::cout<<filePath.toLocal8Bit().data()<<" no match."<<std::endl;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-01-16 21:21:29 +08:00
|
|
|
QSharedPointer<LoadInfo> loadInfo=(*this->loadsToLoadInfo)[fileName];
|
2015-01-15 21:56:30 +08:00
|
|
|
loadInfo->setLoadPath(filePath);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LoadMapping::readMatch(const QString& dir)
|
|
|
|
|
{
|
2015-01-15 20:05:44 +08:00
|
|
|
RecurseDir recurseDir;
|
|
|
|
|
recurseDir.setDir((dir));
|
|
|
|
|
QStringList filePathList=recurseDir.getFiles();
|
|
|
|
|
foreach(QString filePath,filePathList)
|
|
|
|
|
{
|
|
|
|
|
QFileInfo fileInfo(filePath);
|
|
|
|
|
if(!fileInfo.exists())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QString suffix;
|
|
|
|
|
suffix=fileInfo.suffix();
|
|
|
|
|
if(suffix.toLower()!="csv")
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
QFile file(filePath);
|
|
|
|
|
QString line;
|
|
|
|
|
QStringList sep;
|
|
|
|
|
if(file.open(QFile::ReadOnly))
|
|
|
|
|
{
|
|
|
|
|
QTextStream reader(&file);
|
|
|
|
|
while(!reader.atEnd())
|
|
|
|
|
{
|
|
|
|
|
line=reader.readLine().trimmed();
|
|
|
|
|
sep=line.split(',');
|
|
|
|
|
if(sep.length()<2)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
QString SFDid;
|
2015-01-15 21:56:30 +08:00
|
|
|
QRegExp regExp("\\(.*\\)");
|
2015-01-15 20:05:44 +08:00
|
|
|
SFDid=sep.at(0);
|
2015-01-15 21:56:30 +08:00
|
|
|
SFDid=SFDid.replace(regExp,"");
|
|
|
|
|
QVector<QSharedPointer<LoadInfo> > loads;
|
2015-01-15 20:05:44 +08:00
|
|
|
for(int i=1;i<sep.length();i++)
|
|
|
|
|
{
|
2015-01-15 21:56:30 +08:00
|
|
|
QSharedPointer<LoadInfo> t(new LoadInfo);
|
|
|
|
|
t->setLoadName(sep.at(i));
|
|
|
|
|
loads.push_back(t);
|
2015-01-16 21:21:29 +08:00
|
|
|
(*this->loadsToLoadInfo)[sep.at(i)]=t;
|
2015-01-15 20:05:44 +08:00
|
|
|
}
|
2015-01-16 21:21:29 +08:00
|
|
|
(*this->loads)[SFDid]=loads;
|
2015-01-15 20:05:44 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
file.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|