@@ -1,6 +1,6 @@
|
||||
#include "loadinfo.h"
|
||||
|
||||
LoadInfo::LoadInfo()
|
||||
#include <iostream>
|
||||
LoadInfo::LoadInfo(double powerFactor):powerFactor(powerFactor)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -18,6 +18,56 @@ 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,q);
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -27,3 +77,70 @@ 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;
|
||||
ret=true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<filePath.toLocal8Bit().data()<<"not open"<<std::endl;
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user