From 9870b5489ed1c4094f637bcb4c8465cafe958681 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 24 Aug 2024 15:16:35 -0600 Subject: [PATCH 1/2] Update Roshan kill message to include Radiant/Dire percentages Update the `generateRoshanMessage` function to include Radiant/Dire percentages. * **Add Radiant/Dire percentage calculation:** * Add `radiantPercentage` and `direPercentage` properties to the `RoshRes` interface. * Create `calculateRadiantDirePercentages` function to calculate Radiant/Dire percentages based on `minS` and `maxS`. * Update `generateRoshanMessage` function to call `calculateRadiantDirePercentages` and include the percentages in the message. * **Update Roshan event handler:** * Add `radiantPercentage` and `direPercentage` properties to the `res` object in the Roshan event handler. * Update Redis storage to include the new properties. https://github.com/dotabod/backend/issues/416 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/dotabod/backend?shareId=XXXX-XXXX-XXXX-XXXX). --- .../events/gsi-events/event.roshan_killed.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/dota/src/dota/events/gsi-events/event.roshan_killed.ts b/packages/dota/src/dota/events/gsi-events/event.roshan_killed.ts index df0cd834..c6c4e953 100644 --- a/packages/dota/src/dota/events/gsi-events/event.roshan_killed.ts +++ b/packages/dota/src/dota/events/gsi-events/event.roshan_killed.ts @@ -17,6 +17,8 @@ export interface RoshRes { minDate: Date maxDate: Date count: number + radiantPercentage: number + direPercentage: number } // Doing it this way so i18n can pick up the t('') strings @@ -49,6 +51,20 @@ export function getNewRoshTime(res: RoshRes) { return res } +export function calculateRadiantDirePercentages(minS: number, maxS: number) { + const totalDuration = maxS - minS + const radiantDuration = 300 - minS + const direDuration = maxS - 300 + + const radiantPercentage = (radiantDuration / totalDuration) * 100 + const direPercentage = (direDuration / totalDuration) * 100 + + return { + radiantPercentage: radiantPercentage > 0 ? radiantPercentage : 0, + direPercentage: direPercentage > 0 ? direPercentage : 0, + } +} + export function generateRoshanMessage(res: RoshRes, lng: string) { res = getNewRoshTime(res) @@ -63,6 +79,18 @@ export function generateRoshanMessage(res: RoshRes, lng: string) { ) } + const percentages = calculateRadiantDirePercentages(res.minS, res.maxS) + res.radiantPercentage = percentages.radiantPercentage + res.direPercentage = percentages.direPercentage + + msgs.push( + t('roshanPercentages', { + radiant: res.radiantPercentage.toFixed(0), + dire: res.direPercentage.toFixed(0), + lng, + }), + ) + msgs.push(getRoshCountMessage({ lng, count: res.count })) return msgs.join(' ยท ') @@ -113,6 +141,8 @@ eventHandler.registerEvent(`event:${DotaEventTypes.RoshanKilled}`, { minDate, maxDate, count: count + 1, + radiantPercentage: 0, + direPercentage: 0, } await redisClient.client.json.set(`${dotaClient.getToken()}:roshan`, '$', res) From 6a7e022df589611638310f3a19e1d2665686f761 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 16 Sep 2024 16:12:21 -0400 Subject: [PATCH 2/2]