1.重新组织了文件。
2.准备试试把所有元素都读入内存中。 Signed-off-by: facat@lab.com <facat@lab.com>
This commit is contained in:
24
cimparser/cimparser.pro
Normal file
24
cimparser/cimparser.pro
Normal file
@@ -0,0 +1,24 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2014-11-21T17:41:46
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core
|
||||
|
||||
QT -= gui
|
||||
|
||||
TARGET = cimparser
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
|
||||
SOURCES += main.cpp \
|
||||
cimparserbatch.cpp \
|
||||
derivedqthread.cpp
|
||||
|
||||
HEADERS += \
|
||||
cimparserbatch.h \
|
||||
derivedqthread.h
|
||||
317
cimparser/cimparserbatch.cpp
Normal file
317
cimparser/cimparserbatch.cpp
Normal file
@@ -0,0 +1,317 @@
|
||||
#include "cimparserbatch.h"
|
||||
#include "derivedqthread.h"
|
||||
#include <QtDebug>
|
||||
int callmain(char *arg);
|
||||
CIMParserBatch::CIMParserBatch()
|
||||
{
|
||||
}
|
||||
|
||||
void CIMParserBatch::parser(const QString& dir, const QString &scadaDataFilePath)
|
||||
{
|
||||
QDir qdir(dir);
|
||||
QStringList filter;
|
||||
filter<<"*";
|
||||
this->mdirList=qdir.entryInfoList(filter,QDir::NoDotAndDotDot | QDir::AllDirs);
|
||||
this->mite=this->mdirList.constBegin();//后面会用到,就是dir文件下的所有文件
|
||||
this->ReadscadaData(scadaDataFilePath);
|
||||
//this->ExecuteParserApp(NULL);
|
||||
//this->GenerateBatchFile("c:/parser.bat");
|
||||
this->CallFunParser();
|
||||
}
|
||||
|
||||
QString CIMParserBatch::FindXML(const QString& dir)
|
||||
{
|
||||
|
||||
QDir qdir(dir);
|
||||
QStringList filter;
|
||||
filter<<"*.xml";
|
||||
QFileInfoList xmlList;
|
||||
xmlList=qdir.entryInfoList(filter);
|
||||
if(xmlList.size()>1)
|
||||
{
|
||||
std::cout<<dir.toStdString()<<"has more than one xml file."<<std::endl;
|
||||
return "";
|
||||
}
|
||||
if(xmlList.size()==0)
|
||||
{
|
||||
std::cout<<"could not find any xml in "<<dir.toStdString()<<std::endl;
|
||||
return "";
|
||||
}
|
||||
return xmlList.at(0).absoluteFilePath();
|
||||
}
|
||||
|
||||
void CIMParserBatch::ExecuteParserApp(QThread *thread)
|
||||
{
|
||||
if(thread!=NULL)
|
||||
{
|
||||
thread->deleteLater();
|
||||
//先把上一次解析得到的文件拷回去
|
||||
QFileInfoList fileList=this->FindiPsoPrefixedFile("c:/parser");
|
||||
QFileInfo info;
|
||||
info=*(this->mite);//原始文件的路径
|
||||
if(fileList.size()<6)
|
||||
{
|
||||
|
||||
std::cout<<info.baseName().toStdString()<<"parsed, but got fewer files."<<std::endl;
|
||||
}
|
||||
QString fileName;
|
||||
QString desFilePath;
|
||||
fileName=info.fileName();//原始文件的文件名,其实是文件夹名
|
||||
desFilePath=info.absoluteFilePath();
|
||||
desFilePath.replace('/','\\');
|
||||
QString parseFileName;
|
||||
QFileInfo parseFileInfo;
|
||||
QString transNoLoad;
|
||||
QString parsedFile;//计算文件
|
||||
for(QFileInfoList::const_iterator ite=fileList.constBegin();
|
||||
ite!=fileList.constEnd();
|
||||
ite++
|
||||
)
|
||||
{
|
||||
parseFileInfo=*ite;
|
||||
parseFileName=parseFileInfo.fileName();
|
||||
|
||||
if(parseFileName.contains("TransformerNoLoad"))
|
||||
{
|
||||
transNoLoad=desFilePath+"\\iPso_"+fileName+"_TransformerNoLoad.txt";
|
||||
QFile::remove(transNoLoad);
|
||||
QFile::copy(parseFileInfo.absoluteFilePath(),transNoLoad);
|
||||
continue;
|
||||
}
|
||||
if(parseFileName.contains("TransformerNoResistance"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(parseFileName.contains("TransformerInfor"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(parseFileName.contains("LineInfor"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(parseFileName.contains("lineZeroResistance"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
parsedFile=desFilePath+"\\iPso_"+fileName+".txt";
|
||||
QFile::remove(parsedFile);
|
||||
QFile::copy(parseFileInfo.absoluteFilePath(),parsedFile);//TODO:这里会多拷贝一次
|
||||
//开始安放pqi.txt文件
|
||||
QFile::remove(desFilePath+"\\pqi.txt");
|
||||
QFile pqi(desFilePath+"\\pqi.txt");
|
||||
QString lineName;
|
||||
if(pqi.open(QIODevice::WriteOnly))
|
||||
{
|
||||
lineName=fileName.section('_',0,0);
|
||||
|
||||
if(this->mScada.contains(lineName))
|
||||
{
|
||||
QTextStream stream(&pqi);
|
||||
FeederData feederData=this->mScada[lineName];
|
||||
stream<<feederData.p<<" "<<feederData.q<<" "<<0<<endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"pqi of "<<lineName.toStdString()<<" not found."<<std::endl;
|
||||
}
|
||||
pqi.close();
|
||||
}
|
||||
|
||||
}
|
||||
this->mite++;
|
||||
|
||||
|
||||
}
|
||||
if(this->mite==this->mdirList.constEnd())
|
||||
{
|
||||
std::cout<<"job finished."<<std::endl;
|
||||
return;
|
||||
}
|
||||
QString xmlFile;
|
||||
QString dir;//有xml文件的dir
|
||||
QFileInfo fileInfo=*(this->mite);
|
||||
dir=fileInfo.absoluteFilePath();
|
||||
xmlFile=this->FindXML(dir);
|
||||
if(xmlFile=="")
|
||||
{
|
||||
return;
|
||||
}
|
||||
QFile::remove("c:/parser/parser.xml");
|
||||
QFile::copy(xmlFile,"c:/parser/parser.xml");
|
||||
std::cout<<"prepare to parse "<<xmlFile.toStdString()<<std::endl;
|
||||
QFileInfo sizeInfo;
|
||||
DerivedQThread *_thread;
|
||||
sizeInfo=QFileInfo(xmlFile);
|
||||
_thread=new DerivedQThread("E:/lineloss/console/run.bat c:/parser/parser.xml",this);
|
||||
_thread->connect(_thread,SIGNAL(finishedptr(QThread*)),this,SLOT(ExecuteParserApp(QThread*)));
|
||||
_thread->start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
QFileInfoList CIMParserBatch::FindiPsoPrefixedFile(const QString& dir)
|
||||
{
|
||||
QDir qdir(dir);
|
||||
QStringList filter;
|
||||
filter<<"iPso_*";
|
||||
return qdir.entryInfoList(filter);//如果找不到iPso开头的文件,返回的QFileInfoList长度为0。
|
||||
}
|
||||
void CIMParserBatch::ReadscadaData(const QString& dataPath)
|
||||
{
|
||||
QString line;
|
||||
QStringList sep;
|
||||
QFile file(dataPath);
|
||||
if(file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QTextStream stream(&file);
|
||||
while(!stream.atEnd())
|
||||
{
|
||||
line=stream.readLine();
|
||||
line=line.simplified();
|
||||
line.trimmed();
|
||||
sep=line.split(' ');
|
||||
if(sep.size()<3)
|
||||
{
|
||||
std::cout<<"scada file format error!"<<std::endl;
|
||||
qApp->exit();
|
||||
}
|
||||
FeederData feederData;
|
||||
feederData.p=sep.at(1).toDouble();
|
||||
feederData.q=sep.at(2).toDouble();
|
||||
this->mScada.insert(sep.at(0),feederData);
|
||||
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"scada File not open. This file may not exist."<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void CIMParserBatch::GenerateBatchFile(const QString& batFilePath)
|
||||
{
|
||||
QFile bat(batFilePath);
|
||||
QString fullFilePath;
|
||||
QFileInfo info;
|
||||
QString xmlFile;
|
||||
if(bat.open(QIODevice::WriteOnly))
|
||||
{
|
||||
QTextStream stream(&bat);
|
||||
while(this->mite!=this->mdirList.constEnd())
|
||||
{
|
||||
info=*(this->mite);
|
||||
fullFilePath=info.absoluteFilePath();
|
||||
xmlFile=this->FindXML(fullFilePath);
|
||||
//stream<<"call ";
|
||||
stream<<"E:/lineloss/console/readxml1.exe ";
|
||||
stream<<xmlFile<<"\n\r";
|
||||
this->mite++;
|
||||
}
|
||||
bat.close();
|
||||
}
|
||||
std::cout<<"job finished."<<std::endl;
|
||||
}
|
||||
|
||||
void CIMParserBatch::CallFunParser()
|
||||
{
|
||||
while(this->mite!=this->mdirList.constEnd())
|
||||
{
|
||||
|
||||
QString xmlFile;
|
||||
QString dir;//有xml文件的dir
|
||||
QFileInfo fileInfo=*(this->mite);
|
||||
dir=fileInfo.absoluteFilePath();
|
||||
xmlFile=this->FindXML(dir);
|
||||
if(xmlFile=="")
|
||||
{
|
||||
return;
|
||||
}
|
||||
//QFile::remove("c:/parser/parser.xml");
|
||||
//QFile::copy(xmlFile,"c:/parser/parser.xml");
|
||||
std::cout<<"prepare to parse "<<xmlFile.toLocal8Bit().data()<<std::endl;
|
||||
//qDebug()<<xmlFile<<"\n";
|
||||
callmain(const_cast<char *>(xmlFile.toStdString().c_str()));
|
||||
//先把上一次解析得到的文件拷回去
|
||||
//QFileInfoList fileList=this->FindiPsoPrefixedFile("c:/parser");
|
||||
QFileInfo info(xmlFile);
|
||||
// info=*(this->mite);//原始文件的路径
|
||||
// if(fileList.size()<6)
|
||||
// {
|
||||
|
||||
// std::cout<<info.baseName().toStdString()<<"parserd, but got fewer files."<<std::endl;
|
||||
// }
|
||||
// QString fileName;
|
||||
QString desFilePath;
|
||||
desFilePath=info.absolutePath();
|
||||
// fileName=info.fileName();//原始文件的文件名,其实是文件夹名
|
||||
// desFilePath=info.absoluteFilePath();
|
||||
desFilePath.replace('/','\\');
|
||||
// QString parseFileName;
|
||||
// QFileInfo parseFileInfo;
|
||||
// QString transNoLoad;
|
||||
// QString parsedFile;//计算文件
|
||||
// for(QFileInfoList::const_iterator ite=fileList.constBegin();
|
||||
// ite!=fileList.constEnd();
|
||||
// ite++
|
||||
// )
|
||||
// {
|
||||
// parseFileInfo=*ite;
|
||||
// parseFileName=parseFileInfo.fileName();
|
||||
|
||||
// if(parseFileName.contains("变压器无负载"))
|
||||
// {
|
||||
// transNoLoad=desFilePath+"\\iPso_"+fileName+"_变压器无负载.txt";
|
||||
// QFile::remove(transNoLoad);
|
||||
// QFile::copy(parseFileInfo.absoluteFilePath(),transNoLoad);
|
||||
// continue;
|
||||
// }
|
||||
// if(parseFileName.contains("变压器无阻抗"))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// if(parseFileName.contains("变压器信息"))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// if(parseFileName.contains("线路信息"))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// if(parseFileName.contains("线路零阻抗"))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// parsedFile=desFilePath+"\\iPso_"+fileName+".txt";
|
||||
// QFile::remove(parsedFile);
|
||||
// QFile::copy(parseFileInfo.absoluteFilePath(),parsedFile);//TODO:这里会多拷贝一次
|
||||
//开始安放pqi.txt文件
|
||||
QFile::remove(desFilePath+"\\pqi.txt");
|
||||
QFile pqi(desFilePath+"\\pqi.txt");
|
||||
QString lineName;
|
||||
lineName=info.fileName();
|
||||
if(pqi.open(QIODevice::WriteOnly))
|
||||
{
|
||||
lineName=lineName.section('_',0,0);
|
||||
|
||||
if(this->mScada.contains(lineName))
|
||||
{
|
||||
QTextStream stream(&pqi);
|
||||
FeederData feederData=this->mScada[lineName];
|
||||
stream<<feederData.p<<" "<<feederData.q<<" "<<0<<endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"pqi of "<<lineName.toStdString()<<" not found."<<std::endl;
|
||||
}
|
||||
pqi.close();
|
||||
}
|
||||
this->mite++;
|
||||
}
|
||||
|
||||
|
||||
std::cout<<"job finished."<<std::endl;
|
||||
}
|
||||
34
cimparser/cimparserbatch.h
Normal file
34
cimparser/cimparserbatch.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef CIMPARSERBATCH_H
|
||||
#define CIMPARSERBATCH_H
|
||||
#include <QtCore>
|
||||
#include <QDir>
|
||||
#include <QStringList>
|
||||
#include <iostream>
|
||||
#include <QFile>
|
||||
#include <QObject>
|
||||
class CIMParserBatch:public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
typedef struct
|
||||
{
|
||||
double p;
|
||||
double q;
|
||||
}FeederData;
|
||||
CIMParserBatch();
|
||||
void parser(const QString& dir,const QString& scadaDataFilePath);
|
||||
private:
|
||||
QString FindXML(const QString& dir);//返回的是绝对路径
|
||||
QFileInfoList FindiPsoPrefixedFile(const QString& dir);//得到那些解析得到的文体局,是有前缀的。
|
||||
void ReadscadaData(const QString& dataPath);
|
||||
void GenerateBatchFile(const QString& batFilePath);//直接生成一个bat文件算了。
|
||||
void CallFunParser();
|
||||
private slots:
|
||||
void ExecuteParserApp(QThread *);
|
||||
private:
|
||||
QFileInfoList::const_iterator mite;//parser函数里用的
|
||||
QFileInfoList mdirList;
|
||||
QHash<QString,FeederData> mScada;
|
||||
};
|
||||
|
||||
#endif // CIMPARSERBATCH_H
|
||||
30
cimparser/derivedqthread.cpp
Normal file
30
cimparser/derivedqthread.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "derivedqthread.h"
|
||||
#include <QDebug>
|
||||
int callmain(char *args);
|
||||
DerivedQThread::DerivedQThread(const QString &exe, QObject *parent) :
|
||||
QThread(parent),mExe(exe)
|
||||
{
|
||||
connect(this,SIGNAL(finished()),this,SLOT(customedfinished()));
|
||||
}
|
||||
|
||||
void DerivedQThread::run()
|
||||
{
|
||||
QDateTime dateTime;
|
||||
QTime second;
|
||||
dateTime=QDateTime::currentDateTime();
|
||||
second=QTime::currentTime();
|
||||
QString id;
|
||||
id=dateTime.toString();
|
||||
id+=QString::number(second.second());
|
||||
id+=QString::number(second.msec());
|
||||
this->mid=QCryptographicHash::hash ( id.toLatin1(), QCryptographicHash::Md5 ).toHex();
|
||||
//QProcess::execute(this->mExe);
|
||||
//char s;
|
||||
//std::string exe=this->mExe.toStdString();
|
||||
callmain("c:/parser/parser.xml");
|
||||
}
|
||||
|
||||
void DerivedQThread::customedfinished()
|
||||
{
|
||||
emit this->finishedptr(this);
|
||||
}
|
||||
28
cimparser/derivedqthread.h
Normal file
28
cimparser/derivedqthread.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef DERIVEDQTHREAD_H
|
||||
#define DERIVEDQTHREAD_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QProcess>
|
||||
#include <QThread>
|
||||
#include <QDateTime>
|
||||
#include <QCryptographicHash>
|
||||
class DerivedQThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DerivedQThread(const QString &exe, QObject *parent = 0);
|
||||
void run();
|
||||
public:
|
||||
QString mid;
|
||||
protected:
|
||||
QString mExe;
|
||||
|
||||
|
||||
signals:
|
||||
void finishedptr(QThread *);
|
||||
protected slots:
|
||||
void customedfinished();
|
||||
|
||||
};
|
||||
|
||||
#endif // DERIVEDQTHREAD_H
|
||||
18
cimparser/main.cpp
Normal file
18
cimparser/main.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <QCoreApplication>
|
||||
#include "cimparserbatch.h"
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
// QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GBK"));
|
||||
// QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
|
||||
// QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));
|
||||
CIMParserBatch batch;
|
||||
batch.parser("C:/4","C:/200027_.txt");
|
||||
//batch.parser("C:/20","C:/scada/040039_.txt");
|
||||
//batch.parser("C:/20","C:/scada/080004_.txt");
|
||||
//batch.parser("C:/20","C:/scada/120001_.txt");
|
||||
//batch.parser("C:/20","C:/scada/160020_.txt");
|
||||
//batch.parser("C:/20","C:/scada/200027_.txt");
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user