Commit 197168fd authored by Pascal Palenda's avatar Pascal Palenda
Browse files

Switch to csv encoding for data

JSON format had artifacts in its data, thus the switch to csv.
parent 7cce2f5f
......@@ -406,6 +406,24 @@ namespace ITA
return convertFormByteArray<T> ( decoded );
}
template<class T>
static std::string convertToString( const std::vector<T>& data, int iPrecision = 8 )
{
std::stringstream ss;
ss.precision ( iPrecision );
ss << std::scientific;
ss << data.front ( );
std::for_each ( data.begin ( ) + 1, data.end ( ), [&] ( const T& val )
{
ss << ", " << val;
} );
return ss.str ( );
}
};
} // namespace statistics
} // namespace simulation_scheduler
......
......@@ -329,7 +329,7 @@ namespace ITA
return time * 1e6;
} );
JSONNode jnTimeStampArray ( JSON_ARRAY );
/*JSONNode jnTimeStampArray ( JSON_ARRAY );
jnTimeStampArray.set_name ( "TimeStamps" );
jnTimeStampArray.reserve ( vdTimeStamps.size ( ) );
JSONNode jnData ( JSON_NUMBER );
......@@ -340,7 +340,9 @@ namespace ITA
jnTimeStampArray.push_back ( jnData );
}
jnRoot.push_back ( jnTimeStampArray );
jnRoot.push_back ( jnTimeStampArray );*/
jnRoot.push_back ( JSONNode ( "Time Stamps", utils::DataTypeUtils::convertToString ( vdTimeStamps ) ) );
return jnRoot;
}
......@@ -413,7 +415,7 @@ namespace ITA
jnRoot.push_back ( JSONNode ( "Variance", utils::Statistics::calculateVariance ( vdDeltaTime ) ) );
jnRoot.push_back ( JSONNode ( "StdDeviation", utils::Statistics::calculateStandardDeviation ( vdDeltaTime ) ) );
JSONNode jnStartTimeArray ( JSON_ARRAY );
/*JSONNode jnStartTimeArray ( JSON_ARRAY );
jnStartTimeArray.set_name ( "Start Times" );
jnStartTimeArray.reserve ( vdStartTime.size ( ) );
JSONNode jnData( JSON_NUMBER );
......@@ -436,7 +438,10 @@ namespace ITA
jnEndTimeArray.push_back ( jnData );
}
jnRoot.push_back ( jnEndTimeArray );
jnRoot.push_back ( jnEndTimeArray );*/
jnRoot.push_back ( JSONNode ( "Start Times", utils::DataTypeUtils::convertToString ( vdStartTime ) ) );
jnRoot.push_back ( JSONNode ( "End Times", utils::DataTypeUtils::convertToString ( vdEndTime ) ) );
return jnRoot;
}
......@@ -520,7 +525,7 @@ namespace ITA
{
std::vector<std::pair<T, double>> dataVector = oProfileValue.getData<T> ( );
JSONNode jnTimeStampArray ( JSON_ARRAY );
/*JSONNode jnTimeStampArray ( JSON_ARRAY );
jnTimeStampArray.set_name ( "TimeStamps" );
jnTimeStampArray.reserve ( dataVector.size ( ) );
JSONNode jnDataArray ( JSON_ARRAY );
......@@ -534,7 +539,29 @@ namespace ITA
jnDataArray.push_back ( jnData );
jnData = data.second;
jnTimeStampArray.push_back ( jnData );
}
}*/
std::vector<T> vTData ( dataVector.size ( ) );
std::vector<double> vdTimeStamps ( dataVector.size ( ) );
std::transform ( dataVector.begin ( ),
dataVector.end ( ),
vTData.begin ( ),
[] ( const std::pair<T, double>& p ) -> T
{
return p.first;
} );
std::transform ( dataVector.begin ( ),
dataVector.end ( ),
vdTimeStamps.begin ( ),
[] ( const std::pair<T, double>& p ) -> double
{
return p.second;
} );
JSONNode jnTimeStampArray ( "Time Stamps", utils::DataTypeUtils::convertToString ( vdTimeStamps ) );
JSONNode jnDataArray ( "Data", utils::DataTypeUtils::convertToString ( vTData ) );
return std::make_pair ( jnTimeStampArray, jnDataArray );
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment