Advertisement
twx0r67

Valo_MMR_UP_Down

Dec 28th, 2022 (edited)
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | Gaming | 0 0
  1. ((
  2. /** @type {string} */ streamUptimeString,
  3. /** @type {string} */ streamStartDateString,
  4. /** @type {string} */ urlEncodedGetMmrHistoryResponseJson,
  5. ) => {
  6. /* streamStartDateString will be a date string even if the channel is not currently live (the date will be the current
  7. date). This may be a Nightbot bug. This is why streamUptimeString is needed to check whether the channel is live */
  8. if (/\bnot live\b/i.test(streamUptimeString)) {
  9. return 'Pandi is not live';
  10. }
  11.  
  12. const streamStartDate = new Date(streamStartDateString);
  13. if (Number.isNaN(streamStartDate.valueOf())) {
  14. return `Failed to parse stream start date: ${streamStartDateString}`.slice(0, 400);
  15. }
  16.  
  17. const getMmrHistoryResponseJson = decodeURIComponent(urlEncodedGetMmrHistoryResponseJson);
  18. if (/^Error Connecting To Remote Server\b/i.test(getMmrHistoryResponseJson)) {
  19. return getMmrHistoryResponseJson;
  20. }
  21.  
  22. try {
  23. /** @type {{
  24. readonly data: ReadonlyArray<{
  25. readonly mmr_change_to_last_game: number;
  26. readonly date_raw: number;
  27. }>;
  28. }} */
  29. const getMmrHistoryResponse = JSON.parse(getMmrHistoryResponseJson);
  30.  
  31. let mmrChangeThisStream = 0;
  32. let winCountThisStream = 0;
  33. let lossCountThisStream = 0;
  34. for (const {date_raw: dateUnixS, mmr_change_to_last_game: mmrChange} of getMmrHistoryResponse.data) {
  35. const date = new Date(dateUnixS * 1000);
  36. if (date >= streamStartDate) {
  37. mmrChangeThisStream += mmrChange;
  38.  
  39. if (mmrChange > 0) {
  40. winCountThisStream++;
  41. } else {
  42. lossCountThisStream++;
  43. }
  44. }
  45. }
  46.  
  47. return `Pandi is ${mmrChangeThisStream > 0 ? 'UP' : 'DOWN'} ${mmrChangeThisStream}RR${winCountThisStream}-${lossCountThisStream}`;
  48. } catch (e) {
  49. return `Failed to parse MMR history: ${e.message}: ${getMmrHistoryResponseJson}`.slice(0, 400);
  50. }
  51. })
Tags: #Valo_MMR
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement