Пример #1
0
Column* DatapickerCurve::appendColumn(const QString& name) {
	Column* col = new Column(i18n("Column"), AbstractColumn::Numeric);
	col->insertRows(0, m_datasheet->rowCount());
	col->setName(name);
	m_datasheet->addChild(col);

	return col;
}
Пример #2
0
void CSVImporter::initColumn(Column &column, const string &name, const vector<string> &cells)
{
	// we treat single spaces as missing values, because SPSS saves missing values as a single space in CSV files

	column.setName(name);

	// try to make the column nominal

	bool success = true;
	set<int> uniqueValues;
	Column::Ints::iterator intInputItr = column.AsInts.begin();
	Labels &labels = column.labels();
	labels.clear();

	BOOST_FOREACH(const string &value, cells)
	{
		if (value != "NaN" && value != "nan" && value != "" && value != " ")
		{
			try
			{
				int v = lexical_cast<int>(value);
				uniqueValues.insert(v);
				*intInputItr = v;
			}
			catch (...)
			{
				// column can't be made nominal numeric

				success = false;
				break;
			}
		}
		else
		{
			*intInputItr = INT_MIN;
		}

		intInputItr++;
	}

	if (success && uniqueValues.size() <= 24)
	{
		labels.clear();

		BOOST_FOREACH(int value, uniqueValues)
		{
			(void)uniqueValues;
			labels.add(value);
		}
Пример #3
0
void CSVImporter::initColumn(Column &column, const string &name, const vector<string> &cells)
{
	// we treat single spaces as missing values, because SPSS saves missing values as a single space in CSV files

	column.setName(name);

	// try to make the column nominal

	bool success = true;
	set<int> uniqueValues;
	std::vector<int> intValues;
	intValues.reserve(cells.size());

	BOOST_FOREACH(const string &value, cells)
	{
		if (value != "NaN" && value != "nan" && value != "" && value != " ")
		{
			try
			{
				int v = lexical_cast<int>(value);
				uniqueValues.insert(v);
				intValues.push_back(v);
			}
			catch (...)
			{
				// column can't be made nominal numeric

				success = false;
				break;
			}
		}
		else
		{
			intValues.push_back(INT_MIN);
		}
	}

	if (success && uniqueValues.size() <= 24)
	{
		column.setColumnAsNominalOrOrdinal(intValues, uniqueValues);
		return;
	}

	// try to make the column scale
	success = true;
	vector<double> doubleValues;
	doubleValues.reserve(cells.size());

	BOOST_FOREACH(const string &value, cells)
	{
		string v = deEuropeanise(value);
		double doubleValue;

		if (v != "" && v != " ")
		{
			try
			{
				doubleValue = lexical_cast<double>(v);
			}
			catch (...)
			{
				// column can't be made scale
				success = false;
				break;
			}
		}
		else
		{
			doubleValue = NAN;
		}

		doubleValues.push_back(doubleValue);
	}