<commit_before>#include "reporter.h"

#include <QtCore/QPointF>
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
#include <QtCore/QJsonArray>

#include <qrutils/outFile.h>

using namespace twoDModel;

Reporter::Reporter(const QString &messagesFile, const QString &trajectoryFile)
	: mMessagesFile(utils::OutFile::openOrLogError(messagesFile))
	, mTrajectoryFile(utils::OutFile::openOrLogError(trajectoryFile))
{
}

Reporter::~Reporter()
{
}

bool Reporter::lastMessageIsError()
{
	return !mMessages.isEmpty() && mMessages.last().first == Level::error;
}

void Reporter::addInformation(const QString &message)
{
	mMessages << qMakePair(Level::information, message);
}

void Reporter::addError(const QString &message)
{
	mMessages << qMakePair(Level::error, message);
}

void Reporter::newTrajectoryPoint(const QString &robotId, int timestamp, const QPointF &position, qreal rotation)
{
	if (!mTrajectoryFile.isNull()) {
		(*mTrajectoryFile)() << QString("%1 %2 %3 %4 %5\n").arg(robotId
				, QString::number(timestamp)
				, QString::number(position.x())
				, QString::number(position.y())
				, QString::number(rotation));
		mTrajectoryFile->flush();
	}
}

void Reporter::reportMessages()
{
	if (!mMessagesFile) {
		return;
	}

	QJsonArray messages;
	for (const QPair<Level, QString> &message : mMessages) {
		messages.append(QJsonObject({
			{ "level", message.first == Level::information ? "info" : "error" }
			, { "message", message.second }
		}));
	}

	QJsonDocument document;
	document.setArray(messages);
	(*mMessagesFile)() << document.toJson();
}<commit_msg>Fixed build under Qt 5.2 for travis<commit_after>#include "reporter.h"

#include <QtCore/QPointF>
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
#include <QtCore/QJsonArray>

#include <qrutils/outFile.h>

using namespace twoDModel;

Reporter::Reporter(const QString &messagesFile, const QString &trajectoryFile)
	: mMessagesFile(utils::OutFile::openOrLogError(messagesFile))
	, mTrajectoryFile(utils::OutFile::openOrLogError(trajectoryFile))
{
}

Reporter::~Reporter()
{
}

bool Reporter::lastMessageIsError()
{
	return !mMessages.isEmpty() && mMessages.last().first == Level::error;
}

void Reporter::addInformation(const QString &message)
{
	mMessages << qMakePair(Level::information, message);
}

void Reporter::addError(const QString &message)
{
	mMessages << qMakePair(Level::error, message);
}

void Reporter::newTrajectoryPoint(const QString &robotId, int timestamp, const QPointF &position, qreal rotation)
{
	if (!mTrajectoryFile.isNull()) {
		(*mTrajectoryFile)() << QString("%1 %2 %3 %4 %5\n").arg(robotId
				, QString::number(timestamp)
				, QString::number(position.x())
				, QString::number(position.y())
				, QString::number(rotation));
		mTrajectoryFile->flush();
	}
}

void Reporter::reportMessages()
{
	if (!mMessagesFile) {
		return;
	}

	QJsonArray messages;
	for (const QPair<Level, QString> &message : mMessages) {
		messages.append(QJsonObject::fromVariantMap({
			{ "level", message.first == Level::information ? "info" : "error" }
			, { "message", message.second }
		}));
	}

	QJsonDocument document;
	document.setArray(messages);
	(*mMessagesFile)() << document.toJson();
}
{'fraction_non_alphanumeric': 0.1596875, 'fraction_numerical': 0.00375, 'mean_word_length': 6.308219178082192, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2649183', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1074, 'n_words': 194}