pdinklag / MinecraftStats

A Minecraft player statistics browser for the web - supports 1.13 and later!
https://discord.gg/brH5PGG8By
Other
227 stars 53 forks source link

If newAwardWinners do this? #6

Closed Ubiquitous-X closed 9 years ago

Ubiquitous-X commented 9 years ago

This is something you might be able to help me with in an easy way. When running the update.php I also need it to do:

foreach (awardwinner) that differs from the awardwinner in the awardsOutput.txt {

} Is that something you could help with?
pdinklag commented 9 years ago

Probably, but we need to specify your goal. I gather that you are trying to detect awards changing hands?

Ubiquitous-X commented 9 years ago

Yes. When update. php is run, and before it writes to awardOutput.txt, I would need it to check if there is a new #1 in each award, and get the player name and the award name out to a string, before it writes the new awardOutput.txt Of course not all changed rankings, only "if award = new awardwinner; do my code". All I need is that string, the rest of the code I manage.

måndag 13 juli 2015 skrev Patrick Dinklage notifications@github.com:

Probably, but we need to specify your goal. I gather that you are trying to detect awards changing hands?

— Reply to this email directly or view it on GitHub https://github.com/pdinklag/MinecraftStats/issues/6#issuecomment-120822628 .

Skickat från Gmail Mobile

pdinklag commented 9 years ago

Well, there is currently no means to parse the award output, but you could simply load the old $awardsFile into something like $oldAwards before the new awards file is saved (in the //Save awards block): $oldAwards = unserialize(file_get_contents($awardsFile));

Then, you could add a comparison to the loop, like: if ( $awards[$id]['id'] != $oldAwards[$id]['id'] ) { /* new award winner */ }

Yeah, id is ambiguous - the $id variable refers to the stat's ID within the loop, whereas an award's value for 'id' is the UUID of the player holding it.

Anyway, unless you can figure it out quickly, I can offer a code sample tomorrow.

Ubiquitous-X commented 9 years ago

That seems to be a very good solution, I think I'll try to implement that code when I get home. I can read code, and cut anf paste, but have hard time writing it myself. This seems like I understand how to implement.

måndag 13 juli 2015 skrev Patrick Dinklage notifications@github.com:

Well, there is currently no means to parse the award output, but you could simply load the old $awardsFile into something like $oldAwards before the new awards file is saved (in the //Save awards block).

Then, you could add a comparison to the loop, like: if ( $awards[$id]['id'] != $oldAwards[$id]['id'] ) { /* new award winner */ }

Yeah, id is ambiguous - the $id variable refers to the stat's ID within the loop, whereas an award's value for 'id' is the UUID of the player holding it.

Anyway, unless you can figure it out quickly, I can offer a code sample tomorrow.

— Reply to this email directly or view it on GitHub https://github.com/pdinklag/MinecraftStats/issues/6#issuecomment-120845980 .

Skickat från Gmail Mobile

Ubiquitous-X commented 9 years ago

I am so close to the solution, but not 100%. There is actually no loop in the //Save awards block, but in //Create award output. I created a loop before //Save awards that successfully grabs the name of the new winner, and the raw stat name of the correct stat. Of what I understand there is two options from here:

A) Make my new loop associate the stat.name with the correct award name.

B) Implement the $awardsFile comparison in //Create award output.

I am not succeeding in any of those. Maybe you have the solution?

The loop i created was:

`$oldAwards = unserialize(file_get_contents($awardsFile));

    foreach($awards as $id => $newWinner) {         
        if ( $awards[$id]['id'] != $oldAwards[$id]['id'] ) {                            
        echo (getPlayerName($newWinner['id'])); //The player name works correct         
        echo $id; //Need to convert the raw stat name to the award name     
    }       
}   
pdinklag commented 9 years ago

Yep, I meant the award output loop. Just the loading of the old awards file should happen before saving the new one.