Skip to content

Commit

Permalink
Initial Time-series data in JSON
Browse files Browse the repository at this point in the history
Initial time series data in JSON, output using cJSON
  • Loading branch information
sanyalj committed Dec 19, 2014
1 parent d93bb2f commit 99bafdd
Show file tree
Hide file tree
Showing 21 changed files with 1,827 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/third_party/gtest/include/ SYSTEM )
INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/third_party/ObjexxFCL/src/ )
INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/third_party/SQLite/ SYSTEM )
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/third_party/Expat" "${CMAKE_SOURCE_DIR}/third_party/Expat/lib" SYSTEM)
INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/third_party/cJSON )

if( BUILD_TESTING )
option( TEST_ANNUAL_SIMULATION "Use annual simulations for tests instead of only design days" OFF )
Expand All @@ -112,6 +113,7 @@ ADD_SUBDIRECTORY(third_party/Expat)
ADD_SUBDIRECTORY(third_party/FMI)
ADD_SUBDIRECTORY(third_party/zlib)
ADD_SUBDIRECTORY(third_party/DElight)
ADD_SUBDIRECTORY(third_party/cJSON)
IF(NOT APPLE )
ADD_SUBDIRECTORY(third_party/FMUParser)
ENDIF()
Expand Down
4 changes: 3 additions & 1 deletion src/EnergyPlus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ SET( SRC
RefrigeratedCase.hh
ReportSizingManager.cc
ReportSizingManager.hh
ResultsSchema.cc
ResultsSchema.hh
ReturnAirPathManager.cc
ReturnAirPathManager.hh
RoomAirModelManager.cc
Expand Down Expand Up @@ -522,7 +524,7 @@ SET( SRC
# first we will create a static library of EnergyPlus
# this will be linked statically to create the DLL and also the unit tests
add_library( EnergyPlusLib STATIC ${SRC} )
target_link_libraries( EnergyPlusLib objexx sqlite bcvtb epexpat epfmiimport DElight )
target_link_libraries( EnergyPlusLib objexx sqlite bcvtb epexpat epfmiimport DElight cJSON)
if(UNIX AND NOT APPLE)
target_link_libraries( EnergyPlusLib dl )
endif()
Expand Down
1 change: 1 addition & 0 deletions src/EnergyPlus/DataGlobals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ namespace DataGlobals {
int OutputFileZoneSizing( 0 ); // Unit number of zone sizing calc output file
int OutputFileSysSizing( 0 ); // Unit number of system sizing calc output file
int OutputFileMeters( 0 ); // Unit number for meters output
int OutputFileSchema(0); // Unit number for Schema output
std::ostream * mtr_stream( nullptr ); // Internal stream used for mtr output (used for performance)
int StdMeterRecordCount( 0 ); // Count of Meter output records
int OutputFileBNDetails( 0 ); // Unit number for Branch-Node Details
Expand Down
1 change: 1 addition & 0 deletions src/EnergyPlus/DataGlobals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ namespace DataGlobals {
extern int OutputFileZoneSizing; // Unit number of zone sizing calc output file
extern int OutputFileSysSizing; // Unit number of system sizing calc output file
extern int OutputFileMeters; // Unit number for meters output
extern int OutputFileSchema; // Unit number for Schema output
extern std::ostream * mtr_stream; // Internal stream used for mtr output (used for performance)
extern int StdMeterRecordCount; // Count of Meter output records
extern int OutputFileBNDetails; // Unit number for Branch-Node Details
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/ExternalInterface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace ExternalInterface {

// MODULE PARAMETER DEFINITIONS:
extern int const maxVar; // Maximum number of variables to be exchanged
extern int const maxErrMsgLength; // Maximum error message length from xml schema validation
extern int const maxErrMsgLength; // Maximum error message length from json schema validation
extern int const indexSchedule; // Index for schedule in inpVarTypes
extern int const indexVariable; // Index for variable in inpVarTypes
extern int const indexActuator; // Index for actuator in inpVarTypes
Expand Down
121 changes: 112 additions & 9 deletions src/EnergyPlus/OutputProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <InputProcessor.hh>
#include <OutputProcessor.hh>
#include <OutputReportPredefined.hh>
#include <ResultsSchema.hh>
#include <ScheduleManager.hh>
#include <SortAndStringUtilities.hh>
#include <SQLiteProcedures.hh>
Expand Down Expand Up @@ -61,6 +62,7 @@ namespace OutputProcessor {
using namespace DataPrecisionGlobals;
using DataGlobals::MaxNameLength;
using DataGlobals::OutputFileMeters;
using DataGlobals::OutputFileSchema;
using DataGlobals::HourOfDay;
using DataGlobals::DayOfSim;
using DataGlobals::DayOfSimChr;
Expand Down Expand Up @@ -346,7 +348,6 @@ namespace OutputProcessor {
SecondsPerTimeStep = double( MinutesPerTimeStep ) * 60.0;

InitializeMeters();

}

void
Expand Down Expand Up @@ -4111,6 +4112,7 @@ namespace OutputProcessor {
using DataGlobals::eso_stream;
using DataStringGlobals::NL;
using General::strip_trailing_zeros;
using ResultsSchema::OutputSchema;

// Locals

Expand Down Expand Up @@ -4156,7 +4158,18 @@ namespace OutputProcessor {
// Append the min and max strings with date information
ProduceMinMaxString( MinOut, minValueDate, reportingInterval );
ProduceMinMaxString( MaxOut, maxValueDate, reportingInterval );


// add to daily TS data store
if ( reportingInterval == ReportDaily)
OutputSchema.RIDailyTSData.AddToCurrentRRow(repVal);
// add to monthly TS data store
if (reportingInterval == ReportMonthly)
OutputSchema.RIMonthlyTSData.AddToCurrentRRow(repVal);
// add to run period TS data store
if (reportingInterval == ReportSim)
OutputSchema.RIRunPeriodTSData.AddToCurrentRRow(repVal);


if ( sqlite->writeOutputToSQLite() ) {
sqlite->createSQLiteReportVariableDataRecord( reportID, repVal, reportingInterval, minValue, minValueDate, MaxValue, maxValueDate );
}
Expand Down Expand Up @@ -4620,6 +4633,7 @@ namespace OutputProcessor {
using DataGlobals::eso_stream;
using DataStringGlobals::NL;
using General::strip_trailing_zeros;
using ResultsSchema::OutputSchema;

// Locals

Expand Down Expand Up @@ -4656,6 +4670,16 @@ namespace OutputProcessor {
ProduceMinMaxString( MinOut, minValueDate, reportingInterval );
ProduceMinMaxString( MaxOut, maxValueDate, reportingInterval );

// add to daily TS data store
if (reportingInterval == ReportDaily)
OutputSchema.RIDailyTSData.AddToCurrentIRow(repVal);
// add to monthly TS data store
if (reportingInterval == ReportMonthly)
OutputSchema.RIMonthlyTSData.AddToCurrentIRow(repVal);
// add to run period TS data store
if (reportingInterval == ReportSim)
OutputSchema.RIRunPeriodTSData.AddToCurrentIRow(repVal);

if ( sqlite->writeOutputToSQLite() ) {
rminValue = minValue;
rmaxValue = MaxValue;
Expand Down Expand Up @@ -4969,6 +4993,7 @@ SetupOutputVariable(
using InputProcessor::MakeUPPERCase;
using InputProcessor::SameString;
using General::TrimSigDigits;
using namespace ResultsSchema;

// Locals
// SUBROUTINE ARGUMENT DEFINITIONS:
Expand Down Expand Up @@ -5005,8 +5030,8 @@ SetupOutputVariable(
int localIndexGroupKey;
bool invalidUnits;

if ( ! OutputInitialized ) InitializeOutput();

if (!OutputInitialized) InitializeOutput();
//! Errors are severe and fatal because should only be encountered during development.
Item = index( VariableName, '[' );
if ( Item != std::string::npos ) {
Expand Down Expand Up @@ -5199,7 +5224,6 @@ SetupOutputVariable(
}
}
}

}

void
Expand Down Expand Up @@ -5238,6 +5262,7 @@ SetupOutputVariable(
using InputProcessor::SameString;
using General::TrimSigDigits;
using DataOutputs::FindItemInVariableList;
using namespace ResultsSchema;

// Locals
// SUBROUTINE ARGUMENT DEFINITIONS:
Expand Down Expand Up @@ -5266,7 +5291,7 @@ SetupOutputVariable(
int Loop;
int RepFreq;

if ( ! OutputInitialized ) InitializeOutput();
if (!OutputInitialized) InitializeOutput();

//! Errors are severe and fatal because should only be encountered during development.
Item = index( VariableName, '[' );
Expand Down Expand Up @@ -5489,14 +5514,24 @@ UpdateDataandReport( int const IndexTypeKey ) // What kind of data to update (Zo
using namespace DataPrecisionGlobals;
using namespace OutputProcessor;
using ScheduleManager::GetCurrentScheduleValue;
using DataGlobals::HourOfDay;
using DataGlobals::DayOfSimChr;
using DataGlobals::EndHourFlag;
using DataGlobals::EndDayFlag;
using DataGlobals::EndEnvrnFlag;
using DataGlobals::eso_stream;
using DataGlobals::HourOfDay;
using DataGlobals::DayOfSim;
using DataGlobals::DayOfSimChr;
using DataGlobals::OutputFileStandard;
using DataGlobals::MinutesPerTimeStep;
using DataGlobals::ZoneTSReporting;
using DataGlobals::HVACTSReporting;
using DataEnvironment::Month;
using DataEnvironment::DayOfMonth;
using DataEnvironment::Year;
using DataEnvironment::DSTIndicator;
using DataEnvironment::EndMonthFlag;
using General::EncodeMonDayHrMin;
using ResultsSchema::OutputSchema;

// Locals
// SUBROUTINE ARGUMENT DEFINITIONS:
Expand Down Expand Up @@ -5552,6 +5587,23 @@ UpdateDataandReport( int const IndexTypeKey ) // What kind of data to update (Zo

rxTime = ( MinuteNow - StartMinute ) / double( MinutesPerTimeStep );

// R and I data frames for ZoneVar
if (IndexType == ZoneVar && OutputSchema.RIDetailedZoneTSData.RDataFrameEnabled == false)
OutputSchema.InitializeRTSDataFrame(ReportEach, RVariableTypes, NumOfRVariable, ZoneVar);
if (IndexType == ZoneVar && OutputSchema.RIDetailedZoneTSData.IDataFrameEnabled == false)
OutputSchema.InitializeITSDataFrame(ReportEach, IVariableTypes, NumOfIVariable, ZoneVar);

// R and I data frames for HVACVar
if (IndexType == HVACVar && OutputSchema.RIDetailedHVACTSData.RDataFrameEnabled == false)
OutputSchema.InitializeRTSDataFrame(ReportEach, RVariableTypes, NumOfRVariable, HVACVar);
if (IndexType == HVACVar && OutputSchema.RIDetailedHVACTSData.IDataFrameEnabled == false)
OutputSchema.InitializeITSDataFrame(ReportEach, IVariableTypes, NumOfIVariable, HVACVar);

std::string ts = std::to_string(Month) + "/" + std::to_string(DayOfMonth) + " " + std::to_string(HourOfDay) + ":" + std::to_string(TimeValue(1).CurMinute) + ":00";

if (IndexType == ZoneVar) OutputSchema.RIDetailedZoneTSData.NewRow(ts);
if (IndexType == HVACVar) OutputSchema.RIDetailedHVACTSData.NewRow(ts);

// Main "Record Keeping" Loops for R and I variables
for ( Loop = 1; Loop <= NumOfRVariable; ++Loop ) {
if ( RVariableTypes( Loop ).IndexType != IndexType ) continue;
Expand Down Expand Up @@ -5614,8 +5666,10 @@ UpdateDataandReport( int const IndexTypeKey ) // What kind of data to update (Zo
}

WriteRealData( rVar.ReportID, rVar.ReportIDChr, rVar.Which );

++StdOutputRecordCount;

if (IndexType == ZoneVar) OutputSchema.RIDetailedZoneTSData.AddToCurrentRRow(rVar.Which);
if (IndexType == HVACVar) OutputSchema.RIDetailedHVACTSData.AddToCurrentRRow(rVar.Which);
}
}

Expand Down Expand Up @@ -5679,6 +5733,9 @@ UpdateDataandReport( int const IndexTypeKey ) // What kind of data to update (Zo
// only time integer vars actual report as integer only is "detailed"
WriteIntegerData( iVar.ReportID, iVar.ReportIDChr, iVar.Which );
++StdOutputRecordCount;

if (IndexType == ZoneVar) OutputSchema.RIDetailedZoneTSData.AddToCurrentIRow(iVar.Which);
if (IndexType == HVACVar) OutputSchema.RIDetailedHVACTSData.AddToCurrentIRow(iVar.Which);
}
}

Expand All @@ -5692,6 +5749,13 @@ UpdateDataandReport( int const IndexTypeKey ) // What kind of data to update (Zo

if ( EndTimeStepFlag ) {

if (OutputSchema.RITimestepTSData.RDataFrameEnabled == false)
OutputSchema.InitializeRTSDataFrame(ReportTimeStep, RVariableTypes, NumOfRVariable);
if (OutputSchema.RITimestepTSData.IDataFrameEnabled == false)
OutputSchema.InitializeITSDataFrame(ReportTimeStep, IVariableTypes, NumOfIVariable);
std::string ts = std::to_string(Month) + "/" + std::to_string(DayOfMonth) + " " + std::to_string(HourOfDay) + ":" + std::to_string(int(TimeValue(1).CurMinute)) + ":00";
OutputSchema.RITimestepTSData.NewRow(ts);

for ( IndexType = 1; IndexType <= 2; ++IndexType ) {
for ( Loop = 1; Loop <= NumOfRVariable; ++Loop ) {
if ( RVariableTypes( Loop ).IndexType != IndexType ) continue;
Expand Down Expand Up @@ -5735,6 +5799,9 @@ UpdateDataandReport( int const IndexTypeKey ) // What kind of data to update (Zo

WriteRealData( rVar.ReportID, rVar.ReportIDChr, rVar.TSValue );
++StdOutputRecordCount;
// add to timestep TS data store
OutputSchema.RITimestepTSData.AddToCurrentRRow(rVar.TSValue);

}
rVar.TSValue = 0.0;
rVar.thisTSStored = false;
Expand Down Expand Up @@ -5774,6 +5841,7 @@ UpdateDataandReport( int const IndexTypeKey ) // What kind of data to update (Zo

WriteIntegerData( iVar.ReportID, iVar.ReportIDChr, _, iVar.TSValue );
++StdOutputRecordCount;
OutputSchema.RITimestepTSData.AddToCurrentIRow(iVar.TSValue);
}
iVar.TSValue = 0.0;
iVar.thisTSStored = false;
Expand All @@ -5796,6 +5864,11 @@ UpdateDataandReport( int const IndexTypeKey ) // What kind of data to update (Zo
WriteTimeStampFormatData( eso_stream, ReportHourly, TimeStepStampReportNbr, TimeStepStampReportChr, DayOfSim, DayOfSimChr, Month, DayOfMonth, HourOfDay, _, _, DSTIndicator, DayTypes( CurDayType ) );
}

if (OutputSchema.RIHourlyTSData.RDataFrameEnabled == false)
OutputSchema.InitializeRTSDataFrame(ReportHourly, RVariableTypes, NumOfRVariable);
std::string ts = std::to_string(Month) + "/" + std::to_string(DayOfMonth) + " " + std::to_string(HourOfDay) + ":00:00";
OutputSchema.RIHourlyTSData.NewRow(ts);

for ( IndexType = 1; IndexType <= 2; ++IndexType ) { // Zone, HVAC
TimeValue( IndexType ).CurMinute = 0.0;
for ( Loop = 1; Loop <= NumOfRVariable; ++Loop ) {
Expand All @@ -5815,6 +5888,8 @@ UpdateDataandReport( int const IndexTypeKey ) // What kind of data to update (Zo
WriteRealData( rVar.ReportID, rVar.ReportIDChr, rVar.Value );
++StdOutputRecordCount;
rVar.Stored = false;
// add time series value for hourly to data store
OutputSchema.RIHourlyTSData.AddToCurrentRRow(rVar.Value);
}
rVar.StoreValue += rVar.Value;
++rVar.NumStored;
Expand All @@ -5841,6 +5916,7 @@ UpdateDataandReport( int const IndexTypeKey ) // What kind of data to update (Zo
WriteIntegerData( iVar.ReportID, iVar.ReportIDChr, _, iVar.Value );
++StdOutputRecordCount;
iVar.Stored = false;
OutputSchema.RIHourlyTSData.AddToCurrentIRow(iVar.Value);
}
iVar.StoreValue += iVar.Value;
++iVar.NumStored;
Expand All @@ -5867,11 +5943,20 @@ UpdateDataandReport( int const IndexTypeKey ) // What kind of data to update (Zo
}
WriteTimeStampFormatData( eso_stream, ReportDaily, DailyStampReportNbr, DailyStampReportChr, DayOfSim, DayOfSimChr, Month, DayOfMonth, _, _, _, DSTIndicator, DayTypes( CurDayType ) );
}

if (OutputSchema.RIDailyTSData.RDataFrameEnabled == false)
OutputSchema.InitializeRTSDataFrame(ReportDaily, RVariableTypes, NumOfRVariable);
if (OutputSchema.RIDailyTSData.IDataFrameEnabled == false)
OutputSchema.InitializeITSDataFrame(ReportDaily, IVariableTypes, NumOfIVariable);
std::string ts = std::to_string(Month) + "/" + std::to_string(DayOfMonth) + " " + std::to_string(HourOfDay) + ":00:00";
OutputSchema.RIDailyTSData.NewRow(ts);

NumHoursInMonth += 24;
for ( IndexType = 1; IndexType <= 2; ++IndexType ) {
for ( Loop = 1; Loop <= NumOfRVariable; ++Loop ) {
if ( RVariableTypes( Loop ).IndexType == IndexType ) {
RVar >>= RVariableTypes( Loop ).VarPtr;
// store daily value in OutputSchema from within function call 2 levels deep
WriteRealVariableOutput( ReportDaily );
}
} // Number of R Variables
Expand All @@ -5896,12 +5981,21 @@ UpdateDataandReport( int const IndexTypeKey ) // What kind of data to update (Zo
if ( TrackingMonthlyVariables ) {
WriteTimeStampFormatData( eso_stream, ReportMonthly, MonthlyStampReportNbr, MonthlyStampReportChr, DayOfSim, DayOfSimChr, Month );
}

if (OutputSchema.RIMonthlyTSData.RDataFrameEnabled == false)
OutputSchema.InitializeRTSDataFrame(ReportMonthly, RVariableTypes, NumOfRVariable);
if (OutputSchema.RIMonthlyTSData.IDataFrameEnabled == false)
OutputSchema.InitializeITSDataFrame(ReportMonthly, IVariableTypes, NumOfIVariable);
std::string ts = std::to_string(Month) + "/" + std::to_string(DayOfMonth) + " " + std::to_string(HourOfDay) + ":00:00";
OutputSchema.RIMonthlyTSData.NewRow(ts);

NumHoursInSim += NumHoursInMonth;
EndMonthFlag = false;
for ( IndexType = 1; IndexType <= 2; ++IndexType ) { // Zone, HVAC
for ( Loop = 1; Loop <= NumOfRVariable; ++Loop ) {
if ( RVariableTypes( Loop ).IndexType == IndexType ) {
RVar >>= RVariableTypes( Loop ).VarPtr;
// store monthly value in OutputSchema from within function call 2 levels deep
WriteRealVariableOutput( ReportMonthly );
}
} // Number of R Variables
Expand All @@ -5924,10 +6018,19 @@ UpdateDataandReport( int const IndexTypeKey ) // What kind of data to update (Zo
if ( TrackingRunPeriodVariables ) {
WriteTimeStampFormatData( eso_stream, ReportSim, RunPeriodStampReportNbr, RunPeriodStampReportChr, DayOfSim, DayOfSimChr );
}

if (OutputSchema.RIRunPeriodTSData.RDataFrameEnabled == false)
OutputSchema.InitializeRTSDataFrame(ReportSim, RVariableTypes, NumOfRVariable);
if (OutputSchema.RIRunPeriodTSData.IDataFrameEnabled == false)
OutputSchema.InitializeITSDataFrame(ReportSim, IVariableTypes, NumOfIVariable);
std::string ts = std::to_string(Month) + "/" + std::to_string(DayOfMonth) + " " + std::to_string(HourOfDay) + ":00:00";
OutputSchema.RIRunPeriodTSData.NewRow(ts);

for ( IndexType = 1; IndexType <= 2; ++IndexType ) { // Zone, HVAC
for ( Loop = 1; Loop <= NumOfRVariable; ++Loop ) {
if ( RVariableTypes( Loop ).IndexType == IndexType ) {
RVar >>= RVariableTypes( Loop ).VarPtr;
// store runperiod value in OutputSchema from within function call 2 levels deep
WriteRealVariableOutput( ReportSim );
}
} // Number of R Variables
Expand Down
Loading

6 comments on commit 99bafdd

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResultsSchema (sanyalj) - x86_64-Linux-Ubuntu-14.04-gcc-4.8: Tests Failed

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResultsSchema (sanyalj) - x86_64-Linux-Ubuntu-14.04-cppcheck-1.61: OK (0 of 0 tests passed)

Build Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResultsSchema (sanyalj) - x86_64-MacOS-10.9-clang: Tests Failed

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResultsSchema (sanyalj) - x86_64-MacOS-10.9-clang-Debug: Tests Failed

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResultsSchema (sanyalj) - i386-Windows-7-VisualStudio-12: Tests Failed

Build Badge Test Badge

@Myoldmopar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanyalj @mbadams5 This needs to be compiled with -fPIC on UNIX (NOT APPLE?) since it eventually gets compiled into a shared library later. That is if this library even lives in the final version...

Please # to comment.