-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { getCPTiers } from './cp-tiers' |