This commit is contained in:
@@ -119,23 +119,58 @@ namespace PLCDataMonitor
|
||||
return;
|
||||
}
|
||||
|
||||
// 重建连续时间轴(秒)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 【修复】重建连续时间轴(秒)- 自动扣除暂停时间
|
||||
List<double> timeAxis = new List<double>();
|
||||
DateTime firstValid = filteredData.First().Item1;
|
||||
double accumulated = 0;
|
||||
DateTime effectiveStartTime = filteredData.First().Item1;
|
||||
DateTime effectiveEndTime = filteredData.Last().Item1;
|
||||
|
||||
for (int i = 0; i < filteredData.Count; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
timeAxis.Add(0);
|
||||
else
|
||||
DateTime currentTime = filteredData[i].Item1;
|
||||
|
||||
// 1. 计算从开始到现在的总物理时间
|
||||
double totalElapsed = (currentTime - effectiveStartTime).TotalSeconds;
|
||||
|
||||
// 2. 计算这段时间内包含的“暂停时长”总和
|
||||
double totalPauseDuration = 0;
|
||||
foreach (var p in pausePeriods)
|
||||
{
|
||||
accumulated += (filteredData[i].Item1 - filteredData[i - 1].Item1).TotalSeconds;
|
||||
timeAxis.Add(accumulated);
|
||||
// 只计算在当前点之前发生的暂停
|
||||
if (p.end <= effectiveStartTime) continue;
|
||||
if (p.start >= currentTime) break;
|
||||
|
||||
// 计算暂停段与 [开始时间,当前时间] 的重叠部分
|
||||
long overlapStart = p.start > effectiveStartTime ? p.start.Ticks : effectiveStartTime.Ticks;
|
||||
long overlapEnd = p.end < currentTime ? p.end.Ticks : currentTime.Ticks;
|
||||
|
||||
if (overlapEnd > overlapStart)
|
||||
{
|
||||
totalPauseDuration += (overlapEnd - overlapStart) / (double)TimeSpan.TicksPerSecond;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 有效时间 = 物理时间 - 暂停时间
|
||||
double validTime = totalElapsed - totalPauseDuration;
|
||||
timeAxis.Add(Math.Max(0, validTime));
|
||||
}
|
||||
double totalValidSeconds = accumulated; // 有效总时长
|
||||
DateTime effectiveStartTime = firstValid;
|
||||
DateTime effectiveEndTime = filteredData.Last().Item1;
|
||||
|
||||
double totalValidSeconds = timeAxis.Last(); // 更新有效总时长
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 计算最大摩擦力(基于过滤后的数据)
|
||||
double maxFriction1 = filteredData.Max(x => Math.Abs(x.Item2));
|
||||
|
||||
Reference in New Issue
Block a user