Script Data Source error in Report

I have the following code to calculate formulas for a report.

    total_good_parts_per_hour = 7713 * 3
    # Calculate Choko and Bekido for each hour
    chokoValues = []
    bekidoValues = []
    for i in range(1, 10):
        goodPartsValue = data['goodParts24HR%d' % (14 + i)]
        combinedValue = data['combined24HR%d' % (14 + i)]

        if (goodPartsValue + combinedValue) != 0:
            chokoValue = (goodPartsValue / (goodPartsValue + combinedValue)) * 100
            chokoValue = 0

        if total_good_parts_per_hour != 0:
            bekidoValue = (goodPartsValue / total_good_parts_per_hour) * 100
            bekidoValue = 0

        # Store Choko and Bekido values in the data dictionary
        data['Choko%d' % (14 + i)] = chokoValue
        data['Bekido%d' % (14 + i)] = bekidoValue

Since it's in a report I don't know how to go about the debugging process due to the need for the tag historian Query I am using. What I am doing is looking at the XML of the report and seeing what values are being assigned.


These are the values I am getting. None of my combined vales or goodpcs values are 0.


Is there some simple fix I am missing? Or is there some data error I have not found yet?

The modulo indexing syntax looks very strange.
goodPartsValue = data['goodParts24HR%d' % (14 + i)]

How is it supposed to work?

Can you post the data so we can try your script.

The reason for the indexing is because I'm starting from 15. So I take 14 + i to go from 15 to 23.

The data is in the xml. I am pulling it from a tag historian query data source. There is no hard code for the values since they change daily.

Oh, yes. I only came across this once. It's modulo string formatting with a decimal conversion specifier so ['goodParts24HR%d' % (14 + i)] results in,


Carry on then ...

chokoValue = (goodPartsValue / (goodPartsValue + combinedValue)) * 100

Is that doing integer division, by any chance? Notice that 24HR20 = 412.0 (a float) and this gives a non-zero result.

chokoValue = (goodPartsValue * 1.0 / (goodPartsValue + combinedValue)) * 100
to force float.

chokoValue = ((goodPartsValue* 1.00) / (goodPartsValue + combinedValue)) * 100

results in


But apparently

goodPartsValue = float(data[goodPartsKey])
combinedValue = float(data[combinedKey])

works fine


Good catch. They are all integer value type tags. I'm not sure why one got put in as a float while others did not.