Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 计算调用日志中的并发调用数_C#_.net_Algorithm - Fatal编程技术网

C# 计算调用日志中的并发调用数

C# 计算调用日志中的并发调用数,c#,.net,algorithm,C#,.net,Algorithm,有一个呼叫列表,其中包含starttime、stoptime、duration、caller和一些其他属性。现在我尝试从这个列表中可视化并发调用,但我不知道如何开始这个任务。我想在.NETC中实现这个任务 第一个想法是接受每一次呼叫,并将其计数为每秒一个数组,然后我有一个数组,它将每秒一次呼叫计数,但我认为这不是很好:- class CallConcurrentCounterController { static void Main(string[] args) {

有一个呼叫列表,其中包含starttime、stoptime、duration、caller和一些其他属性。现在我尝试从这个列表中可视化并发调用,但我不知道如何开始这个任务。我想在.NETC中实现这个任务

第一个想法是接受每一次呼叫,并将其计数为每秒一个数组,然后我有一个数组,它将每秒一次呼叫计数,但我认为这不是很好:-

 class CallConcurrentCounterController
{
    static void Main(string[] args)
    {    
        var Calls = new ImportDataFromCSV();
        DataTable dataTable = Calls.GetDataTable(Path,Seperator);

        DateTime startTime = new DateTime(2011,07,01);            
        callsBucket(dataTable,startTime);            
    }
    public void callsBucket(DataTable Calls, DateTime startTime)
    {
        var callsBuckets =
            from time in Enumerable.Range(0, (60 * 24))
                .Select(i => startTime.AddMinutes(i)) // Create the times base on start time and current minute.                
            select new // Create an anonymous type
            {
                // Create a property called Time, that stores the time checked
                Time = time,
                // Another property that stores the number of calls happening at that time.
                //CallCount = Calls.Rows.Count(Call => Call.start <= time && Call.stop >= time)                    
                CallCount = Calls.AsEnumerable().Count
                    (Call => DateTime.Parse(Call.ItemArray[0].ToString() + " " + Call.ItemArray[1].ToString()) <= time && 
                             DateTime.Parse(Call.ItemArray[0].ToString() + " " + Call.ItemArray[2].ToString()) >= time)
            };
    }
}
从调用此函数的函数中,将为其提供一个包含n行的DataTable。每行都是一个调用,其属性start ItemArray[1]表示开始时间,stop ItemArray[2]表示停止时间,Date ItemArray[0]以及一些其他属性,如调用者编号


现在我得到了一个按分钟计数的桶。但是如何将callsBuckets类型转换为类似Enumerable的类型呢?

您需要先编写一个方法来确定两个日期时间范围是否重叠。一旦该方法起作用,只需在列表中查找重叠次数最多的调用。或者,如果您需要确定某个特定时间的调用数,只需编写一个方法来检查范围是否覆盖此时间值,并在调用列表中进行计数。

以下内容应该可以帮助您开始。 这将创建一个覆盖全天的分钟窗口,从给定的开始时间开始,每小时60分钟,每天24小时

然后,它统计在此之前开始和之后结束的所有调用。您可以将Count调用更改为Where,以保留每次发生的单个调用的详细信息

var startTime = new DateTime.Today().AddDays(-1); //When to start the minute interval buckets
var callsBuckets =
    from time in Enumerable.Range(0, (60 * 24) // Minutes in a day
                           .Select(i => new DateTime(startTime).AddMinutes(i) // Create the times base on start time and current minute.
    select new // Create an anonymous type
    {
        // Create a property called Time, that stores the time checked
        Time = time,
        // Another property that stores the number of calls happening at that time.
        CallCount = Calls.Count(Call => Call.StartTime <= time && Call.StopTime >= time)
    };

现在,您已经展示了您正在使用一个数据表,请参阅此问题的公认答案:。

您能解释一下如何检查两个日期时间变量的范围重叠吗?类似于这样的内容:private bool intersectsint r1start、int r1end、int r2start、int r2end{return r1start==r2start | | r1start>r2start?r1start使用大写字母作为变量令人困惑。嗨,乔治,我测试了你的代码,但出现了一些错误,我读取了一个带有调用的CSV并将其写入一个名为Calls的数据表,然后我初始化了一个带有参数的函数:Calls、startTime、stopTime并将代码写入其中,但我得到了一个错误,即re不是接受DataRowCollection的函数计数。请参阅我的编辑,我添加了一个链接,您可以使用我的答案查询数据表。