Add debug and log messages
This commit is contained in:
parent
17c87d3b3e
commit
c7fcad5929
1 changed files with 83 additions and 70 deletions
|
@ -1,101 +1,114 @@
|
||||||
const {default: axios} = require("axios");
|
const { default: axios } = require("axios");
|
||||||
const {getParsed, getProfit, splitNumber, getRawCraft} = require("./src/helperFunctions");
|
const { getParsed, getProfit, splitNumber, getRawCraft } = require("./src/helperFunctions");
|
||||||
const {parentPort, workerData} = require("worker_threads");
|
const { parentPort, workerData } = require("worker_threads");
|
||||||
const config = require("./config.json")
|
const config = require("./config.json");
|
||||||
let minProfit = config.data.minSnipeProfit
|
let minProfit = config.data.minSnipeProfit;
|
||||||
let minPercentProfit = config.data.minSnipePP
|
let minPercentProfit = config.data.minSnipePP;
|
||||||
let ignoredAuctions = []
|
let ignoredAuctions = [];
|
||||||
const {Item} = require("./src/Item")
|
const { Item } = require("./src/Item");
|
||||||
const threadsToUse = require("./config.json").data["threadsToUse/speed"]
|
const threadsToUse = require("./config.json").data["threadsToUse/speed"];
|
||||||
const promises = []
|
const promises = [];
|
||||||
|
|
||||||
|
console.log(`[Worker ${workerData.workerNumber}] Worker started`);
|
||||||
|
|
||||||
parentPort.on("message", async (message) => {
|
parentPort.on("message", async (message) => {
|
||||||
|
console.log(`[Worker ${workerData.workerNumber}] Received message: ${message.type}`);
|
||||||
if (message.type === "pageCount") {
|
if (message.type === "pageCount") {
|
||||||
await doTask(message.data)
|
await doTask(message.data);
|
||||||
} else if (message.type === "moulberry") {
|
} else if (message.type === "moulberry") {
|
||||||
workerData.itemDatas = message.data
|
workerData.itemDatas = message.data;
|
||||||
|
console.log(`[Worker ${workerData.workerNumber}] Updated item data`);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
async function parsePage(i) {
|
async function parsePage(i) {
|
||||||
const auctionPage = await axios.get(`https://api.hypixel.net/skyblock/auctions?page=${i}`)
|
console.log(`[Worker ${workerData.workerNumber}] Parsing page ${i}`);
|
||||||
for (const auction of auctionPage.data.auctions) {
|
try {
|
||||||
if (!auction.bin) continue
|
const auctionPage = await axios.get(`https://api.hypixel.net/skyblock/auctions?page=${i}`);
|
||||||
const uuid = auction.uuid
|
for (const auction of auctionPage.data.auctions) {
|
||||||
if (ignoredAuctions.includes(uuid) || config.data.ignoreCategories[auction.category]) continue
|
if (!auction.bin) continue;
|
||||||
const item = await getParsed(auction.item_bytes)
|
const uuid = auction.uuid;
|
||||||
const extraAtt = item["i"][0].tag.ExtraAttributes
|
if (ignoredAuctions.includes(uuid) || config.data.ignoreCategories[auction.category]) continue;
|
||||||
const itemID = extraAtt.id
|
const item = await getParsed(auction.item_bytes);
|
||||||
let startingBid = auction.starting_bid
|
const extraAtt = item["i"][0].tag.ExtraAttributes;
|
||||||
const itemData = workerData.itemDatas[itemID]
|
const itemID = extraAtt.id;
|
||||||
if (!itemData) continue
|
let startingBid = auction.starting_bid;
|
||||||
const lbin = itemData.lbin
|
const itemData = workerData.itemDatas[itemID];
|
||||||
const sales = itemData.sales
|
if (!itemData) continue;
|
||||||
const prettyItem = new Item(item.i[0].tag.display.Name, uuid, startingBid, auction.tier, extraAtt.enchantments,
|
const lbin = itemData.lbin;
|
||||||
extraAtt.hot_potato_count > 10 ? 10 : extraAtt.hot_potato_count, extraAtt.hot_potato_count > 10 ?
|
const sales = itemData.sales;
|
||||||
extraAtt.hot_potato_count - 10 : 0, extraAtt.rarity_upgrades === 1,
|
const prettyItem = new Item(item.i[0].tag.display.Name, uuid, startingBid, auction.tier, extraAtt.enchantments,
|
||||||
extraAtt.art_of_war_count === 1, extraAtt.dungeon_item_level,
|
extraAtt.hot_potato_count > 10 ? 10 : extraAtt.hot_potato_count, extraAtt.hot_potato_count > 10 ?
|
||||||
extraAtt.gems, itemID, auction.category, 0, 0, lbin, sales, auction.item_lore)
|
extraAtt.hot_potato_count - 10 : 0, extraAtt.rarity_upgrades === 1,
|
||||||
const unstableOrMarketManipulated = Math.abs((lbin - itemData.cleanPrice) / lbin) > config.data.maxAvgLbinDiff
|
extraAtt.art_of_war_count === 1, extraAtt.dungeon_item_level,
|
||||||
ignoredAuctions.push(uuid)
|
extraAtt.gems, itemID, auction.category, 0, 0, lbin, sales, auction.item_lore);
|
||||||
const rcCost = config.data.includeCraftCost ? getRawCraft(prettyItem, workerData.bazaarData, workerData.itemDatas) : 0
|
const unstableOrMarketManipulated = Math.abs((lbin - itemData.cleanPrice) / lbin) > config.data.maxAvgLbinDiff;
|
||||||
const carriedByRC = rcCost >= config.data.rawCraftMaxWeightPP * lbin
|
ignoredAuctions.push(uuid);
|
||||||
|
const rcCost = config.data.includeCraftCost ? getRawCraft(prettyItem, workerData.bazaarData, workerData.itemDatas) : 0;
|
||||||
|
const carriedByRC = rcCost >= config.data.rawCraftMaxWeightPP * lbin;
|
||||||
|
|
||||||
if (carriedByRC || unstableOrMarketManipulated || sales <= config.data.minSales || !sales) continue
|
if (carriedByRC || unstableOrMarketManipulated || sales <= config.data.minSales || !sales) continue;
|
||||||
|
|
||||||
if (config.filters.nameFilter.find((name) => itemID.includes(name)) === undefined) {
|
if (config.filters.nameFilter.find((name) => itemID.includes(name)) === undefined) {
|
||||||
if ((lbin + rcCost) - startingBid > minProfit) {
|
if ((lbin + rcCost) - startingBid > minProfit) {
|
||||||
const profitData = getProfit(startingBid, rcCost, lbin)
|
const profitData = getProfit(startingBid, rcCost, lbin);
|
||||||
let auctionType = null
|
let auctionType = null;
|
||||||
if (rcCost > (lbin - startingBid) && profitData.snipeProfit < minProfit) {
|
if (rcCost > (lbin - startingBid) && profitData.snipeProfit < minProfit) {
|
||||||
auctionType = "VALUE"
|
auctionType = "VALUE";
|
||||||
} else if (profitData.snipeProfit >= minProfit && rcCost < (lbin - startingBid)) {
|
} else if (profitData.snipeProfit >= minProfit && rcCost < (lbin - startingBid)) {
|
||||||
auctionType = "SNIPE"
|
auctionType = "SNIPE";
|
||||||
} else if (profitData.snipeProfit >= minProfit && rcCost > 0) {
|
} else if (profitData.snipeProfit >= minProfit && rcCost > 0) {
|
||||||
auctionType = "BOTH"
|
auctionType = "BOTH";
|
||||||
}
|
|
||||||
|
|
||||||
prettyItem.auctionData.ahType = auctionType
|
|
||||||
|
|
||||||
if (auctionType === "VALUE" || auctionType === "BOTH") {
|
|
||||||
if (profitData.RCProfit > config.data.minCraftProfit && profitData.RCPP > config.data.minCraftPP) {
|
|
||||||
prettyItem.auctionData.profit = profitData.RCProfit
|
|
||||||
prettyItem.auctionData.percentProfit = profitData.RCPP
|
|
||||||
parentPort.postMessage(prettyItem)
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (profitData.snipeProfit > minProfit && profitData.snipePP > minPercentProfit) {
|
prettyItem.auctionData.ahType = auctionType;
|
||||||
prettyItem.auctionData.profit = profitData.snipeProfit
|
|
||||||
prettyItem.auctionData.percentProfit = profitData.snipePP
|
if (auctionType === "VALUE" || auctionType === "BOTH") {
|
||||||
parentPort.postMessage(prettyItem)
|
if (profitData.RCProfit > config.data.minCraftProfit && profitData.RCPP > config.data.minCraftPP) {
|
||||||
|
prettyItem.auctionData.profit = profitData.RCProfit;
|
||||||
|
prettyItem.auctionData.percentProfit = profitData.RCPP;
|
||||||
|
parentPort.postMessage(prettyItem);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (profitData.snipeProfit > minProfit && profitData.snipePP > minPercentProfit) {
|
||||||
|
prettyItem.auctionData.profit = profitData.snipeProfit;
|
||||||
|
prettyItem.auctionData.percentProfit = profitData.snipePP;
|
||||||
|
parentPort.postMessage(prettyItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[Worker ${workerData.workerNumber}] Error parsing page ${i}:`, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function doTask(totalPages) {
|
async function doTask(totalPages) {
|
||||||
let startingPage = 0
|
console.log(`[Worker ${workerData.workerNumber}] Starting task for ${totalPages} pages`);
|
||||||
const pagePerThread = splitNumber(totalPages, threadsToUse)
|
let startingPage = 0;
|
||||||
|
const pagePerThread = splitNumber(totalPages, threadsToUse);
|
||||||
|
|
||||||
if (workerData.workerNumber !== 0 && startingPage === 0) {
|
if (workerData.workerNumber !== 0 && startingPage === 0) {
|
||||||
const clonedStarting = pagePerThread.slice()
|
const clonedStarting = pagePerThread.slice();
|
||||||
clonedStarting.splice(workerData.workerNumber, 9999);
|
clonedStarting.splice(workerData.workerNumber, 9999);
|
||||||
clonedStarting.forEach((pagePer) => {
|
clonedStarting.forEach((pagePer) => {
|
||||||
startingPage += pagePer
|
startingPage += pagePer;
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let pageToStop = parseInt(startingPage) + parseInt(pagePerThread[workerData.workerNumber])
|
let pageToStop = parseInt(startingPage) + parseInt(pagePerThread[workerData.workerNumber]);
|
||||||
|
|
||||||
if (pageToStop !== totalPages) {
|
if (pageToStop !== totalPages) {
|
||||||
pageToStop -= 1
|
pageToStop -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`[Worker ${workerData.workerNumber}] Processing pages from ${startingPage} to ${pageToStop}`);
|
||||||
|
|
||||||
for (let i = startingPage; i < pageToStop; i++) {
|
for (let i = startingPage; i < pageToStop; i++) {
|
||||||
promises.push(parsePage(i))
|
promises.push(parsePage(i));
|
||||||
}
|
}
|
||||||
await Promise.all(promises)
|
await Promise.all(promises);
|
||||||
//parentPort.postMessage("finished")
|
console.log(`[Worker ${workerData.workerNumber}] Finished task`);
|
||||||
|
parentPort.postMessage("finished");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue