AtCoderAnotherGraph

heuristic/algoの計算式でレーティンググラフを表示

2022-11-28 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  1. // ==UserScript==
  2. // @name AtCoderAnotherGraph
  3. // @namespace https://twitter.com/merom686
  4. // @version 1.0
  5. // @description heuristic/algoの計算式でレーティンググラフを表示
  6. // @author merom686
  7. // @match https://atcoder.jp/users/*
  8. // @grant GM_xmlhttpRequest
  9. // ==/UserScript==
  10.  
  11. (function(){
  12. if (typeof rating_history === 'undefined') return;
  13. let rating_history_original = [...rating_history];
  14. let ma = location.href.match(/https:\/\/atcoder\.jp\/users\/(\w+)(\?contestType=(\w+))?/);
  15. let type = 'algo';
  16. if (ma[3]) type = ma[3];
  17. let user = ma[1];
  18.  
  19. const S = 724.4744301, R = 0.8271973364;
  20. const T = (1 - 0.9) / Math.sqrt(1 - 0.81);
  21. let F = (n) => {
  22. return T * Math.sqrt(0.81 - Math.pow(0.81, n + 1)) / (0.9 - Math.pow(0.9, n + 1));
  23. };
  24. let f = (n) => {
  25. return (F(n) - T) / (F(1) - T) * 1200;
  26. };
  27. let update = () => {
  28. const e = new CustomEvent('load');
  29. window.dispatchEvent(e);
  30. };
  31.  
  32. let button = document.createElement('button');
  33. button.className = 'btn btn-default';
  34. button.innerText = 'another';
  35. button.onclick = () => {
  36. if ('another' in rating_history[0] || 'another' in rating_history_original[0]){
  37. let temp = rating_history;
  38. rating_history = rating_history_original;
  39. rating_history_original = temp;
  40. update();
  41. return;
  42. }
  43. GM_xmlhttpRequest({
  44. method: 'GET',
  45. url: 'https://atcoder.jp/users/' + user + '/history/json?contestType=' + type,
  46. onload: function(response) {
  47. let n = rating_history.length;
  48. const history_array = JSON.parse(response.responseText);
  49. let p = [];
  50. for (let o of history_array){
  51. if (o.IsRated) p.push(o.Performance);
  52. }
  53. let q = [];
  54. let old = 0, s0 = 0, s1 = 0;
  55. for (let i = 0; i < n; i++){
  56. let r = 0;
  57. if (type == 'algo'){
  58. for (let j = 1; j <= 100; j++){
  59. q.push(p[i] - S * Math.log(j));
  60. }
  61. q.sort((i0, i1) => i1 - i0);
  62. s0 = 0; s1 = 0;
  63. for (let j = 99; j >= 0; j--){
  64. s0 += q[j];
  65. s0 *= R;
  66. s1 += 1;
  67. s1 *= R;
  68. }
  69. r = s0 / s1;
  70. } else {
  71. //if (perf < 400) perf = Math.log(perf / 400) * 400 + 400;
  72. s0 += Math.pow(2.0, p[i] / 800.0);
  73. s0 *= 0.9;
  74. s1 += 1;
  75. s1 *= 0.9;
  76. r = 800 * Math.log2(s0 / s1) - f(i + 1);
  77. }
  78. if (r < 400) r = Math.exp((r - 400) / 400) * 400;
  79. rating_history[i] = { ...rating_history_original[i] };
  80. rating_history[i].NewRating = Math.round(r);
  81. rating_history[i].OldRating = old;
  82. old = rating_history[i].NewRating;
  83. }
  84. rating_history[0].another = 1;
  85. update();
  86. }
  87. });
  88. };
  89. let a = document.getElementById('rating-graph-expand');
  90. a.parentNode.insertBefore(button, a.nextSibling);
  91. })();