| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
*/ |
| 20 |
#ifndef KONCLUDE_TEST_EVALUATION_CREASONEREVALUATIONTABLEMULTIFORMATOUTPUTWRITER_CPP |
| 21 |
#define KONCLUDE_TEST_EVALUATION_CREASONEREVALUATIONTABLEMULTIFORMATOUTPUTWRITER_CPP |
| 22 |
|
| 23 |
#include "CReasonerEvaluationTableMultiFormatOutputWriter.h" |
| 24 |
|
| 25 |
|
| 26 |
namespace Konclude { |
| 27 |
|
| 28 |
namespace Test { |
| 29 |
|
| 30 |
namespace Evaluation { |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
template<class T> |
| 35 |
CReasonerEvaluationTableMultiFormatOutputWriter<T>::CReasonerEvaluationTableMultiFormatOutputWriter() { |
| 36 |
mLastRow = nullptr; |
| 37 |
mSortedIndexBuilded = false; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
template<class T> |
| 42 |
CReasonerEvaluationTableMultiFormatOutputWriter<T>::~CReasonerEvaluationTableMultiFormatOutputWriter() { |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
template<class T> |
| 47 |
QStringList CReasonerEvaluationTableMultiFormatOutputWriter<T>::writeCVSTable(const QString& baseFileName, QString (*convertStringFunction)(const T&)) { |
| 48 |
QStringList outputFileList; |
| 49 |
QString outputFileString(baseFileName+"-table.csv"); |
| 50 |
QFile outputFile(outputFileString); |
| 51 |
if (outputFile.open(QIODevice::WriteOnly)) { |
| 52 |
outputFileList<<outputFileString; |
| 53 |
QString titleString = QString("%1\r\n").arg(mTitles.join("\t")); |
| 54 |
outputFile.write(titleString.toLocal8Bit()); |
| 55 |
foreach (CReasonerEvaluationTableRow* row, mRowList) { |
| 56 |
QString rowString = row->mTitle+"\t"; |
| 57 |
foreach (T value, row->mRowValueList) { |
| 58 |
QString valueString = (*convertStringFunction)(value); |
| 59 |
rowString += QString("%1\t").arg(valueString); |
| 60 |
} |
| 61 |
rowString += "\r\n"; |
| 62 |
outputFile.write(rowString.toLocal8Bit()); |
| 63 |
} |
| 64 |
} |
| 65 |
return outputFileList; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
template<class T> |
| 70 |
QStringList CReasonerEvaluationTableMultiFormatOutputWriter<T>::writeGNUPlotDataTable(const QString& baseFileName, QString (*convertStringFunction)(const T&)) { |
| 71 |
QStringList outputFileList; |
| 72 |
QString outputFileString(baseFileName+"-table.dat"); |
| 73 |
QFile outputFile(outputFileString); |
| 74 |
if (outputFile.open(QIODevice::WriteOnly)) { |
| 75 |
outputFileList<<outputFileString; |
| 76 |
QStringList mIndexAddedTitleList(mTitles); |
| 77 |
mIndexAddedTitleList.insert(1,"Index"); |
| 78 |
QString titleString = QString("\"%1\"\r\n").arg(mIndexAddedTitleList.join("\"\t\"")); |
| 79 |
outputFile.write(titleString.toLocal8Bit()); |
| 80 |
|
| 81 |
cint64 rowIndex = 0; |
| 82 |
foreach (CReasonerEvaluationTableRow* row, mRowList) { |
| 83 |
QString rowString = QString("\"%1\"\t%2\t").arg(getGNUPlotCompatibleTitle(row->mTitle)).arg(rowIndex++); |
| 84 |
foreach (T value, row->mRowValueList) { |
| 85 |
QString valueString = (*convertStringFunction)(value); |
| 86 |
rowString += QString("%1\t").arg(valueString); |
| 87 |
} |
| 88 |
rowString += "\r\n"; |
| 89 |
outputFile.write(rowString.toLocal8Bit()); |
| 90 |
} |
| 91 |
} |
| 92 |
return outputFileList; |
| 93 |
} |
| 94 |
|
| 95 |
template<class T> |
| 96 |
QStringList CReasonerEvaluationTableMultiFormatOutputWriter<T>::writeGNUPlotDataTablesSorted(const QString& baseFileName, QString (*convertStringFunction)(const T&)) { |
| 97 |
QStringList outputFileList; |
| 98 |
cint64 titleIndex = 0; |
| 99 |
cint64 rowCount = mRowList.count(); |
| 100 |
foreach (QString title, mTitles) { |
| 101 |
QString outputFileASCString(baseFileName+QString("-sorted-ascending-by-%1-table.dat").arg(title)); |
| 102 |
QString outputFileDESString(baseFileName+QString("-sorted-descending-by-%1-table.dat").arg(title)); |
| 103 |
|
| 104 |
QString desFileContentString; |
| 105 |
|
| 106 |
QFile outputFileASC(outputFileASCString); |
| 107 |
if (outputFileASC.open(QIODevice::WriteOnly)) { |
| 108 |
|
| 109 |
QStringList mIndexAddedTitleList(mTitles); |
| 110 |
mIndexAddedTitleList.insert(1,"Index"); |
| 111 |
QString titleString = QString("\"%1\"\r\n").arg(mIndexAddedTitleList.join("\"\t\"")); |
| 112 |
outputFileASC.write(titleString.toLocal8Bit()); |
| 113 |
|
| 114 |
cint64 rowIndex = 0; |
| 115 |
if (titleIndex == 0) { |
| 116 |
for (typename QMap<QString,CReasonerEvaluationTableRow*>::const_iterator it = mTitleColumnSortedMap.constBegin(), itEnd = mTitleColumnSortedMap.constEnd(); it != itEnd; ++it) { |
| 117 |
CReasonerEvaluationTableRow* row = it.value(); |
| 118 |
QString rowASCString = QString("\"%1\"\t%2\t").arg(getGNUPlotCompatibleTitle(row->mTitle)).arg(rowIndex); |
| 119 |
QString rowDESString = QString("\"%1\"\t%2\t").arg(getGNUPlotCompatibleTitle(row->mTitle)).arg(rowCount-rowIndex-1); |
| 120 |
foreach (T value, row->mRowValueList) { |
| 121 |
QString valueString = (*convertStringFunction)(value); |
| 122 |
rowASCString += QString("%1\t").arg(valueString); |
| 123 |
rowDESString += QString("%1\t").arg(valueString); |
| 124 |
} |
| 125 |
rowASCString += "\r\n"; |
| 126 |
rowDESString += "\r\n"; |
| 127 |
outputFileASC.write(rowASCString.toLocal8Bit()); |
| 128 |
desFileContentString.prepend(rowDESString); |
| 129 |
++rowIndex; |
| 130 |
} |
| 131 |
} else { |
| 132 |
QMap<T,CReasonerEvaluationTableRow*>* sortedMap = mColumnSortMapList.at(titleIndex-1); |
| 133 |
for (typename QMap<T,CReasonerEvaluationTableRow*>::const_iterator it = sortedMap->constBegin(), itEnd = sortedMap->constEnd(); it != itEnd; ++it) { |
| 134 |
CReasonerEvaluationTableRow* row = it.value(); |
| 135 |
QString rowASCString = QString("\"%1\"\t%2\t").arg(getGNUPlotCompatibleTitle(row->mTitle)).arg(rowIndex); |
| 136 |
QString rowDESString = QString("\"%1\"\t%2\t").arg(getGNUPlotCompatibleTitle(row->mTitle)).arg(rowCount-rowIndex-1); |
| 137 |
foreach (T value, row->mRowValueList) { |
| 138 |
QString valueString = (*convertStringFunction)(value); |
| 139 |
rowASCString += QString("%1\t").arg(valueString); |
| 140 |
rowDESString += QString("%1\t").arg(valueString); |
| 141 |
} |
| 142 |
rowASCString += "\r\n"; |
| 143 |
rowDESString += "\r\n"; |
| 144 |
outputFileASC.write(rowASCString.toLocal8Bit()); |
| 145 |
desFileContentString.prepend(rowDESString); |
| 146 |
++rowIndex; |
| 147 |
} |
| 148 |
} |
| 149 |
outputFileList<<outputFileASCString; |
| 150 |
|
| 151 |
desFileContentString.prepend(titleString); |
| 152 |
QFile outputFileDES(outputFileDESString); |
| 153 |
if (outputFileDES.open(QIODevice::WriteOnly)) { |
| 154 |
outputFileDES.write(desFileContentString.toLocal8Bit()); |
| 155 |
outputFileDES.close(); |
| 156 |
outputFileList<<outputFileDESString; |
| 157 |
} |
| 158 |
|
| 159 |
} |
| 160 |
++titleIndex; |
| 161 |
} |
| 162 |
return outputFileList; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
template<class T> |
| 168 |
QStringList CReasonerEvaluationTableMultiFormatOutputWriter<T>::writeGNUPlotDataTablesSeparateSorted(const QString& baseFileName, QString (*convertStringFunction)(const T&)) { |
| 169 |
QStringList outputFileList; |
| 170 |
QString outputFileASCString(baseFileName+QString("-separate-sorted-ascending-table.dat")); |
| 171 |
QString outputFileDESString(baseFileName+QString("-separate-sorted-descending-table.dat")); |
| 172 |
|
| 173 |
QString desFileContentString; |
| 174 |
cint64 rowCount = mRowList.count(); |
| 175 |
|
| 176 |
QFile outputFileASC(outputFileASCString); |
| 177 |
if (outputFileASC.open(QIODevice::WriteOnly)) { |
| 178 |
|
| 179 |
QStringList mIndexAddedTitleList(mTitles); |
| 180 |
mIndexAddedTitleList.insert(1,"Index"); |
| 181 |
|
| 182 |
QString titleString = QString("\"%1\"\r\n").arg(mIndexAddedTitleList.join("\"\t\"")); |
| 183 |
outputFileASC.write(titleString.toLocal8Bit()); |
| 184 |
|
| 185 |
|
| 186 |
typename QMap<QString,CReasonerEvaluationTableRow*>::iterator itTitles = mTitleColumnSortedMap.begin(), itTitlesEnd = mTitleColumnSortedMap.end(); |
| 187 |
QList< typename QMap<T,CReasonerEvaluationTableRow*>::iterator > itList; |
| 188 |
|
| 189 |
for (typename QList< QMap<T,CReasonerEvaluationTableRow*>* >::const_iterator it = mColumnSortMapList.constBegin(), itEnd = mColumnSortMapList.constEnd(); it != itEnd; ++it) { |
| 190 |
QMap<T,CReasonerEvaluationTableRow*>* sortMap = *it; |
| 191 |
itList.append(sortMap->begin()); |
| 192 |
} |
| 193 |
|
| 194 |
cint64 rowIndex = 0; |
| 195 |
while (itTitles != itTitlesEnd) { |
| 196 |
QString rowASCTitleString = QString("\"%1\"\t%2\t").arg(getGNUPlotCompatibleTitle(itTitles.key())).arg(rowIndex); |
| 197 |
QString rowDESTitleString = QString("\"%1\"\t%2\t").arg(getGNUPlotCompatibleTitle(itTitles.key())).arg(rowCount-rowIndex-1); |
| 198 |
|
| 199 |
cint64 colIndex = 0; |
| 200 |
for (typename QList< typename QMap<T,CReasonerEvaluationTableRow*>::iterator >::iterator it = itList.begin(), itEnd = itList.end(); it != itEnd; ++it) { |
| 201 |
typename QMap<T,CReasonerEvaluationTableRow*>::iterator& itCol = *it; |
| 202 |
|
| 203 |
CReasonerEvaluationTableRow* row = itCol.value(); |
| 204 |
T value = row->mRowValueList.at(colIndex); |
| 205 |
QString valueString = (*convertStringFunction)(value); |
| 206 |
rowASCTitleString += QString("%1\t").arg(valueString); |
| 207 |
rowDESTitleString += QString("%1\t").arg(valueString); |
| 208 |
|
| 209 |
++itCol; |
| 210 |
++colIndex; |
| 211 |
} |
| 212 |
rowASCTitleString += "\r\n"; |
| 213 |
rowDESTitleString += "\r\n"; |
| 214 |
outputFileASC.write(rowASCTitleString.toLocal8Bit()); |
| 215 |
desFileContentString.prepend(rowDESTitleString); |
| 216 |
|
| 217 |
++itTitles; |
| 218 |
++rowIndex; |
| 219 |
} |
| 220 |
|
| 221 |
desFileContentString.prepend(titleString); |
| 222 |
QFile outputFileDES(outputFileDESString); |
| 223 |
if (outputFileDES.open(QIODevice::WriteOnly)) { |
| 224 |
outputFileDES.write(desFileContentString.toLocal8Bit()); |
| 225 |
outputFileDES.close(); |
| 226 |
outputFileList<<outputFileDESString; |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
outputFileList<<outputFileASCString; |
| 232 |
} |
| 233 |
return outputFileList; |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
template<class T> |
| 240 |
QStringList CReasonerEvaluationTableMultiFormatOutputWriter<T>::writeGNUPlotDataTablesSortedSplitted(cint64 splitSize, const QString& baseFileName, QString (*convertStringFunction)(const T&)) { |
| 241 |
QStringList outputFileList; |
| 242 |
cint64 rowCount = mRowList.count(); |
| 243 |
for (cint64 rowStartIndex = 0; rowStartIndex < rowCount; rowStartIndex += splitSize) { |
| 244 |
cint64 rowEndIndex = rowStartIndex+splitSize; |
| 245 |
rowEndIndex = qMin(rowEndIndex,rowCount); |
| 246 |
cint64 titleIndex = 0; |
| 247 |
foreach (QString title, mTitles) { |
| 248 |
QString outputFileASCString(baseFileName+QString("-sorted-ascending-by-%1-split-from-%2-to-%3-table.dat").arg(title).arg(getSplitIndexString(rowStartIndex+1,rowCount)).arg(getSplitIndexString(rowEndIndex,rowCount))); |
| 249 |
QString outputFileDESString(baseFileName+QString("-sorted-descending-by-%1-split-from-%2-to-%3-table.dat").arg(title).arg(getSplitIndexString(rowCount-rowEndIndex+1,rowCount)).arg(getSplitIndexString(rowCount-rowStartIndex,rowCount))); |
| 250 |
|
| 251 |
QString desFileContentString; |
| 252 |
|
| 253 |
QFile outputFileASC(outputFileASCString); |
| 254 |
if (outputFileASC.open(QIODevice::WriteOnly)) { |
| 255 |
|
| 256 |
QStringList mIndexAddedTitleList(mTitles); |
| 257 |
mIndexAddedTitleList.insert(1,"Index"); |
| 258 |
QString titleString = QString("\"%1\"\r\n").arg(mIndexAddedTitleList.join("\"\t\"")); |
| 259 |
outputFileASC.write(titleString.toLocal8Bit()); |
| 260 |
|
| 261 |
cint64 rowIndex = 0; |
| 262 |
if (titleIndex == 0) { |
| 263 |
cint64 rowIndex = 0; |
| 264 |
for (typename QMap<QString,CReasonerEvaluationTableRow*>::const_iterator it = mTitleColumnSortedMap.constBegin(), itEnd = mTitleColumnSortedMap.constEnd(); it != itEnd; ++it) { |
| 265 |
if (rowIndex >= rowStartIndex && rowIndex < rowEndIndex) { |
| 266 |
CReasonerEvaluationTableRow* row = it.value(); |
| 267 |
QString rowASCString = QString("\"%1\"\t%2\t").arg(getGNUPlotCompatibleTitle(row->mTitle)).arg(rowIndex-rowStartIndex); |
| 268 |
QString rowDESString = QString("\"%1\"\t%2\t").arg(getGNUPlotCompatibleTitle(row->mTitle)).arg(rowEndIndex-rowIndex-1); |
| 269 |
foreach (T value, row->mRowValueList) { |
| 270 |
QString valueString = (*convertStringFunction)(value); |
| 271 |
rowASCString += QString("%1\t").arg(valueString); |
| 272 |
rowDESString += QString("%1\t").arg(valueString); |
| 273 |
} |
| 274 |
rowASCString += "\r\n"; |
| 275 |
rowDESString += "\r\n"; |
| 276 |
outputFileASC.write(rowASCString.toLocal8Bit()); |
| 277 |
desFileContentString.prepend(rowDESString); |
| 278 |
} |
| 279 |
++rowIndex; |
| 280 |
} |
| 281 |
} else { |
| 282 |
cint64 rowIndex = 0; |
| 283 |
QMap<T,CReasonerEvaluationTableRow*>* sortedMap = mColumnSortMapList.at(titleIndex-1); |
| 284 |
for (typename QMap<T,CReasonerEvaluationTableRow*>::const_iterator it = sortedMap->constBegin(), itEnd = sortedMap->constEnd(); it != itEnd; ++it) { |
| 285 |
if (rowIndex >= rowStartIndex && rowIndex < rowEndIndex) { |
| 286 |
CReasonerEvaluationTableRow* row = it.value(); |
| 287 |
QString rowASCString = QString("\"%1\"\t%2\t").arg(getGNUPlotCompatibleTitle(row->mTitle)).arg(rowIndex-rowStartIndex); |
| 288 |
QString rowDESString = QString("\"%1\"\t%2\t").arg(getGNUPlotCompatibleTitle(row->mTitle)).arg(rowEndIndex-rowIndex-1); |
| 289 |
foreach (T value, row->mRowValueList) { |
| 290 |
QString valueString = (*convertStringFunction)(value); |
| 291 |
rowASCString += QString("%1\t").arg(valueString); |
| 292 |
rowDESString += QString("%1\t").arg(valueString); |
| 293 |
} |
| 294 |
rowASCString += "\r\n"; |
| 295 |
rowDESString += "\r\n"; |
| 296 |
outputFileASC.write(rowASCString.toLocal8Bit()); |
| 297 |
desFileContentString.prepend(rowDESString); |
| 298 |
} |
| 299 |
++rowIndex; |
| 300 |
} |
| 301 |
} |
| 302 |
outputFileList<<outputFileASCString; |
| 303 |
|
| 304 |
desFileContentString.prepend(titleString); |
| 305 |
QFile outputFileDES(outputFileDESString); |
| 306 |
if (outputFileDES.open(QIODevice::WriteOnly)) { |
| 307 |
outputFileDES.write(desFileContentString.toLocal8Bit()); |
| 308 |
outputFileDES.close(); |
| 309 |
outputFileList<<outputFileDESString; |
| 310 |
} |
| 311 |
|
| 312 |
} |
| 313 |
++titleIndex; |
| 314 |
} |
| 315 |
} |
| 316 |
return outputFileList; |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
template<class T> |
| 321 |
QString CReasonerEvaluationTableMultiFormatOutputWriter<T>::getGNUPlotCompatibleTitle(const QString& string) { |
| 322 |
QString comString = string; |
| 323 |
comString.replace("-request.xml",""); |
| 324 |
comString.replace("_","-"); |
| 325 |
if (comString.length() >= 40) { |
| 326 |
comString = comString.mid(0,37); |
| 327 |
comString += "..."; |
| 328 |
} |
| 329 |
return comString; |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
template<class T> |
| 335 |
QString CReasonerEvaluationTableMultiFormatOutputWriter<T>::getSplitIndexString(cint64 index, cint64 maxIndex) { |
| 336 |
QString maxIndString = QString::number(maxIndex); |
| 337 |
QString indexString = QString::number(index); |
| 338 |
while (indexString.size() < maxIndString.size()) { |
| 339 |
indexString.insert(0,"0"); |
| 340 |
} |
| 341 |
return indexString; |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
template<class T> |
| 346 |
QStringList CReasonerEvaluationTableMultiFormatOutputWriter<T>::writeCVSTablesSortedSplitted(cint64 splitSize, const QString& baseFileName, QString (*convertStringFunction)(const T&)) { |
| 347 |
QStringList outputFileList; |
| 348 |
cint64 rowCount = mRowList.count(); |
| 349 |
for (cint64 rowStartIndex = 0; rowStartIndex < rowCount; rowStartIndex += splitSize) { |
| 350 |
cint64 rowEndIndex = rowStartIndex+splitSize; |
| 351 |
rowEndIndex = qMin(rowEndIndex,rowCount); |
| 352 |
|
| 353 |
|
| 354 |
cint64 titleIndex = 0; |
| 355 |
foreach (QString title, mTitles) { |
| 356 |
QString outputFileASCString(baseFileName+QString("-sorted-ascending-by-%1-split-from-%2-to-%3-table.csv").arg(title).arg(getSplitIndexString(rowStartIndex+1,rowCount)).arg(getSplitIndexString(rowEndIndex,rowCount))); |
| 357 |
QString outputFileDESString(baseFileName+QString("-sorted-descending-by-%1-split-from-%2-to-%3-table.csv").arg(title).arg(getSplitIndexString(rowCount-rowEndIndex+1,rowCount)).arg(getSplitIndexString(rowCount-rowStartIndex,rowCount))); |
| 358 |
|
| 359 |
QString desFileContentString; |
| 360 |
|
| 361 |
QFile outputFileASC(outputFileASCString); |
| 362 |
if (outputFileASC.open(QIODevice::WriteOnly)) { |
| 363 |
|
| 364 |
QString titleString = QString("%1\r\n").arg(mTitles.join("\t")); |
| 365 |
outputFileASC.write(titleString.toLocal8Bit()); |
| 366 |
if (titleIndex == 0) { |
| 367 |
cint64 rowIndex = 0; |
| 368 |
for (typename QMap<QString,CReasonerEvaluationTableRow*>::const_iterator it = mTitleColumnSortedMap.constBegin(), itEnd = mTitleColumnSortedMap.constEnd(); it != itEnd; ++it) { |
| 369 |
if (rowIndex >= rowStartIndex && rowIndex < rowEndIndex) { |
| 370 |
CReasonerEvaluationTableRow* row = it.value(); |
| 371 |
QString rowString = row->mTitle+"\t"; |
| 372 |
foreach (T value, row->mRowValueList) { |
| 373 |
QString valueString = (*convertStringFunction)(value); |
| 374 |
rowString += QString("%1\t").arg(valueString); |
| 375 |
} |
| 376 |
rowString += "\r\n"; |
| 377 |
outputFileASC.write(rowString.toLocal8Bit()); |
| 378 |
|
| 379 |
desFileContentString.prepend(rowString); |
| 380 |
} |
| 381 |
++rowIndex; |
| 382 |
} |
| 383 |
} else { |
| 384 |
QMap<T,CReasonerEvaluationTableRow*>* sortedMap = mColumnSortMapList.at(titleIndex-1); |
| 385 |
cint64 rowIndex = 0; |
| 386 |
for (typename QMap<T,CReasonerEvaluationTableRow*>::const_iterator it = sortedMap->constBegin(), itEnd = sortedMap->constEnd(); it != itEnd; ++it) { |
| 387 |
if (rowIndex >= rowStartIndex && rowIndex < rowEndIndex) { |
| 388 |
CReasonerEvaluationTableRow* row = it.value(); |
| 389 |
QString rowString = row->mTitle+"\t"; |
| 390 |
foreach (T value, row->mRowValueList) { |
| 391 |
QString valueString = (*convertStringFunction)(value); |
| 392 |
rowString += QString("%1\t").arg(valueString); |
| 393 |
} |
| 394 |
rowString += "\r\n"; |
| 395 |
outputFileASC.write(rowString.toLocal8Bit()); |
| 396 |
|
| 397 |
desFileContentString.prepend(rowString); |
| 398 |
} |
| 399 |
++rowIndex; |
| 400 |
} |
| 401 |
} |
| 402 |
outputFileList<<outputFileASCString; |
| 403 |
|
| 404 |
desFileContentString.prepend(titleString); |
| 405 |
QFile outputFileDES(outputFileDESString); |
| 406 |
if (outputFileDES.open(QIODevice::WriteOnly)) { |
| 407 |
outputFileDES.write(desFileContentString.toLocal8Bit()); |
| 408 |
outputFileDES.close(); |
| 409 |
outputFileList<<outputFileDESString; |
| 410 |
} |
| 411 |
|
| 412 |
} |
| 413 |
++titleIndex; |
| 414 |
} |
| 415 |
} |
| 416 |
return outputFileList; |
| 417 |
} |
| 418 |
|
| 419 |
template<class T> |
| 420 |
QStringList CReasonerEvaluationTableMultiFormatOutputWriter<T>::writeCVSTablesSorted(const QString& baseFileName, QString (*convertStringFunction)(const T&)) { |
| 421 |
QStringList outputFileList; |
| 422 |
cint64 titleIndex = 0; |
| 423 |
foreach (QString title, mTitles) { |
| 424 |
QString outputFileASCString(baseFileName+QString("-sorted-ascending-by-%1-table.csv").arg(title)); |
| 425 |
QString outputFileDESString(baseFileName+QString("-sorted-descending-by-%1-table.csv").arg(title)); |
| 426 |
|
| 427 |
QString desFileContentString; |
| 428 |
|
| 429 |
QFile outputFileASC(outputFileASCString); |
| 430 |
if (outputFileASC.open(QIODevice::WriteOnly)) { |
| 431 |
|
| 432 |
QString titleString = QString("%1\r\n").arg(mTitles.join("\t")); |
| 433 |
outputFileASC.write(titleString.toLocal8Bit()); |
| 434 |
if (titleIndex == 0) { |
| 435 |
for (typename QMap<QString,CReasonerEvaluationTableRow*>::const_iterator it = mTitleColumnSortedMap.constBegin(), itEnd = mTitleColumnSortedMap.constEnd(); it != itEnd; ++it) { |
| 436 |
CReasonerEvaluationTableRow* row = it.value(); |
| 437 |
QString rowString = row->mTitle+"\t"; |
| 438 |
foreach (T value, row->mRowValueList) { |
| 439 |
QString valueString = (*convertStringFunction)(value); |
| 440 |
rowString += QString("%1\t").arg(valueString); |
| 441 |
} |
| 442 |
rowString += "\r\n"; |
| 443 |
outputFileASC.write(rowString.toLocal8Bit()); |
| 444 |
desFileContentString.prepend(rowString); |
| 445 |
} |
| 446 |
} else { |
| 447 |
QMap<T,CReasonerEvaluationTableRow*>* sortedMap = mColumnSortMapList.at(titleIndex-1); |
| 448 |
for (typename QMap<T,CReasonerEvaluationTableRow*>::const_iterator it = sortedMap->constBegin(), itEnd = sortedMap->constEnd(); it != itEnd; ++it) { |
| 449 |
CReasonerEvaluationTableRow* row = it.value(); |
| 450 |
QString rowString = row->mTitle+"\t"; |
| 451 |
foreach (T value, row->mRowValueList) { |
| 452 |
QString valueString = (*convertStringFunction)(value); |
| 453 |
rowString += QString("%1\t").arg(valueString); |
| 454 |
} |
| 455 |
rowString += "\r\n"; |
| 456 |
outputFileASC.write(rowString.toLocal8Bit()); |
| 457 |
desFileContentString.prepend(rowString); |
| 458 |
} |
| 459 |
} |
| 460 |
outputFileList<<outputFileASCString; |
| 461 |
|
| 462 |
desFileContentString.prepend(titleString); |
| 463 |
QFile outputFileDES(outputFileDESString); |
| 464 |
if (outputFileDES.open(QIODevice::WriteOnly)) { |
| 465 |
outputFileDES.write(desFileContentString.toLocal8Bit()); |
| 466 |
outputFileDES.close(); |
| 467 |
outputFileList<<outputFileDESString; |
| 468 |
} |
| 469 |
|
| 470 |
} |
| 471 |
++titleIndex; |
| 472 |
} |
| 473 |
return outputFileList; |
| 474 |
} |
| 475 |
|
| 476 |
template<class T> |
| 477 |
QStringList CReasonerEvaluationTableMultiFormatOutputWriter<T>::writeCVSTablesSeparateSorted(const QString& baseFileName, QString (*convertStringFunction)(const T&)) { |
| 478 |
QStringList outputFileList; |
| 479 |
QString outputFileString(baseFileName+QString("-separate-sorted-table.csv")); |
| 480 |
QFile outputFile(outputFileString); |
| 481 |
if (outputFile.open(QIODevice::WriteOnly)) { |
| 482 |
|
| 483 |
outputFileList.append(outputFileString); |
| 484 |
|
| 485 |
QString titleString = QString("%1\r\n").arg(mTitles.join("\t")); |
| 486 |
outputFile.write(titleString.toLocal8Bit()); |
| 487 |
|
| 488 |
|
| 489 |
typename QMap<QString,CReasonerEvaluationTableRow*>::iterator itTitles = mTitleColumnSortedMap.begin(), itTitlesEnd = mTitleColumnSortedMap.end(); |
| 490 |
QList< typename QMap<T,CReasonerEvaluationTableRow*>::iterator > itList; |
| 491 |
|
| 492 |
for (typename QList< QMap<T,CReasonerEvaluationTableRow*>* >::const_iterator it = mColumnSortMapList.constBegin(), itEnd = mColumnSortMapList.constEnd(); it != itEnd; ++it) { |
| 493 |
QMap<T,CReasonerEvaluationTableRow*>* sortMap = *it; |
| 494 |
itList.append(sortMap->begin()); |
| 495 |
} |
| 496 |
|
| 497 |
while (itTitles != itTitlesEnd) { |
| 498 |
QString rowTitleString = QString("%1\t").arg(itTitles.key()); |
| 499 |
|
| 500 |
cint64 colIndex = 0; |
| 501 |
for (typename QList< typename QMap<T,CReasonerEvaluationTableRow*>::iterator >::iterator it = itList.begin(), itEnd = itList.end(); it != itEnd; ++it) { |
| 502 |
typename QMap<T,CReasonerEvaluationTableRow*>::iterator& itCol = *it; |
| 503 |
|
| 504 |
CReasonerEvaluationTableRow* row = itCol.value(); |
| 505 |
T value = row->mRowValueList.at(colIndex); |
| 506 |
QString valueString = (*convertStringFunction)(value); |
| 507 |
rowTitleString += QString("%1\t").arg(valueString); |
| 508 |
|
| 509 |
++itCol; |
| 510 |
++colIndex; |
| 511 |
} |
| 512 |
rowTitleString += "\r\n"; |
| 513 |
outputFile.write(rowTitleString.toLocal8Bit()); |
| 514 |
|
| 515 |
++itTitles; |
| 516 |
} |
| 517 |
|
| 518 |
} |
| 519 |
return outputFileList; |
| 520 |
} |
| 521 |
|
| 522 |
|
| 523 |
template<class T> |
| 524 |
CReasonerEvaluationTableMultiFormatOutputWriter<T>* CReasonerEvaluationTableMultiFormatOutputWriter<T>::addColumnTitles(const QStringList& titleList) { |
| 525 |
mTitles += titleList; |
| 526 |
mSortedIndexBuilded = false; |
| 527 |
return this; |
| 528 |
} |
| 529 |
|
| 530 |
template<class T> |
| 531 |
CReasonerEvaluationTableMultiFormatOutputWriter<T>* CReasonerEvaluationTableMultiFormatOutputWriter<T>::addNewTableRow(const QString& rowTitle, const QList<T>& rowValues) { |
| 532 |
mLastRow = new CReasonerEvaluationTableRow(); |
| 533 |
mLastRow->mTitle = rowTitle; |
| 534 |
mLastRow->mRowValueList += rowValues; |
| 535 |
mRowList.append(mLastRow); |
| 536 |
mSortedIndexBuilded = false; |
| 537 |
return this; |
| 538 |
} |
| 539 |
|
| 540 |
template<class T> |
| 541 |
CReasonerEvaluationTableMultiFormatOutputWriter<T>* CReasonerEvaluationTableMultiFormatOutputWriter<T>::addValuesToLastTableRow(const QList<T>& rowValues) { |
| 542 |
mLastRow->mRowValueList += rowValues; |
| 543 |
mSortedIndexBuilded = false; |
| 544 |
return this; |
| 545 |
} |
| 546 |
|
| 547 |
template<class T> |
| 548 |
CReasonerEvaluationTableMultiFormatOutputWriter<T>* CReasonerEvaluationTableMultiFormatOutputWriter<T>::addNewTableRow(const QString& rowTitle) { |
| 549 |
mLastRow = new CReasonerEvaluationTableRow(); |
| 550 |
mLastRow->mTitle = rowTitle; |
| 551 |
mRowList.append(mLastRow); |
| 552 |
mSortedIndexBuilded = false; |
| 553 |
return this; |
| 554 |
} |
| 555 |
|
| 556 |
template<class T> |
| 557 |
CReasonerEvaluationTableMultiFormatOutputWriter<T>* CReasonerEvaluationTableMultiFormatOutputWriter<T>::buildSortedIndex() { |
| 558 |
if (!mSortedIndexBuilded) { |
| 559 |
if (!mColumnSortMapList.isEmpty()) { |
| 560 |
qDeleteAll(mColumnSortMapList); |
| 561 |
mColumnSortMapList.clear(); |
| 562 |
mTitleColumnSortedMap.clear(); |
| 563 |
} |
| 564 |
mSortedIndexBuilded = true; |
| 565 |
|
| 566 |
foreach (CReasonerEvaluationTableRow* row, mRowList) { |
| 567 |
mTitleColumnSortedMap.insertMulti(row->mTitle,row); |
| 568 |
cint64 columnIndex = 0; |
| 569 |
foreach (T value, row->mRowValueList) { |
| 570 |
if (mColumnSortMapList.count() <= columnIndex) { |
| 571 |
mColumnSortMapList.append(new QMap<T,CReasonerEvaluationTableRow*>()); |
| 572 |
} |
| 573 |
QMap<T,CReasonerEvaluationTableRow*>* columnSortMap = mColumnSortMapList.at(columnIndex); |
| 574 |
columnSortMap->insertMulti(value,row); |
| 575 |
++columnIndex; |
| 576 |
} |
| 577 |
} |
| 578 |
} |
| 579 |
return this; |
| 580 |
} |
| 581 |
|
| 582 |
|
| 583 |
}; // end namespace Evaluation |
| 584 |
|
| 585 |
}; // end namespace Test |
| 586 |
|
| 587 |
}; // end namespace Konclude |
| 588 |
|
| 589 |
#endif // KONCLUDE_TEST_EVALUATION_CREASONEREVALUATIONTABLEMULTIFORMATOUTPUTWRITER_CPP |