Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Conversation

@jmoreira-valory
Copy link
Collaborator

@jmoreira-valory jmoreira-valory commented Feb 19, 2024

Fix duplicate mech calls

Addressess issue #232

) -> tuple[str, dict[Any, Any]]:
"""Parse the trades from the response."""

_mech_statistics = dict(mech_statistics)
Copy link
Collaborator

@Adamantios Adamantios Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you just copying here? If not, is the function's type hint for mech_statistics correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed type dict to Dict globally.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not what I meant 😅
dict was fine.
So you are just copying I assume. Why are you copying?

Copy link
Collaborator

@Adamantios Adamantios Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that you can avoid explicitly copying by not shadowing mech_statistics from the main scope.

Copy link
Collaborator Author

@jmoreira-valory jmoreira-valory Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method needs both the original read-only parameter (which the method doesn't care if it shadows the main one) and I also need a copy of it which I can modify. Both are required in this method: the original and the modifiable one.

Comment on lines +674 to +678
mech_data = _mech_statistics.pop(fpmmTrade["title"], {})
statistics_table[MarketAttribute.MECH_CALLS][
market_status
] += mech_statistics.get(fpmmTrade["title"], {}).get("count", 0)
mech_fees = mech_statistics.get(fpmmTrade["title"], {}).get("fees", 0)
] += mech_data.get("count", 0)
mech_fees = mech_data.get("fees", 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we do not pop here? The loop is for different trades afaict so what changes?

Copy link
Collaborator Author

@jmoreira-valory jmoreira-valory Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do not pop, it will pick again the same values if there is another trade for the same question. This is an issue, because there is no relation between mech calls and trades (we don't know what mech calls are related to each trade). Hence this was the solution adopted.

In summary, this will add up the mech calls for a given question the first time it is visited. Therefore it won't distinguish which calls are related to what trade, which is not an issue, because we only want the total.

@Adamantios Adamantios merged commit a033b0c into develop Feb 20, 2024
@Adamantios Adamantios deleted the fix/duplicate_mech_calls branch February 20, 2024 15:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants