Page MenuHomePhabricator

SecurePoll: Inconsistencies in how we calculate and display small numbers
Open, Needs TriagePublicBUG REPORT

Description

What is the problem?

There seems to be at least two potential bugs here:

  1. On the tally page, small numbers in calculations are displayed as "0" or not displayed at all.
  2. In the "backend", some small numbers are being calculated accurately and others are not.

I don't yet know if any of this will have an impact on the actual results of an election. See https://www.mediawiki.org/wiki/Anti-Harassment_Tools/SecurePoll_Improvements/Test_Results/Precision for a bit more background.

Bug 1

In the tally output of 20_9_5000_1730013084, in round 36 the actual earned votes for candidate 9 is 6.8626284368883533E-6, but is displayed as 0. I thought we were supposed to round numbers to 6 decimal places, so this should display as something like .000007. Moreover, in spite of the "earned" votes being "0", the total votes goes up from 82.000568 to 82.000574.

round_36.png (429×1 px, 14 KB)

In 20_9_5000_439818328, between rounds 3 and 13, candidate 9 does technically have votes transferred to them (of the order of ~4.80449350E-17), but this is not displayed at all (not even as "0"). For example, below candidates 10, 11 and 12 are eliminated because they have 82 votes. Candidate 9 is shown as having 82 votes as well (and nothing transferred), but is not eliminated.

round_12.png (496×1 px, 14 KB)

Bug 2

In the results log of 20_9_5000_439818328, candidate 9's earned votes are stored as 0.0, when in fact they are of the order of ~4.80449350E-17 (calculated with bc from the keep factors in round 13).

Compare this to 20_9_5000_1730013084, where even smaller numbers (such as 7.810096726086052E-21) are being stored accurately.

Steps to reproduce problem

All the files necessary to reproduce the two elections above are here:

Environment

Wiki(s):

Event Timeline

Change 712409 had a related patch set uploaded (by STran; author: STran):

[mediawiki/extensions/SecurePoll@master] Remove rounding from display

https://gerrit.wikimedia.org/r/712409

===== Bug 1

In 20_9_5000_439818328, between rounds 3 and 13, candidate 9 does technically have votes transferred to them (of the order of ~4.80449350E-17), but this is not displayed at all (not even as "0"). For example, below candidates 10, 11 and 12 are eliminated because they have 82 votes. Candidate 9 is shown as having 82 votes as well (and nothing transferred), but is not eliminated.

round_12.png (496×1 px, 14 KB)

Bug 2

In the results log of 20_9_5000_439818328, candidate 9's earned votes are stored as 0.0, when in fact they are of the order of >~4.80449350E-17 (calculated with bc from the keep factors in round 13).

Compare this to 20_9_5000_1730013084, where even smaller numbers (such as 7.810096726086052E-21) are being stored accurately.

I think Bug 2 causes that second case in Bug 1. We can't display a vote gain or loss if it's stored as 0.

My patch only deals with display issues and I've split up the math quirk into its own thing T289185: Use bc in STV algorithm as we discussed in estimation today.

Change 712409 merged by jenkins-bot:

[mediawiki/extensions/SecurePoll@master] Fix rounding display in STV tally output

https://gerrit.wikimedia.org/r/712409

@STran The issue I mentioned in standup.

Round 30 here https://vote.wikimedia.beta.wmflabs.org/wiki/Special:SecurePoll/tally/1449 shows nothing transferred to candidate 9, but in the resultsLog it is 6.6488051686519611E-7 which I thought would be rounded to 1E-6.

But, both number_format( 82.000014592137504, 6) (votes) and number_format( 82.000015257018021, 6) (total) both equal 82.000015, so I guess it makes sense.

blt file for repro

@STran I don't think it likes numbers over 1000.

For example, going to https://vote.wikimedia.beta.wmflabs.org/wiki/Special:SecurePoll/tally/1954 I see errors like these:

