CDRs - format of Usage

107 views
Skip to first unread message

poj...@gmail.com

unread,
Dec 17, 2024, 6:43:52 PM12/17/24
to CGRateS
Hi there,

Is there a way to format the output of "usage" as something else other than h:m:s, which is visually nice but presents a challenge when one needs to sum up duration of calls. 

I'd like to have it in seconds as integer, possible?

For example, when calling APIerSv2.GetCDRs method:
"Usage": "1h13m19s

Thanks.


Arber Katellari

unread,
Dec 20, 2024, 11:29:50 AM12/20/24
to CGRateS
Hello,

You can use CDRsV1.GetCDRs https://pkg.go.dev/github.com/cgrates/cgrates@master/apier/v1#CDRsV1.GetCDRs which returns the usage as integer/nanoseconds, so if you want to convert it to seconds, you would have to divide it by 1,000,000,000.
Feel free to ask if you have further questions about it!

Kind regards!
Arber

Sergiu Pojoga

unread,
Dec 20, 2024, 3:13:31 PM12/20/24
to cgr...@googlegroups.com
Thanks for the suggestion, however it's not really a viable option for me since the main API call I use is ApierV2.ExportCdrsToFile and alike, all of which output Usage in h:m:s format.

At some point I had my hopes up high with APIerSv2.CountCDRs, only to find that it literally counts the number of CDRs without summing up the Usage :(

--
You received this message because you are subscribed to the Google Groups "CGRateS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cgrates+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/cgrates/b7c166a0-c061-4065-8ac4-bd45d5feb238n%40googlegroups.com.

Arber Katellari

unread,
Dec 23, 2024, 10:15:58 AM12/23/24
to CGRateS
Hello again,

For the APIerSv2.GetCDRs we only have two formats (string as you have shown if ToR is *voice, and in nanoseconds if not *voice).
If you are looking to export the CDRs, you can add (or modify if you already have) a template on your "cdre" module in configs like so:

"cdre": {
"usage_seconds": {
"fields": [
{"path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage{*duration_seconds}", "mandatory": true},
],
},
},


This way, when you run ApierV2.ExportCdrsToFile, the usage will be exported as a float in seconds, i.e., 1m38s as 98

Thanks.
Arber

poj...@gmail.com

unread,
Jan 8, 2025, 2:31:01 PM1/8/25
to CGRateS
That worked, thanks  Arber!
Reply all
Reply to author
Forward
0 new messages