cimforreduceloss/testHasttable/special/loadexporter.cpp

72 lines
1.8 KiB
C++
Raw Permalink Normal View History

#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->get3PhP();//p->getPA()+p->getPB()+p->getPC();
double Q=p->get3PhQ();//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);
}