Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the roundoff error in the Avg of N others calculation. #1248

Merged
merged 1 commit into from
Mar 12, 2020

Commits on Mar 6, 2020

  1. Reduce the roundoff error in the Avg of N others calculation.

    The "Average of N others" calculation was performed using the
    AVG() function in SQL then multiplying by the number of rows and
    dividing by the total number of data series. Since AVG() is
    SUM()/COUNT() the calculation was:
    ```
       SUM()         COUNT()
     ---------   *  ---------
      COUNT()         total
    ```
    
    Performing the calculation in this way increases the roundoff error.
    This pull request changes the code to instead calculate the average as
    ```
       SUM()
     ---------
       total
    ```
    which has lower roundoff error due to fewer operations.
    
    The keen eyed reader might ask why not do the calculation in SQL rather
    than the SUM() in SQL and division in PHP. This is to maintain backwards
    compatibility with the existing behaviour where if the average value is
    zero then it is plotted on the chart as a zero. This differs from the
    rest of XDMoD where zero values are not plotted. If the calculation were
    preformed in SQL then a zero would be converted to null in the
    `convertSQLtoPHP()` function. This, of course, could be changed too, but
    this would be a much more intrusive change.
    jpwhite4 committed Mar 6, 2020
    Configuration menu
    Copy the full SHA
    53f0958 View commit details
    Browse the repository at this point in the history