Jump to content

Formatting Signal Results


Marcie
 Share

Recommended Posts

I have a signal based on the formula:

$a/($b+$c)

and I want the result to display as a percentage (33%) instead of a decimal (0.333).  I haven't had much luck adding % as a unit.  How can I change what's displayed?

Link to comment
Share on other sites

Guest Jon Peterson

Hi Marcie,

This should do it:

($a/($b+$c)).setUnits('%')

Presumably your $a/($b+$c) results are unit less. If not, you can set the units on each variable to get the proper results (or remove the units with .setUnits(' '). I've attached a screen shot of a test I just did. 

Let us know how this works. 

Regards,

Jon Peterson

OUTLOOK_E0OZZI42de.png

Link to comment
Share on other sites

Thank you for your help.  My signals don't have units.  The displayed result is 0.333 % now, instead of 33%, though.

The formula is 2/(2+4) from the last 3 rows of the table.

 

2019-05-16_11-23-15.jpg

Edited by Marcie
Link to comment
Share on other sites

  • Seeq Team

The alternative to setUnits is convertUnits. The former just adds overrides the current value with the new unit, the latter applies the math needed to the existing values.

For your case you should probably use

($a/($b+$c)).convertUnits('%')

 

Edited by Ben Johnson
  • Like 1
Link to comment
Share on other sites

Guest Jon Peterson

@Marcie--I just updated my test and confirmed the convertUnits('%') should do it. 

 

I just edited out the below--operator error on my part. Everything is working as expected. 

 

@Ben Johnson, Can you explain the logic Seeq uses with the setUnits? I did the following quick tests:

1. My first test was using two signals, both having the units of F. Presumably the ratio of the two signals results in a unit of 1. Thus, when using setUnits the conversion to percent works. 

2. I then did the same test, but with two signals from our PI Server that had no units. setUnits did not work, but convertUnits did.

3. Same test as 2, but, I first set the units to F, then did the math. I would expect this to work the same as 1. But it did not. 

Thanks,

Jon 

 

 

 

Edited by Jon Peterson
Link to comment
Share on other sites

  • Seeq Team

ConvertUnits requires a compatible units of its input and will do the scaling. Some examples

  • 5m.convertUnits('cm')  = 500cm.
  • 5m.setUnits('cm') = 5cm
  • 5m.setUnits('g') = 5g
  • 5m.convertUnits('g') is an error

I'm a bit surprised by the failure in your 2nd case. setUnits should never fail (almost - there are edge cases in converting string and numeric). I imagine the issue is that the underlying signals have incompatible units for the math prior to the setUnits.

If you have the formulas you tried, we can see if there are precedence issues vs actual bugs.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...