2011-09-02 7 views
3

시작 시간, 종료 시간, 통화 시간, 발신자 및 일부 다른 속성이있는 통화 목록이 있습니다. 이제이 목록에서 동시 호출을 시각화하려고하지만이 작업을 시작하는 방법을 모르겠습니다. 나는 C# 에서이 작업을 실현 싶습니다.동시 통화 수를 Calllog에서 카운트

첫 번째 아이디어는 각 호출을하고, 각 초 배열로 계산 한 후 내가 :-)

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이 제공됩니다. 각 행은 Attributes start ItemArray [1] (시작 시간), Stop ItemArray [2] (중지 시간) 날짜 ItemArray [0]과 같은 다른 속성과 같은 발신자 번호 ...

이제 통화 수를 계산합니다. 하지만 내가 어떻게 Enumerable 같은 유형으로 callsBuckets의 유형을 변환 할 수 있습니까?

답변

2

다음과 같은 것이 시작되어야합니다. 주어진 시작 시간부터 분당 60 분 (하루 종일 24 시간)의 분량의 창을 생성합니다.

그런 다음 이전에 시작된 모든 통화를 계산하고 그 시간 후에 완료합니다. Count 전화를 Where으로 변경하여 매번 발생하는 개별 통화의 세부 정보를 유지할 수 있습니다. 이제 당신이 DataTable를 사용하고 표시 한 것을

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

,이 질문에 대한 허용 대답을 참조하십시오 LINQ query on a DataTable.

+0

변수에 대문자를 사용하는 것은 혼란 스럽습니다. – Amy

+0

Corrected casing –

+0

안녕하세요 George, 코드를 테스트하지만 오류가 발생합니다. CSV를 호출하고 "Calls"라는 DataTable에 기록한 다음 매개 변수가있는 함수를 초기화합니다. Calls, startTime, stopTime 그리고 코드를 작성하십시오. ,하지만 DataRowCollection을 받아들이는 함수 Count가 없다는 오류가 발생합니다. – kockiren

1

두 개의 DateTime 범위가 겹치는 지 여부를 결정하는 방법을 작성해야합니다. 해당 방법이 작동하면 가장 겹치는 번호가있는 전화를 목록에서 찾습니다. 또는 특정 시간 ()에있는 호출 수를 로 결정해야하는 경우 범위에이 시간 값이 포함되는지 확인하는 방법을 작성하고 호출 목록에서 Count()을 수행하면됩니다.

+0

두 개의 DateTime 변수의 범위가 중복되는지 어떻게 확인할 수 있습니까? – kockiren

+0

다음과 같은 내용이 있습니다 :'private bool intersects (int r1start, int r1end, int r2start, int r2end) { return (r1start == r2start) || (r1start> r2start? r1start <= r2end : r2start <= r1end); }' –

관련 문제