It is currently April 25th, 2024, 8:16 am

Convert Bandwidth WebParser String to Kbps, Mbps, Gbps

Get help with creating, editing & fixing problems with skins
KyleJackDaniels
Posts: 5
Joined: December 29th, 2019, 10:06 pm

Convert Bandwidth WebParser String to Kbps, Mbps, Gbps

Post by KyleJackDaniels »

Hello,

This is my first time coding a Rainmeter. I have a WebParser which returns a string value of xxxx Kbps.
Is there a way to convert that xxxx Kbps to either xx.x Mbps or xx.x Gbps?

Code: Select all

[MeasureBandwidthString]
Measure=WebParser
Url=#TautulliGetActivity#
RegExp=(?siU)"wan_bandwidth": (.*), "
LogSubstringErrors=0

[MeterBandwidthCount]
Meter=String
MeasureName=MeasureBandwidth
X=385
Y=0r
FontFace=Trebuchet MS
FontSize=16
FontColor=#FontColor#
AntiAlias=1
Text=Bandwidth %1 - Kbps
Thanks in advance.
Kyle.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Convert Bandwidth WebParser String to Kbps, Mbps, Gbps

Post by jsmorley »

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureString]
Measure=String
String=354693 Kbps
RegExpSubstitute=1
Substitute="([\d]+) .*$":"\1"

[MeasureKbps]
Measure=Calc
Formula=MeasureString

[MeasureMbps]
Measure=Calc
Formula=MeasureString / 1000

[MeasureGbps]
Measure=Calc
Formula=MeasureString / 1000000

[MeterString]
Meter=String
MeasureName=MeasureKbps
MeasureName2=MeasureMbps
MeasureName3=MeasureGbps
FontSize=12
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
NumOfDecimals=1
Text=%1 Kbps | %2 Mbps | %3 Gbps

1.png
You do not have the required permissions to view the files attached to this post.
KyleJackDaniels
Posts: 5
Joined: December 29th, 2019, 10:06 pm

Re: Convert Bandwidth WebParser String to Kbps, Mbps, Gbps

Post by KyleJackDaniels »

@jsmorley

Thank you!
I managed to tweak it a little and just provide Mbps, as the value will never go above 80Mbps and under 0.5Mbps.

Code: Select all

[MeasureBandwidthString]
Measure=WebParser
Url=#TautulliGetActivity#
RegExp=(?siU)"wan_bandwidth": (.*), "
LogSubstringErrors=0

[MeasureBandwidth]
Measure=WebParser
Url=[MeasureBandwidthString]
StringIndex=1

[MeasureMbps]
Measure=Calc
Formula=MeasureBandwidth / 1000

[MeterBandwidthCount]
Meter=String
MeasureName=MeasureMbps
X=385
Y=0r
FontFace=Trebuchet MS
FontSize=16
FontColor=#FontColor#
AntiAlias=1
NumOfDecimals=1
Text=Bandwidth %1 Mbps
Thank you.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Convert Bandwidth WebParser String to Kbps, Mbps, Gbps

Post by jsmorley »

Glad to help.