#include "loadinfo.h" #include LoadInfo::LoadInfo(double powerFactor):powerFactor(powerFactor) { this->pqA=QPair(0,0); this->pqB=QPair(0,0); this->pqC=QPair(0,0); this->ph3P=0; this->ph3Q=0; } LoadInfo::~LoadInfo() { } QString LoadInfo::getLoadName() { return this->loadName; } QString LoadInfo::getLoadPath() { return this->loadPath; } QPair 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(p/1000,q/1000);//返回的是标幺值,基准容量是1MVA } double LoadInfo::get3PhP() { // std::cout<<"get p "<ph3P<ph3P; } double LoadInfo::get3PhQ() { // std::cout<<"get q "<ph3Q<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 pqA=this->getPQ(CurrentA); QPair pqB=this->getPQ(CurrentB); QPair 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; } else { this->ph3P/=1000;//转换为标幺值 } // std::cout<<"nb "<ph3P<ph3Q=this->trimDoubleQuotation(sep.at(6)).toDouble(&ok3PhQ); if(!ok3PhQ) { this->ph3Q=0; } else { this->ph3Q/=1000; } // std::cout<<"nb "<ph3Q<"<