MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / insertTimeSeriesData

Method insertTimeSeriesData

src/utilities/sql/SqlFile_Impl.cpp:675–754  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

673 }
674
675 void SqlFile_Impl::insertTimeSeriesData(const std::string& t_variableType, const std::string& t_indexGroup, const std::string& t_timestepType,
676 const std::string& t_keyValue, const std::string& t_variableName,
677 const openstudio::ReportingFrequency& t_reportingFrequency,
678 const boost::optional<std::string>& t_scheduleName, const std::string& t_variableUnits,
679 const openstudio::TimeSeries& t_timeSeries) {
680 int datadicindex = getNextIndex("reportdatadictionary", "ReportDataDictionaryIndex");
681
682 std::stringstream insertReportDataDictionary;
683 insertReportDataDictionary << "insert into reportdatadictionary (ReportDataDictionaryIndex, IsMeter, Type, IndexGroup, TimestepType, KeyValue, "
684 "Name, ReportingFrequency, ScheduleName, Units) values ("
685 << datadicindex << ", " << "'0'," << "'" << t_variableType << "', " << "'" << t_indexGroup << "', " << "'"
686 << t_timestepType << "', " << "'" << t_keyValue << "', " << "'" << t_variableName << "', " << "'"
687 << t_reportingFrequency.valueName() << "', ";
688
689 if (t_scheduleName) {
690 insertReportDataDictionary << "'" << *t_scheduleName << "', ";
691 } else {
692 insertReportDataDictionary << "null, ";
693 }
694
695 insertReportDataDictionary << "'" << t_variableUnits << "');";
696
697 execAndThrowOnError(insertReportDataDictionary.str());
698
699 std::vector<double> values = toStandardVector(t_timeSeries.values());
700 std::vector<double> days = toStandardVector(t_timeSeries.daysFromFirstReport());
701
702 openstudio::DateTime firstdate = t_timeSeries.firstReportDateTime();
703
704 std::shared_ptr<PreparedStatement> stmt;
705 if (hasYear()) {
706 // we'll let stmt1 have the transaction
707 stmt =
708 std::make_shared<PreparedStatement>("insert into reportdata (ReportDataIndex, TimeIndex, ReportDataDictionaryIndex, Value) values ( ?, "
709 "(select TimeIndex from time where Year=? and Month=? and Day=? and Hour=? and Minute=? limit 1), ?, ?);",
710 m_db, true);
711 } else {
712 stmt = std::make_shared<PreparedStatement>("insert into reportdata (ReportDataIndex, TimeIndex, ReportDataDictionaryIndex, Value) values ( ?, "
713 "(select TimeIndex from time where Month=? and Day=? and Hour=? and Minute=? limit 1), ?, ?);",
714 m_db, true);
715 }
716
717 for (size_t i = 0; i < values.size(); ++i) {
718 openstudio::DateTime dt = firstdate + openstudio::Time(days[i]);
719 double value = values[i];
720
721 if (dt.time().seconds() == 59) {
722 // rounding error, let's help
723 dt += openstudio::Time(0, 0, 0, 1);
724 }
725
726 if (dt.time().seconds() == 1) {
727 // rounding error, let's help
728 dt -= openstudio::Time(0, 0, 0, 1);
729 }
730
731 int year = dt.date().year();
732 int month = dt.date().monthOfYear().value();

Callers

nothing calls this directly

Calls 15

toStandardVectorFunction · 0.85
valueNameMethod · 0.80
daysFromFirstReportMethod · 0.80
firstReportDateTimeMethod · 0.80
secondsMethod · 0.80
monthOfYearMethod · 0.80
hoursMethod · 0.80
minutesMethod · 0.80
execAndThrowOnErrorMethod · 0.80
execAndThrowOnErrorFunction · 0.70
TimeClass · 0.50
strMethod · 0.45

Tested by

no test coverage detected