diff --git a/testHasttable/loadinfo.cpp b/testHasttable/loadinfo.cpp index c2ba62e..875193a 100644 --- a/testHasttable/loadinfo.cpp +++ b/testHasttable/loadinfo.cpp @@ -1,6 +1,6 @@ #include "loadinfo.h" - -LoadInfo::LoadInfo() +#include +LoadInfo::LoadInfo(double powerFactor):powerFactor(powerFactor) { } @@ -18,6 +18,56 @@ 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,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 pqA=this->getPQ(CurrentA); + QPair pqB=this->getPQ(CurrentB); + QPair pqC=this->getPQ(CurrentC); + this->pqA=pqA; + this->pqB=pqB; + this->pqC=pqC; + ret=true; + break; + } + + + } + file.close(); + } + else + { + std::cout< +#include +#include +#include +#include +#include +#include class LoadInfo { public: - explicit LoadInfo(); + explicit LoadInfo(double powerFactor=0.95); ~LoadInfo(); QString getLoadName(); QString getLoadPath(); void setLoadName(const QString &name); void setLoadPath(const QString &path); + bool updateByTime(const QTime& time); + double getPA(); + double getPB(); + double getPC(); + double getQA(); + double getQB(); + double getQC(); private: - + bool isStartWithTime(const QString& str); + QString trimDoubleQuotation(const QString& str); QString loadName; QString loadPath; - + double powerFactor; + QPair pqA; + QPair pqB; + QPair pqC; + QPair getPQ(double current); }; #endif // LOADINFO_H diff --git a/testHasttable/main.cpp b/testHasttable/main.cpp index 3484803..8b198cc 100644 --- a/testHasttable/main.cpp +++ b/testHasttable/main.cpp @@ -4,12 +4,16 @@ #include "task.h" #include #include "loadmapping.h" +#include "loadinfo.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); - LoadMapping lm; - lm.load("D:/Project/佛山项目/数据/搭网架参数文件/泰安/泰安负荷","D:/Project/佛山项目/数据/匹配的数据","D:/Project/佛山项目/数据/exception.txt"); - +// LoadMapping lm; +// lm.load("D:/Project/佛山项目/数据/搭网架参数文件/泰安/泰安负荷","D:/Project/佛山项目/数据/匹配的数据","D:/Project/佛山项目/数据/exception.txt"); + LoadInfo loadInfo; + loadInfo.setLoadPath("D:/Project/佛山项目/数据/搭网架参数文件/泰安/泰安负荷/718发展线/专变/威灵电机工业园电房1.csv"); + loadInfo.updateByTime(QTime(0,15,0)); + std::cout<