Skip to content

Commit

Permalink
Fix comma sensitivity (#5368)
Browse files Browse the repository at this point in the history
* update debug.csv

change separator to ';' and add to entries with a comma as decimal to detect problems like jasp-stats/jasp-issues#2499

* Fix comma import from csv/ods/etc

Partial fix for jasp-stats/jasp-issues#2499

* add some 123.456.789,000 dots combined with commas to the debug dataset

* the event can just be aware of when it ought to be readonly
  • Loading branch information
JorisGoosen authored Jan 4, 2024
1 parent 3a5d2b8 commit 349ea62
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 134 deletions.
6 changes: 3 additions & 3 deletions CommonData/column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1622,18 +1622,18 @@ bool Column::convertValueToIntForImport(const std::string &strValue, int &intVal
return ColumnUtils::getIntValue(strValue, intValue);
}

/// There is a ColumnUtils::convertValueToDoubleForImport that is used during import from readstat and which only looks at workspace empty values
bool Column::convertValueToDoubleForImport(const std::string & strValue, double & doubleValue) const
{
std::string v = strValue;
ColumnUtils::deEuropeaniseForImport(v);
std::string v = ColumnUtils::deEuropeaniseForImport(strValue);

if(isEmptyValue(v))
{
doubleValue = NAN;
return true;
}

return ColumnUtils::getDoubleValue(strValue, doubleValue);
return ColumnUtils::getDoubleValue(v, doubleValue);
}


Expand Down
9 changes: 5 additions & 4 deletions CommonData/columnutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ bool ColumnUtils::isDoubleValue(const string &value)
}


void ColumnUtils::deEuropeaniseForImport(std::string & value)
std::string ColumnUtils::deEuropeaniseForImport(std::string value)
{
int dots = 0,
commas = 0;
Expand All @@ -102,7 +102,7 @@ void ColumnUtils::deEuropeaniseForImport(std::string & value)
if(k == ',')
{
k = '.';
return;
return value;
}

if (commas > 0)
Expand Down Expand Up @@ -133,6 +133,8 @@ void ColumnUtils::deEuropeaniseForImport(std::string & value)

value = uneurope;
}

return value;
}

bool ColumnUtils::convertValueToIntForImport(const std::string &strValue, int &intValue)
Expand All @@ -152,8 +154,7 @@ bool ColumnUtils::convertValueToIntForImport(const std::string &strValue, int &i

bool ColumnUtils::convertValueToDoubleForImport(const std::string & strValue, double & doubleValue)
{
std::string v = strValue;
deEuropeaniseForImport(v);
std::string v = deEuropeaniseForImport(strValue);

if(isEmptyValue(v, EmptyValues::singleton()->workspaceEmptyValues()))
doubleValue = NAN;
Expand Down
27 changes: 13 additions & 14 deletions CommonData/columnutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ class ColumnUtils

static std::string emptyValue;

static bool getIntValue( const std::string & value, int & intValue);
static bool getIntValue( const double & value, int & intValue);
static bool getDoubleValue( const std::string & value, double & doubleValue);

static bool isIntValue( const std::string & value);
static bool isDoubleValue( const std::string & value);

static bool convertValueToIntForImport( const std::string & strValue, int & intValue);
static bool convertValueToDoubleForImport( const std::string & strValue, double & doubleValue);
static bool isEmptyValue( const std::string & val, const stringset & emptyValues);
static bool isEmptyValue( const double val, const doubleset & doubleEmptyValues);
static void convertEscapedUnicodeToUTF8( std::string & inputStr);
static void deEuropeaniseForImport( std::string & value);

static bool getIntValue( const std::string & value, int & intValue);
static bool getIntValue( const double & value, int & intValue);
static bool getDoubleValue( const std::string & value, double & doubleValue);

static bool isIntValue( const std::string & value);
static bool isDoubleValue( const std::string & value);

static bool convertValueToIntForImport( const std::string & strValue, int & intValue);
static bool convertValueToDoubleForImport( const std::string & strValue, double & doubleValue);
static bool isEmptyValue( const std::string & val, const stringset & emptyValues);
static bool isEmptyValue( const double val, const doubleset & doubleEmptyValues);
static void convertEscapedUnicodeToUTF8( std::string & inputStr);
static std::string deEuropeaniseForImport( std::string value);
static std::string doubleToString( double dbl, int precision = 10);

private:
Expand Down
2 changes: 1 addition & 1 deletion Desktop/analysis/analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class Analysis : public AnalysisBase
void requestComputedColumnDestruction( const std::string & columnName);

void refreshTableViewModels();
Q_INVOKABLE void expandAnalysis();
void expandAnalysis();
void emptyQMLCache();

void createFormWhenYouHaveAMoment(QQuickItem* parent = nullptr);
Expand Down
10 changes: 6 additions & 4 deletions Desktop/data/fileevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
#include "exporters/jaspexporter.h"

#include <QTimer>
#include "utilities/qutils.h"
#include "log.h"
#include "utilities/appdirs.h"

FileEvent::FileEvent(QObject *parent, FileEvent::FileMode fileMode)
: QObject(parent), _operation(fileMode)
Expand Down Expand Up @@ -51,8 +50,6 @@ void FileEvent::setDataFilePath(const QString & path)

void FileEvent::setDatabase(const Json::Value & dbInfo)
{
setReadOnly();

_database = dbInfo;
}

Expand Down Expand Up @@ -110,6 +107,11 @@ void FileEvent::chain(FileEvent *event)
connect(event, &FileEvent::completed, this, &FileEvent::chainedComplete);
}

bool FileEvent::isExample() const
{
return path().startsWith(AppDirs::examples());
}

const std::string FileEvent::databaseStr() const
{
return _database.toStyledString();
Expand Down
8 changes: 3 additions & 5 deletions Desktop/data/fileevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ class FileEvent : public QObject
void setComplete(bool success = true, const QString &message = "");
void chain(FileEvent *event);

void setReadOnly() { _readOnly = true; }

bool isDatabase() const { return _database != Json::nullValue; }
bool isOnlineNode() const { return _path.startsWith("http"); }
bool isReadOnly() const { return _readOnly; }
bool isExample() const;
bool isReadOnly() const { return isExample() || isDatabase(); }
bool isCompleted() const { return _completed; }
bool isSuccessful() const { return _success; }

Expand Down Expand Up @@ -83,8 +82,7 @@ private slots:
_dataFilePath,
_last_error = "Unknown error",
_message;
bool _readOnly = false,
_completed = false,
bool _completed = false,
_success = false;
FileEvent * _chainedTo = nullptr;
Exporter * _exporter = nullptr;
Expand Down
1 change: 0 additions & 1 deletion Desktop/widgets/filemenu/datalibrarylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ void DataLibraryListModel::openFile(const QString &path)
{
FileEvent *event = new FileEvent(this->parent(), FileEvent::FileOpen);
event->setPath(path);
event->setReadOnly(); // A file from the Data Library should be read only, also csv file so that its path is not added in the recent list

emit openFileEvent(event);

Expand Down
2 changes: 1 addition & 1 deletion Desktop/widgets/filemenu/filemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void FileMenu::dataSetIOCompleted(FileEvent *event)
if (!event->isDatabase())
{
_recentFiles->pushRecentFilePath(event->path());
if (!event->path().startsWith(AppDirs::examples()))
if (!event->isExample())
_computer->addRecentFolder(event->path());
}

Expand Down
Loading

0 comments on commit 349ea62

Please sign in to comment.