LiamM32 / Eurovision_Condorcet

A program to count votes for the Eurovision Song Contest using a redesigned voting system.
1 stars 2 forks source link

Undefined property: CondorcetPHP\Condorcet\Result::$pairwise #3

Closed LiamM32 closed 1 year ago

LiamM32 commented 1 year ago

These two PHP warnings are output during every cycle through EurovisionSchulze::schulzeVariant(), the latter 6 times each:

PHP Warning:  Undefined property: CondorcetPHP\Condorcet\Result::$pairwise in /home/liam/src/Eurovision_Condorcet/src/Method/EurovisionSchulze.php on line 26
int(7407296)
PHP Warning:  Trying to access array offset on value of type null in /home/liam/src/Eurovision_Condorcet/src/Method/EurovisionSchulze.php on line 28

The line that appears to be the problem is this one: $filteredPairwise = $contest->getResult(methodOptions: ['%tagFilter' => true, 'withTag' => true, 'tags' => $country])->pairwise;

Sorry to bother you again, @julien-boudry , but I don't understand how this function works. I don't know where to start guessing what may be going wrong.

It doesn't seem to be a problem of there being 0 votes registered in each country, as line 38 in Contest.php outputs the number of voters from each country using $this->countVotes($country), and I do get the expected output there.

julien-boudry commented 1 year ago

Don't have the same warning (but others than yours) . I have the impression to not be on the same commit level.

This error is about the new property, available on 4.5 dev only. Are you on the 4.5 branch?

LiamM32 commented 1 year ago

It looks like having the wrong Condorcet branch is indeed the problem. I checked some files in vendor/julien-boudry/condorcet, and they are the versions from the master branch.

In the composer.json file, it specifies "julien-boudry/condorcet": "dev-dev-4.5", which I thought would make it download the specified branch. I don't know if that line is written correctly. I just assumed this is the correct way to write it because that's the option that Netbeans IDE gave me.

Edit: Strangely, this was solved by changing the name in composer.json to the proper format. Composer then downloads the correct branch of Condorcet. It's strange that it works mostly correctly when the name format is wrong, only it downloads the wrong branch of Condorcet.

LiamM32 commented 1 year ago

I made a new commit that solves the warnings. The process still ultimately ended in an error. I solved this in a second commit. The problem was that $election->getResult() function would end in an error if there were 0 votes, which was the case for some of the tags it was looking for.

The program now appears to work properly. The results that it gives look believable, though I haven't tested their accuracy. It's slower than I expected. It may have taken 2 minutes for it to determine the result. But I'm not sure if this is just what I should expect for 4358 votes.

Update: Not everything is going correctly. I noticed that when it counts the number of voters from each country in the $contest->countVotersByCountry() function, it only counts the first vote from each country listed in the .cvotes file.

julien-boudry commented 1 year ago

It must work in much less than 0.5 seconds. It must be another problem, a problematic loop in your method (maybe Schulze himself hasn't predict your way, it can be a complicated math problem), or something. If it continues, open a new issue targeting this. @LiamM32

julien-boudry commented 1 year ago

About the composer, maybe you forget a composer update after an update.

LiamM32 commented 1 year ago

Based on the terminal outputs it gives, it appears to spend most of it's time in EurovisionSchulze::schulzeVariant(). If I place an echo() line in that function, I can see it takes one second per cycle.