Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for legal results filename #366

Merged
merged 4 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions source/FPSciApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ void FPSciApp::updateSession(const String& id, bool forceReload) {
if (!id.empty() && ids.contains(id)) {
// Load the session config specified by the id
sessConfig = experimentConfig.getSessionConfigById(id);
logPrintf("User selected session: %s. Updating now...\n", id);
logPrintf("User selected session: %s. Updating now...\n", id.c_str());
m_userSettingsWindow->setSelectedSession(id);
// Create the session based on the loaded config
sess = Session::create(this, sessConfig);
Expand Down Expand Up @@ -722,9 +722,13 @@ void FPSciApp::updateSession(const String& id, bool forceReload) {
FileSystem::createDirectory(resultsDirPath);
}

const String logName = sessConfig->logger.logToSingleDb ?
resultsDirPath + experimentConfig.description + "_" + userStatusTable.currentUser + "_" + m_expConfigHash :
resultsDirPath + id + "_" + userStatusTable.currentUser + "_" + String(FPSciLogger::genFileTimestamp());
// Create and check log file name
const String logFileBasename = sessConfig->logger.logToSingleDb ?
experimentConfig.description + "_" + userStatusTable.currentUser + "_" + m_expConfigHash :
id + "_" + userStatusTable.currentUser + "_" + String(FPSciLogger::genFileTimestamp());
const String logFilename = FilePath::makeLegalFilename(logFileBasename);
// This is the specified path and log basename with illegal characters replaced, but not suffix (.db)
const String logPath = resultsDirPath + logFilename;

if (systemConfig.hasLogger) {
if (!sessConfig->clickToPhoton.enabled) {
Expand All @@ -738,18 +742,18 @@ void FPSciApp::updateSession(const String& id, bool forceReload) {
m_pyLogger->mergeLogToDb();
}
// Run a new logger if we need to (include the mode to run in here...)
m_pyLogger->run(logName, sessConfig->clickToPhoton.mode);
m_pyLogger->run(logPath, sessConfig->clickToPhoton.mode);
}

// Initialize the experiment (this creates the results file)
sess->onInit(logName+".db", experimentConfig.description + "/" + sessConfig->description);
sess->onInit(logPath, experimentConfig.description + "/" + sessConfig->description);

// Don't create a results file for a user w/ no sessions left
if (m_userSettingsWindow->sessionsForSelectedUser() == 0) {
logPrintf("No sessions remaining for selected user.\n");
}
else {
logPrintf("Created results file: %s.db\n", logName.c_str());
logPrintf("Created results file: %s.db\n", logPath.c_str());
}

if (m_firstSession) {
Expand Down
4 changes: 2 additions & 2 deletions source/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ void Session::onInit(String filename, String description) {
if (m_config->logger.enable) {
UserConfig user = *m_app->currentUser();
// Setup the logger and create results file
logger = FPSciLogger::create(filename, user.id, m_config, description);
logger = FPSciLogger::create(filename + ".db", user.id, m_config, description);
logger->logTargetTypes(m_app->experimentConfig.getSessionTargets(m_config->id)); // Log target info at start of session
logger->logUserConfig(user, m_config->id, m_config->player.turnScale); // Log user info at start of session
m_dbFilename = filename.substr(0, filename.length() - 3);
m_dbFilename = filename;
}

runSessionCommands("start"); // Run start of session commands
Expand Down