/// <summary> /// public method to get the CDR for a user (DID) /// For each user (DID), the CDRs are processed to calculate the following report at specified time /// intervals (8am, 10am, 1pm, 3pm, and 5pm ) : /// /// Total Outbound /// Total Inbound /// Total Call Duration /// Average Call Duration /// /// </summary> public void CreateStrata8CallReport() { // our base reference time that we calculate from, 6am every day DateTime referenceTime = new DateTime(DateTime.Now.Year, DateTime.Today.Month, DateTime.Today.Day, 4, 0, 0); List<GroupReport> userReportList = new List<GroupReport>(); // get our web service interface // CdrDbSvcSoapClient d = new CdrDbSvcSoapClient(); Strata8CdrProcessor.CdrDbSvcReference.CdrDbSvcSoapClient d = new CdrDbSvcSoapClient(); // get the time that we are running at string timeString = DateTime.Now.ToString(); // calculate the time interval starting at 6am every day // we generate a cumulative report starting at 6am every day with reports running at // 8am, 11am, 2pm and 5pm. // our reference time that we calculate from DateTime timeNow = DateTime.Now; TimeSpan timeDelta = timeNow.Subtract(referenceTime); // time from 4am to now DateTime reportFromTime = DateTime.Now.AddHours(8 - timeDelta.TotalHours);// add time zone to our time: 8 hours int indx = 0; foreach (string groupId in this.m_groupList ) { // DataSet ds = d.GetAllCdrsForGroup(groupId, reportFromTime); // For each User the following calculations are performed : userId : field 3 // // Total Inbound Calls : total number of inbound calls determined from the "direction" field 5 (terminating) // Total Outbound Calls : total number of outbound calls determined from the direction field 5 (originating) // Total Call Time : the total of inbound/outbound call times calculated from each of the CDRs for this user // Call Time : answerTime - releaseTime ( field 13 - field 12 ) // Average Call Time : Call Time / Total Number of Calls // GroupReport r = new GroupReport(); r.groupId = groupId; int totalIn = 0; int totalOut = 0; TimeSpan totalCallDuration = new TimeSpan(); // for each CDR we update our report values foreach (DataTable myTable in ds.Tables) { r.totalCalls = myTable.Rows.Count.ToString(); foreach (DataRow myRow in myTable.Rows) { //foreach (DataColumn myColumn in myTable.Columns) //{ // Console.WriteLine(myRow[myColumn]); //} if (myRow.ItemArray[6].Equals("Originating")) //if (myTable.Columns[5].Equals("terminating")) totalOut++; else totalIn++; // get the call duration for this call DateTime d1 = (DateTime)myRow.ItemArray[10]; DateTime d2 = (DateTime)myRow.ItemArray[14]; TimeSpan callDuration = d2.Subtract(d1); // calculate total call duration for this user totalCallDuration = totalCallDuration + callDuration; } } r.totalInboundCalls = totalIn.ToString(); r.totalOutboundCalls = totalOut.ToString(); r.totalCallTime = totalCallDuration.ToString(); if ((totalIn + totalOut) != 0) { double avg = totalCallDuration.TotalMinutes / (totalIn + totalOut); r.averageCallTime = String.Format("{0:##.###}", avg); } r.groupName = m_groupNameList[indx]; indx++; // store the userReport in the list userReportList.Add(r); }// get next user SendStrata8CallReport(userReportList, timeNow, referenceTime); }
/// <summary> /// public method to get the CDR for a user (DID) /// For each user (DID), the CDRs are processed to calculate the following report at specified time /// intervals (8am, 10am, 1pm, 3pm, and 5pm ) : /// /// Total Outbound /// Total Inbound /// Total Call Duration /// Average Call Duration /// /// </summary> public void CreateStrata8CallReport() { // our base reference time that we calculate from, 6am every day DateTime referenceTime = new DateTime(DateTime.Now.Year, DateTime.Today.Month, DateTime.Today.Day, 4, 0, 0); List <GroupReport> userReportList = new List <GroupReport>(); // get our web service interface // CdrDbSvcSoapClient d = new CdrDbSvcSoapClient(); Strata8CdrProcessor.CdrDbSvcReference.CdrDbSvcSoapClient d = new CdrDbSvcSoapClient(); // get the time that we are running at string timeString = DateTime.Now.ToString(); // calculate the time interval starting at 6am every day // we generate a cumulative report starting at 6am every day with reports running at // 8am, 11am, 2pm and 5pm. // our reference time that we calculate from DateTime timeNow = DateTime.Now; TimeSpan timeDelta = timeNow.Subtract(referenceTime); // time from 4am to now DateTime reportFromTime = DateTime.Now.AddHours(8 - timeDelta.TotalHours); // add time zone to our time: 8 hours int indx = 0; foreach (string groupId in this.m_groupList) { // DataSet ds = d.GetAllCdrsForGroup(groupId, reportFromTime); // For each User the following calculations are performed : userId : field 3 // // Total Inbound Calls : total number of inbound calls determined from the "direction" field 5 (terminating) // Total Outbound Calls : total number of outbound calls determined from the direction field 5 (originating) // Total Call Time : the total of inbound/outbound call times calculated from each of the CDRs for this user // Call Time : answerTime - releaseTime ( field 13 - field 12 ) // Average Call Time : Call Time / Total Number of Calls // GroupReport r = new GroupReport(); r.groupId = groupId; int totalIn = 0; int totalOut = 0; TimeSpan totalCallDuration = new TimeSpan(); // for each CDR we update our report values foreach (DataTable myTable in ds.Tables) { r.totalCalls = myTable.Rows.Count.ToString(); foreach (DataRow myRow in myTable.Rows) { //foreach (DataColumn myColumn in myTable.Columns) //{ // Console.WriteLine(myRow[myColumn]); //} if (myRow.ItemArray[6].Equals("Originating")) { //if (myTable.Columns[5].Equals("terminating")) totalOut++; } else { totalIn++; } // get the call duration for this call DateTime d1 = (DateTime)myRow.ItemArray[10]; DateTime d2 = (DateTime)myRow.ItemArray[14]; TimeSpan callDuration = d2.Subtract(d1); // calculate total call duration for this user totalCallDuration = totalCallDuration + callDuration; } } r.totalInboundCalls = totalIn.ToString(); r.totalOutboundCalls = totalOut.ToString(); r.totalCallTime = totalCallDuration.ToString(); if ((totalIn + totalOut) != 0) { double avg = totalCallDuration.TotalMinutes / (totalIn + totalOut); r.averageCallTime = String.Format("{0:##.###}", avg); } r.groupName = m_groupNameList[indx]; indx++; // store the userReport in the list userReportList.Add(r); }// get next user SendStrata8CallReport(userReportList, timeNow, referenceTime); } //CreateStrata8CallReport