AtcoderDevotionGraph

Overlay your devoiting graph on your rating graph

Από την 02/12/2020. Δείτε την τελευταία έκδοση.

  1. // ==UserScript==
  2. // @name AtcoderDevotionGraph
  3. // @namespace http://atcoder.jp/
  4. // @version 1.0.0
  5. // @description Overlay your devoiting graph on your rating graph
  6. // @author kemkemG0
  7. // @include *://atcoder.jp/users*
  8. // @exclude *://atcoder.jp/users/*?graph=rank
  9. // @exclude *://atcoder.jp/users/*/history*
  10. // @grant none
  11. // @require https://code.jquery.com/jquery-1.8.0.min.js
  12. //@run-at document-end
  13.  
  14. // ==/UserScript==
  15.  
  16. "use strict";
  17.  
  18. let scriptsArray = $('script');
  19. scriptsArray[14].remove(); // 対象のタグを消す記述 x[14]がグラフを読み込むjs
  20. //なんでこれ必要?? -->>一度読み込んだscriptタグはDOMから消しても効果は残るからそれを消すため
  21. let copyPage = $("html").clone().html();
  22. $("html").remove();
  23. document.write(copyPage);
  24.  
  25. //##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##
  26.  
  27.  
  28. {
  29. const element = document.getElementsByClassName('btn-text-group')[document.getElementsByClassName('btn-text-group').length - 1];
  30. const insertButton = Object.assign(document.createElement('button'), {
  31. className: '',
  32. id: 'shoujinButtonID',
  33. style: '\
  34. margin-left:100px;\
  35. appearance: none;\
  36. border: 0;\
  37. border-radius: 5px;\
  38. background: #20b2aa;\
  39. color: #fff;\
  40. padding: 5px 10px;\
  41. font-size: 16px;\
  42. '
  43. }
  44. );
  45. insertButton.textContent = "精進"
  46. element.appendChild(insertButton)
  47. }
  48.  
  49. // const
  50. const MARGIN_VAL_X = 86400 * 30;
  51. const MARGIN_VAL_Y_LOW = 100;//
  52. const MARGIN_VAL_Y_HIGH = 300;//自分の最高レート+表示する領域
  53. const OFFSET_X = 50;//グラフの位置?
  54. const OFFSET_Y = 5;
  55. const DEFAULT_WIDTH = 640;
  56. let canvas_status = document.getElementById("ratingStatus");
  57. // <canvas id="ratingStatus" width="1280" height="160"
  58. // style="max-width: 640px; max-height: 80px; height: 100%; width: 100%;"></canvas>
  59. const STATUS_WIDTH = canvas_status.width - OFFSET_X - 10;
  60. const STATUS_HEIGHT = canvas_status.height - OFFSET_Y - 5;
  61. let canvas_graph = document.getElementById("ratingGraph");
  62. /* <canvas id="ratingGraph"
  63. width="1280" height="720"
  64. style="max-width: 640px; max-height: 360px; height: 100%; width: 100%;"></canvas>*/
  65. const PANEL_WIDTH = canvas_graph.width - OFFSET_X - 10;
  66. const PANEL_HEIGHT = canvas_graph.height - OFFSET_Y - 30;
  67. //HIGHEST:932 とかの吹き出しのサイズ
  68. const HIGHEST_WIDTH = 80;
  69. const HIGHEST_HEIGHT = 20;
  70. const LABEL_FONT = "12px Lato";
  71. const START_YEAR = 2010;
  72. const MONTH_NAMES = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  73. const YEAR_SEC = 86400 * 365;
  74. const STEP_SIZE = 400;//グラフのy軸のステップ数
  75. const COLORS = [
  76. [0, "#808080", 0.15],
  77. [400, "#804000", 0.15],
  78. [800, "#008000", 0.15],
  79. [1200, "#00C0C0", 0.2],
  80. [1600, "#0000FF", 0.1],
  81. [2000, "#C0C000", 0.25],
  82. [2400, "#FF8000", 0.2],
  83. [2800, "#FF0000", 0.1]
  84. ];
  85.  
  86. //??????????????????
  87. const STAR_MIN = 3200;
  88. const PARTICLE_MIN = 3;
  89. const PARTICLE_MAX = 20;
  90. const LIFE_MAX = 30;
  91. const EPS = 1e-9;
  92.  
  93. let cj = createjs;
  94. let stage_graph, stage_status;
  95. // graph
  96. let panel_shape, border_shape;
  97. let chart_container, line_shape, vertex_shapes, highest_shape;
  98. let n, x_min, x_max, y_min, y_max;
  99.  
  100. //devoting graph
  101. let devoting_panel_shape, devoting_border_shape;
  102. let devoting_chart_container, devoting_line_shape, devoting_vertex_shapes, devoting_highest_shape;
  103. let devoting_n, devoting_x_min, devoting_x_max, devoting_y_min, devoting_y_max;
  104. let devoting_rating_history = []
  105.  
  106. // status
  107. let border_status_shape;
  108. let rating_text, place_text, diff_text, date_text, contest_name_text;
  109. let particles;
  110. let standings_url;
  111. const username = document.getElementsByClassName("username")[0].textContent;
  112. //クリエイトjsとやらをつかっている
  113. //いい感じにキャンバスの大きさを設定してマウスオーバーもONにする
  114. function initStage(stage, canvas) {
  115. let width = canvas.getAttribute('width');// <canvas width="">を取得
  116. let height = canvas.getAttribute('height');
  117.  
  118. //最悪、なくても画質悪くなったが動いた よくわからん
  119. if (window.devicePixelRatio) {//ピクセル比 によって解像度を変える 本来は2のときに1にしたらぼやけた
  120. //縦横の設定
  121. canvas.setAttribute('width', Math.round(width * window.devicePixelRatio));//Math.round()は四捨五入
  122. canvas.setAttribute('height', Math.round(height * window.devicePixelRatio));
  123. stage.scaleX = stage.scaleY = window.devicePixelRatio;
  124. }
  125. //最大のキャンパスサイズ=もとのキャンバスサイズにする
  126. canvas.style.maxWidth = width + "px";
  127. canvas.style.maxHeight = height + "px";
  128. canvas.style.width = canvas.style.height = "100%";
  129. stage.enableMouseOver();
  130. }
  131. //parent===stageに図形を追加し、その図形をreturnで参照渡し
  132. function newShape(parent) {
  133. let s = new cj.Shape();
  134. parent.addChild(s);
  135. return s;
  136. }
  137. //上のテキストバージョン
  138. function newText(parent, x, y, font) {
  139. let t = new cj.Text("", font, "#000");
  140. t.x = x;
  141. t.y = y;
  142. t.textAlign = "center";
  143. t.textBaseline = "middle";
  144. parent.addChild(t);
  145. return t;
  146. }
  147. //多分一番の大元
  148. function init() {
  149. //rating_history はHTML内で取得してある
  150. //rating_history=[{"EndTime":時間(単位不明),"NewRating":11,"OldRating":0,"Place":5200,"ContestName":"コンテスト名","StandingsUrl":"/contests/m-solutions2020/standings?watching=kemkemG0"}];
  151. n = rating_history.length;
  152. devoting_n = devoting_rating_history.length;
  153. if (n == 0 ) return;
  154.  
  155. //土台のステージ これに図形とかを追加していくイメージ
  156. stage_graph = new cj.Stage("ratingGraph");// Stage("canvasのID");
  157. stage_status = new cj.Stage("ratingStatus");
  158. initStage(stage_graph, canvas_graph);
  159. initStage(stage_status, canvas_status);
  160.  
  161. //グラフのサイズ決定
  162. x_min = 100000000000;
  163. x_max = 0;
  164. y_min = 10000;
  165. y_max = 0;
  166. for (let i = 0; i < n; i++) {
  167. x_min = Math.min(x_min, rating_history[i].EndTime);
  168. x_max = Math.max(x_max, rating_history[i].EndTime);
  169. y_min = Math.min(y_min, rating_history[i].NewRating);
  170. y_max = Math.max(y_max, rating_history[i].NewRating);
  171. }
  172. x_min -= MARGIN_VAL_X;//最初にコンテストに参加した日ー1ヶ月
  173. x_max += MARGIN_VAL_X;//最後にコンテストに参加した日+1ヶ月
  174. y_min = Math.min(1500, Math.max(0, y_min - MARGIN_VAL_Y_LOW));//いい感じに高さも設定
  175. y_max += MARGIN_VAL_Y_HIGH;
  176.  
  177. //精進グラフのサイズ決定
  178. devoting_x_min = 100000000000;
  179. devoting_x_max = 0;
  180. devoting_y_min = 10000;
  181. devoting_y_max = 0;
  182. for (let i = 0; i < devoting_rating_history.length; i++) {
  183. devoting_x_min = Math.min(devoting_x_min, devoting_rating_history[i].epoch_second);
  184. devoting_x_max = Math.max(devoting_x_max, devoting_rating_history[i].epoch_second);
  185. devoting_y_min = Math.min(devoting_y_min, devoting_rating_history[i].point);
  186. devoting_y_max = Math.max(devoting_y_max, devoting_rating_history[i].point);
  187. }
  188. devoting_x_min -= MARGIN_VAL_X;//最初にコンテストに参加した日ー1ヶ月
  189. devoting_x_max += MARGIN_VAL_X;//最後にコンテストに参加した日+1ヶ月
  190. devoting_y_min = Math.min(1500, Math.max(0, devoting_y_min - MARGIN_VAL_Y_LOW));//いい感じに高さも設定
  191. devoting_y_max += MARGIN_VAL_Y_HIGH;
  192.  
  193. //形を決める
  194. y_min = Math.min(y_min, devoting_y_min);
  195. y_max = Math.max(y_max, devoting_y_max);
  196. x_min = Math.min(x_min, devoting_x_min);
  197. x_max = Math.max(x_max, devoting_x_max);
  198.  
  199. initBackground();//背景の描画
  200. initChart();//プロットと直線の描画
  201. initDevotingChart()
  202. stage_graph.update();
  203.  
  204. initStatus();//グラフの上のコンテスト情報とかの描画
  205. stage_status.update();
  206. //マウスオーバー時のほわほわの管理
  207. cj.Ticker.setFPS(60);
  208. cj.Ticker.addEventListener("tick", handleTick);
  209. function handleTick(event) {
  210. updateParticles();
  211. stage_status.update();
  212. }
  213. }
  214.  
  215. function getPer(x, l, r) {
  216. return (x - l) / (r - l);
  217. }
  218. function getColor(x) {
  219. for (let i = COLORS.length - 1; i >= 0; i--) {
  220. if (x >= COLORS[i][0]) return COLORS[i];
  221. }
  222. return [-1, "#000000", 0.1];
  223. }
  224. function initBackground() {
  225.  
  226. panel_shape = newShape(stage_graph);//stage_graphに図形を追加、また panel_shapeはstage_graphの内部とつながってる(オブジェクトは参照渡し)
  227. panel_shape.x = OFFSET_X;
  228. panel_shape.y = OFFSET_Y;
  229. panel_shape.alpha = 0.3;
  230.  
  231. border_shape = newShape(stage_graph);
  232. border_shape.x = OFFSET_X;
  233. border_shape.y = OFFSET_Y;
  234.  
  235. //左の軸のレートの設定
  236. function newLabelY(s, y) {
  237. let t = new cj.Text(s, LABEL_FONT, "#000");
  238. t.x = OFFSET_X - 10;//理解
  239. t.y = OFFSET_Y + y;
  240. t.textAlign = "right";
  241. t.textBaseline = "middle";
  242. stage_graph.addChild(t);
  243. }
  244. //上と同様にX軸のラベルの設定
  245. function newLabelX(s, x, y) {
  246. let t = new cj.Text(s, LABEL_FONT, "#000");
  247. t.x = OFFSET_X + x;
  248. t.y = OFFSET_Y + PANEL_HEIGHT + 2 + y;
  249. t.textAlign = "center";
  250. t.textBaseline = "top";
  251. stage_graph.addChild(t);
  252. }
  253.  
  254. //https://createjs.com/docs/easeljs/classes/Graphics.html Graphics Classのドキュメント
  255. let y1 = 0;
  256. // グラフの中の正方形のパネルを色を設定
  257. for (let i = COLORS.length - 1; i >= 0; i--) {
  258. let y2 = PANEL_HEIGHT - PANEL_HEIGHT * getPer(COLORS[i][0], y_min, y_max);
  259. if (y2 > 0 && y1 < PANEL_HEIGHT) {
  260. y1 = Math.max(y1, 0); //rect ( x, y, w , h )
  261. panel_shape.graphics.beginFill(COLORS[i][1]).rect(0, y1, PANEL_WIDTH, Math.min(y2, PANEL_HEIGHT) - y1);
  262. }
  263. y1 = y2;
  264. }
  265. //Y軸ラベルの設定
  266. for (let i = 0; i <= y_max; i += STEP_SIZE) {
  267. if (i >= y_min) {
  268. let y = PANEL_HEIGHT - PANEL_HEIGHT * getPer(i, y_min, y_max);
  269. newLabelY(String(i), y);
  270. border_shape.graphics.beginStroke("#FFF").setStrokeStyle(0.5);
  271. if (i == 2000) border_shape.graphics.beginStroke("#000");
  272. border_shape.graphics.moveTo(0, y).lineTo(PANEL_WIDTH, y);
  273. }
  274. }
  275. border_shape.graphics.beginStroke("#FFF").setStrokeStyle(0.5);
  276.  
  277. let month_step = 6;
  278. for (let i = 3; i >= 1; i--) {
  279. if (x_max - x_min <= YEAR_SEC * i + MARGIN_VAL_X * 2) month_step = i;//初めてすぐの人は短めに
  280. }
  281.  
  282. //X軸ラベルの設定
  283. let first_flag = true;
  284. for (let i = START_YEAR; i < 3000; i++) {
  285. let break_flag = false;
  286. for (let j = 0; j < 12; j += month_step) {
  287. let month = ('00' + (j + 1)).slice(-2);
  288. let unix = Date.parse(String(i) + "-" + month + "-01T00:00:00") / 1000;
  289. if (x_min < unix && unix < x_max) {
  290. let x = PANEL_WIDTH * getPer(unix, x_min, x_max);
  291. if (j == 0 || first_flag) {
  292. newLabelX(MONTH_NAMES[j], x, 0);
  293. newLabelX(String(i), x, 13);
  294. first_flag = false;
  295. } else {
  296. newLabelX(MONTH_NAMES[j], x, 0);
  297. }
  298. border_shape.graphics.mt(x, 0).lt(x, PANEL_HEIGHT)
  299. }
  300. if (unix > x_max) { break_flag = true; break; }
  301. }
  302. if (break_flag) break;
  303. }
  304. border_shape.graphics.s("#888").ss(1.5).rr(0, 0, PANEL_WIDTH, PANEL_HEIGHT, 2);
  305. }
  306.  
  307. function initChart() {
  308. chart_container = new cj.Container();//コンテナでまとめると、同時に動かせたりして良い
  309. stage_graph.addChild(chart_container);
  310. chart_container.shadow = new cj.Shadow("rgba(0,0,0,0.3)", 1, 2, 3);//チャートの下に影
  311.  
  312. line_shape = newShape(chart_container);
  313. highest_shape = newShape(chart_container);
  314. vertex_shapes = new Array();
  315.  
  316. //マウスおいたら丸が大きくなるやつ
  317. function mouseoverVertex(e) {
  318. vertex_shapes[e.target.i].scaleX = vertex_shapes[e.target.i].scaleY = 1.2;
  319. stage_graph.update();
  320. setStatus(rating_history[e.target.i], true);
  321. };
  322. function mouseoutVertex(e) {
  323. vertex_shapes[e.target.i].scaleX = vertex_shapes[e.target.i].scaleY = 1;
  324. stage_graph.update();
  325. };
  326.  
  327. let highest_i = 0;
  328. for (let i = 0; i < n; i++) {
  329. if (rating_history[highest_i].NewRating < rating_history[i].NewRating) {
  330. highest_i = i;
  331. }
  332. }
  333. //historyの数だけ配列にpushしてイベントリスナーも設定
  334. for (let i = 0; i < n; i++) {
  335. vertex_shapes.push(newShape(chart_container));
  336. vertex_shapes[i].graphics.beginStroke("#FFF");
  337. if (i == highest_i) vertex_shapes[i].graphics.s("#000");//Highestなら外枠を黒に
  338. vertex_shapes[i].graphics.setStrokeStyle(0.5).beginFill(getColor(rating_history[i].NewRating)[1]).dc(0, 0, 3.5);
  339.  
  340. vertex_shapes[i].x = OFFSET_X + PANEL_WIDTH * getPer(rating_history[i].EndTime, x_min, x_max);
  341. vertex_shapes[i].y = OFFSET_Y + (PANEL_HEIGHT - PANEL_HEIGHT * getPer(rating_history[i].NewRating, y_min, y_max));
  342.  
  343. vertex_shapes[i].i = i;//なにこれ??
  344.  
  345. let hitArea = new cj.Shape();
  346. hitArea.graphics.f("#000").dc(1.5, 1.5, 6);
  347. vertex_shapes[i].hitArea = hitArea;
  348. vertex_shapes[i].addEventListener("mouseover", mouseoverVertex);
  349. vertex_shapes[i].addEventListener("mouseout", mouseoutVertex);
  350. }
  351.  
  352. {//highest 関連
  353. let dx = 80;
  354. if ((x_min + x_max) / 2 < rating_history[highest_i].EndTime) dx = -80;
  355. let x = vertex_shapes[highest_i].x + dx;
  356. let y = vertex_shapes[highest_i].y - 16;
  357. highest_shape.graphics.s("#FFF").mt(vertex_shapes[highest_i].x, vertex_shapes[highest_i].y).lt(x, y);
  358. highest_shape.graphics.s("#888").f("#FFF").rr(x - HIGHEST_WIDTH / 2, y - HIGHEST_HEIGHT / 2, HIGHEST_WIDTH, HIGHEST_HEIGHT, 2);
  359. highest_shape.i = highest_i;
  360. let highest_text = newText(stage_graph, x, y, "12px Lato");
  361. highest_text.text = "Highest: " + rating_history[highest_i].NewRating;
  362. highest_shape.addEventListener("mouseover", mouseoverVertex);
  363. highest_shape.addEventListener("mouseout", mouseoutVertex);
  364. }
  365.  
  366.  
  367. for (let j = 0; j < 2; j++) {
  368. if (j == 0) line_shape.graphics.s("#AAA").ss(2);
  369. else line_shape.graphics.s("#FFF").ss(0.5);//線の種類を変えてる? よくわからん
  370.  
  371. line_shape.graphics.mt(vertex_shapes[0].x, vertex_shapes[0].y);
  372. for (let i = 0; i < n; i++) {
  373. line_shape.graphics.lt(vertex_shapes[i].x, vertex_shapes[i].y);
  374. }
  375. }
  376. }
  377. function initDevotingChart() {
  378. devoting_chart_container = new cj.Container();//コンテナでまとめると、同時に動かせたりして良い
  379. stage_graph.addChild(devoting_chart_container);//これは devoting_じゃない
  380. devoting_chart_container.shadow = new cj.Shadow("rgba(0,0,0,0.3)", 1, 2, 3);//チャートの下に影
  381.  
  382. devoting_line_shape = newShape(devoting_chart_container);
  383. devoting_highest_shape = newShape(devoting_chart_container);
  384. devoting_vertex_shapes = new Array();
  385.  
  386. //historyの数だけ配列にpushしてイベントリスナーも設定
  387. for (let i = 0; i < devoting_n; i++) {
  388. devoting_vertex_shapes.push(newShape(devoting_chart_container));
  389. devoting_vertex_shapes[i].graphics.beginStroke("#FFF");
  390. if (i == devoting_n - 1) {
  391. devoting_vertex_shapes[i].graphics.s("#000");
  392. devoting_vertex_shapes[i].graphics.setStrokeStyle(1).beginFill(getColor(devoting_rating_history[i].point)[1]).dc(0, 0, 2.5);
  393. }
  394. else {
  395. devoting_vertex_shapes[i].graphics.setStrokeStyle(0.5).beginFill(getColor(devoting_rating_history[i].point)[1]).dc(0, 0, 2);
  396. }
  397. devoting_vertex_shapes[i].x = OFFSET_X + PANEL_WIDTH * getPer(devoting_rating_history[i].epoch_second, x_min, x_max);//devotingじゃないほうに合わせる?
  398. devoting_vertex_shapes[i].y = OFFSET_Y + (PANEL_HEIGHT - PANEL_HEIGHT * getPer(devoting_rating_history[i].point, y_min, y_max));
  399. devoting_vertex_shapes[i].i = i;
  400. let hitArea = new cj.Shape();
  401. hitArea.graphics.f("#000").dc(1.5, 1.5, 6);
  402. devoting_vertex_shapes[i].hitArea = hitArea;
  403. }
  404. //チャートの線関連
  405. for (let index = 0; index < 2; index++) {
  406. if (index == 0) devoting_line_shape.graphics.s("#AAA").ss(2);
  407. else devoting_line_shape.graphics.s("#FFF").ss(0.5);
  408. devoting_line_shape.graphics.mt(devoting_vertex_shapes[0].x, devoting_vertex_shapes[0].y);
  409. for (let i = 0; i < devoting_rating_history.length; i++) {
  410. devoting_line_shape.graphics.lt(devoting_vertex_shapes[i].x, devoting_vertex_shapes[i].y);
  411. }
  412. }
  413. }
  414. function initStatus() {
  415. border_status_shape = newShape(stage_status);
  416. rating_text = newText(stage_status, OFFSET_X + 75, OFFSET_Y + STATUS_HEIGHT / 2, "48px 'Squada One'");
  417. place_text = newText(stage_status, OFFSET_X + 160, OFFSET_Y + STATUS_HEIGHT / 2.7, "16px Lato");
  418. diff_text = newText(stage_status, OFFSET_X + 160, OFFSET_Y + STATUS_HEIGHT / 1.5, "11px Lato");
  419. diff_text.color = '#888';
  420. date_text = newText(stage_status, OFFSET_X + 200, OFFSET_Y + STATUS_HEIGHT / 4, "14px Lato");
  421. contest_name_text = newText(stage_status, OFFSET_X + 200, OFFSET_Y + STATUS_HEIGHT / 1.6, "20px Lato");
  422. date_text.textAlign = contest_name_text.textAlign = "left";
  423. contest_name_text.maxWidth = STATUS_WIDTH - 200 - 10;
  424. {
  425. let hitArea = new cj.Shape(); hitArea.graphics.f("#000").r(0, -12, contest_name_text.maxWidth, 24);
  426. contest_name_text.hitArea = hitArea;
  427. contest_name_text.cursor = "pointer";
  428. contest_name_text.addEventListener("click", function () {
  429. location.href = standings_url;
  430. });
  431. }
  432. particles = new Array();
  433. for (let i = 0; i < PARTICLE_MAX; i++) {
  434. particles.push(newText(stage_status, 0, 0, "64px Lato"));
  435. particles[i].visible = false;
  436. }
  437. setStatus(rating_history[rating_history.length - 1], false);
  438. }
  439.  
  440. function getRatingPer(x) {
  441. let pre = COLORS[COLORS.length - 1][0] + STEP_SIZE;
  442. for (let i = COLORS.length - 1; i >= 0; i--) {
  443. if (x >= COLORS[i][0]) return (x - COLORS[i][0]) / (pre - COLORS[i][0]);
  444. pre = COLORS[i][0];
  445. }
  446. return 0;
  447. }
  448. //@#//@#//@#//@#//@#//@#//@#// 関係ない //@#//@#//@#//@#//@#//@#//@#//@#//@#//@#
  449. function getOrdinal(x) {
  450. let s = ["th", "st", "nd", "rd"], v = x % 100;
  451. return x + (s[(v - 20) % 10] || s[v] || s[0]);
  452. }
  453. function getDiff(x) {
  454. let sign = x == 0 ? 'ツア' : (x < 0 ? '-' : '+');
  455. return sign + Math.abs(x);
  456. }
  457. function setStatus(data, particle_flag) {
  458. let date = new Date(data.EndTime * 1000);
  459. let rating = data.NewRating, old_rating = data.OldRating;
  460. let place = data.Place;
  461. let contest_name = data.ContestName;
  462. let tmp = getColor(rating); let color = tmp[1], alpha = tmp[2];
  463. border_status_shape.graphics.c().s(color).ss(1).rr(OFFSET_X, OFFSET_Y, STATUS_WIDTH, STATUS_HEIGHT, 2);
  464. rating_text.text = rating;
  465. rating_text.color = color;
  466. place_text.text = getOrdinal(place);
  467. diff_text.text = getDiff(rating - old_rating);
  468. date_text.text = date.toLocaleDateString();
  469. contest_name_text.text = contest_name;
  470. if (particle_flag) {
  471. let particle_num = parseInt(Math.pow(getRatingPer(rating), 2) * (PARTICLE_MAX - PARTICLE_MIN) + PARTICLE_MIN);
  472. setParticles(particle_num, color, alpha, rating);
  473. }
  474. standings_url = data.StandingsUrl;
  475. }
  476. //Particle は マウスオーバー時のくるくるのやつw
  477. function setParticle(particle, x, y, color, alpha, star_flag) {
  478. particle.x = x;
  479. particle.y = y;
  480. let ang = Math.random() * Math.PI * 2;
  481. let speed = Math.random() * 4 + 4;
  482. particle.vx = Math.cos(ang) * speed;
  483. particle.vy = Math.sin(ang) * speed;
  484. particle.rot_speed = Math.random() * 20 + 10;
  485. particle.life = LIFE_MAX;
  486. particle.visible = true;
  487. particle.color = color;
  488.  
  489. if (star_flag) {
  490. particle.text = "★";
  491. } else {
  492. particle.text = "@";
  493. }
  494. particle.alpha = alpha;
  495. }
  496. function setParticles(num, color, alpha, rating) {
  497. for (let i = 0; i < PARTICLE_MAX; i++) {
  498. if (i < num) {
  499. setParticle(particles[i], rating_text.x, rating_text.y, color, alpha, rating >= STAR_MIN);
  500. } else {
  501. particles[i].life = 0;
  502. particles[i].visible = false;
  503. }
  504. }
  505. }
  506. function updateParticle(particle) {
  507. if (particle.life <= 0) {
  508. particle.visible = false;
  509. return;
  510. }
  511. particle.x += particle.vx;
  512. particle.vx *= 0.9;
  513. particle.y += particle.vy;
  514. particle.vy *= 0.9;
  515. particle.life--;
  516. particle.scaleX = particle.scaleY = particle.life / LIFE_MAX;
  517. particle.rotation += particle.rot_speed;
  518. }
  519. function updateParticles() {
  520. for (let i = 0; i < PARTICLE_MAX; i++) {
  521. if (particles[i].life > 0) {
  522. updateParticle(particles[i]);
  523. }
  524. }
  525. }
  526. //@#//@#//@#//@#//@#//@#//@#// 関係ない //@#//@#//@#//@#//@#//@#//@#//@#//@#//@#
  527.  
  528. //##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##
  529.  
  530. async function main() {
  531. //get json
  532. let allJson;
  533. try {
  534. const res = await fetch("https://kenkoooo.com/atcoder/atcoder-api/results?user=" + username);
  535. allJson = await res.json()
  536. console.log(allJson.length)
  537. } catch (reaseon) { console.log('try失敗') }
  538. {
  539. let isExist = {};
  540. for (let i = 0; i < allJson.length; i++) {//なぜか負のポイントがあったから追加
  541. if (allJson[i].result === 'AC' && 0 <= allJson[i].point && allJson[i].point <= 3000 && isExist[allJson[i].problem_id] === undefined) {
  542. devoting_rating_history.push({ ...allJson[i] });
  543. isExist[allJson[i].problem_id] = 0;
  544. }
  545. }
  546. }
  547. function compare(a, b) { return a.epoch_second - b.epoch_second; }//比較関数
  548. devoting_rating_history.sort(compare);//時間順にソート
  549.  
  550. for (let i = 0; i < devoting_rating_history.length - 1; i++) {//合計の累積和的な
  551. devoting_rating_history[i + 1].point += devoting_rating_history[i].point;
  552. devoting_rating_history[i].point /= 100;
  553. }
  554. devoting_rating_history[devoting_rating_history.length - 1].point /= 100;
  555. //今までの累積和/100 が高さ
  556.  
  557. let shoujinButtonID = document.getElementById('shoujinButtonID');
  558. shoujinButtonID.addEventListener('click', function () {
  559. devoting_chart_container.visible = !devoting_chart_container.visible;
  560. stage_graph.update();
  561. });
  562.  
  563. init();
  564.  
  565. }
  566.  
  567. main();