0

我的数据按以下格式列出,(时间值相同,用于示例)

 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);
4

1 回答 1

1

我认为类似的事情可能会完成这项工作。

var results = entities.ExecutionDetails.ToList();

var failures = results.Where(p => p.Result == "Fail");

var sigmaDiff = failures.Sum(p => p.EndTime.Subtract(p.StartTime));

var mtbf = sigmaDiff/failures.Count();
于 2013-04-04T12:09:32.110 回答