开发者

Count concurrent Calls from Calllog

there is a list of Calls, with starttime, stoptime, duration, caller and some other Attributes. Now I try to visualize the concurrent Calls from this list, but I don't know how to start with this task. I want realize this task in .net C#.

First idea was to take each call, and count it to an Array for each second, then I have an array which counts the call for every second, but it is not so nice I think.

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

From the function who is calling this function is given a DataTable with n Rows each Row is a Call with the Attributes start ItemArray[1] (for start-Time), stop ItemArray[2] (for stop-Time), Date ItemArray[0] and some other Attributes such Caller-Number...

Now I get a bucket which counts the calls by minute. But how I can convert the Type of callsBuckets to an type like Enumerable<dateTime,int>?


Something like the following should get you started. This creates minute windows (covering the whole day, 60 mins per hour, 24 hours per day) from a given start time.

It then counts all calls that start before, and finish after that time. You could change the Count call to a Where, to keep the details of the individual calls that were occurring during each time.

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

Now that you've shown you're using a DataTable, see the accepted answer to this question: LINQ query on a DataTable.


You need to start by writing a method which determines whether two DateTime ranges overlap. Once that method is working, simply look for a call in your list that has the most number of overlaps. Alternatively, if you need to determine the number of calls at a particular time, simply write a method that checks whether the range covers this time value, and do a Count() on your list of calls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