#include "output_statistic.h"
#include "QtCore\qfile.h"
#include "QtCore\qtextstream.h"
#include "exportData.h"
#include "common.h"
#include <map>

output_statistic::output_statistic(QDialog *parent)
	: QDialog(parent)
{
	ui.setupUi(this);
	this->setWindowFlags(windowFlags()&~Qt::WindowContextHelpButtonHint);
}

output_statistic::~output_statistic()
{
}

void output_statistic::recMsgFromDialogSetup()
{
#ifdef __ExportData
	_ExportDataInfo data;
	map<string, float> averageData[NumberOfSupportedCameras];

	ui.tabWidget->setTabVisible(1, false);
	ui.tabWidget->setTabVisible(2, false);
	ui.tabWidget->setTabVisible(3, false);
	ui.tabWidget->setTabVisible(4, false);
	ui.tabWidget->setTabVisible(5, false);
	ui.tabWidget->setTabVisible(6, false);
	ui.tabWidget->setTabVisible(7, false);
	ui.tabWidget->setTabText(0, "Statistical data");


	for (int index = 0; index < NumberOfSupportedCameras; index++) {
		data.getAverageData(averageData[index], index);
		QString text;
		text.append(" CameraId: ");
		text.append(std::to_string((int)averageData[index]["CameraId"]).c_str());
		text.append("\n IsNG: ");
		text.append(std::to_string((int)averageData[index]["IsNG"]).c_str());
		text.append("\n IsJdExist: ");
		text.append(std::to_string((int)averageData[index]["IsJdExist"]).c_str());
		text.append("\n TimeCost: ");
		text.append(std::to_string(averageData[index]["TimeCost"]).c_str());
		text.append("\n*************************************************\n");
		ui.textBrowser_1->insertPlainText(text);
	}
	
#else
	QFile file("../conf/camera0_statistic.txt");
	if (file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		QTextStream in(&file);
		ui.textBrowser_1->setText(in.readAll());
	}
	file.close();
	file.setFileName("../conf/camera1_statistic.txt");
	if (file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		QTextStream in(&file);
		ui.textBrowser_2->setText(in.readAll());
	}
	file.close();
	file.setFileName("../conf/camera2_statistic.txt");
	if (file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		QTextStream in(&file);
		ui.textBrowser_3->setText(in.readAll());
	}
	file.close();
	file.setFileName("../conf/camera3_statistic.txt");
	if (file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		QTextStream in(&file);
		ui.textBrowser_4->setText(in.readAll());
	}
	file.close();
	file.setFileName("../conf/camera4_statistic.txt");
	if (file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		QTextStream in(&file);
		ui.textBrowser_5->setText(in.readAll());
	}
	file.close();
	file.setFileName("../conf/camera5_statistic.txt");
	if (file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		QTextStream in(&file);
		ui.textBrowser_6->setText(in.readAll());
	}
	file.close();
	file.setFileName("../conf/camera6_statistic.txt");
	if (file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		QTextStream in(&file);
		ui.textBrowser_7->setText(in.readAll());
	}
	file.close();
	file.setFileName("../conf/camera7_statistic.txt");
	if (file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		QTextStream in(&file);
		ui.textBrowser_8->setText(in.readAll());
	}
	file.close();
#endif
	this->show();
}
