我的数据按以下格式列出,(时间值相同,用于示例)
ID Result StartTime EndTime
1 Fail 4/2/2013 1:17:29 PM 4/2/2013 1:19:30 PM
2 Fail 4/2/2013 1:17:29 PM 4/2/2013 1:19:30 PM
3 Pass 4/2/2013 1:17:29 PM 4/2/2013 1:19:30 PM
4 Fail 4/2/2013 1:17:29 PM 4/2/2013 1:19:30 PM
5 Fail 4/2/2013 1:17:29 PM 4/2/2013 1:19:30 PM
6 Pass 4/2/2013 1:17:29 PM 4/2/2013 1:19:30 PM
7 Fail 4/2/2013 1:17:29 PM 4/2/2013 1:19:30 PM
8 Pass 4/2/2013 1:17:29 PM 4/2/2013 1:19:30 PM
9 pass 4/2/2013 1:17:29 PM 4/2/2013 1:19:30 PM
10 pass 4/2/2013 1:17:29 PM 4/2/2013 1:19:30 PM
我必须使用 ∑ (T1,T2,…Tn) / n 找到 MTBF,其中 n 是故障数,T1,T2,…Tn 是指发生故障之前的正常运行时间。到目前为止,我已经能够计算出每次迭代的经过时间,
using (DatabaseEntities entities = new DatabaseEntities())
{
var result = entities.ExecutionDetails.Select(p => p);
foreach (var p in result)
{
if (p.StartTime.HasValue && p.EndTime.HasValue)
{
var duration = (p.EndTime.Value - p.StartTime.Value).ToString("c");
Console.WriteLine("Duration" + duration);
}
}
}
你能帮我找到正确的方法和查询来捕获相关数据以计算 MTBF。谢谢。
更新代码
var results = entities.TestExecutionDetails.ToList();
var failures = results.Where(p => p.Result == "Fail").Select(p => p);
foreach(var p in failures)
{
if (p.StartTime.HasValue && p.EndTime.HasValue)
{
var elapsedduration = elapsedduration + (p.EndTime.Value - p.StartTime.Value).ToString("c");
}
var mtbf = elapsedduration / failures.Count();
最终更新
TimeSpan elaspsedduration = new TimeSpan(0);
........
.....
foreach (var p in uptime)
{
Console.WriteLine("Uptime is" + uptime);
if (p.StartTime.HasValue && p.EndTime.HasValue)
{
elaspsedduration += (p.EndTime.Value - p.StartTime.Value);
}
var mtbf = elaspsedduration.TotalSeconds / failures;
Console.WriteLine("MTBF Value is " + mtbf);