Can a User Defined value be converted to use in calculations?

I'm trying to be able to make calculations in MassHunter Report Builder to incorporate sample moisture content in the final analyte concentration. I tried using a User Defined field but that won't work in calculations like Sample Amount and Total Amount. Is there a way to convert User Defined fields to numeric for those calculations? Or is there another field that would be useful to use in that way?

Top Replies

  • Hello

     

    Quant has three different fields that can be used in creating a multiplier, which is then used to convert the calculated concentration, which is the amount calculated from the calibration curve, to a final concentration.

     

    The multiplier column can be added in the Compound Method section of the batch table. It cannot be directly edited but displays the multiplier that has been calculated using Dilution, Sample Amount, and Total Sample Amount. 

     

    Multiplier = (Total Sample Amount / Sample Amount) *Dilution

     

    Final Concentration = Calculated Concentration * Multiplier

     

    By default, Dilution (Dil.) has a value of 1. Sample Amount (Amt.) and Total Sample Amount (Tot. Amt.) do not have values and are not used in the calculation unless both have a value entered.

     

    If these do not meet your calculation needs, then it is possible to convert a number that is stored as text to an integer or floating point value in report builder. You can use the IronPython int() or float() functions. In this example I am simply multiplying the final concentration by the value entered in User Defined for the sample

     

    float(BoundItems["Sample"].UserDefined)*BoundItems["TargetPeak"].FinalConcentration

     

    However, if UserDefined is not a valid number string then report generation will halt with an error.

     

    If you'd like a little more robust method, or perhaps a way to allow text to be entered (such as NA if no correction is needed) then you could try the following expression, utilizing the .NET TryParse method.

     

    import System
    isNumber, userDefinedNumber = float.TryParse(BoundItems["Sample"].UserDefined)
    userDefinedNumber*BoundItems["TargetPeak"].FinalConcentration if isNumber else "NA"

     

    When calling a method with 'out' parameters from IronPython you omit the argument and a tuple is returned. For TryParse the first element is either True or False (assigned to isNumber) and the second element contains the converted number (assigned to userDefinedNumber). For a sample with a User Defined value of 5 and another with NA entered the report would look like this.

     

Was this helpful?