180 lines
4.3 KiB
C++
180 lines
4.3 KiB
C++
#include "loadinfo.h"
|
||
#include <iostream>
|
||
LoadInfo::LoadInfo(double powerFactor):powerFactor(powerFactor)
|
||
{
|
||
|
||
this->pqA=QPair<double,double>(0,0);
|
||
this->pqB=QPair<double,double>(0,0);
|
||
this->pqC=QPair<double,double>(0,0);
|
||
this->ph3P=0;
|
||
this->ph3Q=0;
|
||
}
|
||
|
||
LoadInfo::~LoadInfo()
|
||
{
|
||
|
||
}
|
||
|
||
QString LoadInfo::getLoadName()
|
||
{
|
||
return this->loadName;
|
||
}
|
||
QString LoadInfo::getLoadPath()
|
||
{
|
||
return this->loadPath;
|
||
}
|
||
|
||
QPair<double,double> LoadInfo::getPQ(double current)
|
||
{
|
||
//将电流转换为负荷.
|
||
//应该是400V侧电流
|
||
double c=std::acos(this->powerFactor);
|
||
double S=0.4*current;//单位kvA
|
||
double p=std::cos(c)*S;
|
||
double q=std::sin(c)*S;
|
||
return QPair<double,double>(p/1000,q/1000);//返回的是标幺值,基准容量是1MVA
|
||
}
|
||
|
||
double LoadInfo::get3PhP()
|
||
{
|
||
// std::cout<<"get p "<<this->ph3P<<std::endl;
|
||
return this->ph3P;
|
||
}
|
||
|
||
double LoadInfo::get3PhQ()
|
||
{
|
||
// std::cout<<"get q "<<this->ph3Q<<std::endl;
|
||
return this->ph3Q;
|
||
}
|
||
|
||
double LoadInfo::getPA()
|
||
{
|
||
return this->pqA.first;
|
||
}
|
||
double LoadInfo::getPB()
|
||
{
|
||
return this->pqB.first;
|
||
}
|
||
double LoadInfo::getPC()
|
||
{
|
||
return this->pqC.first;
|
||
}
|
||
double LoadInfo::getQA()
|
||
{
|
||
return this->pqA.second;
|
||
}
|
||
double LoadInfo::getQB()
|
||
{
|
||
return this->pqB.second;
|
||
}
|
||
double LoadInfo::getQC()
|
||
{
|
||
return this->pqC.second;
|
||
}
|
||
|
||
bool LoadInfo::isStartWithTime(const QString& str)
|
||
{
|
||
QString sub=str.section(';',0,0);
|
||
if(sub.trimmed().length()==0)
|
||
{
|
||
return false;
|
||
}
|
||
//2014-07-30 00:45:00
|
||
QRegExp regExp("\"\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\"");
|
||
return regExp.exactMatch(sub);
|
||
}
|
||
|
||
|
||
void LoadInfo::setLoadName(const QString &name)
|
||
{
|
||
this->loadName=name;
|
||
}
|
||
void LoadInfo::setLoadPath(const QString &path)
|
||
{
|
||
this->loadPath=path;
|
||
}
|
||
|
||
QString LoadInfo::trimDoubleQuotation(const QString& str)
|
||
{
|
||
return QString(str).replace("\"","").replace("\"","");
|
||
}
|
||
|
||
bool LoadInfo::updateByTime(const QTime& time)
|
||
{
|
||
QString filePath;
|
||
filePath=this->loadPath;
|
||
QFile file(filePath);
|
||
QString line;
|
||
QStringList sep;
|
||
bool ret=false;
|
||
if(file.open(QFile::ReadOnly))
|
||
{
|
||
QTextStream reader(&file);
|
||
while(!reader.atEnd())
|
||
{
|
||
line=reader.readLine().trimmed();
|
||
if(!this->isStartWithTime(line))
|
||
{
|
||
continue;
|
||
}
|
||
sep=line.split(';');
|
||
QString date;
|
||
date=this->trimDoubleQuotation(sep.at(0));
|
||
QString dataTimeStr;
|
||
dataTimeStr=date.section(' ',1,1);
|
||
QTime dataTime;
|
||
dataTime=QTime::fromString(dataTimeStr,"hh:mm:ss");
|
||
if(std::abs(dataTime.secsTo(time))<5)
|
||
{
|
||
//开始读负荷
|
||
bool okA,okB,okC;
|
||
okA=-1;
|
||
okB=-1;
|
||
okC=-1;
|
||
double CurrentA=this->trimDoubleQuotation(sep.at(1)).toDouble(&okA);
|
||
double CurrentB=this->trimDoubleQuotation(sep.at(2)).toDouble(&okB);
|
||
double CurrentC=this->trimDoubleQuotation(sep.at(3)).toDouble(&okC);
|
||
if(!(okA&&okB&&okC))
|
||
{
|
||
ret=false;
|
||
break;
|
||
}
|
||
QPair<double,double> pqA=this->getPQ(CurrentA);
|
||
QPair<double,double> pqB=this->getPQ(CurrentB);
|
||
QPair<double,double> pqC=this->getPQ(CurrentC);
|
||
this->pqA=pqA;
|
||
this->pqB=pqB;
|
||
this->pqC=pqC;
|
||
bool ok3PhP;
|
||
bool ok3PhQ;
|
||
this->ph3P=this->trimDoubleQuotation(sep.at(5)).toDouble(&ok3PhP);
|
||
if(!ok3PhP)
|
||
{
|
||
this->ph3P=0;
|
||
}
|
||
// std::cout<<"nb "<<sep.at(5).toStdString()<<std::endl;
|
||
// std::cout<<this->ph3P<<std::endl;
|
||
this->ph3Q=this->trimDoubleQuotation(sep.at(6)).toDouble(&ok3PhQ);
|
||
if(!ok3PhQ)
|
||
{
|
||
this->ph3Q=0;
|
||
}
|
||
// std::cout<<"nb "<<sep.at(6).toStdString()<<std::endl;
|
||
// std::cout<<this->ph3Q<<std::endl;
|
||
ret=true;
|
||
break;
|
||
}
|
||
|
||
|
||
}
|
||
file.close();
|
||
}
|
||
else
|
||
{
|
||
std::cout<<filePath.toLocal8Bit().data()<<"update by time not open->"<<filePath.toLocal8Bit().data() <<std::endl;
|
||
}
|
||
return ret;
|
||
|
||
}
|
||
|