Skip to content

Add statistical mode to auctions #302

@builder-247

Description

@builder-247
  • Add mode to /skyblock/items/:id endpoint.

Since auctions prices can be thought of as continuous distribution, the prices have to first be split to intervals of equal distance e.g. 5000, 10 000, etc. before calculating mode from these intervals.

core/routes/spec.js

Lines 817 to 851 in 853755b

route: () => '/skyblock/auctions/:id',
func: (req, res, cb) => {
const now = Date.now();
const from = req.query.from || (now - 24 * 60 * 60 * 1000);
const until = req.query.until || now;
if (Number.isNaN(Number(from))) {
return cb(res.status(400).json({ error: "parameter 'from' must be an integer" }));
}
redis.zrangebyscore(req.params.id, from, until, (err, auctions) => {
if (err) {
logger.error(err);
}
const obj = {
average_price: 0,
median_price: 0,
standard_deviation: 0,
min_price: 0,
max_price: 0,
sold: 0,
auctions: {},
};
const priceArray = [];
auctions.forEach((auction) => {
auction = JSON.parse(auction);
if (auction.bids.length > 0) priceArray.push(auction.highest_bid_amount / auction.item.count);
obj.auctions[auction.end] = auction;
});
obj.average_price = average(priceArray);
obj.median_price = median(priceArray);
obj.standard_deviation = stdDev(priceArray);
obj.min_price = min(priceArray);
obj.max_price = max(priceArray);
obj.sold = priceArray.length;
return res.json(obj);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions