I designed the pipeline to calculate the download speed basic on size and time. The function is fine. However, I want to the speed_kb_sec can change to integer(No decimal point). Can you have any solution about it?
My pipeline is listed in the below:
when
has_field("spendtime")
then
let time = to_double($message.spendtime);
let size = to_double($message.bytes);
let bandwidth = size / time ;
let bandwidth_kb = to_double(bandwidth / 1024.0);
set_field("speed_bytes_sec", bandwidth);
set_field("speed_kb_sec", bandwidth_kb);
end
For example,
speed_kb_sec:1064.092460042956 (current)
I want to change speed_kb_sec:1064
when
has_field(“spendtime”)
then
let time = to_double($message.spendtime);
let size = to_double($message.bytes);
let bandwidth = size / time ;
let bandwidth_kb = to_long (bandwidth / 1024.0);
set_field(“speed_bytes_sec”, bandwidth);
set_field(“speed_kb_sec”, bandwidth_kb);
end
Joechen, Sorry about that.
If i change to_double to to_long, look like the above reply. The bandwidth_kb will be 0 for all case.
when
has_field(“spendtime”)
then
let time = to_double($message.spendtime);
let size = to_double($message.bytes);
let bandwidth = size / time ;
let bandwidth_kb = to_long(bandwidth / 1024.0);
set_field(“speed_bytes_sec”, bandwidth);
set_field(“speed_kb_sec”, bandwidth_kb);
end
As an ugly workaround, you could convert bandwidth / 1024.0 to a string (using to_string()), then split on the decimal point using split() or regex(), and then convert the result to a long integer (using to_long()).