<commit_before>/*
 * FogLAMP storage service client
 *
 * Copyright (c) 2018 Dianomic Systems
 *
 * Released under the Apache 2.0 Licence
 *
 * Author: <NAME>
 */
#include <reading_set.h>
#include <string>
#include <rapidjson/document.h>
#include <sstream>
#include <iostream>
#include <time.h>
#include <stdlib.h>

using namespace std;
using namespace rapidjson;

/**
 * Construct a reading set from a JSON document returned from
 * the FogLAMP storage service.
 */
ReadingSet::ReadingSet(const std::string& json)
{
	Document doc;
	doc.Parse(json.c_str());
	if (doc.HasParseError())
	{
		throw new ReadingSetException("Unable to parse results json document");
	}
	if (doc.HasMember("count"))
	{
		m_count = doc["count"].GetUint();
		if (m_count)
		{
			if (!doc.HasMember("readings"))
			{
				throw new ReadingSetException("Missing readings array");
			}
			const Value& readings = doc["readings"];
			if (readings.IsArray())
			{
				// Process every rows and create the result set
				for (auto& reading : readings.GetArray())
				{
					if (!reading.IsObject())
					{
						throw new ReadingSetException("Expected reading to be an object");
					}
					JSONReading *value = new JSONReading(reading);
					m_readings.push_back(value);
				}<commit_msg>FOGL-1174 Fix rows versus readings in ReadingSet<commit_after>/*
 * FogLAMP storage service client
 *
 * Copyright (c) 2018 Dianomic Systems
 *
 * Released under the Apache 2.0 Licence
 *
 * Author: <NAME>
 */
#include <reading_set.h>
#include <string>
#include <rapidjson/document.h>
#include <sstream>
#include <iostream>
#include <time.h>
#include <stdlib.h>

using namespace std;
using namespace rapidjson;

/**
 * Construct a reading set from a JSON document returned from
 * the FogLAMP storage service.
 */
ReadingSet::ReadingSet(const std::string& json)
{
	Document doc;
	doc.Parse(json.c_str());
	if (doc.HasParseError())
	{
		throw new ReadingSetException("Unable to parse results json document");
	}
	if (doc.HasMember("count"))
	{
		m_count = doc["count"].GetUint();
		if (m_count)
		{
			if (!doc.HasMember("rows"))
			{
				throw new ReadingSetException("Missing readings array");
			}
			const Value& readings = doc["rows"];
			if (readings.IsArray())
			{
				// Process every rows and create the result set
				for (auto& reading : readings.GetArray())
				{
					if (!reading.IsObject())
					{
						throw new ReadingSetException("Expected reading to be an object");
					}
					JSONReading *value = new JSONReading(reading);
					m_readings.push_back(value);
				}
{'fraction_non_alphanumeric': 0.13026367571822117, 'fraction_numerical': 0.006296733569460842, 'mean_word_length': 3.7781954887218046, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '1968700', 'n_tokens_mistral': 949, 'n_tokens_neox': 800, 'n_words': 234}