188 lines
6.3 KiB
C++
188 lines
6.3 KiB
C++
|
||
#include <iostream>
|
||
#include <fstream>
|
||
#include <sstream>
|
||
#include <QDir>
|
||
#include <QString>
|
||
#include <QVector>
|
||
#include "aphistory.h"
|
||
|
||
/*
|
||
* Конструктор
|
||
*/
|
||
APHistory::APHistory() {
|
||
//
|
||
}
|
||
|
||
/*
|
||
* Добавление отдельного контейнера для каждого запуска модели
|
||
*/
|
||
void APHistory::addClassHistory() {
|
||
QList<qreal> content;
|
||
avContenmentHistory.push_back(content);
|
||
}
|
||
|
||
/*
|
||
* Добавление отдельного контейнера для данных по группам каждого запуска модели
|
||
*/
|
||
void APHistory::addClassGroupHistory() {
|
||
QList<qreal> groupsContent;
|
||
QVector<QList<qreal> > modelsContent(4, groupsContent);
|
||
groupAvContenmentHistoty.push_back(modelsContent);
|
||
}
|
||
|
||
/*
|
||
* Добавление данных о модели с номером iModel
|
||
*/
|
||
void APHistory::addAvContenmentData(int iModel, qreal avContenmentData){
|
||
avContenmentHistory[iModel].push_back(avContenmentData);
|
||
}
|
||
|
||
/*
|
||
* Добавление данных о модели с номером iModel по группам
|
||
*/
|
||
void APHistory::addGroupAvContenmentData(int iModel, QVector<qreal> avContenmentData){
|
||
for (int iGroup = 0; iGroup < 4; iGroup++) {
|
||
groupAvContenmentHistoty[iModel][iGroup].push_back(avContenmentData[iGroup]);
|
||
}
|
||
}
|
||
|
||
/*
|
||
* Вывод в файл всех данных по модели с номером iModel
|
||
*/
|
||
void APHistory::postPrintModelData(int iModel){
|
||
QString directoryName("Output_for_model_");
|
||
directoryName += QString::number(iModel);
|
||
QDir directory(directoryName);
|
||
if (!directory.exists()){
|
||
directory.mkpath(".");
|
||
}
|
||
std::stringstream fileName;
|
||
fileName << "./Output_for_model_" << iModel << "/avContenment_model" << iModel << ".txt";
|
||
std::ofstream avContOutput(fileName.str().c_str());
|
||
for(int i = 0; i < avContenmentHistory[iModel].size(); i++){
|
||
avContOutput << avContenmentHistory[iModel][i] << std::endl;
|
||
}
|
||
avContOutput.close();
|
||
}
|
||
|
||
void APHistory::postPrintGroupData(int iModel){
|
||
QString directoryName("Output_for_model_");
|
||
directoryName += QString::number(iModel);
|
||
QDir directory(directoryName);
|
||
if (!directory.exists()){
|
||
directory.mkpath(".");
|
||
}
|
||
for (int j = 0; j < 4; j++){
|
||
std::stringstream ss;
|
||
ss << "./Output_for_model_" << iModel << "/avContenment_model" << iModel << "_group" << j << ".txt";
|
||
std::ofstream groupAvContOutput(ss.str().c_str());
|
||
for(int i = 0; i < groupAvContenmentHistoty[iModel][j].size(); i++){
|
||
groupAvContOutput << groupAvContenmentHistoty[iModel][j][i] << std::endl;
|
||
}
|
||
groupAvContOutput.close();
|
||
}
|
||
}
|
||
|
||
void APHistory::postPrintGlobalAverage() {
|
||
for (int iGroup = 0; iGroup < 4; iGroup++) {
|
||
QList<qreal> data = getAverageForGroup(iGroup);
|
||
QString directoryName("Output_for_average");
|
||
QDir directory(directoryName);
|
||
if (!directory.exists()){
|
||
directory.mkpath(".");
|
||
}
|
||
std::stringstream ss;
|
||
ss << "./Output_for_average/avContenmentForAllModels_group" << iGroup << ".txt";
|
||
std::ofstream averageForGroups(ss.str().c_str(), std::ios::app);
|
||
for (int i = 0; i < data.size(); i++) {
|
||
averageForGroups << data[i] << std::endl;
|
||
}
|
||
averageForGroups.close();
|
||
}
|
||
QList<qreal> data = getAverageForAllModels();
|
||
std::ofstream averageForAll("./Output_for_average/avContenmentForAllModels.txt");
|
||
for (int i = 0; i < data.size(); i++) {
|
||
averageForAll << data[i] << std::endl;
|
||
}
|
||
averageForAll.close();
|
||
}
|
||
|
||
/*
|
||
* Вывод в файл последних данных по модели с номером iModel
|
||
*/
|
||
void APHistory::printCurrentContentmentData(int iModel){
|
||
QString directoryName("Output_for_model_");
|
||
directoryName += QString::number(iModel);
|
||
QDir directory(directoryName);
|
||
if (!directory.exists()){
|
||
directory.mkpath(".");
|
||
}
|
||
std::stringstream ss;
|
||
ss << "./Output_for_model_" << iModel << "/avContenment_model" << iModel << ".txt";
|
||
std::ofstream currentAvContOutput(ss.str().c_str(), std::ios::app);
|
||
currentAvContOutput << avContenmentHistory[iModel].last() << std::endl;
|
||
currentAvContOutput.close();
|
||
}
|
||
|
||
void APHistory::printCurrentContentmentGroupData(int iModel){
|
||
QString directoryName("Output_for_model_");
|
||
directoryName += QString::number(iModel);
|
||
QDir directory(directoryName);
|
||
if (!directory.exists()){
|
||
directory.mkpath(".");
|
||
}
|
||
for (int iGroup = 0; iGroup < 4; iGroup++){
|
||
std::stringstream ss;
|
||
ss << "./Output_for_model_" << iModel << "/avContenment_model" << iModel << "_group" << iGroup <<".txt";
|
||
std::ofstream currentAvContOutput(ss.str().c_str(), std::ios::app);
|
||
currentAvContOutput << groupAvContenmentHistoty[iModel][iGroup].last() << std::endl;
|
||
currentAvContOutput.close();
|
||
}
|
||
}
|
||
|
||
QList<qreal> APHistory::getHistory(int iModel) {
|
||
return avContenmentHistory[iModel];
|
||
}
|
||
|
||
QList<qreal> APHistory::getGroupHistory(int iModel, int iGroup) {
|
||
return groupAvContenmentHistoty[iModel][iGroup];
|
||
}
|
||
|
||
QList<qreal> APHistory::getAverageForAllModels() {
|
||
QList<qreal> average;
|
||
int nModels = avContenmentHistory.size();
|
||
if (nModels > 0){
|
||
int nIterations = avContenmentHistory[0].size();
|
||
for (int j = 0; j < nIterations; j++){
|
||
qreal buffer = 0;
|
||
for (int i = 0; i < nModels; i++) {
|
||
buffer += avContenmentHistory[i][j];
|
||
}
|
||
average.push_back(buffer/nModels);
|
||
}
|
||
}
|
||
return average;
|
||
}
|
||
|
||
QList<qreal> APHistory::getAverageForGroup(int group) {
|
||
QList<qreal> average;
|
||
int nModels = groupAvContenmentHistoty.size();
|
||
if (nModels > 0){
|
||
int nIterations = groupAvContenmentHistoty[0][group].size();
|
||
for (int j = 0; j < nIterations; j++){
|
||
qreal buffer = 0;
|
||
for (int i = 0; i < nModels; i++) {
|
||
buffer += groupAvContenmentHistoty[i][group][j];
|
||
}
|
||
average.push_back(buffer/nModels);
|
||
}
|
||
}
|
||
return average;
|
||
}
|
||
|
||
void APHistory::clearHistory() {
|
||
avContenmentHistory.clear();
|
||
groupAvContenmentHistoty.clear();
|
||
}
|