Код: Выделить всё
import polars as pl
#Auctiondata which is used to create the AuctionDF
auctiondata = {"AuctionId": [2095293259, 2096131235, 2094319272, 2094265820, 2094902378, 2096005275],
"Bid": [9499998, 8499998, 8500000 , 1400832, 1400000, 872],
"Buyout": [9499998, 9499998, 8500000, 1450832, 1500000, 900],
"Quantity": [1, 1, 1, 1, 1, 1],
"Time_Left": ['Short', 'Very long', 'Long', 'Short', 'Long', 'Long'],
"ItemId": [24655, 24648, 3184, 14187,6580,1482],
"ItemRand": [-39, -19, 24, 2032, 1020,None],
"ItemSeed": [886505522, 483524644, 384031104, 1995900544,2119510144,None],
"SuffixFactor": [50, 36, 55680, 1664, 10368,None],
"Faction": ['Horde', 'Alliance', 'Alliance', 'Alliance', 'Horde','Horde'],
"RealmName": ['Mograine', 'Bloodfang', 'Firemaw', 'Firemaw', 'Mograine','Mograine'],
"BuyoutGold": ['45', '77', '24', '39', '120','42'],
"BuyoutSilver": ['40', '44', '12', '33', '12','51'],
"BuyoutCopper": ['12', '11', '21', '52', '32','42'],
"BidGold": ['39', '12', '11', '27', '99','23'],
"BidSilver": ['32', '14', '44', '12', '4','42'],
"BidCopper": ['21', '12', '32', '12', '45','33']
}
#itemsData which is used to create the itemsDF
itemsData = {"ID": [24655,24648,3184,14187,6580],
"Display_lang" : ['Consortium Robe','Astralaan Gloves','Hook Dagger','Raincaller Cuffs','Defender Tunic']}
#suffixData which is used to create the suffixDF
suffixData = {"ID": [19, 39],
"Name_lang": ['of Intellect', 'of the Invoker'],
"Enchantment[0]": [2804, 2804],
"Enchantment[1]": [0, 2824],
"Enchantment[2]": [0, 2822],
"Enchantment[3]": [0, 0],
"Enchantment[4]": [0, 0],
"AllocationPct[0]": [10000, 5259],
"AllocationPct[1]": [None, 6153],
"AllocationPct[2]": [None, 5259],
"AllocationPct[3]": [None, None],
"AllocationPct[4]": [None, None]
}
#propertiesData which is used to create the propertiesDF
propertiesData = {"ID": [24, 1020, 2032],
"Name_lang": ['of Strength', 'of the Whale', 'of Healing'],
"Enchantment[0]": [70, 98, 2312],
"Enchantment[1]": [0, 103, 0],
"Enchantment[2]": [0, 0, 0],
"Enchantment[3]": [0, 0, 0],
"Enchantment[4]": [0, 0, 0]
}
#enchantmentsData which is used to create the enchantmentDF
enchantmentsData = {"ID": [70, 98, 103, 2312, 2804, 2822, 2824],
"Name_lang" : ['+3 Strength','+4 Spirit','+5 Stamina','+7 Spell Power','+$i Intellect', '+$i Critical Strike Rating', '+$i Spell Power']}
#resultData which is used in order to create the resultDF
resultData = {"AuctionId" : [2095293259, 2096131235, 2094319272, 2094265820, 2094902378, 2096005275],
"ItemId" : [24655, 24648, 3184, 14187, 6580, 1482],
"ItemName" : ['Consortium Robe','Astralaan Gloves','Hook Dagger','Raincaller Cuffs','Defender Tunic',''],
"RealmName" : ['Mograine', 'Bloodfang', 'Firemaw', 'Firemaw', 'Mograine','Mograine'],
"Faction" : ['Horde', 'Alliance', 'Alliance', 'Alliance', 'Horde','Horde'],
"EnchantmentName" : ['of the Invoker','of Intellect','of Strength','of Healing','of the Whale',''],
"Stat0" : ['+26 Intellect','+36 Intellect','+3 Strength','+13 Healing Spells and +5 Damage Spells','+4 Spirit',''],
"Stat1" : ['+30 Spell Damage and Healing','','','','+5 Stamina',''],
"Stat2" : ['+26 Spell Critical Strike Rating','','','','',''],
"Stat3" : ['','','','','',''],
"Stat4" : ['','','','','',''],
"BuyoutGold" : ['45', '77', '24', '39', '120','42'],
"BuyoutSilver" : ['40', '44', '12', '33', '12','51'],
"BuyoutCopper" : ['12', '11', '21', '52', '32','42'],
"BidGold" : ['39', '12', '11', '27', '99','23'],
"BidSilver" : ['32', '14', '44', '12', '4','42'],
"BidCopper" : ['21', '12', '32', '12', '45','33']}
#"Main" DF
auctionDF = pl.DataFrame(auctiondata)
#The ID column of the below Dataframe refrence to "ItemId" in auctionDF, it's not ALWAYS the ItemId from AuctionDF is within the itemsDF tho, but 99% of the time it is.
itemsDF = pl.DataFrame(itemsData)
#All negative ItemRands (ItemRands lower than 0) from AuctionDF refrences to the ID column of suffixDF, so I would imagine one of the first things to do is to make the ID column in suffixDF negative for a later join?
suffixDF = pl.DataFrame(suffixData)
#All positive ItemRands (ItemRands larger than 0) from AuctionDF refrences to the ID column of propertiesDF
propertiesDF = pl.DataFrame(propertiesData)
#All the various "Enchantment[X] columns from suffixDF and propertiesDF references to the ID column of the enchantmentDF"
enchantmentsDF = pl.DataFrame(enchantmentsData)
#The reason ItemName is blank for the ItemId 1482 is because it does not exist in the itemsDF
resultDF = pl.DataFrame(resultData)
print(resultDF)
Итак, по сути, у нас есть mainDF «AuctionDF»:
ItemId ссылается на Столбец ID в itemsDF, где нам понадобится Display_lang, чтобы столбец «ItemName» в resultDF
ItemRand ссылался либо на свойстваDF (если ItemRand положительный), либо на суффиксDF (если ItemRand отрицательный)В свойствеDF нам нужно получить столбец «Name_lang», который дает нам столбец «EnchantmentName» в resultDF
Кроме того, нам также нужно использовать столбцы Enchantment[0-4] из свойствDF, эти столбцы содержат идентификатор, который ссылается на enchantmentsDF, где нам нужен столбец Name_lang.
В resultDF вы заметите, что есть 5 столбцов StatX (stat0-4), они содержат значение Name_lang из EnchantmnetsDF
Наконец, если Если ItemRand из AuctionsDF имел отрицательное значение, мы бы перешли к «suffixDF», поскольку отрицательный ItemRand является ссылкой на столбец ID в SuffixDF
В SuffixDF вы также найдете Enchantment[0-4], как и мы. в «propertiesDF», а также ссылки на ID в enchantmentsDF. Однако вы быстро заметите, что Name_lang для этих значений выглядит немного по-другому, например «+$i Intellect», это потому, что нам нужно вычислить значение $i самостоятельно.
В SuffixDF также есть дополнительный 5 столбцов AllocationPct[0-4] все эти значения сначала нужно разделить на 10000, например, затем для каждого AllocationPct[0-4], имеющего значение, мы умножаем его на SuffixFactor
Так что для отрицательных рандов (SuffixDF) Enchantment0 и AllocationPct0 дают Stat0, Enchantment1 и AllocationPct1 дают Stat1 и т. д.
Пример расчета элемента с отрицательным рандом:
ItemId 24655 из AuctionDF имеет ItemRand -39 и SuffixFactor 50
Мы берем -39, ищем в SuffixDF (столбец ID), видим Enchantment0 = 2804
Мы ищем 2804 в столбце ID в EnchantmentsDF, который имеет Name_lang = +$i Интеллект
Теперь мы вычисляем $i, взглянув на AllocationPct0 в SuffixDF, который равен 5259
Затем мы делим 5259 на 10000 (5259/10000 = 0,5259)
Теперь умножаем 0 ,5259 с SuffixFactor (50) и использовать для него пол (0,5259*50 = 26,295 = пол(26,295) = 26)
Теперь у нас есть Stat0 = +26 интеллекта
Возможно, я допустил небольшие ошибки в данных, поскольку вводил все это вручную.
Если есть какие-либо вопросы или вы думаете, что я допустил ошибку, не стесняйтесь спрашивать.
С уважением
Подробнее здесь: https://stackoverflow.com/questions/734 ... ples-inclu