加了更新LoadInfo负荷的功能。

Signed-off-by: dmy@lab <dmy@lab.lab>
This commit is contained in:
dmy@lab 2015-01-16 18:08:01 +08:00
parent 491f5e2276
commit 56da69b835
3 changed files with 147 additions and 8 deletions

View File

@ -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;
}

View File

@ -2,20 +2,38 @@
#define LOADINFO_H
#include <QString>
#include <QTime>
#include <QFile>
#include <QTextStream>
#include <QRegExp>
#include <cmath>
#include <QPair>
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<double,double> pqA;
QPair<double,double> pqB;
QPair<double,double> pqC;
QPair<double,double> getPQ(double current);
};
#endif // LOADINFO_H

View File

@ -4,12 +4,16 @@
#include "task.h"
#include <iostream>
#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<<loadInfo.getPA()<<std::endl;
// ReadWrite aa;
// RegexExtract re;
// re.extract("D:/Project/佛山项目/数据/df8003/df8600/exportfiles/exportmodel_pw.xml");