void ApplyMeasureNowDialog::runMeasure() { runmanager::ConfigOptions co(true); if (co.getTools().getAllByName("ruby").tools().size() == 0) { QMessageBox::information(this, "Missing Ruby", "Ruby could not be located.\nOpenStudio will scan for tools.", QMessageBox::Ok); co.findTools(true); openstudio::runmanager::RunManager rm; rm.setConfigOptions(co); rm.showConfigGui(); rm.getConfigOptions().saveQSettings(); emit toolsUpdated(); if (co.getTools().getAllByName("ruby").tools().size() == 0) { QMessageBox::information(this, "Missing Ruby", "Ruby was not located by tool search.\nPlease ensure Ruby correctly installed.\nSimulation aborted.", QMessageBox::Ok); m_mainPaneStackedWidget->setCurrentIndex(m_inputPageIdx); m_timer->stop(); this->okButton()->hide(); this->backButton()->hide(); return; } } m_mainPaneStackedWidget->setCurrentIndex(m_runningPageIdx); m_timer->start(50); this->okButton()->hide(); this->backButton()->hide(); OS_ASSERT(m_model); openstudio::OSAppBase * app = OSAppBase::instance(); m_workingDir = openstudio::toPath(app->currentDocument()->modelTempDir()) / openstudio::toPath("ApplyMeasureNow"); openstudio::path modelPath = m_workingDir / openstudio::toPath("modelClone.osm"); openstudio::path epwPath; // DLM: todo look at how this is done in the run tab removeWorkingDir(); // save cloned model to temp directory m_model->save(modelPath,true); // remove? this is shown only in debug (EW) QString path("Measure Output Location: "); path.append(toQString(m_workingDir)); m_jobPath->setText(path); analysis::RubyMeasure rubyMeasure = m_currentMeasureItem->measure(); // DLM: should be able to assert this bool hasIncompleteArguments = m_currentMeasureItem->hasIncompleteArguments(); OS_ASSERT(!hasIncompleteArguments); runmanager::RubyJobBuilder rjb(*m_bclMeasure, rubyMeasure.arguments()); openstudio::path p = getOpenStudioRubyIncludePath(); QString arg = "-I"; arg.append(toQString(p)); rjb.addToolArgument(arg.toStdString()); openstudio::runmanager::Workflow wf; rjb.addToWorkflow(wf); wf.add(co.getTools()); wf.setInputFiles(modelPath, openstudio::path()); m_job = wf.create(m_workingDir, modelPath); // DLM: you could make rm a class member then you would not have to call waitForFinished here runmanager::RunManager rm; bool queued = rm.enqueue(*m_job, true); OS_ASSERT(queued); std::vector<runmanager::Job> jobs = rm.getJobs(); OS_ASSERT(jobs.size() == 1); rm.waitForFinished (); QTimer::singleShot(0, this, SLOT(displayResults())); }
bool saveRunManagerDatabase(const openstudio::path& osmPath, const openstudio::path& modelTempDir, const std::map<openstudio::path,std::vector<ruleset::UserScriptInfo> >& userScriptsByFolder, std::vector <double> useRadianceForDaylightingCalculations, QWidget* parent) { bool newToolsFound = false; openstudio::path rmdbPath = modelTempDir / toPath("resources/run.db"); openstudio::path scriptsDir = modelTempDir / toPath("resources/scripts"); openstudio::path simulationDir = openstudio::toPath("run"); try { // this run db exists just to hold the jobs to be loaded from later, it is not unpaused openstudio::runmanager::RunManager rm(rmdbPath, true, true, false); // this should not be necessary as rm was constructed with truncate set to true? rm.clearJobs(); openstudio::runmanager::ConfigOptions co = rm.getConfigOptions(); newToolsFound = co.findTools(true, true, true, true); rm.setConfigOptions(co); openstudio::runmanager::Workflow wf; bool ruby_installed = rm.getConfigOptions().getTools().getAllByName("ruby").tools().size() > 0; openstudio::path radiancePath; std::vector<openstudio::runmanager::ToolInfo> rad = rm.getConfigOptions().getTools().getAllByName("rad").tools(); if (!rad.empty()) { radiancePath = rad.back().localBinPath.parent_path(); } bool ruby_jobs_skipped = wf.addStandardWorkflow(scriptsDir, ruby_installed, getOpenStudioRubyIncludePath(), userScriptsByFolder, useRadianceForDaylightingCalculations.size() > 0, radiancePath, modelTempDir / toPath("resources"), true); if (ruby_jobs_skipped) { QMessageBox::information(parent, "No Ruby Interpreter", "Measures were provided but no ruby interpreter could be found. Scripts will not be run.", QMessageBox::Ok); } openstudio::runmanager::Tools tools = rm.getConfigOptions().getTools(); wf.add(tools); wf.addParam(runmanager::JobParam("flatoutdir")); openstudio::runmanager::Job j = wf.create(simulationDir, toPath("../in.osm")); rm.enqueue(j, true); } catch (const std::exception &e) { QMessageBox::information(parent, "Error Initiating Simulation", e.what(), QMessageBox::Ok); } return newToolsFound; }
void addRadianceToProject(openstudio::analysisdriver::SimpleProject &t_project) { openstudio::analysis::Problem problem = t_project.analysis().problem(); OptionalInt index = getProjectRadianceJobIndex(t_project); if (index) { return; // nothing to do } openstudio::runmanager::ConfigOptions co(true); std::vector<openstudio::runmanager::ToolInfo> rad = co.getTools().getAllByName("rad").tools(); if (!rad.empty()) { openstudio::path radiancePath = rad.back().localBinPath.parent_path(); OptionalInt index = problem.getWorkflowStepIndexByJobType(runmanager::JobType::ModelToIdf); if (index) { LOG_FREE(Debug, "WorkflowTools", "Adding radiance job at location " << *index); openstudio::runmanager::WorkItem wi = runmanager::Workflow::radianceDaylightCalculations(getOpenStudioRubyIncludePath(), radiancePath); wi.jobkeyname = "pat-radiance-job"; problem.insert(*index, wi); } } }
bool ExportSpreadsheet::exportSpreadsheet(const analysisdriver::SimpleProject& project) { //Make sure a QApplication exists openstudio::Application::instance().application(); //get the project's directory openstudio::path projectPath = project.projectDir(); LOG_FREE(Debug, "ExportSpreadsheet", "Starting export of projectPath:" << toString(projectPath)); openstudio::path rubyPath; #if defined(Q_OS_WIN) rubyPath = getOpenStudioEmbeddedRubyPath() / toPath("bin/ruby.exe"); #else rubyPath = "ruby"; #endif openstudio::path rubyIncludePath = getOpenStudioRubyIncludePath(); if (!boost::filesystem::exists(rubyIncludePath)) { LOG_FREE(Error, "ExportSpreadsheet", "Ruby include path '" << rubyIncludePath << "' cannot be found."); return false; } openstudio::path scriptPath = getOpenStudioRubyScriptsPath() / openstudio::toPath("openstudio/analysisdriver/ExportToSpreadsheet.rb"); if (!boost::filesystem::exists(scriptPath)) { LOG_FREE(Error, "ExportSpreadsheet", "ExportToSpreadsheet script '" << scriptPath << "' cannot be found."); return false; } QStringList args; args << "-I"; args << openstudio::toQString(rubyIncludePath); args << openstudio::toQString(scriptPath); args << openstudio::toQString(projectPath); auto p = new QProcess(); p->start(toQString(rubyPath), args); if (!p->waitForStarted(30000)) { p->terminate(); p->deleteLater(); LOG_FREE(Error, "ExportSpreadsheet", "Process failed to start"); return false; } if (!p->waitForFinished(300000)) { p->terminate(); p->deleteLater(); LOG_FREE(Error, "ExportSpreadsheet", "Process failed to complete"); return false; } QByteArray error = p->readAllStandardError(); std::string errorString = toString(QString(error)); LOG_FREE(Debug, "ExportSpreadsheet", "StandardError:" << std::endl << errorString); QByteArray output = p->readAllStandardOutput(); std::string outputString = toString(QString(output)); LOG_FREE(Debug, "ExportSpreadsheet", "StandardOutput:" << std::endl << outputString); // remove previous export openstudio::path exportPath = projectPath / toPath("analysis_spreadsheet_export"); openstudio::path modelMeasuresCSV = exportPath / toPath("spreadsheet_model_measures_export.csv"); openstudio::path energyplusMeasuresCSV = exportPath / toPath("spreadsheet_energyplus_measures_export.csv"); openstudio::path reportingMeasuresCSV = exportPath / toPath("spreadsheet_reporting_measures_export.csv"); openstudio::path outputsCSV = exportPath / toPath("spreadsheet_outputs_export.csv"); bool result = ((p->exitStatus() == QProcess::NormalExit) && boost::filesystem::exists(modelMeasuresCSV) && boost::filesystem::exists(energyplusMeasuresCSV) && boost::filesystem::exists(reportingMeasuresCSV) && boost::filesystem::exists(outputsCSV)); p->deleteLater(); return result; }