Advertisement
twx0r67

Valo_mmr_match_history

Dec 28th, 2022 (edited)
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | Gaming | 0 0
  1. ((
  2. /** @type {string} */ streamUptimeString,
  3. /** @type {string} */ streamStartDateString,
  4. /** @type {string} */ urlEncodedGetMmrHistoryResponseJson,
  5. ) => {
  6.  
  7. const streamStartDate = new Date(streamStartDateString);
  8. if (Number.isNaN(streamStartDate.valueOf())) {
  9. return `Failed to parse stream start date: ${streamStartDateString}`.slice(0, 400);
  10. }
  11.  
  12. const getMmrHistoryResponseJson = decodeURIComponent(urlEncodedGetMmrHistoryResponseJson);
  13. if (/^Error Connecting To Remote Server\b/i.test(getMmrHistoryResponseJson)) {
  14. return getMmrHistoryResponseJson;
  15. }
  16.  
  17. try {
  18. /** @type {{
  19. readonly data: ReadonlyArray<{
  20. readonly mmr_change_to_last_game: number;
  21. readonly date_raw: number;
  22. }>;
  23. }} */
  24.  
  25. const getMmrHistoryResponse = JSON.parse(getMmrHistoryResponseJson);
  26.  
  27. let mmrChangeThisStream = 0;
  28. let winCountThisStream = 0;
  29. let lossCountThisStream = 0;
  30. for (const {date_raw: dateUnixS, mmr_change_to_last_game: mmrChange} of getMmrHistoryResponse.data) {
  31. const date = new Date(dateUnixS * 1000);
  32. if (date >= streamStartDate) {
  33. mmrChangeThisStream += mmrChange;
  34.  
  35. if (mmrChange > 0) {
  36. winCountThisStream++;
  37. } else {
  38. lossCountThisStream++;
  39. }
  40. }
  41. }
  42.  
  43. let text = "";
  44. for (const {date_raw: dateUnixS, mmr_change_to_last_game: mmrChange} of getMmrHistoryResponse.data) {
  45. text += "[" + mmrChange + "] ";
  46. }
  47.  
  48. return `Pandii's Valo Match History (Elo change) :: ${text}`;
  49. } catch (e) {
  50. return `Failed to parse MMR history: ${e.message}: ${getMmrHistoryResponseJson}`.slice(0, 400);
  51. }
  52. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement