添加检测数据导出为XML,读取XML文件统计平均值的功能输出到产量统计的功能
parent
aa9e765f26
commit
fc3e8de896
@ -0,0 +1,178 @@
|
||||
#include "exportData.h"
|
||||
#include "QtCore\qfile.h"
|
||||
#include "QtCore\qtextstream.h"
|
||||
#include<string>
|
||||
|
||||
extern SyncQueue<_ExportDataInfo>* export_Data_Info_queue;
|
||||
|
||||
ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent)
|
||||
{
|
||||
char xmlPath[256];
|
||||
for (int index = 0; index < NumberOfSupportedCameras; index++)
|
||||
{
|
||||
XMLError error;
|
||||
pDocument[index] = new XMLDocument();
|
||||
memset(xmlPath, 0, 256);
|
||||
sprintf(xmlPath, EXPORTDATA_FILE, index);
|
||||
error = pDocument[index]->LoadFile(xmlPath);
|
||||
if (error != XML_SUCCESS)
|
||||
{
|
||||
XMLDeclaration* declaration = pDocument[index]->NewDeclaration();
|
||||
pDocument[index]->InsertFirstChild(declaration);
|
||||
XMLElement* root = pDocument[0]->NewElement("Root");
|
||||
pDocument[0]->InsertEndChild(root);
|
||||
pDocument[index]->SaveFile(xmlPath);
|
||||
}
|
||||
/*
|
||||
_ExportDataInfo data;
|
||||
data.cameraId = index;
|
||||
data.cameraTotal = 3;
|
||||
data.timeCost = "3ms";
|
||||
insertXMLNode(xmlPath, data);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
void ExportDataThread::init()
|
||||
{
|
||||
b_quit = false;
|
||||
}
|
||||
|
||||
void ExportDataThread::start_work()
|
||||
{
|
||||
start(HighestPriority);
|
||||
}
|
||||
|
||||
void ExportDataThread::stop()
|
||||
{
|
||||
b_quit = true;
|
||||
_ExportDataInfo data;
|
||||
export_Data_Info_queue->put(data);
|
||||
}
|
||||
|
||||
bool _ExportDataInfo::getAverageData(map<string, float> &averageData, int index)
|
||||
{
|
||||
XMLDocument doc;
|
||||
char xmlPath[256];
|
||||
XMLError error;
|
||||
map<string, float> data;
|
||||
|
||||
memset(xmlPath, 0, 256);
|
||||
sprintf(xmlPath, EXPORTDATA_FILE, index);
|
||||
error = doc.LoadFile(xmlPath);
|
||||
if (error != XML_SUCCESS)
|
||||
if (doc.LoadFile(xmlPath) != 0)
|
||||
{
|
||||
cout << "load xml file failed" << endl;
|
||||
return false;
|
||||
}
|
||||
XMLElement* root = doc.RootElement();
|
||||
XMLElement* userNode = root->FirstChildElement("Camera");
|
||||
data["CameraId"] = index;
|
||||
data["IsNG"] = 0;
|
||||
data["IsJdExist"] = 0;
|
||||
data["Total"] = 0;
|
||||
while (userNode != NULL)
|
||||
{
|
||||
if (atoi(userNode->Attribute("Id")) == index) {
|
||||
data["IsNG"]++;
|
||||
data["IsJdExist"]++;
|
||||
data["Total"]++;
|
||||
XMLElement* IsNgNode = userNode->FirstChildElement("IsNG");
|
||||
data["IsNg"] = strcmp(IsNgNode->GetText(), "TRUE");
|
||||
XMLElement* IsJdExistNode = userNode->FirstChildElement("IsJdExist");
|
||||
if (strcmp(IsJdExistNode->GetText(), "TRUE") == 0)
|
||||
data["IsJdExist"]++;
|
||||
XMLElement* TimeCostNode = userNode->FirstChildElement("TimeCost");
|
||||
data["TimeCost"] += stof(TimeCostNode->GetText());
|
||||
}
|
||||
userNode = userNode->NextSiblingElement();//ÏÂÒ»¸öÐֵܽڵã
|
||||
}
|
||||
if (data["Total"] == 0)
|
||||
return false;
|
||||
data["TimeCost"] = data["TimeCost"] / data["Total"];
|
||||
|
||||
averageData = data;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int ExportDataThread::insertXMLNode(const char* xmlPath, _ExportDataInfo& data)
|
||||
{
|
||||
XMLElement* root = pDocument[data.cameraId]->RootElement();
|
||||
|
||||
if (root == NULL) {
|
||||
root = pDocument[data.cameraId]->NewElement("Root");
|
||||
pDocument[data.cameraId]->InsertEndChild(root);
|
||||
pDocument[data.cameraId]->SaveFile(xmlPath);
|
||||
}
|
||||
|
||||
XMLElement* CameraNode = pDocument[data.cameraId]->NewElement("Camera");
|
||||
CameraNode->SetAttribute("Id", data.cameraId);
|
||||
CameraNode->SetAttribute("Count ", data.cameraTotal);
|
||||
root->InsertEndChild(CameraNode);
|
||||
|
||||
XMLElement* IsNG = pDocument[data.cameraId]->NewElement("IsNG");
|
||||
XMLText* IsNGText = pDocument[data.cameraId]->NewText(data.isNg ? "TRUE" : "FALSE");
|
||||
IsNG->InsertEndChild(IsNGText);
|
||||
CameraNode->InsertEndChild(IsNG);
|
||||
|
||||
XMLElement* timeCost = pDocument[data.cameraId]->NewElement("TimeCost");
|
||||
timeCost->InsertEndChild(pDocument[data.cameraId]->NewText(data.timeCost.c_str()));
|
||||
CameraNode->InsertEndChild(timeCost);
|
||||
|
||||
XMLElement* isJdExist = pDocument[data.cameraId]->NewElement("IsJdExist");
|
||||
isJdExist->InsertEndChild(pDocument[data.cameraId]->NewText(data.isJdExist[0] ? "TRUE" : "FALSE"));
|
||||
CameraNode->InsertEndChild(isJdExist);
|
||||
|
||||
// XMLElement* jdInterval = pDocument[data.cameraId]->NewElement("JdInterval");
|
||||
// jdInterval->InsertEndChild(pDocument[data.cameraId]->NewText((const char*)&data.jdInterval));
|
||||
// CameraNode->InsertEndChild(jdInterval);
|
||||
|
||||
// XMLElement* jdInterval = pDocument[data.cameraId]->NewElement("jdPointsLocation");
|
||||
// jdInterval->InsertEndChild(pDocument[data.cameraId]->NewText(data.getPoint(0).c_str()));
|
||||
// CameraNode->InsertEndChild(jdInterval);
|
||||
|
||||
return pDocument[data.cameraId]->SaveFile(xmlPath);
|
||||
}
|
||||
|
||||
void ExportDataThread::run()
|
||||
{
|
||||
while (!b_quit) {
|
||||
_ExportDataInfo element;
|
||||
export_Data_Info_queue->take(element);
|
||||
if (element.cameraId != -1) {
|
||||
char buf[256];
|
||||
memset(buf, 0, 256);
|
||||
sprintf(buf, EXPORTDATA_FILE, element.cameraId);
|
||||
insertXMLNode(buf, element);
|
||||
}
|
||||
}
|
||||
|
||||
for (int index = 0; index < NumberOfSupportedCameras; index++) {
|
||||
pDocument[index]->~XMLDocument();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ExportDataThread::check_save_dir(std::string dir_path)
|
||||
{
|
||||
bool b_find = false;
|
||||
for (int i = 0; i < vec_save_dirs.size(); i++)
|
||||
{
|
||||
if (dir_path == vec_save_dirs[i])
|
||||
{
|
||||
b_find = true;
|
||||
}
|
||||
}
|
||||
if (!b_find)
|
||||
{
|
||||
QString dir_str = QString::fromStdString(dir_path);
|
||||
QDir dir;
|
||||
if (!dir.exists(dir_str))
|
||||
{
|
||||
dir.mkpath(dir_str);
|
||||
}
|
||||
vec_save_dirs.push_back(dir_path);
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
#include <QDialog>
|
||||
#include "ui_output_statistic.h"
|
||||
#include <vector>
|
||||
#include <qdir.h>
|
||||
#include <iostream>
|
||||
#include <SyncQueue.h>
|
||||
#include <qthread.h>
|
||||
#include "basecamera.h"
|
||||
#include "tinyxml2.h"
|
||||
#include <map>
|
||||
|
||||
#define EXPORTDATA_FILE "D:/conf/camera%d_data_info.xml"
|
||||
|
||||
using namespace tinyxml2;
|
||||
|
||||
class _ExportDataInfo
|
||||
{
|
||||
struct JdPoint //´´½¨µãµÄÊý¾Ý
|
||||
{
|
||||
string x;
|
||||
string y;
|
||||
};
|
||||
|
||||
public:
|
||||
int cameraId;
|
||||
int shotCounts;
|
||||
int jd[20];
|
||||
string timeCost;
|
||||
float jdInterval;
|
||||
bool isNg;
|
||||
bool isJdExist[20];
|
||||
long long cameraTotal;
|
||||
std::vector<JdPoint> jdPointsLocation;
|
||||
float jdSize[20];
|
||||
|
||||
bool getAverageData(map<string, float>& averageData, int index);
|
||||
|
||||
string getPoint(int index) {
|
||||
string point = "(";
|
||||
point += jdPointsLocation.at(index).x + ',' + jdPointsLocation.at(index).y + ')';
|
||||
return point;
|
||||
}
|
||||
|
||||
_ExportDataInfo()
|
||||
{
|
||||
cameraId = -1;
|
||||
jdInterval = 0.0;
|
||||
isNg = false;
|
||||
for (int i = 0; i < 20; i++)isJdExist[i] = false;
|
||||
for (int i = 0; i < 20; i++)jd[i] = 0;
|
||||
timeCost = "0ms";
|
||||
for (int i = 0; i < 20; i++)jdSize[i] = 0.0;
|
||||
shotCounts = 0;
|
||||
}
|
||||
};
|
||||
|
||||
extern SyncQueue<_ExportDataInfo>* export_Data_Info_queue;
|
||||
|
||||
class ExportDataThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
signals:
|
||||
|
||||
|
||||
public:
|
||||
ExportDataThread(QObject* parent = 0);
|
||||
~ExportDataThread()
|
||||
{
|
||||
stop();
|
||||
//export_Data_Info_queue->put(data);
|
||||
quit();
|
||||
wait();
|
||||
}
|
||||
|
||||
void init();
|
||||
void start_work();
|
||||
void stop();
|
||||
int insertXMLNode(const char* xmlPath, _ExportDataInfo& data);
|
||||
protected:
|
||||
void run();
|
||||
void check_save_dir(std::string dir_path);
|
||||
public:
|
||||
bool b_quit;
|
||||
std::vector<std::string> vec_save_dirs;
|
||||
tinyxml2::XMLDocument *pDocument[NumberOfSupportedCameras];
|
||||
};
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue