1.如果负荷路径为空就不打开。
2.把所有负荷24时段输出到一个文件中。 Signed-off-by: dmy@lab <dmy@lab.lab>
This commit is contained in:
71
testHasttable/special/loadexporter.cpp
Normal file
71
testHasttable/special/loadexporter.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "loadexporter.h"
|
||||
#include <iostream>
|
||||
LoadExporter::LoadExporter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LoadExporter::~LoadExporter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LoadExporter::add(const QString& fileName, QSharedPointer<LoadInfo> loadInfo)
|
||||
{
|
||||
this->ht.add(fileName,loadInfo);
|
||||
// if(loadInfo->getLoadPath().trimmed().length()==0)
|
||||
// {
|
||||
// std::cout<<"fd"<<std::endl;
|
||||
// }
|
||||
}
|
||||
|
||||
void LoadExporter::toSingleFile(const QString& filePath)
|
||||
{
|
||||
//先按时间形成一个List
|
||||
QHash<QString,QList<QPair<double,double> > > loadSequence;
|
||||
//24个时段
|
||||
for(int i=0;i<24;i++)
|
||||
{
|
||||
QTime time(i,0);
|
||||
this->updateByTime(time);
|
||||
QStringList keys;
|
||||
keys=this->ht.keys();
|
||||
foreach(QString key, keys)
|
||||
{
|
||||
QSharedPointer<LoadInfo> p=this->ht.get(key);
|
||||
double P=p->getPA()+p->getPB()+p->getPC();
|
||||
double Q=p->getQA()+p->getQB()+p->getQC();
|
||||
loadSequence[key].push_back(QPair<double,double>(P,Q) );
|
||||
}
|
||||
}
|
||||
|
||||
QFile file(filePath);
|
||||
if(file.open(QFile::WriteOnly))
|
||||
{
|
||||
QTextStream stream(&file);
|
||||
QStringList keys;
|
||||
keys=loadSequence.keys();
|
||||
foreach(QString key, keys)
|
||||
{
|
||||
stream<<key<<",";
|
||||
QList<QPair<double,double> > loadList=loadSequence[key];
|
||||
int seq=0;
|
||||
for(QList<QPair<double,double> >::iterator ite=loadList.begin();ite!=loadList.end();ite++)
|
||||
{
|
||||
stream<<"["<<seq++<<"]"<<"("<<ite->first<<"&&"<<ite->second<<")"<<",";
|
||||
}
|
||||
stream<<"\t\n";
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"cannot create file to export load."<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void LoadExporter::updateByTime(const QTime &time)
|
||||
{
|
||||
LoadMapping loadMapping;
|
||||
loadMapping.broadcastUpdateByTime(time);
|
||||
}
|
||||
33
testHasttable/special/loadexporter.h
Normal file
33
testHasttable/special/loadexporter.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef LOADEXPORTER_H
|
||||
#define LOADEXPORTER_H
|
||||
#include "loadinfo.h"
|
||||
#include "singletonbase.h"
|
||||
#include "loadmapping.h"
|
||||
//把所有按潘国超的要求输出到一个文件中。2015.02.5
|
||||
|
||||
#include <QString>
|
||||
#include <QSharedPointer>
|
||||
#include <QTime>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QStringList>
|
||||
#include <QList>
|
||||
#include <QHash>
|
||||
#include <QPair>
|
||||
|
||||
class LoadExporter
|
||||
{
|
||||
class HT_TYPE:public SingletonBase<QString,QSharedPointer<LoadInfo>,HT_TYPE >
|
||||
{};
|
||||
public:
|
||||
LoadExporter();
|
||||
~LoadExporter();
|
||||
void add(const QString &fileName, QSharedPointer<LoadInfo> loadInfo);
|
||||
void toSingleFile(const QString& filePath);
|
||||
void updateByTime(const QTime &time);
|
||||
private:
|
||||
HT_TYPE ht;
|
||||
|
||||
};
|
||||
|
||||
#endif // LOADEXPORTER_H
|
||||
Reference in New Issue
Block a user