update algo to select k samples

This commit is contained in:
marsteralex 2022-09-11 14:42:49 +02:00
parent 67201a5ce2
commit 8706ddf733
10 changed files with 128 additions and 55 deletions

View File

@ -1,9 +1,10 @@
mode = 'PLAY' mode = 'PLAY'
allData = {} allData = {}
total = 0 total = 0
unseenTotal = 0
probList = [] probList = []
nameList = [] nameList = []
weightedCards = []
indWeighedCards = 0
k = 12 k = 12
extra = 3 extra = 3
artDict = {} artDict = {}
@ -50,13 +51,21 @@ fetchToResponse(firstFetch)
function putIntoMapAndFetch(data) { function putIntoMapAndFetch(data) {
putIntoMap(data.data) putIntoMap(data.data)
if (whichGuesser == 'artist') {
newArtistData = createNewArtistMap()
allData = newArtistData[0]
total = newArtistData[1]
}
for (const [key, value] of Object.entries(allData)) { for (const [key, value] of Object.entries(allData)) {
nameList.push(key) nameList.push(key)
probList.push( probList.push(
value.length + (probList.length === 0 ? 0 : probList[probList.length - 1]) value.length + (probList.length === 0 ? 0 : probList[probList.length - 1])
) )
unseenTotal = total for (let j = 0; j < value.length; j++) {
weightedCards.push(key)
} }
}
shuffleArray(weightedCards)
window.console.log(allData) window.console.log(allData)
window.console.log(total) window.console.log(total)
window.console.log(probList) window.console.log(probList)
@ -74,31 +83,35 @@ function putIntoMapAndFetch(data) {
} else if (whichGuesser === 'artist') { } else if (whichGuesser === 'artist') {
document.getElementById('guess-type').innerText = 'Aesthetic Consultation' document.getElementById('guess-type').innerText = 'Aesthetic Consultation'
} }
window.console.log(whichGuesser)
setUpNewGame() setUpNewGame()
} }
function getKSamples() { function getKSamples() {
let usedCounters = new Set() let usedCounters = new Set()
let currentTotal = unseenTotal
let samples = {} let samples = {}
let i = 0 let i = 0
while (i < k) { let allCards = []
let rand = Math.floor(Math.random() * currentTotal)
let count = 0
for (const [key, value] of Object.entries(allData)) { for (const [key, value] of Object.entries(allData)) {
for (let j = 0; j < value.length; j++) {
allCards.push(key)
}
}
shuffleArray(allCards)
for (let j = 0; j < allCards.length; j++) {
key = allCards[j]
value = allData[key]
if (usedCounters.has(key)) { if (usedCounters.has(key)) {
continue continue
} else if (count >= rand) { } else {
window.console.log(key)
usedCounters.add(key) usedCounters.add(key)
currentTotal -= value.length
unseenTotal--
let randIndex = Math.floor(Math.random() * value.length) let randIndex = Math.floor(Math.random() * value.length)
let arts = allData[key].splice(randIndex, 1) let arts = allData[key].splice(randIndex, 1)
samples[arts[0].artImg] = [key, arts[0].normalImg] samples[arts[0].artImg] = [key, arts[0].normalImg]
i++ i++
if (i >= k) {
break break
} else {
count += value.length
} }
} }
} }
@ -108,15 +121,18 @@ function getKSamples() {
} }
} }
let count = 0 let count = 0
while (count < extra) { let ind = 0
let rand = Math.floor(Math.random() * total) shuffleArray(weightedCards)
for (let j = 0; j < nameList.length; j++) { for (let j = 0; j < weightedCards.length; j++) {
if (j >= rand) { key = weightedCards[j]
if (usedCounters.has(nameList[j])) { value = weightedCards[key]
break if (usedCounters.has(key)) {
} continue
usedCounters.add(nameList[j]) } else {
count += 1 window.console.log(key)
usedCounters.add(key)
count++
if (count >= extra) {
break break
} }
} }
@ -124,12 +140,35 @@ function getKSamples() {
return [samples, usedCounters] return [samples, usedCounters]
} }
function createNewArtistMap() {
let usedCounters = new Set()
let samples = {}
let i = 0
let newTotal = 0
while (i < k + extra) {
let rand = Math.floor(Math.random() * total)
let count = 0
for (const [key, value] of Object.entries(allData)) {
if (usedCounters.has(key)) {
continue
} else if (count >= rand) {
usedCounters.add(key)
samples[key] = value
newTotal += value.length
i++
break
} else {
count += value.length
}
}
}
return [samples, newTotal]
}
function fetchToResponse(fetch) { function fetchToResponse(fetch) {
return fetch return fetch
.then((response) => response.json()) .then((response) => response.json())
.then((json) => { .then((json) => putIntoMapAndFetch(json))
putIntoMapAndFetch(json)
})
} }
function determineIfSkip(card) { function determineIfSkip(card) {
@ -157,7 +196,8 @@ function determineIfSkip(card) {
card.set_type === 'token' || card.set_type === 'token' ||
card.set_type === 'vanguard' || card.set_type === 'vanguard' ||
card.set_type === 'planechase' || card.set_type === 'planechase' ||
card.set_type === 'archenemy' card.set_type === 'archenemy' ||
card.set_type === 'memorabilia'
) { ) {
return true return true
} }
@ -241,7 +281,9 @@ function setUpNewGame() {
setWordsLeft() setWordsLeft()
// select new cards // select new cards
window.console.log(k)
let sampledData = getKSamples() let sampledData = getKSamples()
window.console.log(k)
artDict = sampledData[0] artDict = sampledData[0]
let randomImages = Object.keys(artDict) let randomImages = Object.keys(artDict)
shuffleArray(randomImages) shuffleArray(randomImages)
@ -278,17 +320,32 @@ function checkAnswers() {
let incorrect = true let incorrect = true
if (currCard.dataset.name) { if (currCard.dataset.name) {
// remove image text // remove image text
let guess = removeSymbol( let guessWithSymbol = document.getElementById(
document.getElementById(currCard.dataset.name).innerText currCard.dataset.name
) ).innerHTML
let ans = removeSymbol(artDict[currCard.dataset.url][0]) let ansWithSymbol = artDict[currCard.dataset.url][0]
window.console.log(ans, guess) let guess = removeSymbol(guessWithSymbol)
let ans = removeSymbol(ansWithSymbol)
incorrect = ans !== guess incorrect = ans !== guess
// decide if their guess was correct // decide if their guess was correct
// window.console.log(ans, guess, incorrect)
if (incorrect) {
window.console.log(
document.getElementById(currCard.dataset.name),
guess,
ans
)
document.getElementById(currCard.dataset.name).innerHTML =
'<strike>' + guessWithSymbol + '</strike><br/>' + ansWithSymbol
} }
if (incorrect) currCard.classList.add('incorrect') }
if (incorrect) {
currCard.classList.add('incorrect')
// tally some kind of score // tally some kind of score
if (incorrect) score-- score--
// show the correct answer
}
// show the correct card // show the correct card
currCard.style.backgroundImage = currCard.style.backgroundImage =
"url('" + artDict[currCard.dataset.url][1] + "')" "url('" + artDict[currCard.dataset.url][1] + "')"

View File

@ -26,20 +26,31 @@ def generate_initial_query(category):
'.*player%28%5C.%7C+or+planeswalker%29%7C.*opponent%28%5C.%7C+or+planeswalker%29%29%2F%29' \ '.*player%28%5C.%7C+or+planeswalker%29%7C.*opponent%28%5C.%7C+or+planeswalker%29%29%2F%29' \
'+%28type%3Ainstant+or+type%3Asorcery%29+not%3Aadventure+not%3Adfc' '+%28type%3Ainstant+or+type%3Asorcery%29+not%3Aadventure+not%3Adfc'
elif category == 'commander': elif category == 'commander':
string_query += 'is%3Acommander+%28not%3Adigital+-banned%3Acommander+or+is%3Adigital+legal%3Ahistoricbrawl+or+legal%3Acommander+or+legal%3Abrawl%29' string_query += 'is%3Acommander+%28not%3Adigital+-banned%3Acommander+or+is%3Adigital+legal%3Ahistoricbrawl' \
'+or+legal%3Acommander+or+legal%3Abrawl%29'
# elif category == 'zombie': # elif category == 'zombie':
# string_query += '-type%3Alegendary+type%3Azombie+-type%3Atoken' # string_query += '-type%3Alegendary+type%3Azombie+-type%3Atoken'
# elif category == 'artifact': # elif category == 'artifact':
# string_query += 't%3Aartifact&order=released&dir=asc&unique=prints&page=' # string_query += 't%3Aartifact&order=released&dir=asc&unique=prints&page='
elif category == 'artist': elif category == 'artist':
string_query += '%28a%3A"Carl+Critchlow"+or+a%3A"Chippy"+or+a%3A"Christopher+Moeller"+or+a%3A"christopher+rush"+or+a%3A"Daarken"+or+a%3A"Donato+Giancola"+or+a%3A"Douglas+Shuler"+or+a%3A"Eric+Deschamps"+or+a%3A"greg+staples"+or+a%3A"heather+Hudson"+or+a%3A"igor+kieryluk"+or+a%3A"Jeff+Miracola"+or+a%3A"johannes+voss"+or+a%3A"Julie+Baroh"+or+a%3A"kev+walker"+or+a%3A"Lius+Lasahido"+or+a%3A"Livia+Prima"+or+a%3A"Magali+Villeneuve"+or+a%3A"Mark+Poole"+or+a%3A"Mark+Tedin"+or+a%3A"Mark+Zug"+or+a%3A"Nils+Hamm"+or+a%3A"pete+venters"+or+a%3A"randy+gallegos"+or+a%3A"rebecca+guay"+or+a%3A"rk+post"+or+a%3A"rob+alexander"+or+a%3A"ron+spencer"+or+a%3A"Scott+M+Fischer"+or+a%3A"seb+mckinnon"+or+a%3A"steve+argyle"+or+a%3A"Svetlin+Velinov"+or+a%3A"Veronique+Meignaud"+or+a%3A"Wylie+Beckert"+or+a%3A“Amy+Weber”+or+a%3A“Dan+Frazier”+or+a%3A“David+Martin”+or+a%3A“DiTerlizzi”+or+a%3A“Ernanda+Souza”+or+a%3A“Franz+Vohwinkel”+or+a%3A“Phil+Foglio”+or+a%3A“Rachta+Lin”+or+a%3A“Thomas+M.+Baxa”+or+a%3A“Victor+Adame+Minguez”+or+a%3A“Volkan+Baǵa”%29+not%3Adfc' string_query += '%28a%3A"Carl+Critchlow"+or+a%3A"Chippy"+or+a%3A"Christopher+Moeller"+or+a%3A"christopher+rush"' \
'+or+a%3A"Daarken"+or+a%3A"Donato+Giancola"+or+a%3A"Douglas+Shuler"+or+a%3A"Eric+Deschamps"' \
'+or+a%3A"greg+staples"+or+a%3A"heather+Hudson"+or+a%3A"igor+kieryluk"+or+a%3A"Jeff+Miracola"+or+' \
'a%3A"johannes+voss"+or+a%3A"Julie+Baroh"+or+a%3A"kev+walker"+or+a%3A"Lius+Lasahido"+or+a%3A"Livia+Prima"' \
'+or+a%3A"Magali+Villeneuve"+or+a%3A"Mark+Poole"+or+a%3A"Mark+Tedin"+or+a%3A"Mark+Zug"+or+a%3A"Nils+Hamm"' \
'+or+a%3A"pete+venters"+or+a%3A"randy+gallegos"+or+a%3A"rebecca+guay"+or+a%3A"rk+post"+or+a%3A"rob+alexander"' \
'+or+a%3A"ron+spencer"+or+a%3A"Scott+M+Fischer"+or+a%3A"seb+mckinnon"+or+a%3A"steve+argyle"+or+' \
'a%3A"Svetlin+Velinov"+or+a%3A"Veronique+Meignaud"+or+a%3A"Wylie+Beckert"+or+a%3A“Amy+Weber”+or+' \
'a%3A“Dan+Frazier”+or+a%3A“David+Martin”+or+a%3A“DiTerlizzi”+or+a%3A“Ernanda+Souza”+or+a%3A“Franz+Vohwinkel”' \
'+or+a%3A“Phil+Foglio”+or+a%3A“Thomas+M.+Baxa”+or+a%3A“Victor+Adame+Minguez”+or' \
'+a%3A“Volkan+Baǵa”%29+artists%3D1'
# add category string query here # add category string query here
if category != 'artist': if category != 'artist':
string_query += '+-%28set%3Asld+%28%28cn>%3D231+cn<%3D233%29+or+%28cn>%3D321+cn<%3D324%29+or+%28cn>%3D185+cn' \ string_query += '+-%28set%3Asld+%28cn>%3D231+cn<%3D233+or+cn>%3D436+cn<%3D440+or+cn>%3D321+cn<%3D324+or' \
'<%3D189%29+or+%28cn>%3D138+cn<%3D142%29+or+%28cn>%3D364+cn<%3D368%29+or+cn%3A669+or+cn%3A670%29+-set%3Acmb2+-set%3Acmb1+-set%3Aplist' \ '+cn>%3D185+cn<%3D189+or+cn>%3D138+cn<%3D142+or+cn>%3D364+cn<%3D368+or+cn%3A669+or+cn%3A670%29%29+' \
'%29' '-%28set%3Asta+cn>%3D64+cn<%3D126%29+-set%3Acmb2+-set%3Acmb1+-set%3Aplist'
string_query += '+-name%3A%2F%5EA-%2F+not%3Asplit+-st%3Amemorabilia' \ string_query += '+-name%3A%2F%5EA-%2F+not%3Asplit+-st%3Amemorabilia' \
'+language%3Aenglish&order=released&dir=asc&unique=prints&page=' '&order=released&dir=asc&unique=prints&page='
print(string_query) print(string_query)
return string_query return string_query
@ -54,6 +65,11 @@ def generate_initial_special_query(category):
print(string_query) print(string_query)
return string_query return string_query
# def generate_initial_artist_query():
# string_query = 'https://api.scryfall.com/cards/search?q=artists%3D1+-st%3Afunny+not%3Adigital+-st%3Atoken+-t%3Avanguard+-st%3Amemorabilia+-t%3Ascheme+-t%3Aplane+-t%3APhenomenon&unique=art&as=grid&order=artist&page='
# print(string_query)
# return string_query
def fetch_and_write_all(category, query): def fetch_and_write_all(category, query):
count = 1 count = 1

View File

@ -263,7 +263,7 @@
id="artist" id="artist"
name="whichguesser" name="whichguesser"
value="artist" value="artist"
onchange="updateSettingDefault(true, true, true, 'only include cards')" onchange="updateSettingDefault(false, true, true, 'only include cards')"
/> />
<label class="radio-label" for="artist"> <label class="radio-label" for="artist">
<img <img

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"059bba56-5feb-42e4-8c2e-e2f1e6ba11f9": "Dan Frazier", "bfdeaf09-f915-4058-8e8b-bcac3bc43c33": "Mark Poole", "a9ddb513-51c7-455c-ab8f-5b90aae9f75b": "Douglas Shuler", "bba720a4-46b3-493b-8653-8980e6a8c252": "Julie Baroh", "9ee9a9cc-c09e-486f-918b-69f80cbc4188": "Mark Tedin", "c1160787-e72e-4f89-b361-c6864f7a4e3a": "Amy Weber", "35906871-6c78-4ab2-9ed1-e6792c8efb74": "Rob Alexander", "c96773f0-346c-4f7d-9271-2d98cc5d86e1": "Christopher Rush", "dab52c11-0564-4207-a4a1-c1735c946a65": "Ron Spencer", "d54c4a1a-c0c5-4834-84db-125d341f3ad8": "Pete Venters", "3bfc0fd7-f6ce-4c3f-a755-aaafc84ac704": "Phil Foglio", "4441fe52-9e41-40c1-9b74-8510426279ab": "Heather Hudson", "a5048cc7-438a-4378-98e4-da99b78e1db0": "Randy Gallegos", "f8f662fa-d597-46a3-afb2-91d6e13243e2": "Rebecca Guay", "9b465bde-3656-4495-ace4-af4ce29999ed": "Jeff Miracola", "f366a0ee-a0cd-466d-ba6a-90058c7a31a6": "Kev Walker", "a36f01a0-e51a-48b2-a556-b9b3bc73f969": "Chippy", "23b0cf43-3e43-44c6-8329-96446eca5bce": "Scott M. Fischer", "90332db2-aecb-4d79-917b-95cbeb8d0cb6": "Donato Giancola", "ed44dce4-30cf-4c2c-b2e1-a19ba2295690": "DiTerlizzi", "48e2b98c-5467-4671-bd42-4c3746115117": "Mark Zug", "81ae0f3f-1d88-4125-9aeb-b15b4c734c82": "rk post", "17948f16-611a-44b8-8d10-9895a0bdfff1": "Carl Critchlow", "3a243c17-3baa-4b53-9599-645311cd7d3d": "Franz Vohwinkel", "ff346569-557d-4043-ae44-97c2c7cabd7d": "Thomas M. Baxa", "93d65564-bf00-447b-8406-e2031f03b6b1": "Greg Staples", "21e10012-06ae-44f2-b38d-3824dd2e73d4": "Christopher Moeller", "996ad764-4ae0-4952-8bb5-5a75c9d68275": "David Martin", "37970e22-9cee-44c1-af44-5ee27cf26b76": "Eric Deschamps", "93bec3c0-0260-4d31-8064-5d01efb4153f": "Volkan Ba\u01f5a", "c540d1fc-1500-457f-93cf-d6069ee66546": "Nils Hamm", "e607a0d4-fc12-4c01-9e3f-501f5269b9cb": "Daarken", "a44ddda4-5331-4f83-aac9-3e00ed36bd7b": "Steve Argyle", "41084244-a313-4d14-8123-db05855f9cfe": "V\u00e9ronique Meignaud", "9c3e9d17-509f-485c-9360-46d897ce716b": "Igor Kieryluk", "ffd063ae-c097-4f26-b2e6-b1e2137708bc": "Svetlin Velinov", "3593dd7e-c547-4a32-81cd-7da725f60118": "Johannes Voss", "ad4caca0-8d89-44ce-a1a6-d5ca905bd6fb": "Seb McKinnon", "9e6a55ae-be4d-4c23-a2a5-135737ffd879": "Magali Villeneuve", "0a0e9093-ce44-4a69-93a7-09b63e7c330d": "Lius Lasahido", "bd8f7368-5b10-4554-b6b8-d052c6aca89f": "Victor Adame Minguez", "0f41e561-bc26-4d85-aab6-66c384e01b74": "Livia Prima", "074daf3d-0849-4c4a-b5a5-c276384e81e5": "Wylie Beckert", "e87a8b19-f97f-4df0-9dda-1310ab0257bb": "Ernanda Souza", "22639b52-9021-4c88-b53a-35d3fc9ebcdd": "Rachta Lin"} {"059bba56-5feb-42e4-8c2e-e2f1e6ba11f9": "Dan Frazier", "bfdeaf09-f915-4058-8e8b-bcac3bc43c33": "Mark Poole", "a9ddb513-51c7-455c-ab8f-5b90aae9f75b": "Douglas Shuler", "bba720a4-46b3-493b-8653-8980e6a8c252": "Julie Baroh", "9ee9a9cc-c09e-486f-918b-69f80cbc4188": "Mark Tedin", "c1160787-e72e-4f89-b361-c6864f7a4e3a": "Amy Weber", "35906871-6c78-4ab2-9ed1-e6792c8efb74": "Rob Alexander", "c96773f0-346c-4f7d-9271-2d98cc5d86e1": "Christopher Rush", "dab52c11-0564-4207-a4a1-c1735c946a65": "Ron Spencer", "d54c4a1a-c0c5-4834-84db-125d341f3ad8": "Pete Venters", "3bfc0fd7-f6ce-4c3f-a755-aaafc84ac704": "Phil Foglio", "4441fe52-9e41-40c1-9b74-8510426279ab": "Heather Hudson", "a5048cc7-438a-4378-98e4-da99b78e1db0": "Randy Gallegos", "f8f662fa-d597-46a3-afb2-91d6e13243e2": "Rebecca Guay", "9b465bde-3656-4495-ace4-af4ce29999ed": "Jeff Miracola", "f366a0ee-a0cd-466d-ba6a-90058c7a31a6": "Kev Walker", "a36f01a0-e51a-48b2-a556-b9b3bc73f969": "Chippy", "23b0cf43-3e43-44c6-8329-96446eca5bce": "Scott M. Fischer", "90332db2-aecb-4d79-917b-95cbeb8d0cb6": "Donato Giancola", "ed44dce4-30cf-4c2c-b2e1-a19ba2295690": "DiTerlizzi", "48e2b98c-5467-4671-bd42-4c3746115117": "Mark Zug", "81ae0f3f-1d88-4125-9aeb-b15b4c734c82": "rk post", "17948f16-611a-44b8-8d10-9895a0bdfff1": "Carl Critchlow", "3a243c17-3baa-4b53-9599-645311cd7d3d": "Franz Vohwinkel", "ff346569-557d-4043-ae44-97c2c7cabd7d": "Thomas M. Baxa", "93d65564-bf00-447b-8406-e2031f03b6b1": "Greg Staples", "21e10012-06ae-44f2-b38d-3824dd2e73d4": "Christopher Moeller", "996ad764-4ae0-4952-8bb5-5a75c9d68275": "David Martin", "37970e22-9cee-44c1-af44-5ee27cf26b76": "Eric Deschamps", "93bec3c0-0260-4d31-8064-5d01efb4153f": "Volkan Ba\u01f5a", "c540d1fc-1500-457f-93cf-d6069ee66546": "Nils Hamm", "e607a0d4-fc12-4c01-9e3f-501f5269b9cb": "Daarken", "a44ddda4-5331-4f83-aac9-3e00ed36bd7b": "Steve Argyle", "41084244-a313-4d14-8123-db05855f9cfe": "V\u00e9ronique Meignaud", "9c3e9d17-509f-485c-9360-46d897ce716b": "Igor Kieryluk", "ffd063ae-c097-4f26-b2e6-b1e2137708bc": "Svetlin Velinov", "3593dd7e-c547-4a32-81cd-7da725f60118": "Johannes Voss", "ad4caca0-8d89-44ce-a1a6-d5ca905bd6fb": "Seb McKinnon", "9e6a55ae-be4d-4c23-a2a5-135737ffd879": "Magali Villeneuve", "0a0e9093-ce44-4a69-93a7-09b63e7c330d": "Lius Lasahido", "bd8f7368-5b10-4554-b6b8-d052c6aca89f": "Victor Adame Minguez", "0f41e561-bc26-4d85-aab6-66c384e01b74": "Livia Prima", "074daf3d-0849-4c4a-b5a5-c276384e81e5": "Wylie Beckert", "e87a8b19-f97f-4df0-9dda-1310ab0257bb": "Ernanda Souza"}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long