Example #1
0
        public void TestLogValue()
        {
            double expectedAvg = double.NaN;
            double expectedMax = double.NaN;
            double expectedMin = double.NaN;
            double expectedTime = double.NaN;
            double expectedValue = double.NaN;

            LogValue v = new LogValue();
            Assert.AreEqual(v.avg, expectedAvg, "LogValue Accessor is unexpected value.");
            Assert.AreEqual(v.max, expectedMax, "LogValue Accessor is unexpected value.");
            Assert.AreEqual(v.min, expectedMin, "LogValue Accessor is unexpected value.");
            Assert.AreEqual(v.time, expectedTime, "LogValue Accessor is unexpected value.");
            Assert.AreEqual(v.value, expectedValue, "LogValue Accessor is unexpected value.");

            expectedAvg = 0.1;
            expectedMax = 0.2;
            expectedMin = 0.3;
            expectedTime = 0.4;
            expectedValue = 0.5;

            v = new LogValue(expectedTime, expectedValue, expectedAvg, expectedMin, expectedMax);
            Assert.AreEqual(v.avg, expectedAvg, "LogValue Accessor is unexpected value.");
            Assert.AreEqual(v.max, expectedMax, "LogValue Accessor is unexpected value.");
            Assert.AreEqual(v.min, expectedMin, "LogValue Accessor is unexpected value.");
            Assert.AreEqual(v.time, expectedTime, "LogValue Accessor is unexpected value.");
            Assert.AreEqual(v.value, expectedValue, "LogValue Accessor is unexpected value.");
        }
Example #2
0
 /// <summary>
 /// Get the uniqueue log data from the current simulator.
 /// </summary>
 /// <param name="startTime">The start time of log file.</param>
 /// <param name="endTime">The endt time of log file.</param>
 /// <param name="interval">The interval of log file.</param>
 /// <param name="fullID">The FullID of log data.</param>
 /// <returns>The list of log data.</returns>
 private LogData GetUniqueLogData(
     double startTime,
     double endTime,
     double interval,
     string fullID)
 {
     if (startTime < 0.0)
     {
         startTime = 0.0;
     }
     if (endTime <= 0.0)
     {
         endTime = m_currentProject.Simulator.GetCurrentTime();
     }
     if (this.m_simulationTimeLimit > 0.0 && endTime > this.m_simulationTimeLimit)
     {
         endTime = this.m_simulationTimeLimit;
     }
     if (startTime > endTime)
     {
         double tmpTime = startTime;
         startTime = endTime;
         endTime = tmpTime;
     }
     WrappedDataPointVector dataPointVector = null;
     if (interval <= 0.0)
     {
         lock (m_currentProject.Simulator)
         {
             dataPointVector
                 = m_currentProject.Simulator.GetLoggerData(
                     fullID,
                     startTime,
                     endTime
                     );
         }
     }
     else
     {
         lock (m_currentProject.Simulator)
         {
             dataPointVector
                 = m_currentProject.Simulator.GetLoggerData(
                     fullID,
                     startTime,
                     endTime,
                     interval
                     );
         }
     }
     List<LogValue> logValueList = new List<LogValue>();
     double lastTime = -1.0;
     for (int i = 0; i < dataPointVector.GetArraySize(); i++)
     {
         if (lastTime == dataPointVector.GetTime(i))
         {
             continue;
         }
         LogValue logValue = new LogValue(
             dataPointVector.GetTime(i),
             dataPointVector.GetValue(i),
             dataPointVector.GetAvg(i),
             dataPointVector.GetMin(i),
             dataPointVector.GetMax(i)
             );
         logValueList.Add(logValue);
         lastTime = dataPointVector.GetTime(i);
     }
     string modelID = null;
     if (m_currentProject.LogableEntityPathDic.ContainsKey(fullID))
     {
         modelID = m_currentProject.LogableEntityPathDic[fullID];
     }
     string key = null;
     string type = null;
     string propName = null;
     Util.ParseFullPN(fullID, out type, out key, out propName);
     if (logValueList.Count == 1 && logValueList[0].time == 0.0)
     {
         LogValue logValue =
             new LogValue(
                endTime,
                logValueList[0].value,
                logValueList[0].avg,
                logValueList[0].min,
                logValueList[0].max
                );
         logValueList.Add(logValue);
     }
     LogData logData = new LogData(
         modelID,
         key,
         type,
         propName,
         logValueList
         );
     dataPointVector.Dispose();
     return logData;
 }