2021-08-26 12:48:55 [YSeNt-rwfjiz1jlhHBIJCAAAABQ] deployment-mediawiki11 votewiki 1.37.0-alpha error ERROR: [YSeNt-rwfjiz1jlhHBIJCAAAABQ] /wiki/Special:SecurePoll/tally/1954   PHP Notice: A non well formed numeric value encountered {"exception_url":"/wiki/Special:SecurePoll/tally/1954","reqId":"YSeNt-rwfjiz1jlhHBIJCAAAABQ","caught_by":"mwe_handler"} 
[Exception ErrorException] (/srv/mediawiki/php-master/extensions/SecurePoll/includes/Talliers/STVTallier.php:294) PHP Notice: A non well formed numeric value encountered
  #0 /srv/mediawiki/php-master/extensions/SecurePoll/includes/Talliers/STVTallier.php(294): MWExceptionHandler::handleError(integer, string, string, integer, array)
  #1 /srv/mediawiki/php-master/extensions/SecurePoll/includes/Talliers/ElectionTallier.php(185): MediaWiki\Extensions\SecurePoll\Talliers\STVTallier->getHtmlResult()
  #2 /srv/mediawiki/php-master/extensions/SecurePoll/includes/Pages/TallyPage.php(208): MediaWiki\Extensions\SecurePoll\Talliers\ElectionTallier->getHtmlResult()
  #3 /srv/mediawiki/php-master/extensions/SecurePoll/includes/Pages/TallyPage.php(92): MediaWiki\Extensions\SecurePoll\Pages\TallyPage->showTallyResult()
  #4 /srv/mediawiki/php-master/extensions/SecurePoll/includes/SpecialSecurePoll.php(70): MediaWiki\Extensions\SecurePoll\Pages\TallyPage->execute(array)
  #5 /srv/mediawiki/php-master/includes/specialpage/SpecialPage.php(646): MediaWiki\Extensions\SecurePoll\SpecialSecurePoll->execute(string)
  #6 /srv/mediawiki/php-master/includes/specialpage/SpecialPageFactory.php(1366): SpecialPage->run(string)
  #7 /srv/mediawiki/php-master/includes/MediaWiki.php(314): MediaWiki\SpecialPage\SpecialPageFactory->executePath(string, RequestContext)
  #8 /srv/mediawiki/php-master/includes/MediaWiki.php(925): MediaWiki->performRequest()
  #9 /srv/mediawiki/php-master/includes/MediaWiki.php(559): MediaWiki->main()
  #10 /srv/mediawiki/php-master/index.php(53): MediaWiki->run()
  #11 /srv/mediawiki/php-master/index.php(46): wfIndexMain()
  #12 /srv/mediawiki/w/index.php(3): require(string)
  #13 {main}
2021-08-26 12:48:55 [YSeNt-rwfjiz1jlhHBIJCAAAABQ] deployment-mediawiki11 votewiki 1.37.0-alpha error ERROR: [YSeNt-rwfjiz1jlhHBIJCAAAABQ] /wiki/Special:SecurePoll/tally/1954   PHP Notice: A non well formed numeric value encountered {"exception_url":"/wiki/Special:SecurePoll/tally/1954","reqId":"YSeNt-rwfjiz1jlhHBIJCAAAABQ","caught_by":"mwe_handler"} 
[Exception ErrorException] (/srv/mediawiki/php-master/extensions/SecurePoll/includes/Talliers/STVTallier.php:317) PHP Notice: A non well formed numeric value encountered
  #0 /srv/mediawiki/php-master/extensions/SecurePoll/includes/Talliers/STVTallier.php(317): MWExceptionHandler::handleError(integer, string, string, integer, array)
  #1 /srv/mediawiki/php-master/extensions/SecurePoll/includes/Talliers/ElectionTallier.php(185): MediaWiki\Extensions\SecurePoll\Talliers\STVTallier->getHtmlResult()
  #2 /srv/mediawiki/php-master/extensions/SecurePoll/includes/Pages/TallyPage.php(208): MediaWiki\Extensions\SecurePoll\Talliers\ElectionTallier->getHtmlResult()
  #3 /srv/mediawiki/php-master/extensions/SecurePoll/includes/Pages/TallyPage.php(92): MediaWiki\Extensions\SecurePoll\Pages\TallyPage->showTallyResult()
  #4 /srv/mediawiki/php-master/extensions/SecurePoll/includes/SpecialSecurePoll.php(70): MediaWiki\Extensions\SecurePoll\Pages\TallyPage->execute(array)
  #5 /srv/mediawiki/php-master/includes/specialpage/SpecialPage.php(646): MediaWiki\Extensions\SecurePoll\SpecialSecurePoll->execute(string)
  #6 /srv/mediawiki/php-master/includes/specialpage/SpecialPageFactory.php(1366): SpecialPage->run(string)
  #7 /srv/mediawiki/php-master/includes/MediaWiki.php(314): MediaWiki\SpecialPage\SpecialPageFactory->executePath(string, RequestContext)
  #8 /srv/mediawiki/php-master/includes/MediaWiki.php(925): MediaWiki->performRequest()
  #9 /srv/mediawiki/php-master/includes/MediaWiki.php(559): MediaWiki->main()
  #10 /srv/mediawiki/php-master/index.php(53): MediaWiki->run()
  #11 /srv/mediawiki/php-master/index.php(46): wfIndexMain()
  #12 /srv/mediawiki/w/index.php(3): require(string)
  #13 {main}

And also:

2021-08-26 12:48:56 [YSeNt-rwfjiz1jlhHBIJCAAAABQ] deployment-mediawiki11 votewiki 1.37.0-alpha formatnum WARNING: Language::formatNum with non-numeric string {"number":"1,666.666668"}
2021-08-26 12:48:56 [YSeNt-rwfjiz1jlhHBIJCAAAABQ] deployment-mediawiki11 votewiki 1.37.0-alpha formatnum WARNING: Language::formatNum with non-numeric string {"number":"1,555.555557"} 
2021-08-26 12:48:56 [YSeNt-rwfjiz1jlhHBIJCAAAABQ] deployment-mediawiki11 votewiki 1.37.0-alpha formatnum WARNING: Language::formatNum with non-numeric string {"number":"1,185.185187"}

Leads to weird output in the tally page like: "1": 2,000 - 1 = 1,666.666668 (keep factor: 0.833333)

blt file for reprod

I also saw this when testing the Irish general election, but I have not been able to upload this successfully to beta.

Other examples:

Also raised T290134, numbers less than 0.0001 appear as 0.