Draft
Conversation
Add a new Discord command `/preview` to query the preview of the updated 30-days average player value based on the current session. * **`django/discordbot/bot.py`** - Add the `/preview` command to the bot. - Implement logic to fetch the current session and calculate the preview of the updated 30-days average player value. - Send the calculated preview value and the current 30-days average player value as a response to the Discord user. * **`django/stats/models.py`** - Add a method `calculate_preview_player_value` to the `GamingSession` model to calculate the preview of the updated 30-days average player value. - Implement logic to fetch the current session and calculate the preview of the updated 30-days average player value. * **`django/stats/tests.py`** - Add test cases to verify the `/preview` command in the `discordbot` bot. - Add test cases to verify the `calculate_preview_player_value` method in the `GamingSession` model. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/kosmotive/cs2pb?shareId=XXXX-XXXX-XXXX-XXXX).
kostrykin
commented
Jan 3, 2025
Comment on lines
+204
to
+225
| def calculate_preview_player_value(self) -> Optional[float]: | ||
| """ | ||
| Calculate the preview of the updated 30-days average player value. | ||
| """ | ||
| if self.is_closed: | ||
| return None | ||
|
|
||
| # Calculate the player value for each participant in the current session | ||
| player_values = [] | ||
| for m in self.squad.memberships.all(): | ||
| ctx = FeatureContext( | ||
| MatchParticipation.objects.filter(player = m.player, pmatch__sessions = self), | ||
| m.player, | ||
| ) | ||
| pv_today = Features.player_value(ctx) | ||
| if pv_today is not None: | ||
| player_values.append(pv_today) | ||
|
|
||
| # Calculate the average player value | ||
| if player_values: | ||
| return sum(player_values) / len(player_values) | ||
| return None |
Contributor
Author
There was a problem hiding this comment.
This code computes the average player value of all participants in the current session, instead of computing the 30-days average of only a single player.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a new Discord command
/previewto query the preview of the updated 30-days average player value based on the current session.django/discordbot/bot.py/previewcommand to the bot.django/stats/models.pycalculate_preview_player_valueto theGamingSessionmodel to calculate the preview of the updated 30-days average player value.django/stats/tests.py/previewcommand in thediscordbotbot.calculate_preview_player_valuemethod in theGamingSessionmodel.For more details, open the Copilot Workspace session.