wxFileName t4p::JsTagsSqlSchemaAsset() { wxFileName asset = AssetRootDir(); asset.AppendDir(wxT("sql")); wxFileName sqlFile(asset.GetPath(), wxT("js_tags.sql")); return sqlFile; }
void TimeDependentValuationFixture::SetUp() { // load model openstudio::path modelPath = resourcesPath()/ openstudio::toPath(GetParam().first)/ openstudio::toPath("in.osm"); openstudio::model::OptionalModel oModel = openstudio::model::Model::load(modelPath); ASSERT_TRUE(oModel); m_model = *oModel; // set TDV file openstudio::path tdvPath = resourcesPath()/openstudio::toPath(GetParam().second); openstudio::OptionalTimeDependentValuationFile oTdvFile = openstudio::TimeDependentValuationFile::load(tdvPath); ASSERT_TRUE(oTdvFile); openstudio::model::OptionalTimeDependentValuation oTdv = openstudio::model::TimeDependentValuation::setTimeDependentValuation(m_model,*oTdvFile); ASSERT_TRUE(oTdv); // set SqlFile openstudio::path sqlPath = resourcesPath()/ openstudio::toPath(GetParam().first)/ openstudio::toPath("eplusout.sql"); if (!boost::filesystem::exists(sqlPath)) { sqlPath = resourcesPath()/ openstudio::toPath(GetParam().first)/ openstudio::toPath("in.sql"); } openstudio::SqlFile sqlFile(sqlPath); m_model.setSqlFile(sqlFile); }
wxFileName t4p::ResourceSqlSchemaAsset() { wxFileName asset = AssetRootDir(); asset.AppendDir(wxT("sql")); wxFileName sqlFile(asset.GetPath(), wxT("resources.sql")); return sqlFile; }
wxFileName t4p::DetectorSqlSchemaAsset() { wxFileName asset = AssetRootDir(); asset.AppendDir(wxT("sql")); wxFileName sqlFile(asset.GetPath(), wxT("detectors.sql")); return sqlFile; }
std::string SqlUtils::determineSql(std::string sqlFilename) { std::string sql; std::string sqlFile(resourcePath + "/" + sqlFilename); std::ifstream sqlStream(sqlFile.c_str()); if (sqlStream.good()) { std::getline(sqlStream, sql); sqlStream.close(); } else { std::string errmsg("File "); errmsg.append(sqlFile); errmsg.append(" does not exist.\n"); throw std::runtime_error(errmsg); } return sql; }
// Construct the login dialog using a QWidget and QDialog. On executiong of // the login dialog, a connection to the database must be first established. // The login credentials will be checked by the database to determine if the // user is a valid user in the database of the inventory management system. // // args: // parent (QWidget*): The widget that is used for drawing the child widget. LoginDialog::LoginDialog(QWidget* parent) : QDialog(parent), uiLogin(new Ui::LoginDialog) { uiLogin->setupUi(this); QString sqlPath = qApp->applicationDirPath() + "/sql/db.sqlite3"; QFileInfo sqlFile(sqlPath); sqlDB = sqlDAL::getInstance(sqlPath); if(sqlDB->connect() && sqlFile.isFile()) uiLogin->loginResult->setText("[+]Database connection established"); else uiLogin->loginResult->setText("[!]Invalid database"); }
QString ReleaseDialog::getReadFilePath(QDateTime &start, QDateTime &end) { QString path = QCoreApplication::applicationDirPath(); QString readjsonPath = path; readjsonPath.append("/JSON/"); QString destPath = jsonPath; destPath.append("sql.json"); QFile sqlFile(destPath); if(sqlFile.exists()) sqlFile.remove(); bool res = true; if(sqlFile.open(QIODevice::WriteOnly | QIODevice::Append)) { while(res) { QString tempPath = readjsonPath; tempPath.append("/"); tempPath.append(start.toString("yyyy-MM-dd")); tempPath.append(".json"); QFile file(tempPath); if(file.exists()) { if(file.open(QIODevice::ReadOnly)) { sqlFile.write(file.readAll()); sqlFile.write("\r\n"); } file.close(); } start = start.addDays(1); if(start > end || start > currentDate) res = false; } } sqlFile.close(); return destPath; }
void DataBase::_createDB() { QResource sqlFile(":/sql/database.sql"); QFile f(sqlFile.absoluteFilePath()); if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) qFatal("Could not open the sql file"); QTextStream stream(&f); QStringList commands = stream.readAll().split(";"); foreach (const QString &command, commands) { if (command.trimmed().isEmpty()) continue; QSqlQuery query(_db); query.prepare(command); if (!query.exec()) qFatal("Could not execute the command: %s \n", command.toStdString().c_str()); } f.close(); }
void ModelToRadJob::startImpl(const boost::shared_ptr<ProcessCreator> &) { openstudio::path outpath = outdir(); QWriteLocker l(&m_mutex); JobErrors errors; errors.result = ruleset::OSResultValue::Success; try { if (!m_model) { m_model = modelFile(); } if (!m_sql) { m_sql = sqlFile(); } resetFiles(m_files, m_model); } catch (const std::runtime_error &e) { errors.result = ruleset::OSResultValue::Fail; errors.addError(ErrorType::Error, e.what()); } if (!m_sql || !m_model) { errors.result = ruleset::OSResultValue::Fail; errors.addError(ErrorType::Error, "Unable to find required model or sql file"); } LOG(Info, "ModelToRad starting, filename: " << toString(m_model->fullPath)); LOG(Info, "ModelToRad starting, outdir: " << toString(outpath)); l.unlock(); emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Starting)); emitStarted(); emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Processing)); if (errors.result == ruleset::OSResultValue::Fail) { setErrors(errors); return; } try { boost::filesystem::create_directories(outpath); // // setup // LOG(Debug, "Working Directory: " + openstudio::toString(outpath)); // get model boost::optional<openstudio::IdfFile> idf = openstudio::IdfFile::load(m_model->fullPath); openstudio::model::Model model = openstudio::model::Model(idf.get()); // load the sql file openstudio::SqlFile sqlFile(m_sql->fullPath); if (!sqlFile.connectionOpen()) { LOG(Error, "SqlFile connection is not open"); errors.result = ruleset::OSResultValue::Fail; errors.addError(ErrorType::Error, "SqlFile collection is not open"); setErrors(errors); return; } // set the sql file model.setSqlFile(sqlFile); if (!model.sqlFile()) { LOG(Error, "SqlFile is not set on model"); errors.result = ruleset::OSResultValue::Fail; errors.addError(ErrorType::Error, "SqlFile is not set on model"); setErrors(errors); return; } openstudio::radiance::ForwardTranslator ft; std::vector<openstudio::path> outfiles = ft.translateModel(outpath, model); // capture translator errors and warnings? //ft.errors(); //ft.warnings(); Files outfileinfos; for (std::vector<openstudio::path>::const_iterator itr = outfiles.begin(); itr != outfiles.end(); ++itr) { FileInfo fi = RunManager_Util::dirFile(*itr); LOG(Info, "Output file generated: " << openstudio::toString(fi.fullPath)); emitOutputFileChanged(fi); outfileinfos.append(fi); } l.relock(); m_outputfiles = outfileinfos; /// Do work here - and be sure to set output files too } catch (const std::runtime_error &e) { errors.addError(ErrorType::Error, "Error with conversion (runtime_error): " + std::string(e.what())); errors.result = ruleset::OSResultValue::Fail; } catch (const std::exception &e) { errors.addError(ErrorType::Error, "Error with conversion: " + std::string(e.what())); errors.result = ruleset::OSResultValue::Fail; } setErrors(errors); }
void OpenStudioPostProcessJob::startImpl(const boost::shared_ptr<ProcessCreator> &) { QWriteLocker l(&m_mutex); JobErrors errors; errors.result = ruleset::OSResultValue::Success; try { m_sql = sqlFile(); m_osm = osmFile(); resetFiles(m_files, m_sql, m_osm); } catch (const std::exception &e) { JobErrors error; error.result = ruleset::OSResultValue::Fail; error.addError(ErrorType::Error, e.what()); errors = error; } if (m_sql) { LOG(Info, "OpenStudioPostProcess starting, filename: " << toString(m_sql->fullPath)); } LOG(Info, "OpenStudioPostProcess starting, outdir: " << toString(outdir())); l.unlock(); emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Starting)); emitStarted(); emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Processing)); if (errors.result == ruleset::OSResultValue::Fail) { setErrors(errors); return; } try { SqlFile sqlFile(m_sql->fullPath); boost::optional<openstudio::model::Model> model = model::Model::load(m_osm->fullPath); if (!model) { throw std::runtime_error("Unable to load model file from " + openstudio::toString(m_osm->fullPath)); } model->setSqlFile(sqlFile); boost::filesystem::create_directories(outdir(true)); std::vector<Attribute> attributes = PostProcessReporting::go(sqlFile); // ETH@20140219 - Not great to add an object here either, but needed for // Facility, and Building is really the same case. (If get this far with // simulation, no harm in accessing data through Building, which has // smart defaults for all fields.) model::Building building = model->getUniqueModelObject<model::Building>(); LOG(Debug,"Extracting attributes from model::Building."); boost::optional<Attribute> attribute; boost::optional<double> value = building.floorArea(); if (value){ attribute = Attribute("floorArea", *value, "m^2"); attribute->setDisplayName("Floor Area"); attributes.push_back(*attribute); } value = building.conditionedFloorArea(); if (value){ attribute = Attribute("conditionedFloorArea", *value, "m^2"); attribute->setDisplayName("Conditioned Floor Area"); attributes.push_back(*attribute); } // ETH@20140218 - Not great to add an object here, but otherwise, do not get // calibration results table in PAT. model::Facility facility = model->getUniqueModelObject<model::Facility>(); LOG(Debug,"Extracting attributes from model::Facility."); value = facility.economicsCapitalCost(); if (value){ attribute = Attribute("economicsCapitalCost", *value, "$"); attribute->setDisplayName("Capital Cost"); attributes.push_back(*attribute); } value = facility.economicsTLCC(); if (value){ attribute = Attribute("economicsTLCC", *value, "$"); attribute->setDisplayName("Total Life Cycle Cost"); attributes.push_back(*attribute); } value = facility.annualWaterTotalCost(); if (value){ attribute = Attribute("annualWaterTotalCost", *value, "$"); attribute->setDisplayName("Annual Water Total Cost"); attributes.push_back(*attribute); } attribute = facility.endUsesAttribute(); if (attribute){ attributes.push_back(*attribute); } attribute = facility.calibrationResultAttribute(); if (attribute){ attributes.push_back(*attribute); } boost::optional<model::TimeDependentValuation> timeDependentValuation = model->getOptionalUniqueModelObject<model::TimeDependentValuation>(); if (timeDependentValuation){ LOG(Debug,"Extracting attributes from model::TimeDependentValuation."); boost::optional<Attribute> attribute; boost::optional<double> value = timeDependentValuation->energyTimeDependentValuation(); if (value){ attribute = Attribute("energyTimeDependentValuation", *value, "J"); attribute->setDisplayName("Energy Time Dependent Valuation"); attributes.push_back(*attribute); } value = timeDependentValuation->costTimeDependentValuation(); if (value){ attribute = Attribute("costTimeDependentValuation", *value, "$"); attribute->setDisplayName("Cost Time Dependent Valuation"); attributes.push_back(*attribute); } } if (attributes.empty()) { LOG(Warn, "No attributes loaded for report"); } Attribute report("Report", attributes); bool result = report.saveToXml(outdir() / openstudio::toPath("report.xml")); if (!result){ LOG_AND_THROW("Failed to write report.xml"); } } catch (const std::exception &e) { LOG(Error, "Error with OpenStudioPostProcessJob: " + std::string(e.what())); errors.addError(ErrorType::Error, "Error with OpenStudioPostProcessJob: " + std::string(e.what())); errors.result = ruleset::OSResultValue::Fail; } // Change this to whatever output files you generate emitOutputFileChanged(RunManager_Util::dirFile(outdir() / openstudio::toPath("report.xml"))); setErrors(errors); }
void EnergyPlusPostProcessJob::startImpl(const boost::shared_ptr<ProcessCreator> &) { openstudio::path outpath = outdir(); QWriteLocker l(&m_mutex); JobErrors errors; errors.result = ruleset::OSResultValue::Success; try { m_sql = sqlFile(); resetFiles(m_files, m_sql); } catch (const std::exception &e) { std::vector<std::pair<ErrorType, std::string> > err; err.push_back(std::make_pair(ErrorType::Error, e.what())); errors = JobErrors(ruleset::OSResultValue::Fail, err); } if (m_sql) { LOG(Info, "EnergyPlusPostProcess starting, filename: " << toString(m_sql->fullPath)); } LOG(Info, "EnergyPlusPostProcess starting, outdir: " << toString(outpath)); l.unlock(); emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Starting)); emitStarted(); emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Processing)); if (errors.result == ruleset::OSResultValue::Fail) { setErrors(errors); return; } SqlFile sqlFile(m_sql->fullPath); try { boost::filesystem::create_directories(outpath); std::vector<Attribute> attributes = PostProcessReporting::go(sqlFile); if (attributes.empty()) { LOG(Warn, "No attributes loaded for report"); } Attribute report("Report", attributes); bool result = report.saveToXml(outpath / openstudio::toPath("report.xml")); if (!result){ LOG_AND_THROW("Failed to write report.xml"); } } catch (const std::exception &e) { LOG(Error, "Error with EnergyPlusPostProcessJob: " + std::string(e.what())); errors.addError(ErrorType::Error, "Error with EnergyPlusPostProcessJob: " + std::string(e.what())); errors.result = ruleset::OSResultValue::Fail; } // Change this to whatever output files you generate emitOutputFileChanged(RunManager_Util::dirFile(outpath / openstudio::toPath("report.xml"))); setErrors(errors); }
void OpenStudioPostProcessJob::startImpl(const boost::shared_ptr<ProcessCreator> &) { QWriteLocker l(&m_mutex); JobErrors errors; errors.result = ruleset::OSResultValue::Success; try { m_sql = sqlFile(); m_osm = osmFile(); resetFiles(m_files, m_sql, m_osm); } catch (const std::exception &e) { JobErrors error; error.result = ruleset::OSResultValue::Fail; error.addError(ErrorType::Error, e.what()); errors = error; } if (m_sql) { LOG(Info, "OpenStudioPostProcess starting, filename: " << toString(m_sql->fullPath)); } LOG(Info, "OpenStudioPostProcess starting, outdir: " << toString(outdir())); l.unlock(); emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Starting)); emitStarted(); emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Processing)); if (errors.result == ruleset::OSResultValue::Fail) { setErrors(errors); return; } try { SqlFile sqlFile(m_sql->fullPath); boost::optional<openstudio::model::Model> model = model::Model::load(m_osm->fullPath); if (!model) { throw std::runtime_error("Unable to load model file from " + openstudio::toString(m_osm->fullPath)); } model->setSqlFile(sqlFile); boost::filesystem::create_directories(outdir(true)); std::vector<Attribute> attributes = PostProcessReporting::go(sqlFile); boost::optional<model::Building> building = model->getOptionalUniqueModelObject<model::Building>(); if (building) { LOG(Debug,"Extracting attributes from model::Building."); boost::optional<Attribute> attribute = building->getAttribute("floorArea"); if (attribute){ attribute->setDisplayName("Floor Area"); attribute->setUnits("m^2"); attributes.push_back(*attribute); } attribute = building->getAttribute("conditionedFloorArea"); if (attribute){ attribute->setDisplayName("Conditioned Floor Area"); attribute->setUnits("m^2"); attributes.push_back(*attribute); } } boost::optional<model::Facility> facility = model->getOptionalUniqueModelObject<model::Facility>(); if (facility){ LOG(Debug,"Extracting attributes from model::Facility."); boost::optional<Attribute> attribute = facility->getAttribute("economicsCapitalCost"); if (attribute){ attribute->setDisplayName("Capital Cost"); attribute->setUnits("$"); attributes.push_back(*attribute); } attribute = facility->getAttribute("economicsTLCC"); if (attribute){ attribute->setDisplayName("Total Life Cycle Cost"); attribute->setUnits("$"); attributes.push_back(*attribute); } attribute = facility->getAttribute("annualWaterTotalCost"); if (attribute){ attribute->setDisplayName("Annual Water Total Cost"); attribute->setUnits("$"); attributes.push_back(*attribute); } attribute = facility->getAttribute("endUsesAttribute"); if (attribute){ attributes.push_back(*attribute); } } boost::optional<model::TimeDependentValuation> timeDependentValuation = model->getOptionalUniqueModelObject<model::TimeDependentValuation>(); if (timeDependentValuation){ LOG(Debug,"Extracting attributes from model::TimeDependentValuation."); boost::optional<Attribute> attribute = timeDependentValuation->getAttribute("energyTimeDependentValuation"); if (attribute){ attribute->setDisplayName("Energy Time Dependent Valuation"); attribute->setUnits("J"); attributes.push_back(*attribute); } attribute = timeDependentValuation->getAttribute("costTimeDependentValuation"); if (attribute){ attribute->setDisplayName("Cost Time Dependent Valuation"); attribute->setUnits("$"); attributes.push_back(*attribute); } } if (attributes.empty()) { LOG(Warn, "No attributes loaded for report"); } Attribute report("Report", attributes); bool result = report.saveToXml(outdir() / openstudio::toPath("report.xml")); if (!result){ LOG_AND_THROW("Failed to write report.xml"); } } catch (const std::exception &e) { LOG(Error, "Error with OpenStudioPostProcessJob: " + std::string(e.what())); errors.addError(ErrorType::Error, "Error with OpenStudioPostProcessJob: " + std::string(e.what())); errors.result = ruleset::OSResultValue::Fail; } // Change this to whatever output files you generate emitOutputFileChanged(RunManager_Util::dirFile(outdir() / openstudio::toPath("report.xml"))); setErrors(errors); }
bool DatabaseManager::createDB() { QSqlDatabase db = QSqlDatabase::database(DB_CONNECTION_NAME); // Db does not exist, or is corrupted. Open a new one and fill it. if (!db.open()) { qDebug() << db.lastError().text(); return false; } QFile sqlFile(":/personal-qt.sql"); if (sqlFile.open(QIODevice::ReadOnly | QIODevice::Text)) { QString sql = ""; QTextStream in(&sqlFile); QSqlQuery qry(db); // qry.prepare(in.readAll()); while (!in.atEnd()) { QString line = in.readLine(); if (line.startsWith('#')) { qDebug() << line; } else { sql += line; if (line.contains(';')) { qDebug() << sql; if (!qry.exec(sql)) { qDebug() << qry.lastError().text(); sqlFile.close(); db.close(); return false; } sql = ""; } } } sqlFile.close(); db.close(); return true; } else { db.close(); return false; } }