-
-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Description
- Add mode to
/skyblock/items/:idendpoint.
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.
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
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed