This commit is contained in:
Azalea 2024-02-16 01:46:11 -05:00
parent 6afcb364d1
commit 643e0e0c1f
5 changed files with 271 additions and 273 deletions

View File

@ -1,18 +1,18 @@
import {aqua_host, data_host} from "./config"; import { aqua_host, data_host } from './config'
import type {TrendEntry} from "./generalTypes"; import type { TrendEntry } from './generalTypes'
import type {MaimaiUserSummaryEntry} from "./maimaiTypes"; import type { MaimaiUserSummaryEntry } from './maimaiTypes'
const multTable = [ const multTable = [
[100.5, 22.4, "SSSp"], [ 100.5, 22.4, 'SSSp' ],
[100, 21.6, "SSS"], [ 100, 21.6, 'SSS' ],
[99.5, 21.1, "SSp"], [ 99.5, 21.1, 'SSp' ],
[99, 20.8, "SS"], [ 99, 20.8, 'SS' ],
[98, 20.3, "Sp"], [ 98, 20.3, 'Sp' ],
[97, 20, "S"], [ 97, 20, 'S' ],
[94, 16.8, "AAA"], [ 94, 16.8, 'AAA' ],
[90, 15.2, "AA"], [ 90, 15.2, 'AA' ],
[80, 13.6, "A"] [ 80, 13.6, 'A' ]
] ]
@ -27,7 +27,7 @@ export function getMult(achievement: number) {
export async function getMaimai(endpoint: string, params: any) { export async function getMaimai(endpoint: string, params: any) {
return await fetch(`${aqua_host}/Maimai2Servlet/${endpoint}`, { return await fetch(`${aqua_host}/Maimai2Servlet/${endpoint}`, {
method: "POST", method: 'POST',
body: JSON.stringify(params) body: JSON.stringify(params)
}).then(res => res.json()) }).then(res => res.json())
} }
@ -37,15 +37,15 @@ export async function getMaimaiAllMusic(): Promise<{ [key: string]: any }> {
} }
export async function getMaimaiApi(endpoint: string, params: any) { export async function getMaimaiApi(endpoint: string, params: any) {
let url = new URL(`${aqua_host}/api/game/maimai2new/${endpoint}`) const url = new URL(`${aqua_host}/api/game/maimai2new/${endpoint}`)
Object.keys(params).forEach(key => url.searchParams.append(key, params[key])) Object.keys(params).forEach(key => url.searchParams.append(key, params[key]))
return await fetch(url).then(res => res.json()) return await fetch(url).then(res => res.json())
} }
export async function getMaimaiTrend(userId: number): Promise<TrendEntry[]> { export async function getMaimaiTrend(userId: number): Promise<TrendEntry[]> {
return await getMaimaiApi("trend", {userId}) return await getMaimaiApi('trend', { userId })
} }
export async function getMaimaiUser(userId: number): Promise<MaimaiUserSummaryEntry> { export async function getMaimaiUser(userId: number): Promise<MaimaiUserSummaryEntry> {
return await getMaimaiApi("user-summary", {userId}) return await getMaimaiApi('user-summary', { userId })
} }

View File

@ -7,13 +7,12 @@ import {
LinearScale, LinearScale,
PointElement, PointElement,
CategoryScale, TimeScale, type ChartOptions, type LineOptions, CategoryScale, TimeScale, type ChartOptions, type LineOptions,
} from 'chart.js'; } from 'chart.js'
import moment from "moment/moment"; import moment from 'moment/moment'
// @ts-ignore // @ts-expect-error Cal-heatmap does not have proper types
import CalHeatmap from "cal-heatmap"; import CalHeatmap from 'cal-heatmap'
// @ts-ignore // @ts-expect-error Cal-heatmap does not have proper types
import CalTooltip from 'cal-heatmap/plugins/Tooltip'; import CalTooltip from 'cal-heatmap/plugins/Tooltip'
import type {Line} from "svelte-chartjs";
export function title(t: string) { export function title(t: string) {
document.title = `AquaNet - ${t}` document.title = `AquaNet - ${t}`
@ -29,11 +28,11 @@ export function registerChart() {
PointElement, PointElement,
CategoryScale, CategoryScale,
TimeScale TimeScale
); )
} }
export function renderCal(el: HTMLElement, d: {date: any, value: any}[]) { export function renderCal(el: HTMLElement, d: {date: any, value: any}[]) {
const cal = new CalHeatmap(); const cal = new CalHeatmap()
return cal.paint({ return cal.paint({
itemSelector: el, itemSelector: el,
domain: { domain: {
@ -54,15 +53,15 @@ export function renderCal(el: HTMLElement, d: {date: any, value: any}[]) {
}, },
}, },
date: { start: moment().subtract(1, 'year').add(1, 'month').toDate() }, date: { start: moment().subtract(1, 'year').add(1, 'month').toDate() },
theme: "dark", theme: 'dark',
}, [ }, [
[ CalTooltip, { text: (_: Date, v: number, d: any) => [ CalTooltip, { text: (_: Date, v: number, d: any) =>
`${v ?? "No"} songs played on ${d.format('MMMM D, YYYY')}`}] `${v ?? 'No'} songs played on ${d.format('MMMM D, YYYY')}` }]
]); ])
} }
export const CHARTJS_OPT: ChartOptions<"line"> = { export const CHARTJS_OPT: ChartOptions<'line'> = {
responsive: true, responsive: true,
maintainAspectRatio: false, maintainAspectRatio: false,
// TODO: Show point on hover // TODO: Show point on hover
@ -85,7 +84,7 @@ export const CHARTJS_OPT: ChartOptions<"line"> = {
display: false display: false
}, },
tooltip: { tooltip: {
mode: "index", mode: 'index',
intersect: false intersect: false
} }
}, },
@ -97,5 +96,5 @@ export const CHARTJS_OPT: ChartOptions<"line"> = {
* @param obj HashMap<string, boolean> * @param obj HashMap<string, boolean>
*/ */
export function clazz(obj: { [key: string]: boolean }) { export function clazz(obj: { [key: string]: boolean }) {
return Object.keys(obj).filter(k => obj[k]).join(" ") return Object.keys(obj).filter(k => obj[k]).join(' ')
} }

View File

@ -1,7 +1,6 @@
import './app.sass' import './app.sass'
import App from './App.svelte' import App from './App.svelte'
// @ts-ignore const app = new App({ target: document.getElementById('app')! })
const app = new App({target: document.getElementById('app')})
export default app export default app