I am looking for a bit of guidance on how to parse CDR data from flat text files received from a PBX for reporting. The files are set width rather than using a delimiting character.
I have found something called text Field Parser but wonder if there is a better, simpler way.
http://csharphelper.com/blog/2017/02/use-a-textfieldparser-to-read-fixed-width-data-c/
I’ve added some examples from the vendor below so you can see the exact format and what the fields mean.
Example
The following is an example of an External SMDR record:
01/14 09:24 00:00:59 T201 003 P001 100 1011T 1405
Where, 01/14 is the date the caller contacted your contact center 09:24 is the time the call originated 00:00:59 is the amount of time the agent spoke with the caller before transferring the call T201 is the number of the trunk that the caller dialed in to 003 is the time to answer for the agent (not the time spent in queue) P001 is the reporting number of the ACD path queue the call was queued to 100 is the reporting number of the agent group 1011 is the ID of the agent who first answered the call T is the transferred call identifier 1405 is the ID of the agent whom the call was transferred to
This means that an outside caller dialed in to the contact center on Trunk 201, on January 14th at 9:24 AM. The call was queued to the ACD Path Queue 1 (shown as P001), queued to Agent Group 100, and answered by Agent 1011 after 3 seconds waiting in queue. The agent who answered the call talked to the customer for 59 seconds before transferring the call to Agent 1405. Internal SMDR records An Internal SMDR record is generated by the PBX when 1. A call is completed (i.e. when all parties involved in the call have hung up) between two devices on the PBX (extensions or agents), with no outside parties (trunks) involved in the call 2. The call is an internal answered call only 3. Calls to ACD queues report based on the dialable number of the queue, not the reporting number as found in the External SMDR records. 4. All parties in the call have their Class of Services set to enable SMDR Internal recording 5. The PBX has the Internal SMDR option enabled.
Example
The following is an example of an Internal SMDR record:
01/14 07:20 00:00:10 6979 002 6515 I 7015
Where, 1/14 is the date the call was made 07:20 is the time the call originated 00:00:10 is the length of the call 6979 is the extension that the call was made from 002 is the time to answer for the agent (not the time spent in queue) 6515 is the dialable number of the ACD queue the call was made to I is the internal call identifier 7015 is the ID of the agent who answered the call This means that on January 14th at 7:20 AM, internal Extension 6979 dialed the ACD Queue P001 with dialable number 6515. The call was answered by Agent 7015 after 2 seconds of wait time. The two parties talked for 10 seconds. There was no external caller involved in this call
I want to be able to parse the CDR/ SMDR data above and put into a database so it can be reported on. I can quite easily do this with CSV data but just need some guidance on the best way to do this with set width data.
For fixed width parsing you'll want to use String.Substring()
. Reference to the MS Docs.
In your example you would do something along the lines of (Note: I could be off by one, but you should get the general picture)
var line = "01/14 09:24 00:00:59 T201 003 P001 100 1011T 1405";
//If we think about the string as an array then:
//we start at index 0 and continue until we get to index 4.
var date = line.Substring(0,4) //This will be 01/14 as a string.
//We start at index 5 and continue until we get to index 10.
var time = line.Substring(5,10) //This shooould be 09:24 as a string.
You would continue in this fashion until you have all the data you'd want from the line.