Yudaotor / EsportsHelper

通过selenium模拟浏览器来自动观看电竞比赛获取电竞典藏罐,当没有比赛时智能休眠.(Automatically watch e-sports games through undetected_chromedriver to farm esports capsule, when there is no match intelligent sleep.)
MIT License
201 stars 20 forks source link

New Drops are not counted #138

Open ReformedDoge opened 3 months ago

ReformedDoge commented 3 months ago

I noticed today that I haven't received any webhook drop notifications since March, so I began investigating the issue.

I found that I hadn't set countDrops to any value in my config file. However, as I understand it, countDrops defaults to True. Therefore, this should not be the cause of the issue https://github.com/Yudaotor/EsportsHelper/blob/a3429db1c987b5f4ab79e6728b78b2ff710b6757/EsportsHelper/Config.py#L85 I tested the webhook by setting connectorTest to True, and it succeeded. This indicates that the webhook itself is working correctly. I debugged currentDropsList, and it successfully retrieved and set the data.

Based on my findings, I suspect that the issue may be related to the following line of code: https://github.com/Yudaotor/EsportsHelper/blob/a3429db1c987b5f4ab79e6728b78b2ff710b6757/EsportsHelper/Rewards.py#L544

If unlockedDateMillis is older than stats.lastDropCheckTime - 6000, that drop will not be included in the newDropList i think that's the issue

As I understand, stats.lastDropCheckTime is updated at the end of the checkNewDrops function. The frequency of checkNewDrops calls is influenced by delays and sleep periods in watchMatches function in (Match.py) https://github.com/Yudaotor/EsportsHelper/blob/a3429db1c987b5f4ab79e6728b78b2ff710b6757/EsportsHelper/Match.py#L105-L232

~~Should we subtract the maximum possible delay or sleep time (whatever is greater) from stats.lastDropCheckTime to ensure that no drops are missed? Increasing the time window or adjusting the logic to account for potential delays might resolve the issue. max sleep time as i understand is 1 hour~~

Please let me know if this adjustment would help or if there are any other factors to consider. Also, it would be useful to know if other users are experiencing the same issue. I have yet to test this change since I haven’t received any new drops recently.

Thank you!

ReformedDoge commented 3 months ago

Apologies, I accidentally closed the issue by mistake

Sorting the currentDropsList and tracking the latest drop timestamp can be a more efficient way to handle this problem (Again, assuming it is indeed the cause. Here’s a possible approach)

class DropTracker:
    def __init__(self):
        self.latestProcessedDropTime = int(datetime.now().timestamp() * 1e3)  # Initialize with current time

    def checkNewDrops(self, currentDropsList):
        # Sort drops by unlockedDateMillis in descending order
        sorted_drops = sorted(currentDropsList, key=lambda drop: drop.get("unlockedDateMillis", 0), reverse=True)

        newDropList = []
        for drop in sorted_drops:
            unlockedDateMillis = drop.get("unlockedDateMillis", -1)

            # Early exit if we encounter a drop older than the latest processed drop time
            if unlockedDateMillis <= self.latestProcessedDropTime:
                break

            newDropList.append(drop)
            self.latestProcessedDropTime = unlockedDateMillis

        return newDropList

Create an instance of DropTracker somewhere in the script. drop_tracker = DropTracker() Use checkNewDrops to get the list of new drops. new_drops = drop_tracker.checkNewDrops(currentDropsList)

This approach dynamically updates latestProcessedDropTime based on the most recent drop it processes. It does not use a fixed time window but instead ensures that only drops newer than the most recently processed one are considered. As a result, it inherently accounts for any delays or gaps between checks.

Here is the updated Rewards.py that I will be testing for the next couple of days. https://github.com/ReformedDoge/EsportsHelper/commit/80e6276a4b39eb64a9f1da9b9a24b881389ef172

Yudaotor commented 3 months ago

I don't think I've seen anyone else raise a similar issue and I've been busy lately, so let me know here if you get any results on your end!

ReformedDoge commented 3 months ago

Hi @Yudaotor

I’ve determined that the getRewardByLog function in NetworkHandler.py is the cause of the problem.

Issue Details

The issue occurs when revisiting the reward page after the initial visit. If the earnedDrops requests are not present in the performance log (driver.get_log('performance')), the stats object is not updated, and we end up with drop data from the initial request only.

Solution

To resolve this, I implemented a delay and retry mechanism. This approach ensures that the earnedDrops endpoint is always captured in the performance log when visiting the reward page. The key changes involve:

With these changes, I’ve finally seen new drops reflected in the GUI after months of not being able to. The connector is now functioning properly as well: image

Fix Commit: aeb9636cd2f8f761bd8ed453e6903c7339582131

Additional Enhancement: A new class to track new drops more effectively: 298dd54e2cdb1896fbf36a8d9c866c0564cd88b6

I can create a pull request if other users are experiencing the same issue, or if you would like to review and merge these changes. Please let me know how you'd like to proceed or if there's anything else I can assist with.

DRCX commented 1 month ago

I don't think I've seen anyone else raise a similar issue and I've been busy lately, so let me know here if you get any results on your end!我认为我没有看到其他人提出类似的问题,而且我最近很忙,所以如果你得到任何结果,请在这里告诉我!

入围赛确实没有一个罐子掉落,我2个号都是这样...