| 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 |
|
| 21 |
#include "CAnalyseDataCVSFileWriterObserver.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Test { |
| 27 |
|
| 28 |
namespace Analyse { |
| 29 |
|
| 30 |
|
| 31 |
CAnalyseDataCVSFileWriterObserver::CAnalyseDataCVSFileWriterObserver(const QString &outputFilename) { |
| 32 |
filename = outputFilename; |
| 33 |
file = 0; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
CAnalyseDataCVSFileWriterObserver::~CAnalyseDataCVSFileWriterObserver() { |
| 38 |
if (file) { |
| 39 |
file->close(); |
| 40 |
delete file; |
| 41 |
file = 0; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
CAnalyseDataObserver *CAnalyseDataCVSFileWriterObserver::notifyDataUpdate(CAnalyseDataSeries *data) { |
| 47 |
if (!file) { |
| 48 |
file = new QFile(filename); |
| 49 |
if (file->open(QIODevice::Append)) { |
| 50 |
QString headerString; |
| 51 |
qint64 count = data->getAnalyseDataDescription()->getAnalyseValueCount(); |
| 52 |
for (qint64 i = 0; i < count; ++i) { |
| 53 |
QString valueName = data->getAnalyseDataDescription()->getValueDescription(i)->getValueName(); |
| 54 |
headerString.append(valueName+",\t"); |
| 55 |
} |
| 56 |
headerString.append("\n"); |
| 57 |
file->write(headerString.toLocal8Bit()); |
| 58 |
} else { |
| 59 |
delete file; |
| 60 |
file = 0; |
| 61 |
} |
| 62 |
} |
| 63 |
if (file) { |
| 64 |
QString valueString; |
| 65 |
qint64 count = data->getAnalyseDataDescription()->getAnalyseValueCount(); |
| 66 |
CAnalyseDataLinker *dataLinker = data->getAnalyseDataLinker(); |
| 67 |
CAnalyseData *analyseData = dataLinker->getData(); |
| 68 |
for (qint64 i = 0; i < count; ++i) { |
| 69 |
CAnalyseValue *analyseValue = analyseData->getValue(i); |
| 70 |
CConvertStringAnalyseValue *stringAnalyseValue = 0; |
| 71 |
if (analyseValue) { |
| 72 |
dynamic_cast<CConvertStringAnalyseValue *>(analyseValue); |
| 73 |
} |
| 74 |
if (stringAnalyseValue) { |
| 75 |
QString value = stringAnalyseValue->getString(); |
| 76 |
valueString.append(value+",\t"); |
| 77 |
} else { |
| 78 |
valueString.append(",\t"); |
| 79 |
} |
| 80 |
} |
| 81 |
valueString.append("\n"); |
| 82 |
file->write(valueString.toLocal8Bit()); |
| 83 |
} |
| 84 |
return this; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
}; // end namespace Analyse |
| 90 |
|
| 91 |
}; // end namespace Test |
| 92 |
|
| 93 |
}; // end namespace Konclude |