Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add statistical mode to auctions #302

Open
builder-247 opened this issue Jan 24, 2020 · 0 comments
Open

Add statistical mode to auctions #302

builder-247 opened this issue Jan 24, 2020 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@builder-247
Copy link
Member

  • 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);
});

@builder-247 builder-247 added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant