Skip to content

Instantly share code, notes, and snippets.

@outloudvi
Last active October 9, 2023 13:49
Show Gist options
  • Save outloudvi/18268d56e11bdf7bfa23adff861303fc to your computer and use it in GitHub Desktop.
Save outloudvi/18268d56e11bdf7bfa23adff861303fc to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "e485ff6d-ae2b-4ae9-b4b3-74d5d6759598",
"metadata": {},
"outputs": [
{
"data": {},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import resultData from './result.json' assert {type: \"json\"}"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "3a41c577-f334-44f1-bf9a-e2a5d01043f0",
"metadata": {},
"outputs": [
{
"data": {},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import * as Plot from \"npm:@observablehq/plot\"\n",
"import { DOMParser, SVGElement } from \"npm:linkedom\""
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "fc164692-33a4-43f4-93d1-ab194ed42e0f",
"metadata": {},
"outputs": [
{
"data": {},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function mergeText(arr) {\n",
" return typeof arr === \"string\" ? arr : arr.map(x => {\n",
" if (typeof x === \"string\") return x\n",
" return x.text\n",
" }).join(\"\")\n",
"}\n",
"\n",
"function findRanking(x, name) {\n",
" const line = x.split(\"\\n\").find(x => x.includes(name))\n",
" if (line === undefined) return 100\n",
" return Number(line.match(/^\\d+/)[0])\n",
"}\n",
"\n",
"var getRanks = (name) => {\n",
" const raw = resultData.messages\n",
" .map(x => [x.date, mergeText(x.text)])\n",
" .filter(x => x[1].includes(\"音游排行\"))\n",
" .map(x => ({date: new Date(x[0]), rank: findRanking(x[1], name)}))\n",
"\n",
" const firstValid = raw.findIndex(x => x.rank !== 100)\n",
" return raw.slice(firstValid)\n",
"}\n",
"\n",
"var getMultipleRanks = (names) => names.map(x => getRanks(x).map(y => ({...y, name: x}))).reduce((a,b) => [...a, ...b])\n",
"\n",
"var ranks = getMultipleRanks([\"ユメステ\", \"アイプラ\", \"プロセカ\", \"バンドリ\"])"
]
},
{
"cell_type": "code",
"execution_count": 66,
"id": "6a98b365-7755-422e-ab10-45aeb23bff46",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<figure style=\"max-width:initial\" class=\"plot-d6a7b5-figure\"><div class=\"plot-d6a7b5-swatches plot-d6a7b5-swatches-wrap\"><style>.plot-d6a7b5-swatches {\n",
" font-family: system-ui, sans-serif;\n",
" font-size: 10px;\n",
" margin-bottom: 0.5em;\n",
"}\n",
".plot-d6a7b5-swatch &gt; svg {\n",
" margin-right: 0.5em;\n",
" overflow: visible;\n",
"}\n",
".plot-d6a7b5-swatches-wrap {\n",
" display: flex;\n",
" align-items: center;\n",
" min-height: 33px;\n",
" flex-wrap: wrap;\n",
"}\n",
".plot-d6a7b5-swatches-wrap .plot-d6a7b5-swatch {\n",
" display: inline-flex;\n",
" align-items: center;\n",
" margin-right: 1em;\n",
"}</style><span class=\"plot-d6a7b5-swatch\"><svg fill=\"#4e79a7\" height=\"15\" width=\"15\"><rect height=\"100%\" width=\"100%\" /></svg>アイプラ</span><span class=\"plot-d6a7b5-swatch\"><svg fill=\"#f28e2c\" height=\"15\" width=\"15\"><rect height=\"100%\" width=\"100%\" /></svg>バンドリ</span><span class=\"plot-d6a7b5-swatch\"><svg fill=\"#e15759\" height=\"15\" width=\"15\"><rect height=\"100%\" width=\"100%\" /></svg>プロセカ</span><span class=\"plot-d6a7b5-swatch\"><svg fill=\"#76b7b2\" height=\"15\" width=\"15\"><rect height=\"100%\" width=\"100%\" /></svg>ユメステ</span></div><svg viewBox=\"0 0 640 400\" height=\"400\" width=\"640\" text-anchor=\"middle\" font-size=\"10\" font-family=\"system-ui, sans-serif\" fill=\"currentColor\" class=\"plot-d6a7b5\"><style>.plot-d6a7b5 {\n",
" display: block;\n",
" background: white;\n",
" height: auto;\n",
" height: intrinsic;\n",
" max-width: 100%;\n",
"}\n",
".plot-d6a7b5 text,\n",
".plot-d6a7b5 tspan {\n",
" white-space: pre;\n",
"}</style><g stroke=\"currentColor\" fill=\"none\" aria-label=\"y-axis tick\"><path d=\"M0,0L-6,0\" transform=\"translate(40,370)\" /><path d=\"M0,0L-6,0\" transform=\"translate(40,335)\" /><path d=\"M0,0L-6,0\" transform=\"translate(40,300)\" /><path d=\"M0,0L-6,0\" transform=\"translate(40,265)\" /><path d=\"M0,0L-6,0\" transform=\"translate(40,230)\" /><path d=\"M0,0L-6,0\" transform=\"translate(40,195)\" /><path d=\"M0,0L-6,0\" transform=\"translate(40,160)\" /><path d=\"M0,0L-6,0\" transform=\"translate(40,125)\" /><path d=\"M0,0L-6,0\" transform=\"translate(40,90)\" /><path d=\"M0,0L-6,0\" transform=\"translate(40,55)\" /><path d=\"M0,0L-6,0\" transform=\"translate(40,20)\" /></g><g transform=\"translate(-9,0)\" font-variant=\"tabular-nums\" text-anchor=\"end\" aria-label=\"y-axis tick label\"><text transform=\"translate(40,370)\" y=\"0.32em\">100</text><text transform=\"translate(40,335)\" y=\"0.32em\">90</text><text transform=\"translate(40,300)\" y=\"0.32em\">80</text><text transform=\"translate(40,265)\" y=\"0.32em\">70</text><text transform=\"translate(40,230)\" y=\"0.32em\">60</text><text transform=\"translate(40,195)\" y=\"0.32em\">50</text><text transform=\"translate(40,160)\" y=\"0.32em\">40</text><text transform=\"translate(40,125)\" y=\"0.32em\">30</text><text transform=\"translate(40,90)\" y=\"0.32em\">20</text><text transform=\"translate(40,55)\" y=\"0.32em\">10</text><text transform=\"translate(40,20)\" y=\"0.32em\">0</text></g><g transform=\"translate(-37,-17)\" text-anchor=\"start\" aria-label=\"y-axis label\"><text transform=\"translate(40,20)\" y=\"0.71em\">↓ rank</text></g><g stroke=\"currentColor\" fill=\"none\" aria-label=\"x-axis tick\"><path d=\"M0,0L0,6\" transform=\"translate(140.43607549356304,370)\" /><path d=\"M0,0L0,6\" transform=\"translate(250.6432593692527,370)\" /><path d=\"M0,0L0,6\" transform=\"translate(364.5240160407987,370)\" /><path d=\"M0,0L0,6\" transform=\"translate(478.4047727123447,370)\" /><path d=\"M0,0L0,6\" transform=\"translate(588.6119565880344,370)\" /></g><g transform=\"translate(0,9)\" font-variant=\"tabular-nums\" aria-label=\"x-axis tick label\"><text transform=\"translate(140.43607549356304,370)\"><tspan y=\"0.71em\" x=\"0\">Jun</tspan><tspan dy=\"1em\" x=\"0\">2023</tspan></text><text transform=\"translate(250.6432593692527,370)\" y=\"0.71em\">Jul</text><text transform=\"translate(364.5240160407987,370)\" y=\"0.71em\">Aug</text><text transform=\"translate(478.4047727123447,370)\" y=\"0.71em\">Sep</text><text transform=\"translate(588.6119565880344,370)\" y=\"0.71em\">Oct</text></g><g stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"1.5\" fill=\"none\" aria-label=\"line\"><path d=\"M344.934,23.5L348.156,23.5L351.829,23.5L355.503,23.5L359.177,23.5L362.85,23.5L366.524,23.5L370.197,23.5L373.871,23.5L377.545,23.5L381.218,23.5L384.892,27L388.565,27L392.239,30.5L395.913,23.5L399.586,23.5L403.26,23.5L406.933,23.5L410.607,23.5L414.281,23.5L417.954,27L421.628,34L425.301,34L428.975,30.5L432.648,30.5L436.322,37.5L439.995,37.5L443.669,41L447.343,41L451.017,41L454.69,41L458.363,48L462.038,48L465.711,41L469.383,44.5L473.057,41L476.731,41L480.404,23.5L484.078,23.5L487.752,27L491.425,27L495.099,41L498.772,41L502.446,44.5L506.119,48L509.793,48L513.466,48L517.14,41L520.813,44.5L524.487,51.5L528.161,55L531.834,58.5L535.508,55L539.181,62L542.855,65.5L546.529,58.5L550.202,51.5L553.876,51.5L557.549,44.5L561.223,48L564.897,48L568.57,44.5L572.244,51.5L575.917,55L579.591,55L583.264,55L586.938,58.5L590.611,58.5L594.285,69L597.959,69L601.632,65.5L605.306,69L608.979,69L612.653,69L616.327,62L620,62\" stroke=\"#76b7b2\" /><path d=\"M40,65.5L40.037,65.5L40.045,65.5L43.25,72.5L46.923,79.5L50.597,76L54.27,65.5L57.944,65.5L61.617,76L65.291,100.5L68.964,93.5L72.638,163.5L76.311,184.5L79.985,198.5L83.659,191.5L87.333,142.5L91.006,170.5L94.68,205.5L98.353,240.5L102.027,230L105.7,244L109.374,146L113.047,142.5L116.721,174L120.395,212.5L124.068,230L127.742,240.5L131.415,198.5L135.089,191.5L138.763,233.5L142.436,216L146.11,209L149.783,268.5L153.457,244L157.13,240.5L160.804,254.5L164.477,251L168.151,261.5L171.824,219.5L175.498,177.5L179.172,167L182.845,135.5L186.519,142.5L190.192,125L193.866,139L197.54,167L201.213,195L204.887,195L208.56,184.5L212.234,139L215.907,146L219.581,160L223.254,100.5L226.198,23.5L226.928,23.5L230.602,23.5L234.275,23.5L237.949,23.5L241.622,30.5L245.296,44.5L248.969,55L252.643,69L256.317,76L259.99,65.5L263.664,55L267.337,69L271.011,83L274.684,107.5L278.358,167L282.033,191.5L285.706,198.5L289.379,202L293.052,174L296.726,223L300.4,223L304.073,216L307.747,181L311.42,188L315.094,170.5L318.768,219.5L322.441,177.5L326.114,156.5L329.788,219.5L333.462,226.5L337.136,111L340.809,142.5L344.483,195L344.934,198.5L348.156,261.5L351.829,265L355.503,209L359.177,226.5L362.85,233.5L366.524,251L370.197,258L373.871,261.5L377.545,289.5L381.218,286L384.892,289.5L388.565,282.5L392.239,268.5L395.913,303.5L399.586,303.5L403.26,272L406.933,272L410.607,275.5L414.281,289.5L417.954,251L421.628,258L425.301,314L428.975,303.5L432.648,293L436.322,272L439.995,272L443.669,296.5L447.343,321L451.017,289.5L454.69,338.5L458.363,289.5L462.038,338.5L465.711,282.5L469.383,314L473.057,282.5L476.731,272L480.404,307L484.078,272L487.752,272L491.425,230L495.099,244L498.772,251L502.446,230L506.119,261.5L509.793,272L513.466,303.5L517.14,258L520.813,247.5L524.487,223L528.161,230L531.834,300L535.508,314L539.181,317.5L542.855,314L546.529,289.5L550.202,251L553.876,247.5L557.549,261.5L561.223,268.5L564.897,268.5L568.57,258L572.244,181L575.917,142.5L579.591,146L583.264,163.5L586.938,212.5L590.611,237L594.285,202L597.959,170.5L601.632,142.5L605.306,163.5L608.979,184.5L612.653,233.5L616.327,216L620,195\" stroke=\"#4e79a7\" /><path d=\"M40,23.5L40.037,23.5L40.045,23.5L43.25,23.5L46.923,23.5L50.597,23.5L54.27,23.5L57.944,23.5L61.617,23.5L65.291,23.5L68.964,23.5L72.638,23.5L76.311,23.5L79.985,23.5L83.659,23.5L87.333,23.5L91.006,23.5L94.68,23.5L98.353,23.5L102.027,23.5L105.7,23.5L109.374,23.5L113.047,23.5L116.721,23.5L120.395,23.5L124.068,23.5L127.742,23.5L131.415,23.5L135.089,27L138.763,27L142.436,23.5L146.11,23.5L149.783,23.5L153.457,23.5L157.13,23.5L160.804,23.5L164.477,23.5L168.151,23.5L171.824,23.5L175.498,23.5L179.172,27L182.845,23.5L186.519,27L190.192,27L193.866,27L197.54,27L201.213,27L204.887,27L208.56,27L212.234,23.5L215.907,23.5L219.581,23.5L223.254,23.5L226.198,30.5L226.928,30.5L230.602,30.5L234.275,30.5L237.949,27L241.622,23.5L245.296,23.5L248.969,23.5L252.643,23.5L256.317,23.5L259.99,23.5L263.664,23.5L267.337,23.5L271.011,23.5L274.684,23.5L278.358,23.5L282.033,27L285.706,23.5L289.379,23.5L293.052,23.5L296.726,23.5L300.4,23.5L304.073,27L307.747,23.5L311.42,23.5L315.094,23.5L318.768,23.5L322.441,23.5L326.114,23.5L329.788,23.5L333.462,23.5L337.136,23.5L340.809,27L344.483,27L344.934,30.5L348.156,30.5L351.829,30.5L355.503,27L359.177,27L362.85,27L366.524,27L370.197,27L373.871,27L377.545,27L381.218,27L384.892,23.5L388.565,23.5L392.239,23.5L395.913,27L399.586,27L403.26,27L406.933,27L410.607,27L414.281,27L417.954,23.5L421.628,23.5L425.301,27L428.975,27L432.648,27L436.322,27L439.995,27L443.669,23.5L447.343,23.5L451.017,27L454.69,30.5L458.363,30.5L462.038,23.5L465.711,23.5L469.383,27L473.057,27L476.731,23.5L480.404,30.5L484.078,27L487.752,23.5L491.425,23.5L495.099,23.5L498.772,23.5L502.446,23.5L506.119,23.5L509.793,23.5L513.466,23.5L517.14,23.5L520.813,23.5L524.487,27L528.161,30.5L531.834,30.5L535.508,27L539.181,23.5L542.855,23.5L546.529,27L550.202,27L553.876,27L557.549,27L561.223,27L564.897,23.5L568.57,23.5L572.244,23.5L575.917,23.5L579.591,23.5L583.264,23.5L586.938,23.5L590.611,23.5L594.285,23.5L597.959,23.5L601.632,23.5L605.306,23.5L608.979,23.5L612.653,23.5L616.327,23.5L620,23.5\" stroke=\"#e15759\" /><path d=\"M40.037,58.5L40.045,58.5L43.25,58.5L46.923,58.5L50.597,58.5L54.27,58.5L57.944,62L61.617,62L65.291,62L68.964,58.5L72.638,65.5L76.311,69L79.985,62L83.659,62L87.333,62L91.006,62L94.68,58.5L98.353,62L102.027,62L105.7,62L109.374,62L113.047,58.5L116.721,58.5L120.395,55L124.068,58.5L127.742,58.5L131.415,58.5L135.089,62L138.763,62L142.436,58.5L146.11,58.5L149.783,55L153.457,51.5L157.13,55L160.804,55L164.477,55L168.151,58.5L171.824,58.5L175.498,58.5L179.172,51.5L182.845,58.5L186.519,69L190.192,62L193.866,69L197.54,69L201.213,65.5L204.887,65.5L208.56,65.5L212.234,62L215.907,55L219.581,55L223.254,62L226.198,65.5L226.928,65.5L230.602,58.5L234.275,62L237.949,58.5L241.622,41L245.296,41L248.969,41L252.643,44.5L256.317,41L259.99,41L263.664,37.5L267.337,41L271.011,44.5L274.684,51.5L278.358,44.5L282.033,51.5L285.706,51.5L289.379,51.5L293.052,51.5L296.726,58.5L300.4,58.5L304.073,58.5L307.747,58.5L311.42,58.5L315.094,55L318.768,55L322.441,62L326.114,58.5L329.788,62L333.462,62L337.136,62L340.809,62L344.483,62L344.934,62L348.156,58.5L351.829,51.5L355.503,51.5L359.177,41L362.85,44.5L366.524,51.5L370.197,55L373.871,58.5L377.545,55L381.218,55L384.892,58.5L388.565,58.5L392.239,62L395.913,65.5L399.586,58.5L403.26,62L406.933,62L410.607,62L414.281,62L417.954,62L421.628,62L425.301,72.5L428.975,62L432.648,62L436.322,65.5L439.995,65.5L443.669,62L447.343,62L451.017,69L454.69,69L458.363,65.5L462.038,65.5L465.711,65.5L469.383,69L473.057,69L476.731,72.5L480.404,72.5L484.078,69L487.752,69L491.425,69L495.099,76L498.772,79.5L502.446,76L506.119,65.5L509.793,65.5L513.466,69L517.14,62L520.813,62L524.487,65.5L528.161,58.5L531.834,48L535.508,44.5L539.181,48L542.855,62L546.529,62L550.202,62L553.876,62L557.549,76L561.223,55L564.897,65.5L568.57,62L572.244,62L575.917,62L579.591,62L583.264,58.5L586.938,65.5L590.611,62L594.285,65.5L597.959,65.5L601.632,62L605.306,65.5L608.979,62L612.653,76L616.327,76L620,76\" stroke=\"#f28e2c\" /></g></svg></figure>"
]
},
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"var document = new DOMParser().parseFromString(\"<!DOCTYPE html><html></html>\")\n",
"\n",
"var plot = Plot.plot({\n",
" color: {legend: true},\n",
" marks: [\n",
" Plot.lineY(ranks, {x: \"date\", y: \"rank\", stroke: \"name\"})\n",
" ],\n",
" document,\n",
" y: {\n",
" domain: [100, 0]\n",
" }\n",
"}).toString()\n",
"\n",
"var display = {\n",
" [Symbol.for(\"Jupyter.display\")]() {\n",
" return {\n",
" \"text/html\": plot\n",
" }\n",
" }\n",
"}\n",
"\n",
"display"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e8f793e6-b9d3-4bdf-86a5-64819385bc5c",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Deno",
"language": "typescript",
"name": "deno"
},
"language_info": {
"file_extension": ".ts",
"mimetype": "text/x.typescript",
"name": "typescript",
"nb_converter": "script",
"pygments_lexer": "typescript",
"version": "5.2.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment