2024-12-05 16:08:50 +00:00
|
|
|
import { PrismaClient } from '@prisma/client'
|
|
|
|
import { writeFileSync } from 'fs'
|
|
|
|
|
|
|
|
const db = new PrismaClient()
|
|
|
|
|
|
|
|
const color_names = {
|
|
|
|
"mono-white": ["W"],
|
|
|
|
"mono-black": ["B"],
|
|
|
|
"mono-blue": ["U"],
|
|
|
|
"mono-green": ["G"],
|
|
|
|
"mono-red": ["R"],
|
|
|
|
"colorless": [],
|
|
|
|
"azorius": ["W","U"],
|
|
|
|
"dimir": ["U","B"],
|
|
|
|
"rakdos": ["B","R"],
|
|
|
|
"gruul": ["R","G"],
|
|
|
|
"selesnya": ["G","W"],
|
|
|
|
"orzhov": ["W","B"],
|
|
|
|
"izzet": ["U","R"],
|
|
|
|
"golgari": ["B","G"],
|
|
|
|
"boros": ["R","W"],
|
|
|
|
"simic": ["G","U"],
|
|
|
|
"esper": ["W","U","B"],
|
|
|
|
"grixis": ["U","B","R"],
|
|
|
|
"jund": ["B","R","G"],
|
|
|
|
"naya": ["R","G","W"],
|
|
|
|
"bant": ["G","W","U"],
|
|
|
|
"abzan": ["W","B","G"],
|
|
|
|
"jeskai": ["U","R","W"],
|
|
|
|
"sultai": ["B","G","U"],
|
|
|
|
"mardu": ["R","W","B"],
|
|
|
|
"temur": ["G","U","R"],
|
|
|
|
"yore-tiller": ["W","U","B","R"],
|
|
|
|
"glint-eye": ["U","B","R","G"],
|
|
|
|
"dune-brood": ["B","R","G","W"],
|
|
|
|
"ink-treader": ["R","G","W","U"],
|
|
|
|
"witch-maw": ["G","W","U","B"],
|
|
|
|
"five-color": ["G","W","U","B","R"],
|
|
|
|
}
|
|
|
|
|
|
|
|
function getColorName(colorArray) {
|
|
|
|
const colorArrayID = colorArray.sort().join(',')
|
|
|
|
for (const colorName of Object.keys(color_names)) {
|
|
|
|
if(colorArrayID === color_names[colorName].sort().join(',')){
|
|
|
|
return(colorName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// I need to create
|
|
|
|
// Lands
|
|
|
|
// lands.json
|
|
|
|
// All jsons lands from colors
|
|
|
|
// Types
|
|
|
|
|
|
|
|
async function createJson() {
|
|
|
|
console.log("Fetching data...")
|
|
|
|
const bsets = await db.bset.findMany({
|
|
|
|
relationLoadStrategy: "join",
|
|
|
|
include: {
|
|
|
|
sets: {
|
|
|
|
include: {
|
2024-12-27 15:41:39 +00:00
|
|
|
cards: {
|
|
|
|
include: {
|
|
|
|
decks: true
|
|
|
|
}
|
|
|
|
}
|
2024-12-05 16:08:50 +00:00
|
|
|
}
|
2024-12-27 15:41:39 +00:00
|
|
|
},
|
|
|
|
decks: true
|
2024-12-05 16:08:50 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-12-27 15:41:39 +00:00
|
|
|
|
|
|
|
let bsets_export = []
|
2024-12-05 16:08:50 +00:00
|
|
|
let all_cards = []
|
|
|
|
bsets.forEach((bset) => {
|
2024-12-27 15:41:39 +00:00
|
|
|
let icons = []
|
|
|
|
let set_codes = []
|
2024-12-05 16:08:50 +00:00
|
|
|
bset.sets.forEach((set) => {
|
2024-12-27 15:41:39 +00:00
|
|
|
icons.push(set.icon_svg_uri)
|
|
|
|
set_codes.push(set.code)
|
|
|
|
let cards_temp = set.cards
|
|
|
|
for(let i = 0; i < cards_temp.length; i++){
|
|
|
|
cards_temp[i].bset_id = bset.id
|
|
|
|
}
|
|
|
|
all_cards = [...all_cards, ...cards_temp]
|
2024-12-05 16:08:50 +00:00
|
|
|
})
|
2024-12-27 15:41:39 +00:00
|
|
|
bsets_export.push({name: bset.name, sanitized_name: bset.sanitized_name, icons, set_codes})
|
2024-12-05 16:08:50 +00:00
|
|
|
})
|
|
|
|
|
2024-12-27 15:41:39 +00:00
|
|
|
writeFileSync(import.meta.dirname + "/json/misc/bsets.json",JSON.stringify(bsets_export), 'utf8')
|
2024-12-05 16:08:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const landsData = {}
|
|
|
|
for (const colorName of Object.keys(color_names)) {
|
|
|
|
landsData[colorName] = []
|
|
|
|
}
|
|
|
|
const type_dict = {"creature": [],"land": [],"instant": [],"sorcery": [], "planeswalker": [], "artifact": [], "enchantment": []}
|
|
|
|
const colorsData = {"mono-white": structuredClone(type_dict),"mono-black": structuredClone(type_dict),"mono-blue": structuredClone(type_dict),"mono-green": structuredClone(type_dict),"mono-red": structuredClone(type_dict),"colorless": structuredClone(type_dict),"multicolor": structuredClone(type_dict)}
|
|
|
|
|
|
|
|
for (const card of all_cards) {
|
2024-12-27 15:41:39 +00:00
|
|
|
let card_object = {
|
|
|
|
"name": card.name,
|
|
|
|
"sanitized_name": card.sanitized_name,
|
|
|
|
"normal_image": card.normal_image,
|
|
|
|
"small_image": card.small_image,
|
|
|
|
"type": card.type,
|
|
|
|
"layout": card.layout,
|
|
|
|
"price": card.price,
|
|
|
|
"cardmarket_uri": card.cardmarket_uri,
|
|
|
|
"nbr_decks": card.decks.length,
|
|
|
|
"total_decks": bsets.find((bset) => bset.id == card.bset_id).decks.length,
|
|
|
|
"colors": card.colors,
|
|
|
|
}
|
|
|
|
|
|
|
|
card_object.percent_decks = (card_object.total_decks != 0) ? parseInt(10000 * (card_object.nbr_decks / card_object.total_decks)) / 100 : 0
|
|
|
|
|
2024-12-05 16:08:50 +00:00
|
|
|
const colorName = getColorName(card.colors)
|
|
|
|
if (card.type == "land") {
|
|
|
|
if (colorName != "") {
|
2024-12-27 15:41:39 +00:00
|
|
|
landsData[colorName].push(card_object)
|
2024-12-05 16:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (card.colors.length <= 1) {
|
2024-12-27 15:41:39 +00:00
|
|
|
colorsData[colorName][card.type].push(card_object)
|
2024-12-05 16:08:50 +00:00
|
|
|
} else {
|
2024-12-27 15:41:39 +00:00
|
|
|
colorsData["multicolor"][card.type].push(card_object)
|
2024-12-05 16:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (const index of Object.keys(colorsData)) {
|
2024-12-27 15:41:39 +00:00
|
|
|
let JSONToWrite = colorsData[index]
|
|
|
|
for (const key of Object.keys(JSONToWrite)){
|
|
|
|
JSONToWrite[key].sort((a,b) => b.percent_decks - a.percent_decks)
|
|
|
|
}
|
|
|
|
writeFileSync(import.meta.dirname + "/json/top/" + index + ".json",JSON.stringify(JSONToWrite), 'utf8')
|
2024-12-05 16:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const landsJsonRoot = [[],[],[],[]]
|
|
|
|
for (const colorName of Object.keys(color_names)){
|
|
|
|
if(color_names[colorName].length <= 3){
|
|
|
|
let index = color_names[colorName].length - 1
|
|
|
|
if(index < 0) { index = 0 }
|
|
|
|
landsJsonRoot[index].push({ "name": colorName, "count": landsData[colorName].length})
|
|
|
|
} else {
|
|
|
|
landsJsonRoot[3].push({ "name": colorName, "count": landsData[colorName].length})
|
|
|
|
}
|
2024-12-27 15:41:39 +00:00
|
|
|
let JSONToWrite = landsData[colorName]
|
|
|
|
JSONToWrite.sort((a,b) => b.percent_decks - a.percent_decks)
|
|
|
|
writeFileSync(import.meta.dirname + "/json/lands/" + colorName + ".json",JSON.stringify(JSONToWrite), 'utf8')
|
2024-12-05 16:08:50 +00:00
|
|
|
}
|
|
|
|
writeFileSync(import.meta.dirname + "/json/lands/lands.json",JSON.stringify(landsJsonRoot), 'utf8')
|
|
|
|
}
|
|
|
|
|
|
|
|
createJson()
|