Skip to content

Add preview command to Discord bot#47

Draft
kostrykin wants to merge 1 commit intomasterfrom
kostrykin/add-preview-command
Draft

Add preview command to Discord bot#47
kostrykin wants to merge 1 commit intomasterfrom
kostrykin/add-preview-command

Conversation

@kostrykin
Copy link
Contributor

@kostrykin kostrykin commented Jan 3, 2025

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.

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 kostrykin marked this pull request as draft January 3, 2025 19:37
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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant