Skip to content

Commit

Permalink
A simple cp tier tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunoru committed Apr 8, 2024
1 parent c10f6b7 commit ac78908
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 0 deletions.
5 changes: 5 additions & 0 deletions frontend/src/layouts/MainLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ const essentialLinks: EssentialLinkProps[] = [
// icon: 'integration_instructions',
// to: '/scripts',
// },
{
title: 'Miscellaneous',
icon: 'miscellaneous_services',
to: '/misc',
},
{
title: 'Settings',
icon: 'settings',
Expand Down
63 changes: 63 additions & 0 deletions frontend/src/pages/MiscPage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<template>
<page-base class="row items-top justify-evenly" title="Miscellaneous">
<q-card class="col">
<q-splitter v-model="splitterModel">
<template v-slot:before>
<q-tabs v-model="tab" vertical class="text-teal">
<q-tab name="cp-tiers" icon="list" label="CP Tiers" />
</q-tabs>
</template>

<template v-slot:after>
<q-tab-panels v-model="tab" animated>
<q-tab-panel name="cp-tiers">
<div class="q-pa-md">
<q-input v-model="cpTiers.input" filled autogrow label="CSV data (format: cp,paste)" />
<q-btn
class="q-mt-md"
color="primary"
label="Import All"
type="submit"
@click="cpTiers.action"
:loading="cpTiers.loading"
/>
<q-input class="q-mt-md" v-model="cpTiers.output" filled autogrow label="Output" readonly />
</div>
</q-tab-panel>
</q-tab-panels>
</template>
</q-splitter>
</q-card>
</page-base>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { getCPTiers } from 'vgc-tools'
import PageBase from '../layouts/PageBase.vue'
const splitterModel = ref(20)
const tab = ref('')
const cpTiers = ref({
input: '',
loading: false,
action: async () => {
cpTiers.value.loading = true
const input = cpTiers.value.input.split('\n').map((line) => {
const [cp, pasteUrl] = line.split(',')
return { cp: Number(cp), pasteUrl }
})
try {
const output = await getCPTiers(input)
cpTiers.value.output = output.map((tier) => `${tier.cp}: ${tier.pokes.join(', ')}`).join('\n')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
cpTiers.value.output = err.toString()
}
cpTiers.value.loading = false
},
output: '',
})
</script>
4 changes: 4 additions & 0 deletions frontend/src/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const routes: RouteRecordRaw[] = [
// path: 'scripts',
// component: () => import('pages/ScriptsPage.vue'),
// },
{
path: 'misc',
component: () => import('pages/MiscPage.vue'),
},
{
path: 'settings',
component: () => import('pages/SettingsPage.vue'),
Expand Down
1 change: 1 addition & 0 deletions vgc-tools/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export type * from '@pkmn/types'
export * from './models/index.js'
export * from './analytics/index.js'
export * from './import-replay.js'
export * from './misc/index.js'
29 changes: 29 additions & 0 deletions vgc-tools/src/misc/cp-tiers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const getCPTiers = async (data: Array<{ cp: number; pasteUrl: string }>) => {
const pokes = {} as { [poke: string]: number }
for (const { cp, pasteUrl } of data) {
console.log(`${cp} from ${pasteUrl}`)
const response = await fetch(pasteUrl.trim() + '/json')
const data = (await response.json()) as { paste: string }
for (const poke of data.paste.split('\r\n\r\n')) {
const [firstLine] = poke.split('\r\n')
const pokeName = firstLine.split('@')[0].trim()
if (pokeName) {
if (!(pokeName in pokes)) {
pokes[pokeName] = 0
}
pokes[pokeName] += cp
}
}
}
const tiers = {} as { [tier: number]: string[] }
for (const poke in pokes) {
const cp = pokes[poke]
if (!(cp in tiers)) {
tiers[cp] = []
}
tiers[cp].push(poke)
}
return Object.entries(tiers)
.map(([cp, pokes]) => ({ cp: +cp, pokes }))
.sort((a, b) => b.cp - a.cp)
}
1 change: 1 addition & 0 deletions vgc-tools/src/misc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { getCPTiers } from './cp-tiers'

0 comments on commit ac78908

Please sign in to comment.